com.atlassian.mail
Class MailUtils

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

public class MailUtils
extends java.lang.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 javax.mail.internet.MimeBodyPart createAttachmentMimeBodyPart(java.lang.String path)
          Produces a mimebodypart object from an attachment file path.
static javax.mail.internet.MimeBodyPart createZippedAttachmentMimeBodyPart(java.lang.String path)
           
static MailUtils.Attachment[] getAttachments(javax.mail.Message message)
          Gets all parts of a message that are attachments rather than alternative inline bits.
static com.opensymphony.user.User getAuthorFromSender(javax.mail.Message message)
          Deprecated. Now incorporated into JIRA due to app-specific logic, will be removed in a future release. (complain to chris@atlassian.com)
static java.lang.String getBody(javax.mail.Message message)
          Get the body of the message as a String.
static com.opensymphony.user.User getFirstValidUser(javax.mail.Address[] addresses)
          Deprecated. Now incorporated into JIRA due to app-specific logic, will be removed in a future release. (complain to chris@atlassian.com)
static java.util.List getSenders(javax.mail.Message message)
          Returns a List of trimmed non-null email addresses from the given potentially dirty pile of addresses listed as senders on the given message.
static boolean hasRecipient(java.lang.String matchEmail, javax.mail.Message message)
           
static javax.mail.internet.InternetAddress[] parseAddresses(java.lang.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 javax.mail.internet.InternetAddress[] parseAddresses(java.lang.String addresses)
                                                            throws javax.mail.internet.AddressException
Parse addresses from a comma (and space) separated string into the proper array

Throws:
javax.mail.internet.AddressException

getBody

public static java.lang.String getBody(javax.mail.Message message)
                                throws javax.mail.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

getAttachments

public static MailUtils.Attachment[] getAttachments(javax.mail.Message message)
                                             throws javax.mail.MessagingException,
                                                    java.io.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:
javax.mail.MessagingException
java.io.IOException

getAuthorFromSender

public static com.opensymphony.user.User getAuthorFromSender(javax.mail.Message message)
                                                      throws javax.mail.MessagingException
Deprecated. Now incorporated into JIRA due to app-specific logic, will be removed in a future release. (complain to chris@atlassian.com)

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

getFirstValidUser

public static com.opensymphony.user.User getFirstValidUser(javax.mail.Address[] addresses)
Deprecated. Now incorporated into JIRA due to app-specific logic, will be removed in a future release. (complain to chris@atlassian.com)

Given an array of addresses, this method returns the first valid address.

Parameters:
addresses - addresses to be used to search for a User.
Returns:
a User for the email address or null.

hasRecipient

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

getSenders

public static java.util.List getSenders(javax.mail.Message message)
                                 throws javax.mail.MessagingException
Returns a List of trimmed non-null email addresses from the given potentially dirty pile of addresses listed as senders on the given message.

Parameters:
message - the message from which to get senders.
Returns:
a nice List of email addresses.
Throws:
javax.mail.MessagingException - if the senders can't be retrieved from message.

createAttachmentMimeBodyPart

public static javax.mail.internet.MimeBodyPart createAttachmentMimeBodyPart(java.lang.String path)
                                                                     throws javax.mail.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:
javax.mail.MessagingException

createZippedAttachmentMimeBodyPart

public static javax.mail.internet.MimeBodyPart createZippedAttachmentMimeBodyPart(java.lang.String path)
                                                                           throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException


Copyright © 2008 Atlassian Software Systems Pty Ltd. All Rights Reserved.