Class MailParser


  • public final class MailParser
    extends Object
    Parses a MimeMessage and stores the individual parts such as context text, attachments etc.
    • Constructor Detail

      • MailParser

        public MailParser​(javax.mail.internet.MimeMessage message)
        Create a new MailParser for the given MimeMessage.
        Parameters:
        message - the MimeMessage to parse
    • Method Detail

      • parse

        public MailParser parse()
                         throws javax.mail.MessagingException,
                                IOException
        Parse the message.
        Returns:
        the MailParser instance itself
        Throws:
        IOException - generally thrown by DataHandler
        javax.mail.MessagingException - for failures
      • getTo

        public List<javax.mail.internet.InternetAddress> getTo()
                                                        throws javax.mail.MessagingException
        Get list of "to" recipients of the message.
        Returns:
        list of InternetAddress
        Throws:
        javax.mail.MessagingException - if unable to get addresses
      • getCc

        public List<javax.mail.internet.InternetAddress> getCc()
                                                        throws javax.mail.MessagingException
        Get list of "cc" recipients of the message.
        Returns:
        list of InternetAddress
        Throws:
        javax.mail.MessagingException - if unable to get addresses
      • getBcc

        public List<javax.mail.internet.InternetAddress> getBcc()
                                                         throws javax.mail.MessagingException
        Get list of "bcc" recipients of the message.
        Returns:
        list of InternetAddress
        Throws:
        javax.mail.MessagingException - if unable to get addresses
      • getFrom

        public javax.mail.internet.InternetAddress getFrom()
                                                    throws javax.mail.MessagingException
        Get "from" address of the message.
        Returns:
        InternetAddress or null if unable to read "from" field
        Throws:
        javax.mail.MessagingException - if unable to get address
      • getReplyTo

        public javax.mail.internet.InternetAddress getReplyTo()
                                                       throws javax.mail.MessagingException
        Get "replyTo" address of the message.
        Returns:
        InternetAddress or null unable to read "replyTo" field.
        Throws:
        javax.mail.MessagingException - if unable to get address
      • getSubject

        public String getSubject()
                          throws javax.mail.MessagingException
        Get the message subject line.
        Returns:
        message subject line
        Throws:
        javax.mail.MessagingException - for failure
      • getText

        public String getText()
        Get plain text content if available.
        Returns:
        the content as plain text
      • getHtml

        public String getHtml()
        Get the html content if available.
        Returns:
        the html content
      • getSummary

        public String getSummary()
        Get the first line of the email as summary.
        Returns:
        return short text as summary
      • getSafeHtml

        public String getSafeHtml()
        Get sanitized safe html.
        Returns:
        sanitized html
      • isMultiPart

        public boolean isMultiPart()
        Whether the message is multipart message.
        Returns:
        true if multipart false otherwise
      • hasAttachments

        public boolean hasAttachments()
        Whether the message has attachments.
        Returns:
        true if has attachments false otherwise
      • getAttachments

        public List<javax.activation.DataSource> getAttachments()
        Get attachments.
        Returns:
        list of DataSource
      • getHeader

        public String getHeader​(String name)
                         throws javax.mail.MessagingException
        Get the first header value for the the header name.
        Parameters:
        name - header name
        Returns:
        first header value if found else null
        Throws:
        javax.mail.MessagingException - for failures