List of usage examples for org.apache.commons.codec.net QCodec encode
public String encode(final String pString, final String charset) throws EncoderException
From source file:com.zimbra.cs.imap.ImapMessage.java
static Pair<Long, InputStream> getContent(MailItem item) throws ServiceException { if (item instanceof Message) { return new Pair<Long, InputStream>(item.getSize(), item.getContentStream()); } else if (item instanceof Contact) { try {// w w w. j a v a 2 s. c o m VCard vcard = VCard.formatContact((Contact) item); QCodec qcodec = new QCodec(); qcodec.setEncodeBlanks(true); StringBuilder header = new StringBuilder(); header.append("Subject: ").append(qcodec.encode(vcard.fn, MimeConstants.P_CHARSET_UTF8)) .append(ImapHandler.LINE_SEPARATOR); synchronized (GMT_DATE_FORMAT) { header.append("Date: ").append(GMT_DATE_FORMAT.format(new Date(item.getDate()))) .append(ImapHandler.LINE_SEPARATOR); } header.append("Content-Type: text/x-vcard; charset=\"utf-8\"").append(ImapHandler.LINE_SEPARATOR); header.append("Content-Transfer-Encoding: 8bit").append(ImapHandler.LINE_SEPARATOR); ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(header.toString().getBytes(MimeConstants.P_CHARSET_ASCII)); baos.write(ImapHandler.LINE_SEPARATOR_BYTES); baos.write(vcard.getFormatted().getBytes(MimeConstants.P_CHARSET_UTF8)); return new Pair<Long, InputStream>((long) baos.size(), new SharedByteArrayInputStream(baos.toByteArray())); } catch (Exception e) { throw ServiceException.FAILURE("problems serializing contact " + item.getId(), e); } } else { return EMPTY_CONTENT; } }