talx x1.0.5

talx.util
Class MessageUtils

java.lang.Object
  extended bytalx.util.MessageUtils

public class MessageUtils
extends java.lang.Object

Contains static methods for message attachment processing.


Nested Class Summary
static class MessageUtils.ByteArrayDataSource
           
 
Method Summary
static javax.mail.internet.MimeMessage combine(javax.mail.internet.MimeMessage[] messages)
          Combines the list of messages into a single multipart message.
static javax.mail.internet.MimeMessage copy(javax.mail.internet.MimeMessage message)
          Copies the given message into a new message object.
static javax.mail.internet.MimeMessage createMessage(java.lang.String[] toAddresses, java.lang.String[] toNames, java.lang.String fromAddress, java.lang.String fromName, java.lang.String subject, java.lang.Object body)
          Returns a MimeMessage from the given address, to the given address with the given subject and body.
static javax.mail.internet.MimeMessage createMessage(java.lang.String toAddress, java.lang.String toName, java.lang.String fromAddress, java.lang.String fromName, java.lang.String subject, java.lang.Object body)
          Returns a MimeMessage from the given address, to the given address with the given subject and body.
static javax.mail.internet.MimePart[] getFiles(javax.mail.internet.MimeMessage m)
          Returns the file attachments of a message.
static java.awt.Image[] getImages(javax.mail.internet.MimeMessage m)
          Extracts images from a message, if present.
static java.lang.String getInlineText(javax.mail.internet.MimeMessage m)
          Returns the concatenation of all the inline text parts of a message.
static java.io.InputStream[] getMusic(javax.mail.internet.MimeMessage m)
          Extracts images from a message, if present.
static javax.mail.internet.MimePart[] getParts(javax.mail.internet.MimeMessage m, java.lang.String contentDescription)
          Returns the portions of a message matching the given content description.
static java.io.InputStream[] getSounds(javax.mail.internet.MimeMessage m)
          Extracts images from a message, if present.
static java.lang.String[][] getText(javax.mail.internet.MimeMessage m)
          Returns the text parts of a message.
static boolean isAdminReport(javax.mail.internet.MimeMessage m)
          Returns true if the message is a multipart/report type.
static boolean isRenderable(javax.mail.internet.MimeMessage m)
          Returns true if the message contains only parts that are recognized by this system.
static boolean sendCPISCommand(java.security.PrivateKey key, java.lang.String toName, java.lang.String toAddress, java.lang.String fromName, java.lang.String fromAddress, java.lang.String command, java.lang.String restart, java.lang.String context, java.sql.ResultSet files, java.lang.String subjectLine)
          Sends a CPIS command from the server to the client.
static java.lang.String[] splitAddress(java.lang.String address, boolean raw)
          Returns username and major subdomain from given address.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createMessage

public static javax.mail.internet.MimeMessage createMessage(java.lang.String[] toAddresses,
                                                            java.lang.String[] toNames,
                                                            java.lang.String fromAddress,
                                                            java.lang.String fromName,
                                                            java.lang.String subject,
                                                            java.lang.Object body)
                                                     throws javax.mail.MessagingException
Returns a MimeMessage from the given address, to the given address with the given subject and body. The sent date is also automatically set to now.

Important Note: This method does not call the saveChanges method on the newly constructed message. Thus, the calling program can continue to add more headers. However, this also means that the calling program must call saveChanges before attempting to send the message.

Parameters:
toAddresses - the list of valid, parseable email addresses to send the message to. None of these can be null.
toNames - the list of personal names corresponding to the entries of toAddresses. These can be null and the length can be less than the length of toAddresses. Thus, if none of the personal names are know, this can be a zero-length array. If certain names are unknown, those entries in the array can be null.
fromAddress - a parseable address that the message is from.
fromName - the personal name that the message is from.
subject - the subject header for the message. If null, the subject is not set. If the empty string, then the subject is set to blank.
body - the body of the message. If this is a CharSequence or number, the resulting message body will be the result of the toString method for the object. If this is a MimeMultiPart, For other types of object, the body will be constructed from an ObjectDataSource object constructed with the object.
Throws:
javax.mail.MessagingException - if the message cannot be constructed, including problems parsing the to and from addresses, and obtaining a valid data handler. The valid types of Object for the body are:
  • CharSequence
  • Number
  • Multipart
  • MimePart
  • File
  • Serializable
java.lang.NullPointerException - if any entries of toAddresses are null.

createMessage

public static javax.mail.internet.MimeMessage createMessage(java.lang.String toAddress,
                                                            java.lang.String toName,
                                                            java.lang.String fromAddress,
                                                            java.lang.String fromName,
                                                            java.lang.String subject,
                                                            java.lang.Object body)
                                                     throws javax.mail.MessagingException
Returns a MimeMessage from the given address, to the given address with the given subject and body. This is just a convenience method to create messages to single recipients. It puts the to information into arrays and calls the other createMessage().

Throws:
javax.mail.MessagingException

splitAddress

