org.apache.james.transport.mailets
Class Redirect

java.lang.Object
  |
  +--org.apache.mailet.GenericMailet
        |
        +--org.apache.james.transport.mailets.Redirect
All Implemented Interfaces:
Mailet, MailetConfig

public class Redirect
extends GenericMailet

A mailet providing configurable redirection services
This mailet can produce listserver, forward and notify behaviour, with the original message intact, attached, appended or left out altogether.
This built in functionality is controlled by the configuration as laid out below.

However it is also designed to be easily subclassed to make authoring redirection mailets simple.
By extending it and overriding one or more of these methods new behaviour can be quickly created without the author having to address any other issue than the relevant one:

The configuration parameters are:

<recipients> A comma delimited list of email addresses for recipients of this message, it will use the "to" list if not specified. These addresses will only appear in the To: header if no "to" list is supplied.
<to> A comma delimited list of addresses to appear in the To: header, the email will only be delivered to these addresses if they are in the recipients list.
The recipients list will be used if this is not supplied.
<sender> A single email address to appear in the From: header
It can include constants "sender" and "postmaster"
<message> A text message to be the body of the email. Can be omitted.
<inline>

One of the following items:

  • unaltered     The original message is the new message, for forwarding/aliasing
  • heads          The headers of the original message are appended to the message
  • body           The body of the original is appended to the new message
  • all               Both headers and body are appended
  • none           Neither body nor headers are appended
<attachment>

One of the following items:

  • heads      The headers of the original are attached as text
  • body       The body of the original is attached as text
  • all           Both headers and body are attached as a single text file
  • none       Nothing is attached
  • message  The original message is attached as type message/rfc822, this means that it can, in many cases, be opened, resent, fw'd, replied to etc by email client software.
<passThrough> TRUE or FALSE, if true the original message continues in the mailet processor after this mailet is finished. False causes the original to be stopped.
<attachError> TRUE or FALSE, if true any error message available to the mailet is appended to the message body (except in the case of inline == unaltered)
<replyto> A single email address to appear in the Rely-To: header, can also be "sender" or "postmaster", this header is not set if this is omited.
<prefix> An optional subject prefix prepended to the original message subject, for example:
Undeliverable mail:
<static>

TRUE or FALSE, if this is true it hints to the mailet that none of the parameters are set dynamically, and therefore they can be set once in the init method.
False tells the mailet to call all the "getters" for every mail processed.

This defaults to false.
It should be TRUE in all cases, except where one of the getter methods has been overriden to provide dynamic values, such as a listserve which might override getRecipients() to get a list from a users repository.

Example:

<mailet match="RecipientIs=test@localhost" class="Redirect">
<recipients>x@localhost, y@localhost, z@localhost</recipients>
<to>list@localhost</to>
<sender>owner@localhost</sender>
<message>sent on from James</message>
<inline>unaltered</inline>
<passThrough>FALSE</passThrough>
<replyto>postmaster</replyto>
<prefix xml:space="preserve">[test mailing] </prefix>
<!-- note the xml:space="preserve" to preserve whitespace -->
<static>TRUE</static>
</mailet>

and:

<mailet match="All" class="Redirect">
<recipients>x@localhost</recipients>
<sender>postmaster</sender>
<message xml:space="preserve">Message marked as spam:
</message>
<inline>heads</inline>
<attachment>message</attachment>
<passThrough>FALSE</passThrough>
<attachError>TRUE</attachError>
<replyto>postmaster</replyto>
<prefix>[spam notification]</prefix>
<static>TRUE</static>
</mailet>

Author:
Danny Angus

