Example usage for javax.mail.internet ContentDisposition toString

List of usage examples for javax.mail.internet ContentDisposition toString

Introduction

In this page you can find the example usage for javax.mail.internet ContentDisposition toString.

Prototype

@Override
public String toString() 

Source Link

Document

Retrieve a RFC2045 style string representation of this ContentDisposition.

Usage

From source file:immf.Util.java

public static void setFileName(Part part, String filename, String charset, String lang)
        throws MessagingException {

    ContentDisposition disposition;
    String[] strings = part.getHeader("Content-Disposition");
    if (strings == null || strings.length < 1) {
        disposition = new ContentDisposition(Part.ATTACHMENT);
    } else {/*from www  . j  ava 2s .  c o  m*/
        disposition = new ContentDisposition(strings[0]);
        disposition.getParameterList().remove("filename");
    }

    part.setHeader("Content-Disposition",
            disposition.toString() + encodeParameter("filename", filename, charset, lang));

    ContentType cType;
    strings = part.getHeader("Content-Type");
    if (strings == null || strings.length < 1) {
        cType = new ContentType(part.getDataHandler().getContentType());
    } else {
        cType = new ContentType(strings[0]);
    }

    try {
        // I want to public the MimeUtility#doEncode()!!!
        String mimeString = MimeUtility.encodeWord(filename, charset, "B");
        // cut <CRLF>...
        StringBuffer sb = new StringBuffer();
        int i;
        while ((i = mimeString.indexOf('\r')) != -1) {
            sb.append(mimeString.substring(0, i));
            mimeString = mimeString.substring(i + 2);
        }
        sb.append(mimeString);

        cType.setParameter("name", new String(sb));
    } catch (UnsupportedEncodingException e) {
        throw new MessagingException("Encoding error", e);
    }
    part.setHeader("Content-Type", cType.toString());
}

From source file:com.adaptris.mail.MailSenderImp.java

private void addAttachmentsToMessage(MimeMultipart multipart) throws MailException {
    try {/*from ww  w.  ja  v  a2s.c  om*/
        for (Attachment a : attachments) {
            MimeBodyPart part = create(a.getBytes(), new InternetHeaders(), a.getEncoding());
            part.setHeader(Mail.CONTENT_TYPE, a.getContentType());
            ContentDisposition cd = new ContentDisposition();
            cd.setDisposition(Mail.DISPOSITION_TYPE_ATTACHMENT);
            if (a.getFilename() != null) {
                cd.setParameter(Mail.DISPOSITION_PARAM_FILENAME, a.getFilename());
            }
            part.setDisposition(cd.toString());
            multipart.addBodyPart(part);
        }
    } catch (Exception e) {
        throw new MailException(e);
    }
}