Package org.apache.commons.mail.util
Class MimeMessageParser
java.lang.Object
org.apache.commons.mail.util.MimeMessageParser
Parses a MimeMessage and stores the individual parts such a plain text,
HTML text and attachments.
- Since:
- 1.3
-
Constructor Summary
ConstructorsConstructorDescriptionMimeMessageParser(javax.mail.internet.MimeMessage message) Constructs an instance with the MimeMessage to be extracted. -
Method Summary
Modifier and TypeMethodDescriptionprotected DataSourcecreateDataSource(javax.mail.Multipart parent, javax.mail.internet.MimePart part) Parses the MimePart to create a DataSource.Find an attachment using its content-id.findAttachmentByName(String name) Find an attachment using its name.List<javax.mail.Address> getBcc()List<javax.mail.Address> getCc()Returns a collection of all content-ids in the parsed message.protected StringgetDataSourceName(javax.mail.Part part, DataSource dataSource) Determines the name of the data source if it is not already set.getFrom()javax.mail.internet.MimeMessageList<javax.mail.Address> getTo()booleanbooleanbooleanbooleanparse()Does the actual extraction.protected voidparse(javax.mail.Multipart parent, javax.mail.internet.MimePart part) Extracts the content of a MimeMessage recursively.
-
Constructor Details
-
MimeMessageParser
Constructs an instance with the MimeMessage to be extracted.- Parameters:
message- the message to parse
-
-
Method Details
-
parse
Does the actual extraction.- Returns:
- this instance
- Throws:
Exception- parsing the mime message failed
-
getTo
- Returns:
- the 'to' recipients of the message
- Throws:
Exception- determining the recipients failed
-
getCc
- Returns:
- the 'cc' recipients of the message
- Throws:
Exception- determining the recipients failed
-
getBcc
- Returns:
- the 'bcc' recipients of the message
- Throws:
Exception- determining the recipients failed
-
getFrom
- Returns:
- the 'from' field of the message
- Throws:
Exception- parsing the mime message failed
-
getReplyTo
- Returns:
- the 'replyTo' address of the email
- Throws:
Exception- parsing the mime message failed
-
getSubject
- Returns:
- the mail subject
- Throws:
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.- Parameters:
parent- the parent multi-partpart- the current MimePart- Throws:
javax.mail.MessagingException- parsing the MimeMessage failedIOException- parsing the MimeMessage failed
-
createDataSource
protected DataSource createDataSource(javax.mail.Multipart parent, javax.mail.internet.MimePart part) throws javax.mail.MessagingException, IOException Parses the MimePart to create a DataSource.- Parameters:
parent- the parent multi-partpart- the current part to be processed- Returns:
- the DataSource
- Throws:
javax.mail.MessagingException- creating the DataSource failedIOException- creating the DataSource failed
-
getMimeMessage
- Returns:
- Returns the mimeMessage.
-
isMultipart
- Returns:
- Returns the isMultiPart.
-
getPlainContent
- Returns:
- Returns the plainContent if any
-
getAttachmentList
- Returns:
- Returns the attachmentList.
-
getContentIds
Returns a collection of all content-ids in the parsed message.The content-ids are stripped of any angle brackets, i.e. "part1" instead of "<part1>".
- Returns:
- the collection of content ids.
- Since:
- 1.3.4
-
getHtmlContent
- Returns:
- Returns the htmlContent if any
-
hasPlainContent
- Returns:
- true if a plain content is available
-
hasHtmlContent
- Returns:
- true if HTML content is available
-
hasAttachments
- Returns:
- true if attachments are available
-
findAttachmentByName
Find an attachment using its name.- Parameters:
name- the name of the attachment- Returns:
- the corresponding datasource or null if nothing was found
-
findAttachmentByCid
Find an attachment using its content-id.The content-id must be stripped of any angle brackets, i.e. "part1" instead of "<part1>".
- Parameters:
cid- the content-id of the attachment- Returns:
- the corresponding datasource or null if nothing was found
- Since:
- 1.3.4
-
getDataSourceName
protected String getDataSourceName(javax.mail.Part part, DataSource dataSource) throws javax.mail.MessagingException, UnsupportedEncodingException Determines the name of the data source if it is not already set.- Parameters:
part- the mail partdataSource- the data source- Returns:
- the name of the data source or
nullif no name can be determined - Throws:
javax.mail.MessagingException- accessing the part failedUnsupportedEncodingException- decoding the text failed
-