org.mailster.message
Class SmtpMessage

java.lang.Object
  extended by org.mailster.message.SmtpMessage
All Implemented Interfaces:
java.io.Serializable

public class SmtpMessage
extends java.lang.Object
implements java.io.Serializable

Container for a complete SMTP message - headers and message body.

See Also:
Serialized Form

Field Summary
private  java.lang.StringBuilder body
          Message body.
private  java.lang.String charset
           
private  java.lang.String content
           
private  SmtpHeadersInterface headers
          Headers.
private static int id
          Likewise, a global id for Message-ID generation.
private  java.lang.String internalDate
           
private  SmtpMessagePart internalParts
           
private static javax.mail.Session MAIL_SESSION
          Variable used for MimeMessage conversion.
private  java.lang.String messageID
           
private  java.lang.Boolean needsConversion
           
private  java.lang.String oldPreferredContentType
           
private  java.util.List<java.lang.String> recipients
          Recipients (read from envelope)
private static long serialVersionUID
           
 
Constructor Summary
SmtpMessage()
          Constructor.
 
Method Summary
protected  void addRecipients(java.util.List<java.lang.String> l)
          Add a list of recipients to the list of recipients.
protected  void append(boolean isHeaderData, java.lang.String line)
          Update the headers or body of the message.
 javax.mail.internet.MimeMessage asMimeMessage()
          Converts from a SmtpMessage to a MimeMessage.
 java.lang.String getBody()
          Get the message body.
 java.lang.String getBodyCharset()
          Get the charset specified in Content-Type header.
 java.lang.String getDate()
          Note : this method generates and stores a date header if the mail doesn't have one.
 SmtpHeadersInterface getHeaders()
           
 java.lang.String getHeaderValue(java.lang.String name)
          Get the first value associated with a given header name.
 java.lang.String[] getHeaderValues(java.lang.String name)
          Get the value(s) associated with the given header name.
 SmtpMessagePart getInternalParts()
           
 java.lang.String getMessageID()
          Get a unique value to use 'as' a Message-ID.
 java.lang.String getPreferredContent(java.lang.String preferredContentType)
           
 java.util.List<java.lang.String> getRecipients()
          Returns the recipients of this message (from the SMTP envelope).
 int getSize()
          Return the size of the content of this message in bytes.
 java.lang.String getSubject()
           
 java.lang.String getTo()
           
 java.lang.String toString()
          String representation of the SmtpMessage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

MAIL_SESSION

private static final transient javax.mail.Session MAIL_SESSION
Variable used for MimeMessage conversion.


headers

private SmtpHeadersInterface headers
Headers.


body

private java.lang.StringBuilder body
Message body.


recipients

private java.util.List<java.lang.String> recipients
Recipients (read from envelope)


internalParts

private SmtpMessagePart internalParts

content

private java.lang.String content

oldPreferredContentType

private java.lang.String oldPreferredContentType

messageID

private java.lang.String messageID

internalDate

private java.lang.String internalDate

charset

private java.lang.String charset

needsConversion

private java.lang.Boolean needsConversion

id

private static int id
Likewise, a global id for Message-ID generation.

Constructor Detail

SmtpMessage

public SmtpMessage()
Constructor. Initializes headers Map and body buffer.

Method Detail

append

protected void append(boolean isHeaderData,
                      java.lang.String line)
Update the headers or body of the message.

Parameters:
isHeaderData - true if data is part of the mail header
line - the line of mail data

getMessageID

public java.lang.String getMessageID()
Get a unique value to use 'as' a Message-ID. If the headers don't contain a Message-ID header value, this implementation generates it by concatenating the message object's hashCode(), a global ID (incremented on every use), the current time (in milliseconds), the string "Mailster", and this user's local address generated by InetAddress.getLocalHost(). (The address defaults to "localhost" if getLocalHost() returns null.) ...Mailster@

See Also:
InetAddress

getHeaderValues

public java.lang.String[] getHeaderValues(java.lang.String name)
Get the value(s) associated with the given header name.

Parameters:
name - header name
Returns:
value(s) associated with the header name

getHeaderValue

public java.lang.String getHeaderValue(java.lang.String name)
Get the first value associated with a given header name.

Parameters:
name - header name
Returns:
first value associated with the header name

getBody

public java.lang.String getBody()
Get the message body.

Returns:
message body

asMimeMessage

public javax.mail.internet.MimeMessage asMimeMessage()
                                              throws javax.mail.MessagingException,
                                                     java.io.UnsupportedEncodingException
Converts from a SmtpMessage to a MimeMessage.

Returns:
a MimeMessage object
Throws:
javax.mail.MessagingException - if MimeMessage creation fails
java.io.UnsupportedEncodingException - if charset is unknown

toString

public java.lang.String toString()
String representation of the SmtpMessage.

Overrides:
toString in class java.lang.Object
Returns:
a String

getHeaders

public SmtpHeadersInterface getHeaders()

getDate

public java.lang.String getDate()
Note : this method generates and stores a date header if the mail doesn't have one.


getTo

public java.lang.String getTo()

getSubject

public java.lang.String getSubject()

getInternalParts

public SmtpMessagePart getInternalParts()

getPreferredContent

public java.lang.String getPreferredContent(java.lang.String preferredContentType)

getBodyCharset

public java.lang.String getBodyCharset()
Get the charset specified in Content-Type header.

Returns:
charset, null if none specified.

addRecipients

protected void addRecipients(java.util.List<java.lang.String> l)
Add a list of recipients to the list of recipients.


getRecipients

public java.util.List<java.lang.String> getRecipients()
Returns the recipients of this message (from the SMTP envelope). Bcc recipients are consequently exposed for testing.

Returns:
the list of recipients

getSize

public int getSize()
Return the size of the content of this message in bytes. Return 0 if the size cannot be determined.

Note that this number may not be an exact measure of the content size and may or may not account for any transfer encoding of the content.

This implementation returns the size of the message body (if not null), otherwise, it returns 0.

Returns:
size of content in bytes