List of usage examples for org.apache.commons.codec.net QCodec QCodec
public QCodec()
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 {/*from w ww. jav a2 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; } }
From source file:com.haulmont.cuba.core.app.EmailSender.java
protected String encodeAttachmentName(SendingAttachment attachment) { String encodedFileName;// w w w . j a v a2s . c o m try { QCodec qCodec = new QCodec(); encodedFileName = qCodec.encode(attachment.getName()); } catch (EncoderException e) { encodedFileName = attachment.getName(); } return encodedFileName; }
From source file:com.zimbra.cs.mime.Mime.java
public static String encodeFilename(String filename) { try {/*from w w w . j a v a 2 s.c o m*/ // JavaMail doesn't use RFC 2231 encoding, and we're not going to, either... if (!StringUtil.isAsciiString(filename)) { return new QCodec().encode(filename, MimeConstants.P_CHARSET_UTF8); } } catch (EncoderException ee) { } return filename; }
From source file:org.apache.abdera.i18n.text.Rfc2047Helper.java
/** * Used to decode a string as specified by RFC 2047 * // w ww.j ava 2 s . co m * @param value The encoded string */ public static String decode(String value) { if (value == null) return null; try { // try BCodec first return (new BCodec()).decode(value); } catch (DecoderException de) { // try QCodec next try { return (new QCodec()).decode(value); } catch (Exception ex) { return value; } } catch (Exception e) { return value; } }
From source file:org.xwiki.velocity.tools.EscapeTool.java
/** * Encode a text using the Q encoding specified in <a href="http://www.ietf.org/rfc/rfc2047.txt">RFC 2047</a>. UTF-8 * is used as the character encoding, and no line breaking is performed. The resulting text is already wrapped with * the encoded word markers, starting with {@code =?UTF-8?Q?} and ending with {@code ?=}. * * @param content the text to encode/*from www . j a va 2 s.com*/ * @return the text converted into an encoded word using the Q encoding */ public String q(Object content) { if (content != null) { try { return new QCodec().encode(String.valueOf(content)).replace(' ', '_'); } catch (EncoderException ex) { // Just return null } } return null; }