com.atlassian.mail
Class MailUtils

java.lang.Object
  extended by com.atlassian.mail.MailUtils

public class MailUtils
extends Object


Nested Class Summary
static class MailUtils.Attachment
          Very simple representation of a mail attachment after it has been extracted from a message.
 
Constructor Summary
MailUtils()
           
 
Method Summary
static MimeBodyPart createAttachmentMimeBodyPart(String path)
          Produces a mimebodypart object from an attachment file path.
static MimeBodyPart createZippedAttachmentMimeBodyPart(String path)
           
static MailUtils.Attachment[] getAttachments(Message message)
          Gets all parts of a message that are attachments rather than alternative inline bits.
static User getAuthorFromSender(Message message)
          Get the user that has the same email address as the author of the message.
static String getBody(Message message)
          Get the body of the message as a String.
static User getFirstValidUser(Address[] addresses)
          Given an array of addresses, this method returns the first valid address.
static boolean hasRecipient(String matchEmail, Message message)
           
static InternetAddress[] parseAddresses(String addresses)
          Parse addresses from a comma (and space) separated string into the proper array
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MailUtils

public MailUtils()
Method Detail

parseAddresses

public static InternetAddress[] parseAddresses(String addresses)
                                        throws AddressException
Parse addresses from a comma (and space) separated string into the proper array

Throws:
AddressException

getBody

public static String getBody(Message message)
                      throws MessagingException
Get the body of the message as a String. The algorithm for finding the body is as follows:
  1. If the message is a single part, and that part is text/plain, return it.
  2. If the message is a single part, and that part is text/html, convert it to text (stripping out the HTML) and return it.
  3. If the message is multi-part, return the first text/plain part that isn't marked explicitly as an attachment.
  4. If the message is multi-part, but does not contain any text/plain parts, return the first text/html part that isn't marked explicitly as an attachment, converting it to text and stripping the HTML.
  5. If nothing is found in any of the steps above, return null.

Note: If the message contains nested multipart parts, an HTML part nested at a higher level will take precedence over a text part nested deeper.

Parameters:
message - The message to retrieve the body from
Returns:
The message body, or null if the message could not be parsed
Throws:
javax.mail.MessagingException - If there was an error getting the content from the message
MessagingException

getAttachments

public static MailUtils.Attachment[] getAttachments(Message message)
                                             throws MessagingException,
                                                    IOException
Gets all parts of a message that are attachments rather than alternative inline bits.

Parameters:
message - the message from which to extract the attachments
Returns:
an array of the extracted attachments
Throws:
MessagingException
IOException

getAuthorFromSender

public static User getAuthorFromSender(Message message)
                                throws MessagingException
Get the user that has the same email address as the author of the message. If multiple authors, take the first one.

Parameters:
message - The message to get the author from.
Returns:
The user who has the same email address as the author of the message
Throws:
javax.mail.MessagingException - If an error occurred getting the message author
MessagingException

getFirstValidUser

public static User getFirstValidUser(Address[] addresses)
Given an array of addresses, this method returns the first valid address.

Parameters:
addresses -
Returns:

hasRecipient

public static boolean hasRecipient(String matchEmail,
                                   Message message)
                            throws MessagingException
Returns:
true if at least one of the recipients matches the email address given.
Throws:
MessagingException

createAttachmentMimeBodyPart

public static MimeBodyPart createAttachmentMimeBodyPart(String path)
                                                 throws MessagingException
Produces a mimebodypart object from an attachment file path. An attachment needs to be in this form to be attached to an email for sending

Parameters:
path -
Returns:
Throws:
MessagingException

createZippedAttachmentMimeBodyPart

public static MimeBodyPart createZippedAttachmentMimeBodyPart(String path)
                                                       throws MessagingException
Throws:
MessagingException


Atlassian Mail is developed by Atlassian Software Systems.