类 MimeMessageParser
- java.lang.Object
-
- net.risesoft.util.MimeMessageParser
-
public class MimeMessageParser extends Object
Parses a MimeMessage and stores the individual parts such a plain text, HTML text and attachments.- 从以下版本开始:
- 1.3
-
-
构造器概要
构造器 构造器 说明 MimeMessageParser(javax.mail.internet.MimeMessage message)Constructs an instance with the MimeMessage to be extracted.
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected javax.activation.DataSourcecreateDataSource(javax.mail.Multipart parent, javax.mail.internet.MimePart part)Parses the MimePart to create a DataSource.javax.activation.DataSourcefindAttachmentByCid(String cid)Find an attachment using its content-id.javax.activation.DataSourcefindAttachmentByName(String name)Find an attachment using its name.javax.activation.DataSourcefindInlineByCid(String cid)javax.activation.DataSourcefindInlineImageByCid(String cid)Find an inline image using its content-id.Collection<String>getAttachmentContentIds()Returns a collection of all attachment content-ids in the parsed message.List<javax.activation.DataSource>getAttachmentList()List<javax.mail.Address>getBcc()List<javax.mail.Address>getCc()protected StringgetDataSourceName(javax.mail.Part part, javax.activation.DataSource dataSource)Determines the name of the data source if it is not already set.StringgetFrom()StringgetHtmlContent()Collection<String>getInlineContentIds()Returns a collection of all inline content-ids in the parsed message.Collection<String>getInlineImageContentIds()Returns a collection of all inline image content-ids in the parsed message.List<javax.activation.DataSource>getInlineList()javax.mail.internet.MimeMessagegetMimeMessage()StringgetPlainContent()StringgetReplyTo()StringgetSubject()List<javax.mail.Address>getTo()booleanhasAttachments()booleanhasHtmlContent()booleanhasPlainContent()booleanisMultipart()MimeMessageParserparse()Does the actual extraction.protected voidparse(javax.mail.Multipart parent, javax.mail.internet.MimePart part)Extracts the content of a MimeMessage recursively.
-
-
-
方法详细资料
-
findInlineByCid
public javax.activation.DataSource findInlineByCid(String cid)
-
parse
public MimeMessageParser parse() throws Exception
Does the actual extraction.- 返回:
- this instance
- 抛出:
Exception- parsing the mime message failed
-
getTo
public List<javax.mail.Address> getTo() throws Exception
- 返回:
- the 'to' recipients of the message
- 抛出:
Exception- determining the recipients failed
-
getCc
public List<javax.mail.Address> getCc() throws Exception
- 返回:
- the 'cc' recipients of the message
- 抛出:
Exception- determining the recipients failed
-
getBcc
public List<javax.mail.Address> getBcc() throws Exception
- 返回:
- the 'bcc' recipients of the message
- 抛出:
Exception- determining the recipients failed
-
getFrom
public String getFrom() throws Exception
- 返回:
- the 'from' field of the message
- 抛出:
Exception- parsing the mime message failed
-
getReplyTo
public String getReplyTo() throws Exception
- 返回:
- the 'replyTo' address of the email
- 抛出:
Exception- parsing the mime message failed
-
getSubject
public String getSubject() throws Exception
- 返回:
- the mail subject
- 抛出:
Exception- parsing the mime message failed
-
parse
protected void parse(javax.mail.Multipart parent, javax.mail.internet.MimePart part) throws javax.mail.MessagingException, IOExceptionExtracts the content of a MimeMessage recursively.- 参数:
parent- the parent multi-partpart- the current MimePart- 抛出:
javax.mail.MessagingException- parsing the MimeMessage failedIOException- parsing the MimeMessage failed
-
createDataSource
protected javax.activation.DataSource createDataSource(javax.mail.Multipart parent, javax.mail.internet.MimePart part) throws javax.mail.MessagingException, IOExceptionParses the MimePart to create a DataSource.- 参数:
parent- the parent multi-partpart- the current part to be processed- 返回:
- the DataSource
- 抛出:
javax.mail.MessagingException- creating the DataSource failedIOException- creating the DataSource failed
-
getMimeMessage
public javax.mail.internet.MimeMessage getMimeMessage()
- 返回:
- Returns the mimeMessage.
-
isMultipart
public boolean isMultipart()
- 返回:
- Returns the isMultiPart.
-
getPlainContent
public String getPlainContent()
- 返回:
- Returns the plainContent if any
-
getAttachmentList
public List<javax.activation.DataSource> getAttachmentList()
- 返回:
- Returns the attachmentList.
-
getInlineList
public List<javax.activation.DataSource> getInlineList()
- 返回:
- Returns the inlineList.
-
getAttachmentContentIds
public Collection<String> getAttachmentContentIds()
Returns a collection of all attachment content-ids in the parsed message.The content-ids are stripped of any angle brackets, i.e. "part1" instead of "<part1>".
- 返回:
- the collection of content ids.
- 从以下版本开始:
- 1.3.4
-
getInlineContentIds
public Collection<String> getInlineContentIds()
Returns a collection of all inline content-ids in the parsed message.The content-ids are stripped of any angle brackets, i.e. "part1" instead of "<part1>".
- 返回:
- the collection of content ids.
- 从以下版本开始:
- 1.3.4
-
getInlineImageContentIds
public Collection<String> getInlineImageContentIds()
Returns a collection of all inline image content-ids in the parsed message.The content-ids are stripped of any angle brackets, i.e. "part1" instead of "<part1>".
- 返回:
- the collection of content ids.
- 从以下版本开始:
- 1.3.4
-
getHtmlContent
public String getHtmlContent()
- 返回:
- Returns the htmlContent if any
-
hasPlainContent
public boolean hasPlainContent()
- 返回:
- true if a plain content is available
-
hasHtmlContent
public boolean hasHtmlContent()
- 返回:
- true if HTML content is available
-
hasAttachments
public boolean hasAttachments()
- 返回:
- true if attachments are available
-
findAttachmentByName
public javax.activation.DataSource findAttachmentByName(String name)
Find an attachment using its name.- 参数:
name- the name of the attachment- 返回:
- the corresponding datasource or null if nothing was found
-
findAttachmentByCid
public javax.activation.DataSource findAttachmentByCid(String cid)
Find an attachment using its content-id.The content-id must be stripped of any angle brackets, i.e. "part1" instead of "<part1>".
- 参数:
cid- the content-id of the attachment- 返回:
- the corresponding datasource or null if nothing was found
- 从以下版本开始:
- 1.3.4
-
findInlineImageByCid
public javax.activation.DataSource findInlineImageByCid(String cid)
Find an inline image using its content-id.The content-id must be stripped of any angle brackets, i.e. "part1" instead of "<part1>".
- 参数:
cid- the content-id of the inline image- 返回:
- the corresponding datasource or null if nothing was found
- 从以下版本开始:
- 1.3.4
-
getDataSourceName
protected String getDataSourceName(javax.mail.Part part, javax.activation.DataSource dataSource) throws javax.mail.MessagingException, UnsupportedEncodingException
Determines the name of the data source if it is not already set.- 参数:
part- the mail partdataSource- the data source- 返回:
- the name of the data source or
nullif no name can be determined - 抛出:
javax.mail.MessagingException- accessing the part failedUnsupportedEncodingException- decoding the text failed
-
-