org.apache.commons.mail.util
Class MimeMessageParser

java.lang.Object
  extended by org.apache.commons.mail.util.MimeMessageParser

public class MimeMessageParser
extends Object

Parses a MimeMessage and stores the individual parts such a plain text, HTML text and attachments.

Since:
1.3
Version:
$Id: MimeMessageParser.java 1420381 2012-12-11 20:18:05Z tn $

Constructor Summary
MimeMessageParser(MimeMessage message)
          Constructs an instance with the MimeMessage to be extracted.
 
Method Summary
protected  DataSource createDataSource(Multipart parent, MimePart part)
          Parses the MimePart to create a DataSource.
 DataSource findAttachmentByName(String name)
          Find an attachment using its name.
 List<DataSource> getAttachmentList()
           
 List<Address> getBcc()
           
 List<Address> getCc()
           
protected  String getDataSourceName(Part part, DataSource dataSource)
          Determines the name of the data source if it is not already set.
 String getFrom()
           
 String getHtmlContent()
           
 MimeMessage getMimeMessage()
           
 String getPlainContent()
           
 String getReplyTo()
           
 String getSubject()
           
 List<Address> getTo()
           
 boolean hasAttachments()
           
 boolean hasHtmlContent()
           
 boolean hasPlainContent()
           
 boolean isMultipart()
           
 MimeMessageParser parse()
          Does the actual extraction.
protected  void parse(Multipart parent, MimePart part)
          Extracts the content of a MimeMessage recursively.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MimeMessageParser

public MimeMessageParser(MimeMessage message)
Constructs an instance with the MimeMessage to be extracted.

Parameters:
message - the message to parse
Method Detail

parse

public MimeMessageParser parse()
                        throws Exception
Does the actual extraction.

Returns:
this instance
Throws:
Exception - parsing the mime message failed

getTo

public List<Address> getTo()
                    throws Exception
Returns:
the 'to' recipients of the message
Throws:
Exception - determining the recipients failed

getCc

public List<Address> getCc()
                    throws Exception
Returns:
the 'cc' recipients of the message
Throws:
Exception - determining the recipients failed

getBcc

public List<Address> getBcc()
                     throws Exception
Returns:
the 'bcc' recipients of the message
Throws:
Exception - determining the recipients failed

getFrom

public String getFrom()
               throws Exception
Returns:
the 'from' field of the message
Throws:
Exception - parsing the mime message failed

getReplyTo

public String getReplyTo()
                  throws Exception
Returns:
the 'replyTo' address of the email
Throws:
Exception - parsing the mime message failed

getSubject

public String getSubject()
                  throws Exception
Returns:
the mail subject
Throws:
Exception - parsing the mime message failed

parse

protected void parse(Multipart parent,
                     MimePart part)
              throws MessagingException,
                     IOException
Extracts the content of a MimeMessage recursively.

Parameters:
parent - the parent multi-part
part - the current MimePart
Throws:
MessagingException - parsing the MimeMessage failed
IOException - parsing the MimeMessage failed

createDataSource

protected DataSource createDataSource(Multipart parent,
                                      MimePart part)
                               throws MessagingException,
                                      IOException
Parses the MimePart to create a DataSource.

Parameters:
parent - the parent multi-part
part - the current part to be processed
Returns:
the DataSource
Throws:
MessagingException - creating the DataSource failed
IOException - creating the DataSource failed

getMimeMessage

public MimeMessage getMimeMessage()
Returns:
Returns the mimeMessage.

isMultipart

public boolean isMultipart()
Returns:
Returns the isMultiPart.

getPlainContent

public String getPlainContent()
Returns:
Returns the plainContent if any

getAttachmentList

public List<DataSource> getAttachmentList()
Returns:
Returns the attachmentList.

getHtmlContent

public String getHtmlContent()
Returns:
Returns the htmlContent if any

hasPlainContent

public boolean hasPlainContent()
Returns:
true if a plain content is available

hasHtmlContent

public boolean hasHtmlContent()
Returns:
true if HTML content is available

hasAttachments

public boolean hasAttachments()
Returns:
true if attachments are available

findAttachmentByName

public DataSource findAttachmentByName(String name)
Find an attachment using its name.

Parameters:
name - the name of the attachment
Returns:
the corresponding datasource or null if nothing was found

getDataSourceName

protected String getDataSourceName(Part part,
                                   DataSource dataSource)
                            throws MessagingException,
                                   UnsupportedEncodingException
Determines the name of the data source if it is not already set.

Parameters:
part - the mail part
dataSource - the data source
Returns:
the name of the data source or null if no name can be determined
Throws:
MessagingException - accessing the part failed
UnsupportedEncodingException - decoding the text failed


Copyright © 2001-2013 The Apache Software Foundation. All Rights Reserved.