public static java.lang.String[] splitAddress(java.lang.String address,
                                              boolean raw)
Returns username and major subdomain from given address. This method contains all of our know-how about interpreting addresses. If know buddies are not being recognized, this method should be updated to decode the abherent address format.

Parameters:
address - the address string to parse.
raw - if true, the address is interpreted as a Mime address header, otherwise, it is assumed to have the form someone@somewhere. Note that Mime address strings can have the form someusername@sub.domain.dom (personal name) or personal name <someusername@sub.domain.dom> if raw is true, this method will attempt to remove the personal name before proceeding.
Returns:
index 0 = username; 1 = subdomain.dom; everything in lowercase.

isAdminReport

public static boolean isAdminReport(javax.mail.internet.MimeMessage m)
Returns true if the message is a multipart/report type.


isRenderable

public static boolean isRenderable(javax.mail.internet.MimeMessage m)
Returns true if the message contains only parts that are recognized by this system.


getImages

public static java.awt.Image[] getImages(javax.mail.internet.MimeMessage m)
                                  throws javax.mail.MessagingException
Extracts images from a message, if present.

Parameters:
m - the message containing an image.
Returns:
an array of images, possibly empty.
Throws:
javax.mail.MessagingException

getSounds

public static java.io.InputStream[] getSounds(javax.mail.internet.MimeMessage m)
                                       throws javax.mail.MessagingException
Extracts images from a message, if present.

Parameters:
m - the message containing an image.
Returns:
an array of images, possibly empty.
Throws:
javax.mail.MessagingException

getMusic

public static java.io.InputStream[] getMusic(javax.mail.internet.MimeMessage m)
                                      throws javax.mail.MessagingException
Extracts images from a message, if present.

Parameters:
m - the message containing an image.
Returns:
an array of images, possibly empty.
Throws:
javax.mail.MessagingException

getParts

public static javax.mail.internet.MimePart[] getParts(javax.mail.internet.MimeMessage m,
                                                      java.lang.String contentDescription)
                                               throws javax.mail.MessagingException
Returns the portions of a message matching the given content description. If contentDescription is non-null, the returned MimeParts are required to be marked with a content description that starts with the given String. If the given string is null, then only MimeParts that have no contentDescription will be returned.

Parameters:
m - the message to search
contentDescription - the content description to match, or null.
Returns:
an array of the body parts that have the given content-description.
Throws:
javax.mail.MessagingException

getFiles

public static javax.mail.internet.MimePart[] getFiles(javax.mail.internet.MimeMessage m)
                                               throws javax.mail.MessagingException
Returns the file attachments of a message. Note that this method and the getInline method are not opposites. Some parts may be returned by both and some parts may be returned by neither. The behavior is determined by the mail program that sent the message.

Returns:
an array of the body parts that have their filename or name attributes set.
Throws:
javax.mail.MessagingException

getText

public static java.lang.String[][] getText(javax.mail.internet.MimeMessage m)
                                    throws javax.mail.MessagingException
Returns the text parts of a message.

Returns:
an array of the text parts of m where getText(m)[i][0] is the mime type of the string and getText(m)[i][1] is the text.
Throws:
javax.mail.MessagingException

getInlineText

public static java.lang.String getInlineText(javax.mail.internet.MimeMessage m)
                                      throws javax.mail.MessagingException
Returns the concatenation of all the inline text parts of a message.

Returns:
a String object that results from concatenating text parts marked as inlined. If the message has the type "text", then that text is returned. If the message is multipart, then only the top-level part is searched for inline text. If no such text can be found, null is returned.
Throws:
javax.mail.MessagingException

combine

public static javax.mail.internet.MimeMessage combine(javax.mail.internet.MimeMessage[] messages)
                                               throws javax.mail.MessagingException
Combines the list of messages into a single multipart message. The list of messages become attachments to the returned message. If there are no messages in the list, null is returned.

Throws:
java.lang.NullPointerException - if the first message is null. Other nulls in the list will not result in an exception being thrown.
javax.mail.MessagingException

copy

public static javax.mail.internet.MimeMessage copy(javax.mail.internet.MimeMessage message)
                                            throws javax.mail.MessagingException
Copies the given message into a new message object.

Throws:
java.lang.NullPointerException - if the message is null.
javax.mail.MessagingException

sendCPISCommand

public static boolean sendCPISCommand(java.security.PrivateKey key,
                                      java.lang.String toName,
                                      java.lang.String toAddress,
                                      java.lang.String fromName,
                                      java.lang.String fromAddress,
                                      java.lang.String command,
                                      java.lang.String restart,
                                      java.lang.String context,
                                      java.sql.ResultSet files,
                                      java.lang.String subjectLine)
Sends a CPIS command from the server to the client. This is used by the webserver to send a command.

Returns:
true if the command was successfully sent.
Throws:
ServletException - if a messaging exception is encountered.

talx x1.0.5

© 2001-2005 University of Oregon.
Eugene OR 97403, U.S.A. All Rights Reserved.