Example usage for javax.mail.internet MimePart getDisposition

List of usage examples for javax.mail.internet MimePart getDisposition

Introduction

In this page you can find the example usage for javax.mail.internet MimePart getDisposition.

Prototype

public String getDisposition() throws MessagingException;

Source Link

Document

Return the disposition of this part.

Usage

From source file:com.zimbra.cs.mime.Mime.java

private static MPartInfo generateMPartInfo(MimePart mp, MPartInfo parent, String prefix, int partNum) {
    boolean inDigest = parent != null && parent.mContentType.equals(MimeConstants.CT_MULTIPART_DIGEST);
    String ctdefault = inDigest ? MimeConstants.CT_MESSAGE_RFC822 : MimeConstants.CT_DEFAULT;
    String cts = getContentType(mp, ctdefault);

    String disp = null, filename = getFilename(mp);
    int size = 0;
    try {//from   w ww  . java 2 s. com
        disp = mp.getDisposition();
    } catch (Exception e) {
    }
    try {
        size = mp.getSize();
    } catch (MessagingException me) {
    }

    // the top-level part of a non-multipart message is numbered "1"
    boolean isMultipart = cts.startsWith(MimeConstants.CT_MULTIPART_PREFIX);
    if (!isMultipart && mp instanceof MimeMessage)
        prefix = (prefix.length() > 0 ? (prefix + ".") : "") + '1';

    MPartInfo mpart = new MPartInfo();
    mpart.mPart = mp;
    mpart.mParent = parent;
    mpart.mContentType = cts;
    mpart.mPartName = prefix;
    mpart.mPartNum = partNum;
    mpart.mSize = size;
    mpart.mChildren = null;
    mpart.mDisposition = (disp == null
            ? (inDigest && cts.equals(MimeConstants.CT_MESSAGE_RFC822) ? Part.ATTACHMENT : "")
            : disp.toLowerCase());
    mpart.mFilename = (filename == null ? "" : filename);
    return mpart;
}

From source file:org.simplejavamail.internal.util.MimeMessageParser.java

/**
 * Extracts the content of a MimeMessage recursively.
 *
 * @param part   the current MimePart//from w  w w.j  av  a2s  .c  o  m
 * @throws MessagingException parsing the MimeMessage failed
 * @throws IOException        parsing the MimeMessage failed
 */
private void parse(final MimePart part) throws MessagingException, IOException {
    extractCustomUserHeaders(part);

    if (isMimeType(part, "text/plain") && plainContent == null
            && !Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
        plainContent = (String) part.getContent();
    } else {
        if (isMimeType(part, "text/html") && htmlContent == null
                && !Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
            htmlContent = (String) part.getContent();
        } else {
            if (isMimeType(part, "multipart/*")) {
                final Multipart mp = (Multipart) part.getContent();
                final int count = mp.getCount();

                // iterate over all MimeBodyPart
                for (int i = 0; i < count; i++) {
                    parse((MimeBodyPart) mp.getBodyPart(i));
                }
            } else {
                final DataSource ds = createDataSource(part);
                // If the diposition is not provided, the part should be treat as attachment
                if (part.getDisposition() == null || Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
                    this.attachmentList.put(part.getContentID(), ds);
                } else if (Part.INLINE.equalsIgnoreCase(part.getDisposition())) {
                    this.cidMap.put(part.getContentID(), ds);
                } else {
                    throw new IllegalStateException("invalid attachment type");
                }
            }
        }
    }
}