Package com.axelor.mail
Class MailParser
- java.lang.Object
-
- com.axelor.mail.MailParser
-
public final class MailParser extends Object
Parses aMimeMessage
and stores the individual parts such as context text, attachments etc.
-
-
Constructor Summary
Constructors Constructor Description MailParser(javax.mail.internet.MimeMessage message)
Create a newMailParser
for 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.InternetAddress
getFrom()
Get "from" address of the message.String
getHeader(String name)
Get the first header value for the the header name.String
getHtml()
Get the html content if available.javax.mail.internet.InternetAddress
getReplyTo()
Get "replyTo" address of the message.String
getSafeHtml()
Get sanitized safe html.String
getSubject()
Get the message subject line.String
getSummary()
Get the first line of the email as summary.String
getText()
Get plain text content if available.List<javax.mail.internet.InternetAddress>
getTo()
Get list of "to" recipients of the message.boolean
hasAttachments()
Whether the message has attachments.boolean
isMultiPart()
Whether the message is multipart message.MailParser
parse()
Parse the message.
-
-
-
Constructor Detail
-
MailParser
public MailParser(javax.mail.internet.MimeMessage message)
Create a newMailParser
for the givenMimeMessage
.- Parameters:
message
- theMimeMessage
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 byDataHandler
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
-
-