Example usage for javax.mail.internet MimeUtility quote

List of usage examples for javax.mail.internet MimeUtility quote

Introduction

In this page you can find the example usage for javax.mail.internet MimeUtility quote.

Prototype

public static String quote(String word, String specials) 

Source Link

Document

A utility method to quote a word, if the word contains any characters from the specified 'specials' list.

The HeaderTokenizer class defines two special sets of delimiters - MIME and RFC 822.

Usage

From source file:mitm.common.mail.MimeUtils.java

/**
 * Returns the content type text/subtype for the text. The charset is ascii if text only contains ascii characters. 
 * If text contains non-ascii characters the encoding will be charsetIfNotAscii.
 *///  w w  w.j a  v a2  s  . c o m
public static String getContentTypeForText(String text, String charsetIfNotAscii, String subtype) {
    String charset = CharacterEncoding.US_ASCII;

    if (!MiscStringUtils.isPrintableAscii(text)) {
        charset = charsetIfNotAscii;
    }

    return "text/" + subtype + "; charset=" + MimeUtility.quote(charset, "()<>@,;:\\\"\t []/?=");
}

From source file:com.linuxbox.enkive.web.AttachmentRetrieveServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    final MessageRetrieverService retriever = getMessageRetrieverService();
    final String attachmentUUID = req.getParameter(PARAM_ATTACHMENT_ID);

    try {/*from   ww  w.jav a2 s .  c  o  m*/
        EncodedContentReadData attachment = retriever.retrieveAttachment(attachmentUUID);

        String filename = req.getParameter(PARAM_FILE_NAME);
        if (filename == null || filename.isEmpty()) {
            filename = attachment.getFilename();
        }
        if (filename == null || filename.isEmpty()) {
            filename = DEFAULT_FILE_NAME;
        }

        String mimeType = req.getParameter(PARAM_MIME_TYPE);
        if (mimeType == null || mimeType.isEmpty()) {
            mimeType = attachment.getMimeType();
        }

        // is there a purpose to the nested trys?
        try {
            if (mimeType != null) {
                resp.setContentType(mimeType);
            }
            resp.setCharacterEncoding("utf-8");
            resp.setHeader("Content-disposition",
                    "attachment;  filename=" + MimeUtility.quote(filename, HeaderTokenizer.MIME));

            final InputStream in = attachment.getBinaryContent();
            final OutputStream out = resp.getOutputStream();

            IOUtils.copy(in, out);
            IOUtils.closeQuietly(in);
            IOUtils.closeQuietly(out);
        } catch (ContentException e) {
            LOGGER.error("error transferring attachment  " + attachmentUUID, e);
            resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                    "error transferring attachment " + attachmentUUID + "; see server logs");
        }
    } catch (CannotRetrieveException e) {
        LOGGER.error("error retrieving attachment " + attachmentUUID, e);
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                "error retrieving attachment " + attachmentUUID + "; see server logs");
    }
}

From source file:jenkins.plugins.mailer.tasks.MimeMessageBuilder.java

private String contentType() {
    return String.format("%s; charset=%s", mimeType, MimeUtility.quote(charset, HeaderTokenizer.MIME));
}

From source file:org.kuali.coeus.sys.framework.controller.KcTransactionalDocumentActionBase.java

/**
 * Quotes a string that follows RFC 822 and is valid to include in an http header.
 * // w  ww .  ja v a2  s .c o  m
 * <p>
 * This really should be a part of {@link org.kuali.rice.kns.util.WebUtils WebUtils}.
 * <p>
 * 
 * For example: without this method, file names with spaces will not show up to the client correctly.
 * 
 * <p>
 * This method is not doing a Base64 encode just a quoted printable character otherwise we would have
 * to set the encoding type on the header.
 * <p>
 * 
 * @param s the original string
 * @return the modified header string
 */
protected static String getValidHeaderString(String s) {
    return MimeUtility.quote(s, HeaderTokenizer.MIME);
}

From source file:org.kuali.kra.coi.personfinancialentity.FinancialEntityAction.java

protected static String getValidHeaderString(String s) {
    return MimeUtility.quote(s, HeaderTokenizer.MIME);
}