org.mule.providers.email
Class SimpleMailMessageAdapter

java.lang.Object
  extended byorg.mule.providers.AbstractMessageAdapter
      extended byorg.mule.providers.email.SimpleMailMessageAdapter
All Implemented Interfaces:
Serializable, ThreadSafeAccess, UMOMessageAdapter
Direct Known Subclasses:
MailMessageAdapter

public class SimpleMailMessageAdapter
extends AbstractMessageAdapter

SimpleMailMessageAdapter is an adapter for mail messages. Unlike MailMessageAdapter this preserves the message intact in its original form.

Header values are stored in two formats. First, as historically used by MailMessageAdapter, a single String value is stored for each distinct header name (if a header is repeated only one value is stored). Secondly, a list of values for each distinct header is stored in a property name prefixed by HEADER_LIST_PREFIX (which produces an invalid header name according to RFC 822 and so (i) avoids conflict with the first property type and (ii) will cause current applications that wrongly assume all properties are simple header values to fail fast). The utility methods isListHeader(String), toHeader(String) and toListHeader(String) identify and convert between property and header names as required.

See Also:
Serialized Form

Field Summary
static String HEADER_LIST_PREFIX
           
 
Fields inherited from class org.mule.providers.AbstractMessageAdapter
attachments, DEFAULT_FAILFAST, encoding, exceptionPayload, id, logger, properties, READ, WRITE
 
Constructor Summary
  SimpleMailMessageAdapter(Object object)
           
protected SimpleMailMessageAdapter(SimpleMailMessageAdapter template)
           
 
Method Summary
 Object getPayload()
           
 byte[] getPayloadAsBytes()
          Converts the message implementation into a byte array representation
 String getPayloadAsString(String encoding)
          Converts the message implementation into a String representation
protected  void handleMessage(Message message)
          By default, this simply stores the entire message as a single message.
static boolean isListHeader(String name)
          Check whether a property name has the format associated with a list of header values
 ThreadSafeAccess newThreadCopy()
          By default we return "this".
protected  void setMessage(Part message)
           
static String toHeader(String name)
          Convert a property name associated with a list of header values to the relevant header name (ie drop the prefix)
static String toListHeader(String header)
          Convert a header name to the property name associated with a list of header values (ie prepend the prefix)
 
Methods inherited from class org.mule.providers.AbstractMessageAdapter
addAttachment, addProperties, assertAccess, clearProperties, convertToBytes, getAttachment, getAttachmentNames, getBooleanProperty, getCorrelationGroupSize, getCorrelationId, getCorrelationSequence, getDoubleProperty, getEncoding, getExceptionPayload, getIntProperty, getLongProperty, getPayloadAsString, getProperty, getProperty, getPropertyNames, getReplyTo, getStringProperty, getUniqueId, isDisabled, newException, removeAttachment, removeProperty, resetAccessControl, setBooleanProperty, setCorrelationGroupSize, setCorrelationId, setCorrelationSequence, setDoubleProperty, setEncoding, setExceptionPayload, setIntProperty, setLongProperty, setProperty, setReplyTo, setStringProperty, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HEADER_LIST_PREFIX

public static final String HEADER_LIST_PREFIX
See Also:
Constant Field Values
Constructor Detail

SimpleMailMessageAdapter

public SimpleMailMessageAdapter(Object object)
                         throws MessagingException

SimpleMailMessageAdapter

protected SimpleMailMessageAdapter(SimpleMailMessageAdapter template)
Method Detail

handleMessage

protected void handleMessage(Message message)
                      throws Exception
By default, this simply stores the entire message as a single message. Sub-classes may override with more complex processing.

Throws:
Exception

setMessage

protected void setMessage(Part message)

getPayload

public Object getPayload()
Returns:
the current message

getPayloadAsBytes

public byte[] getPayloadAsBytes()
                         throws Exception
Description copied from interface: UMOMessageAdapter
Converts the message implementation into a byte array representation

Returns:
byte array of the message
Throws:
Exception - Implemetation may throw an endpoint specific exception

getPayloadAsString

public String getPayloadAsString(String encoding)
                          throws Exception
Description copied from interface: UMOMessageAdapter
Converts the message implementation into a String representation

Parameters:
encoding - The encoding to use when transforming the message (if necessary). The parameter is used when converting from a byte array
Returns:
String representation of the message payload
Throws:
Exception - Implementation may throw an endpoint specific exception

isListHeader

public static boolean isListHeader(String name)
Check whether a property name has the format associated with a list of header values

Parameters:
name - A property name
Returns:
true if the name is associated with a list of header values (more exactly, if it starts with HEADER_LIST_PREFIX, which gives an invalid header name according to RFC822).

toHeader

public static String toHeader(String name)
Convert a property name associated with a list of header values to the relevant header name (ie drop the prefix)

Parameters:
name - A property name
Returns:
The associated header name (ie with HEADER_LIST_PREFIX removed)

toListHeader

public static String toListHeader(String header)
Convert a header name to the property name associated with a list of header values (ie prepend the prefix)

Parameters:
header - A header name
Returns:
The associated list property name (ie with HEADER_LIST_PREFIX prepended)

newThreadCopy

public ThreadSafeAccess newThreadCopy()
Description copied from class: AbstractMessageAdapter
By default we return "this". This allows older code to inter-operate but doesn't, of course, give the required safety. Subclasses should override this method. Re-writing the threading handling should remove this requirement....

Specified by:
newThreadCopy in interface ThreadSafeAccess
Overrides:
newThreadCopy in class AbstractMessageAdapter
Returns:
A new copy of this


Copyright © 2003-2008 MuleSource, Inc.. All Rights Reserved.