Java Code Examples for javax.mail.Part#getSize()

The following examples show how to use javax.mail.Part#getSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageHelper.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
boolean hasBody() throws MessagingException {
    List<Part> all = new ArrayList<>();
    all.addAll(plain);
    all.addAll(html);

    for (Part p : all)
        if (p.getSize() > 0)
            return true;

    return false;
}
 
Example 2
Source File: MessageHelper.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
Long getBodySize() throws MessagingException {
    Long size = null;

    List<Part> all = new ArrayList<>();
    all.addAll(plain);
    all.addAll(html);
    for (Part p : all) {
        int s = p.getSize();
        if (s >= 0)
            if (size == null)
                size = (long) s;
            else
                size += (long) s;
    }

    for (EntityAttachment attachment : getAttachments())
        if (attachment.size != null &&
                (EntityAttachment.PGP_MESSAGE.equals(attachment.encryption) ||
                        EntityAttachment.SMIME_MESSAGE.equals(attachment.encryption) ||
                        EntityAttachment.SMIME_SIGNED_DATA.equals(attachment.encryption)))
            if (size == null)
                size = attachment.size;
            else
                size += attachment.size;

    return size;
}
 
Example 3
Source File: SubethaEmailMessagePart.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Object can be built on existing message part only.
 * 
 * @param messagePart Message part.
 */
public SubethaEmailMessagePart(Part messagePart)
{
    ParameterCheck.mandatory("messagePart", messagePart);

    try
    {
        fileSize = messagePart.getSize();
        fileName = messagePart.getFileName();
        contentType = messagePart.getContentType();

        Matcher matcher = encodingExtractor.matcher(contentType);
        if (matcher.find())
        {
            encoding = matcher.group(1);
            if (!Charset.isSupported(encoding))
            {
                throw new EmailMessageException(ERR_UNSUPPORTED_ENCODING, encoding);
            }
        }

        try
        {
            contentInputStream = messagePart.getInputStream(); 
        }
        catch (Exception ex)
        {
            throw new EmailMessageException(ERR_FAILED_TO_READ_CONTENT_STREAM, ex.getMessage());
        }
    }
    catch (MessagingException e)
    {
        throw new EmailMessageException(ERR_INCORRECT_MESSAGE_PART, e.getMessage());
    }
}