Constructor Summary
Redirect()
           
 
Method Summary
 boolean attachError()
          return true to append a description of any error to the main body part if getInlineType does not return "UNALTERED"
 int getAttachmentType()
          returns one of these values to indicate how to attach the original message BODY : original message body is attached as plain text to the new message HEADS : original message headers are attached as plain text to the new message ALL : original is attached as plain text with all headers MESSAGE : original message is attached as type message/rfc822, a complete mail message.
 int getInLineType()
          returns one of these values to indicate how to append the original message UNALTERED : original message is the new message body BODY : original message body is appended to the new message HEADS : original message headers are appended to the new message ALL : original is appended with all headers NONE : original is not appended
 String getMailetInfo()
          Return a string describing this mailet.
 String getMessage()
          must return either an empty string, or a message to which the redirect can be attached/appended
 boolean getPassThrough()
          return true to allow thie original message to continue through the processor, false to GHOST it
 Collection getRecipients()
          must return a Collection of recipient MailAddresses
 MailAddress getReplyTo()
          Returns the reply to address as a string.
 MailAddress getSender()
          returns the senders address, as a MailAddress
 String getSubjectPrefix()
          return a prefix for the message subject
 InternetAddress[] getTo()
          returns an array of InternetAddress 'es for the To: header
 void init()
          init will setup static values for sender, recipients, message text, and reply to
if isStatic() returns true it calls getSender(), getReplyTo(), getMessage(), and getRecipients() and getTo()
 boolean isStatic()
          return true to reduce calls to getTo, getSender, getRecipients, getReplyTo amd getMessage where these values don't change (eg hard coded, or got at startup from the mailet config)
return false where any of these methods generate their results dynamically eg in response to the message being processed, or by refrence to a repository of users
 void service(Mail mail)
          Service does the hard work,and redirects the mail in the form specified
 
Methods inherited from class org.apache.mailet.GenericMailet
destroy, getInitParameter, getInitParameterNames, getMailetConfig, getMailetContext, getMailetName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Redirect

public Redirect()
Method Detail

getAttachmentType

public int getAttachmentType()
returns one of these values to indicate how to attach the original message


getInLineType

public int getInLineType()
returns one of these values to indicate how to append the original message


getMailetInfo

public String getMailetInfo()
Return a string describing this mailet.

Specified by:
getMailetInfo in interface Mailet
Overrides:
getMailetInfo in class GenericMailet
Returns:
a string describing this mailet

getMessage

public String getMessage()
must return either an empty string, or a message to which the redirect can be attached/appended


getPassThrough

public boolean getPassThrough()
return true to allow thie original message to continue through the processor, false to GHOST it


getRecipients

public Collection getRecipients()
must return a Collection of recipient MailAddresses


getReplyTo

public MailAddress getReplyTo()
Returns the reply to address as a string.

Returns:
the replyto address for the mail as a string

getSender

public MailAddress getSender()
returns the senders address, as a MailAddress


isStatic

public boolean isStatic()
return true to reduce calls to getTo, getSender, getRecipients, getReplyTo amd getMessage where these values don't change (eg hard coded, or got at startup from the mailet config)
return false where any of these methods generate their results dynamically eg in response to the message being processed, or by refrence to a repository of users


getSubjectPrefix

public String getSubjectPrefix()
return a prefix for the message subject


getTo

public InternetAddress[] getTo()
returns an array of InternetAddress 'es for the To: header


attachError

public boolean attachError()
return true to append a description of any error to the main body part if getInlineType does not return "UNALTERED"


init

public void init()
          throws MessagingException
init will setup static values for sender, recipients, message text, and reply to
if isStatic() returns true it calls getSender(), getReplyTo(), getMessage(), and getRecipients() and getTo()

Overrides:
init in class GenericMailet
Throws:
MessagingException - if an exception occurs that interrupts the mailet's normal operation

service

public void service(Mail mail)
             throws MessagingException
Service does the hard work,and redirects the mail in the form specified

Specified by:
service in interface Mailet
Specified by:
service in class GenericMailet
Parameters:
mail - the mail to process and redirect
Throws:
MessagingException - if a problem arising formulating the redirected mail


"Copyright © 1999-2002 Apache Jakarta Project. All Rights Reserved."