org.liquidsite.util.mail
Class MailMessage

java.lang.Object
  extended byorg.liquidsite.util.mail.MailMessage
Direct Known Subclasses:
GroupMailMessage, SimpleMailMessage

public abstract class MailMessage
extends java.lang.Object

An email message. This is the base class for all types of email messages in the outgoing mail queue. The queue will iterate over all the message recipients one by one and send each one a single unique message. Due to queueing considerations, it is possible that other messages are delivered before all emails have been generated for a message.


Constructor Summary
MailMessage()
           
 
Method Summary
protected  javax.mail.internet.MimeMessage createMessage(javax.mail.Session session, javax.mail.internet.InternetAddress recipient)
          Creates a Java mail MIME message.
 java.lang.String getAttribute(java.lang.String name)
          Returns the value for a specified attribute.
 java.util.Collection getAttributeNames()
          Returns a collection with all the attribute names.
protected abstract  javax.mail.internet.MimeMessage getNextMessage(javax.mail.Session session)
          Creates the next Java mail MIME message from this mail message.
abstract  java.lang.String getRecipient()
          Returns a string representation of the message recipient.
 java.lang.String getReplyTo()
          Returns the message reply to address.
 javax.mail.internet.InternetAddress getReplyToAddress()
          Returns the message reply to address.
 java.lang.String getSubject()
          Returns the message subject.
 java.lang.String getText()
          Returns the message text.
protected abstract  boolean hasMoreMessages()
          Checks if there remains any Java mail MIME messages to generate.
 boolean isValid()
          Checks if this message is valid.
 void setAttribute(java.lang.String name, java.lang.String value)
          Sets a message attribute value.
 void setReplyTo(java.lang.String address)
          Sets the message reply-to address.
 void setSubject(java.lang.String subject)
          Sets the message subject.
 void setText(java.lang.String text)
          Sets the message text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MailMessage

public MailMessage()
Method Detail

isValid

public boolean isValid()
Checks if this message is valid. A message becomes valid once it has at least one recipient and non-empty subject and text content.

Returns:
true if the message is valid, or false otherwise

getRecipient

public abstract java.lang.String getRecipient()
Returns a string representation of the message recipient. This method is used for logging purposes, so the returned string shouldn't be too long.

Returns:
the message recipient

getReplyTo

public java.lang.String getReplyTo()
Returns the message reply to address.

Returns:
the message reply to address, or null if none has been set

getReplyToAddress

public javax.mail.internet.InternetAddress getReplyToAddress()
Returns the message reply to address.

Returns:
the message reply to address, or null if none has been set

setReplyTo

public void setReplyTo(java.lang.String address)
                throws MailMessageException
Sets the message reply-to address.

Parameters:
address - the reply-to address
Throws:
MailMessageException - if the reply-to address wasn't possible to parse correctly

getSubject

public java.lang.String getSubject()
Returns the message subject.

Returns:
the message subject, or an empty string if not set

setSubject

public void setSubject(java.lang.String subject)
Sets the message subject.

Parameters:
subject - the message subject

getText

public java.lang.String getText()
Returns the message text.

Returns:
the message text, or an empty string if not set

setText

public void setText(java.lang.String text)
Sets the message text.

Parameters:
text - the message text

getAttribute

public java.lang.String getAttribute(java.lang.String name)
Returns the value for a specified attribute. Message attributes can be used for storing information about the origin of a message or other information that is not part of the message itself.

Parameters:
name - the message attribute name
Returns:
the message attribute value, or null if not set

getAttributeNames

public java.util.Collection getAttributeNames()
Returns a collection with all the attribute names. Message attributes can be used for storing information about the origin of a message or other information that is not part of the message itself.

Returns:
a collection with the message attribute names

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String value)
Sets a message attribute value. Message attributes can be used for storing information about the origin of a message or other information that is not part of the message itself.

Parameters:
name - the message attribute name
value - the message attribute value

hasMoreMessages

protected abstract boolean hasMoreMessages()
Checks if there remains any Java mail MIME messages to generate.

Returns:
true if there are more messages to generate, or false otherwise

getNextMessage

protected abstract javax.mail.internet.MimeMessage getNextMessage(javax.mail.Session session)
                                                           throws MailMessageException
Creates the next Java mail MIME message from this mail message.

Parameters:
session - the Java mail session
Returns:
the Java MIME message created
Throws:
MailMessageException - if the message couldn't be created correctly

createMessage

protected javax.mail.internet.MimeMessage createMessage(javax.mail.Session session,
                                                        javax.mail.internet.InternetAddress recipient)
                                                 throws MailMessageException
Creates a Java mail MIME message.

Parameters:
session - the Java mail session
recipient - the mail recipient
Returns:
the Java MIME message created
Throws:
MailMessageException - if the message couldn't be created correctly