类 MimeMessageParser


  • public class MimeMessageParser
    extends Object
    Parses a MimeMessage and stores the individual parts such a plain text, HTML text and attachments.
    从以下版本开始:
    1.3
    • 构造器详细资料

      • MimeMessageParser

        public MimeMessageParser​(javax.mail.internet.MimeMessage message)
        Constructs an instance with the MimeMessage to be extracted.
        参数:
        message - the message to parse
    • 方法详细资料

      • findInlineByCid

        public javax.activation.DataSource findInlineByCid​(String cid)
      • getTo

        public List<javax.mail.Address> getTo()
                                       throws Exception
        返回:
        the 'to' recipients of the message
        抛出:
        Exception - determining the recipients failed
      • getCc

        public List<javax.mail.Address> getCc()
                                       throws Exception
        返回:
        the 'cc' recipients of the message
        抛出:
        Exception - determining the recipients failed
      • getBcc

        public List<javax.mail.Address> getBcc()
                                        throws Exception
        返回:
        the 'bcc' recipients of the message
        抛出:
        Exception - determining the recipients failed
      • getFrom

        public String getFrom()
                       throws Exception
        返回:
        the 'from' field of the message
        抛出:
        Exception - parsing the mime message failed
      • getReplyTo

        public String getReplyTo()
                          throws Exception
        返回:
        the 'replyTo' address of the email
        抛出:
        Exception - parsing the mime message failed
      • getSubject

        public String getSubject()
                          throws Exception
        返回:
        the mail subject
        抛出:
        Exception - parsing the mime message failed
      • parse

        protected void parse​(javax.mail.Multipart parent,
                             javax.mail.internet.MimePart part)
                      throws javax.mail.MessagingException,
                             IOException
        Extracts the content of a MimeMessage recursively.
        参数:
        parent - the parent multi-part
        part - the current MimePart
        抛出:
        javax.mail.MessagingException - parsing the MimeMessage failed
        IOException - parsing the MimeMessage failed
      • createDataSource

        protected javax.activation.DataSource createDataSource​(javax.mail.Multipart parent,
                                                               javax.mail.internet.MimePart part)
                                                        throws javax.mail.MessagingException,
                                                               IOException
        Parses the MimePart to create a DataSource.
        参数:
        parent - the parent multi-part
        part - the current part to be processed
        返回:
        the DataSource
        抛出:
        javax.mail.MessagingException - creating the DataSource failed
        IOException - creating the DataSource failed
      • getMimeMessage

        public javax.mail.internet.MimeMessage getMimeMessage()
        返回:
        Returns the mimeMessage.
      • isMultipart

        public boolean isMultipart()
        返回:
        Returns the isMultiPart.
      • getPlainContent

        public String getPlainContent()
        返回:
        Returns the plainContent if any
      • getAttachmentList

        public List<javax.activation.DataSource> getAttachmentList()
        返回:
        Returns the attachmentList.
      • getInlineList

        public List<javax.activation.DataSource> getInlineList()
        返回:
        Returns the inlineList.
      • getAttachmentContentIds

        public Collection<String> getAttachmentContentIds()
        Returns a collection of all attachment content-ids in the parsed message.

        The content-ids are stripped of any angle brackets, i.e. "part1" instead of "<part1>".

        返回:
        the collection of content ids.
        从以下版本开始:
        1.3.4
      • getInlineContentIds

        public Collection<String> getInlineContentIds()
        Returns a collection of all inline content-ids in the parsed message.

        The content-ids are stripped of any angle brackets, i.e. "part1" instead of "<part1>".

        返回:
        the collection of content ids.
        从以下版本开始:
        1.3.4
      • getInlineImageContentIds

        public Collection<String> getInlineImageContentIds()
        Returns a collection of all inline image content-ids in the parsed message.

        The content-ids are stripped of any angle brackets, i.e. "part1" instead of "<part1>".

        返回:
        the collection of content ids.
        从以下版本开始:
        1.3.4
      • getHtmlContent

        public String getHtmlContent()
        返回:
        Returns the htmlContent if any
      • hasPlainContent

        public boolean hasPlainContent()
        返回:
        true if a plain content is available
      • hasHtmlContent

        public boolean hasHtmlContent()
        返回:
        true if HTML content is available
      • hasAttachments

        public boolean hasAttachments()
        返回:
        true if attachments are available
      • findAttachmentByName

        public javax.activation.DataSource findAttachmentByName​(String name)
        Find an attachment using its name.
        参数:
        name - the name of the attachment
        返回:
        the corresponding datasource or null if nothing was found
      • findAttachmentByCid

        public javax.activation.DataSource findAttachmentByCid​(String cid)
        Find an attachment using its content-id.

        The content-id must be stripped of any angle brackets, i.e. "part1" instead of "<part1>".

        参数:
        cid - the content-id of the attachment
        返回:
        the corresponding datasource or null if nothing was found
        从以下版本开始:
        1.3.4
      • findInlineImageByCid

        public javax.activation.DataSource findInlineImageByCid​(String cid)
        Find an inline image using its content-id.

        The content-id must be stripped of any angle brackets, i.e. "part1" instead of "<part1>".

        参数:
        cid - the content-id of the inline image
        返回:
        the corresponding datasource or null if nothing was found
        从以下版本开始:
        1.3.4
      • getDataSourceName

        protected String getDataSourceName​(javax.mail.Part part,
                                           javax.activation.DataSource dataSource)
                                    throws javax.mail.MessagingException,
                                           UnsupportedEncodingException
        Determines the name of the data source if it is not already set.
        参数:
        part - the mail part
        dataSource - the data source
        返回:
        the name of the data source or null if no name can be determined
        抛出:
        javax.mail.MessagingException - accessing the part failed
        UnsupportedEncodingException - decoding the text failed