Class MailParser

java.lang.Object
com.axelor.mail.MailParser

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

    • MailParser

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

    • parse

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

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

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

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

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

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

      public String getSubject() throws jakarta.mail.MessagingException
      Get the message subject line.
      Returns:
      message subject line
      Throws:
      jakarta.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<jakarta.activation.DataSource> getAttachments()
      Get attachments.
      Returns:
      list of DataSource
    • getHeader

      public String getHeader(String name) throws jakarta.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:
      jakarta.mail.MessagingException - for failures