Package com.axelor.mail
Class MailParser
- java.lang.Object
-
- com.axelor.mail.MailParser
-
public final class MailParser extends Object
Parses aMimeMessageand stores the individual parts such as context text, attachments etc.
-
-
Constructor Summary
Constructors Constructor Description MailParser(javax.mail.internet.MimeMessage message)Create a newMailParserfor the givenMimeMessage.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<javax.activation.DataSource>getAttachments()Get attachments.List<javax.mail.internet.InternetAddress>getBcc()Get list of "bcc" recipients of the message.List<javax.mail.internet.InternetAddress>getCc()Get list of "cc" recipients of the message.javax.mail.internet.InternetAddressgetFrom()Get "from" address of the message.StringgetHeader(String name)Get the first header value for the the header name.StringgetHtml()Get the html content if available.javax.mail.internet.InternetAddressgetReplyTo()Get "replyTo" address of the message.StringgetSafeHtml()Get sanitized safe html.StringgetSubject()Get the message subject line.StringgetSummary()Get the first line of the email as summary.StringgetText()Get plain text content if available.List<javax.mail.internet.InternetAddress>getTo()Get list of "to" recipients of the message.booleanhasAttachments()Whether the message has attachments.booleanisMultiPart()Whether the message is multipart message.MailParserparse()Parse the message.
-
-
-
Constructor Detail
-
MailParser
public MailParser(javax.mail.internet.MimeMessage message)
Create a newMailParserfor the givenMimeMessage.- Parameters:
message- theMimeMessageto parse
-
-
Method Detail
-
parse
public MailParser parse() throws javax.mail.MessagingException, IOException
Parse the message.- Returns:
- the
MailParserinstance itself - Throws:
IOException- generally thrown byDataHandlerjavax.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.MessagingExceptionGet "from" address of the message.- Returns:
InternetAddressor 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.MessagingExceptionGet "replyTo" address of the message.- Returns:
InternetAddressor 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
-
-