|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.mailet.GenericMailet org.apache.james.transport.mailets.AbstractRedirect
public abstract class AbstractRedirect
Abstract mailet providing configurable redirection services.
This mailet can be 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:
For each of the methods above (generically called "getX()" methods in this class
and its subclasses), there is an associated "getX(Mail)" method and most times
a "setX(Mail, Tx, Mail)" method.
The roles are the following:
Here follows the typical pattern of those methods:
...
Tx x;
...
protected boolean getX(Mail originalMail) throws MessagingException {
boolean x = (isStatic()) ? this.x : getX();
...
return x;
}
...
public void init() throws MessagingException {
...
isStatic = (getInitParameter("static") == null) ? false : new Boolean(getInitParameter("static")).booleanValue();
if(isStatic()) {
...
X = getX();
...
}
...
public void service(Mail originalMail) throws MessagingException {
...
setX(newMail, getX(originalMail), originalMail);
...
}
...
The isStatic variable and method is used to allow for the situations
(deprecated since version 2.2, but possibly used by previoulsy written extensions
to Redirect
) in which the getX() methods are non static: in this case
isStatic()
must return false.
Finally, a "getX()" method may return a "special address" (see AbstractRedirect.SpecialAddress
),
that later will be resolved ("late bound") by a "getX(Mail)" or "setX(Mail, Tx, Mail)":
it is a dynamic value that does not require isStatic
to be false.
Supports by default the passThrough
init parameter (false if missing).
Subclasses can override this behaviour overriding getPassThrough()
.
Nested Class Summary | |
---|---|
protected static class |
AbstractRedirect.SpecialAddress
Class containing "special addresses" constants. |
Field Summary | |
---|---|
protected static int |
ALL
|
protected static int |
BODY
|
protected static int |
HEADS
|
protected boolean |
isDebug
Controls certain log messages. |
protected boolean |
isStatic
Holds the value of the static init parameter. |
protected static int |
MESSAGE
|
protected static int |
NONE
|
protected static int |
UNALTERED
|
Constructor Summary | |
---|---|
AbstractRedirect()
|
Method Summary | |
---|---|
protected boolean |
attachError()
Gets the attachError property. |
protected boolean |
attachError(Mail originalMail)
Gets the attachError property,
built dynamically using the original Mail object. |
protected void |
buildAlteredMessage(Mail newMail,
Mail originalMail)
Builds the message of the newMail in case it has to be altered. |
static void |
changeSubject(javax.mail.internet.MimeMessage message,
java.lang.String newValue)
It changes the subject of the supplied message to to supplied value but it also tries to preserve the original charset information. |
protected java.lang.String[] |
getAllowedInitParameters()
Gets the expected init parameters. |
protected int |
getAttachmentType()
Gets the attachment property. |
protected int |
getAttachmentType(Mail originalMail)
Gets the attachment property,
built dynamically using the original Mail object. |
protected boolean |
getFakeDomainCheck()
Gets the fakeDomainCheck property. |
protected boolean |
getFakeDomainCheck(Mail originalMail)
Gets the fakeDomainCheck property,
built dynamically using the original Mail object. |
protected int |
getInLineType()
Gets the inline property. |
protected int |
getInLineType(Mail originalMail)
Gets the inline property,
built dynamically using the original Mail object. |
protected java.lang.String |
getMessage()
Gets the message property. |
protected java.lang.String |
getMessage(Mail originalMail)
Gets the message property,
built dynamically using the original Mail object. |
protected java.lang.String |
getMessageHeaders(javax.mail.internet.MimeMessage message)
Utility method for obtaining a string representation of a Message's headers |
protected boolean |
getPassThrough()
Gets the passThrough property. |
protected boolean |
getPassThrough(Mail originalMail)
Gets the passThrough property,
built dynamically using the original Mail object. |
protected java.util.Collection |
getRecipients()
Gets the recipients property. |
protected java.util.Collection |
getRecipients(Mail originalMail)
Gets the recipients property,
built dynamically using the original Mail object. |
protected MailAddress |
getReplyTo()
Gets the replyto property. |
protected MailAddress |
getReplyTo(Mail originalMail)
Gets the replyTo property,
built dynamically using the original Mail object. |
protected MailAddress |
getReversePath()
Gets the reversePath property. |
protected MailAddress |
getReversePath(Mail originalMail)
Gets the reversePath property,
built dynamically using the original Mail object. |
protected MailAddress |
getSender()
Gets the sender property. |
protected MailAddress |
getSender(Mail originalMail)
Gets the sender property,
built dynamically using the original Mail object. |
protected MailAddress |
getSpecialAddress(java.lang.String addressString,
java.lang.String[] allowedSpecials)
Returns the AbstractRedirect.SpecialAddress that corresponds to an init parameter value. |
protected java.lang.String |
getSubject()
Gets the subject property. |
protected java.lang.String |
getSubject(Mail originalMail)
Gets the subject property,
built dynamically using the original Mail object. |
protected java.lang.String |
getSubjectPrefix()
Gets the prefix property. |
protected java.lang.String |
getSubjectPrefix(Mail originalMail)
Gets the subjectPrefix property,
built dynamically using the original Mail object. |
protected javax.mail.internet.InternetAddress[] |
getTo()
Gets the to property. |
protected javax.mail.internet.InternetAddress[] |
getTo(Mail originalMail)
Gets the to property,
built dynamically using the original Mail object. |
protected int |
getTypeCode(java.lang.String param)
A private method to convert types from string to int. |
void |
init()
Mailet initialization routine. |
protected boolean |
isReply()
Gets the isReply property. |
protected boolean |
isReply(Mail originalMail)
Gets the isReply property,
built dynamically using the original Mail object. |
protected boolean |
isStatic()
Gets the static property. |
protected java.util.Collection |
replaceInternetAddresses(Mail mail,
java.util.Collection list)
Returns a new Collection built over list replacing special addresses with real InternetAddress -es. |
protected java.util.Collection |
replaceMailAddresses(Mail mail,
java.util.Collection list)
Returns a new Collection built over list replacing special addresses with real MailAddress -es. |
protected boolean |
senderDomainIsValid(Mail mail)
Checks if a sender domain of mail is valid. |
void |
service(Mail originalMail)
Service does the hard work,and redirects the originalMail in the form specified. |
protected void |
setIsReply(Mail newMail,
boolean isReply,
Mail originalMail)
Sets the "In-Reply-To:" header of newMail to the "Message-Id:" of originalMail, if isReply is true. |
protected void |
setRecipients(Mail newMail,
java.util.Collection recipients,
Mail originalMail)
Sets the recipients of newMail to recipients. |
protected void |
setReplyTo(Mail newMail,
MailAddress replyTo,
Mail originalMail)
Sets the "Reply-To:" header of newMail to replyTo. |
protected void |
setReversePath(MailImpl newMail,
MailAddress reversePath,
Mail originalMail)
Sets the "reverse-path" of newMail to reversePath. |
protected void |
setSender(Mail newMail,
MailAddress sender,
Mail originalMail)
Sets the "From:" header of newMail to sender. |
protected void |
setSubjectPrefix(Mail newMail,
java.lang.String subjectPrefix,
Mail originalMail)
Builds the subject of newMail appending the subject of originalMail to subjectPrefix. |
protected void |
setTo(Mail newMail,
javax.mail.internet.InternetAddress[] to,
Mail originalMail)
Sets the "To:" header of newMail to to. |
Methods inherited from class org.apache.mailet.GenericMailet |
---|
destroy, getInitParameter, getInitParameter, getInitParameterNames, getMailetConfig, getMailetContext, getMailetInfo, getMailetName, init, log, log |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected boolean isDebug
protected boolean isStatic
static
init parameter.
protected static final int UNALTERED
protected static final int HEADS
protected static final int BODY
protected static final int ALL
protected static final int NONE
protected static final int MESSAGE
Constructor Detail |
---|
public AbstractRedirect()
Method Detail |
---|
protected java.lang.String[] getAllowedInitParameters()
protected boolean isStatic()
Gets the static
property.
Return true to reduce calls to getTo, getSender, getRecipients, getReplyTo, getReversePath 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 reference to a repository of users.
It is now (from version 2.2) somehow obsolete, as should be always true because the "good practice"
is to use "getX()" methods statically, and use instead "getX(Mail)" methods for dynamic situations.
A false value is now meaningful only for subclasses of Redirect
older than version 2.2
that were relying on this.
Is a "getX()" method.
protected boolean getPassThrough() throws javax.mail.MessagingException
passThrough
property.
Return true to allow the original message to continue through the processor, false to GHOST it.
Is a "getX()" method.
passThrough
init parameter, or false if missing
javax.mail.MessagingException
protected boolean getPassThrough(Mail originalMail) throws javax.mail.MessagingException
passThrough
property,
built dynamically using the original Mail object.
Is a "getX(Mail)" method.
getPassThrough()
javax.mail.MessagingException
protected boolean getFakeDomainCheck() throws javax.mail.MessagingException
fakeDomainCheck
property.
Return true to check if the sender domain is valid.
Is a "getX()" method.
fakeDomainCheck
init parameter, or true if missing
javax.mail.MessagingException
protected boolean getFakeDomainCheck(Mail originalMail) throws javax.mail.MessagingException
fakeDomainCheck
property,
built dynamically using the original Mail object.
Is a "getX(Mail)" method.
getFakeDomainCheck()
javax.mail.MessagingException
protected int getInLineType() throws javax.mail.MessagingException
inline
property.
May return one of the following values to indicate how to append the original message
to build the new message:
UNALTERED
: original message is the new message bodyBODY
: original message body is appended to the new messageHEADS
: original message headers are appended to the new messageALL
: original is appended with all headersNONE
: original is not appended
inline
init parameter, or UNALTERED
if missing
javax.mail.MessagingException
protected int getInLineType(Mail originalMail) throws javax.mail.MessagingException
inline
property,
built dynamically using the original Mail object.
Is a "getX(Mail)" method.
getInLineType()
javax.mail.MessagingException
protected int getAttachmentType() throws javax.mail.MessagingException
attachment
property.
May return one of the following values to indicate how to attach the original message
to the new message:
BODY
: original message body is attached as plain text to the new messageHEADS
: original message headers are attached as plain text to the new messageALL
: original is attached as plain text with all headersMESSAGE
: original message is attached as type message/rfc822, a complete mail message.NONE
: original is not attached
attachment
init parameter, or NONE
if missing
javax.mail.MessagingException
protected int getAttachmentType(Mail originalMail) throws javax.mail.MessagingException
attachment
property,
built dynamically using the original Mail object.
Is a "getX(Mail)" method.
getAttachmentType()
javax.mail.MessagingException
protected java.lang.String getMessage() throws javax.mail.MessagingException
message
property.
Returns a message to which the original message can be attached/appended
to build the new message.
Is a "getX()" method.
message
init parameter or an empty string if missing
javax.mail.MessagingException
protected java.lang.String getMessage(Mail originalMail) throws javax.mail.MessagingException
message
property,
built dynamically using the original Mail object.
Is a "getX(Mail)" method.
getMessage()
javax.mail.MessagingException
protected java.util.Collection getRecipients() throws javax.mail.MessagingException
recipients
property.
Returns the collection of recipients of the new message,
or null if no change is requested.
Is a "getX()" method.
recipients
init parameter
or the postmaster address
or SpecialAddress.SENDER
or SpecialAddress.FROM
or SpecialAddress.REPLY_TO
or SpecialAddress.REVERSE_PATH
or SpecialAddress.UNALTERED
or SpecialAddress.RECIPIENTS
or null
if missing
javax.mail.MessagingException
protected java.util.Collection getRecipients(Mail originalMail) throws javax.mail.MessagingException
recipients
property,
built dynamically using the original Mail object.
Is a "getX(Mail)" method.
replaceMailAddresses(org.apache.mailet.Mail, java.util.Collection)
on getRecipients()
,
javax.mail.MessagingException
protected void setRecipients(Mail newMail, java.util.Collection recipients, Mail originalMail) throws javax.mail.MessagingException
javax.mail.MessagingException
protected javax.mail.internet.InternetAddress[] getTo() throws javax.mail.MessagingException
to
property.
Returns the "To:" recipients of the new message.
or null if no change is requested.
Is a "getX()" method.
to
init parameter
or the postmaster address
or SpecialAddress.SENDER
or SpecialAddress.REVERSE_PATH
or SpecialAddress.FROM
or SpecialAddress.REPLY_TO
or SpecialAddress.UNALTERED
or SpecialAddress.TO
or null
if missing
javax.mail.MessagingException
protected javax.mail.internet.InternetAddress[] getTo(Mail originalMail) throws javax.mail.MessagingException
to
property,
built dynamically using the original Mail object.
Its outcome will be the the value the TO: header will be set to,
that could be different from the real recipient (see getRecipients()
).
Is a "getX(Mail)" method.
replaceInternetAddresses(org.apache.mailet.Mail, java.util.Collection)
on getRecipients()
,
javax.mail.MessagingException
protected void setTo(Mail newMail, javax.mail.internet.InternetAddress[] to, Mail originalMail) throws javax.mail.MessagingException
javax.mail.MessagingException
protected MailAddress getReplyTo() throws javax.mail.MessagingException
replyto
property.
Returns the Reply-To address of the new message,
or null if no change is requested.
Is a "getX()" method.
replyto
init parameter
or the postmaster address
or SpecialAddress.SENDER
or SpecialAddress.UNALTERED
or SpecialAddress.NULL
or null
if missing
javax.mail.MessagingException
protected MailAddress getReplyTo(Mail originalMail) throws javax.mail.MessagingException
replyTo
property,
built dynamically using the original Mail object.
Is a "getX(Mail)" method.
getReplyTo()
replacing SpecialAddress.UNALTERED
if applicable with null
and SpecialAddress.SENDER
with the original mail sender
javax.mail.MessagingException
protected void setReplyTo(Mail newMail, MailAddress replyTo, Mail originalMail) throws javax.mail.MessagingException
Sets the "Reply-To:" header of newMail to replyTo.
If the requested value isSpecialAddress.NULL
will remove the "Reply-To:" header.
If the requested value is null does nothing.
Is a "setX(Mail, Tx, Mail)" method.
javax.mail.MessagingException
protected MailAddress getReversePath() throws javax.mail.MessagingException
reversePath
property.
Returns the reverse-path of the new message,
or null if no change is requested.
Is a "getX()" method.
reversePath
init parameter
or the postmaster address
or SpecialAddress.SENDER
or SpecialAddress.NULL
or SpecialAddress.UNALTERED
or null
if missing
javax.mail.MessagingException
protected MailAddress getReversePath(Mail originalMail) throws javax.mail.MessagingException
reversePath
property,
built dynamically using the original Mail object.
Is a "getX(Mail)" method.
getReversePath()
,
replacing SpecialAddress.SENDER
if applicable with null,
replacing SpecialAddress.UNALTERED
and SpecialAddress.REVERSE_PATH
if applicable with null,
but not replacing SpecialAddress.NULL
that will be handled by setReversePath(org.apache.james.core.MailImpl, org.apache.mailet.MailAddress, org.apache.mailet.Mail)
javax.mail.MessagingException
protected void setReversePath(MailImpl newMail, MailAddress reversePath, Mail originalMail) throws javax.mail.MessagingException
SpecialAddress.NULL
sets it to "<>".
If the requested value is null does nothing.
Is a "setX(Mail, Tx, Mail)" method.
javax.mail.MessagingException
protected MailAddress getSender() throws javax.mail.MessagingException
sender
property.
Returns the new sender as a MailAddress,
or null if no change is requested.
Is a "getX()" method.
sender
init parameter
or the postmaster address
or SpecialAddress.SENDER
or SpecialAddress.UNALTERED
or null
if missing
javax.mail.MessagingException
protected MailAddress getSender(Mail originalMail) throws javax.mail.MessagingException
sender
property,
built dynamically using the original Mail object.
Is a "getX(Mail)" method.
getSender()
replacing SpecialAddress.UNALTERED
and SpecialAddress.SENDER
if applicable with null
javax.mail.MessagingException
protected void setSender(Mail newMail, MailAddress sender, Mail originalMail) throws javax.mail.MessagingException
javax.mail.MessagingException
protected java.lang.String getSubject() throws javax.mail.MessagingException
subject
property.
Returns a string for the new message subject.
Is a "getX()" method.
subject
init parameter or null if missing
javax.mail.MessagingException
protected java.lang.String getSubject(Mail originalMail) throws javax.mail.MessagingException
subject
property,
built dynamically using the original Mail object.
Is a "getX(Mail)" method.
getSubject()
javax.mail.MessagingException
protected java.lang.String getSubjectPrefix() throws javax.mail.MessagingException
prefix
property.
Returns a prefix for the new message subject.
Is a "getX()" method.
prefix
init parameter or an empty string if missing
javax.mail.MessagingException
protected java.lang.String getSubjectPrefix(Mail originalMail) throws javax.mail.MessagingException
subjectPrefix
property,
built dynamically using the original Mail object.
Is a "getX(Mail)" method.
getSubjectPrefix()
javax.mail.MessagingException
protected void setSubjectPrefix(Mail newMail, java.lang.String subjectPrefix, Mail originalMail) throws javax.mail.MessagingException
javax.mail.MessagingException
protected boolean attachError() throws javax.mail.MessagingException
attachError
property.
Returns a boolean indicating whether to append a description of any error to the main body part
of the new message, if getInlineType does not return "UNALTERED".
Is a "getX()" method.
attachError
init parameter; false if missing
javax.mail.MessagingException
protected boolean attachError(Mail originalMail) throws javax.mail.MessagingException
attachError
property,
built dynamically using the original Mail object.
Is a "getX(Mail)" method.
attachError()
javax.mail.MessagingException
protected boolean isReply() throws javax.mail.MessagingException
isReply
property.
Returns a boolean indicating whether the new message must be considered
a reply to the original message, setting the IN_REPLY_TO header of the new
message to the id of the original message.
Is a "getX()" method.
isReply
init parameter; false if missing
javax.mail.MessagingException
protected boolean isReply(Mail originalMail) throws javax.mail.MessagingException
isReply
property,
built dynamically using the original Mail object.
Is a "getX(Mail)" method.
isReply()
javax.mail.MessagingException
protected void setIsReply(Mail newMail, boolean isReply, Mail originalMail) throws javax.mail.MessagingException
javax.mail.MessagingException
public void init() throws javax.mail.MessagingException
isStatic()
returns true.
init
in class GenericMailet
javax.mail.MessagingException
- if an exception occurs that interrupts the mailet's normal operationpublic void service(Mail originalMail) throws javax.mail.MessagingException
service
in interface Mailet
service
in class GenericMailet
originalMail
- the mail to process and redirect
javax.mail.MessagingException
- if a problem arises formulating the redirected mailprotected int getTypeCode(java.lang.String param)
param
- the string type
protected java.lang.String getMessageHeaders(javax.mail.internet.MimeMessage message) throws javax.mail.MessagingException
javax.mail.MessagingException
protected void buildAlteredMessage(Mail newMail, Mail originalMail) throws javax.mail.MessagingException
originalMail
- the original Mail objectnewMail
- the Mail object to build
javax.mail.MessagingException
protected final MailAddress getSpecialAddress(java.lang.String addressString, java.lang.String[] allowedSpecials) throws javax.mail.MessagingException
AbstractRedirect.SpecialAddress
that corresponds to an init parameter value.
The init parameter value is checked against a String[] of allowed values.
The checks are case insensitive.
addressString
- the string to check if is a special addressallowedSpecials
- a String[] with the allowed special addresses
javax.mail.MessagingException
- if is a special address not in the allowedSpecials arrayprotected final boolean senderDomainIsValid(Mail mail) throws javax.mail.MessagingException
Checks if a sender domain of mail is valid.
If we do not do this check, and someone uses a redirection mailet in a
processor initiated by SenderInFakeDomain, then a fake
sender domain will cause an infinite loop (the forwarded
e-mail still appears to come from a fake domain).
Although this can be viewed as a configuration error, the
consequences of such a mis-configuration are severe enough
to warrant protecting against the infinite loop.
This check can be skipped if getFakeDomainCheck(Mail)
returns true.
mail
- the mail object to check
MailetContext.getMailServers(java.lang.String)
returns true for
the sender host part
javax.mail.MessagingException
public static void changeSubject(javax.mail.internet.MimeMessage message, java.lang.String newValue) throws javax.mail.MessagingException
message
- the message of which subject is changednewValue
- the new (unencoded) value of the subject. It must
not be null.
javax.mail.MessagingException
- - according to the JavaMail doc most likely
this is never thrownprotected java.util.Collection replaceMailAddresses(Mail mail, java.util.Collection list)
MailAddress
-es.SpecialAddress.SENDER
, SpecialAddress.REVERSE_PATH
,
SpecialAddress.FROM
, SpecialAddress.REPLY_TO
,
SpecialAddress.RECIPIENTS
, SpecialAddress.TO
,
SpecialAddress.NULL
and SpecialAddress.UNALTERED
.SpecialAddress.FROM
is made equivalent to SpecialAddress.SENDER
;
SpecialAddress.TO
is made equivalent to SpecialAddress.RECIPIENTS
.SpecialAddress.REPLY_TO
uses the ReplyTo header if available, otherwise the
From header if available, otherwise the Sender header if available, otherwise the return-path.SpecialAddress.NULL
and SpecialAddress.UNALTERED
are ignored.
protected java.util.Collection replaceInternetAddresses(Mail mail, java.util.Collection list) throws javax.mail.MessagingException
InternetAddress
-es.SpecialAddress.SENDER
, SpecialAddress.REVERSE_PATH
,
SpecialAddress.FROM
, SpecialAddress.REPLY_TO
,
SpecialAddress.RECIPIENTS
, SpecialAddress.TO
,
SpecialAddress.NULL
and SpecialAddress.UNALTERED
.SpecialAddress.RECIPIENTS
is made equivalent to SpecialAddress.TO
.SpecialAddress.FROM
uses the From header if available, otherwise the Sender header if available,
otherwise the return-path.SpecialAddress.REPLY_TO
uses the ReplyTo header if available, otherwise the
From header if available, otherwise the Sender header if available, otherwise the return-path.SpecialAddress.UNALTERED
is ignored.
javax.mail.MessagingException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |