Example usage for javax.mail Part setFileName

List of usage examples for javax.mail Part setFileName

Introduction

In this page you can find the example usage for javax.mail Part setFileName.

Prototype

public void setFileName(String filename) throws MessagingException;

Source Link

Document

Set the filename associated with this part, if possible.

Usage

From source file:mitm.application.djigzo.james.mailets.BlackberrySMIMEAdapter.java

private void replaceSMIMEAttachment(MimeMessage containerMessage, MimeMessage sourceMessage)
        throws MessagingException, IOException, PartException {
    Part smimePart = findAttachment(containerMessage);

    if (sourceMessage.getSize() > directSizeLimit) {
        /*/*from  w  w w.  j  av  a2  s .c om*/
         * The message is too large to be sent to the BB directly so we should 
         * sent it as an attachment that can be downloaded and handled using
         * a content handler on the BB
         */
        String filename = downloadAttachmentName + DOWNLOAD_ATTACHMENT_EXTENSION;

        smimePart.setFileName(filename);
    }

    smimePart.setDataHandler(new DataHandler(
            new ByteArrayDataSource(sourceMessage.getInputStream(), "application/octet-stream")));
}

From source file:com.duroty.utils.mail.MessageUtilities.java

/**
 * A better version of setFileName() which will encode the name if
 * necessary. Why doesn't JAVA Mail do this?
 *
 * @param part the part to manipulate//from  w  w w .ja va 2 s  . co m
 * @param name the give file name encoded in UTF (JAVA)
 * @param charset the encoding character set
 *
 * @throws MessagingException DOCUMENT ME!
 */
public static void setFileName(Part part, String name, String charset) throws MessagingException {
    try {
        name = MimeUtility.encodeWord(name, charset, null);
    } catch (Exception xex) {
    }

    part.setFileName(name);
}