Class RecipientRewriteProcessor

java.lang.Object
ch.tocco.nice2.messaging.mail.impl.processor.RecipientRewriteProcessor
All Implemented Interfaces:
MessageProcessor

@Component @Order(0) public class RecipientRewriteProcessor extends Object implements MessageProcessor
This processor can rewrite recipient addresses according to a configured set of mapping rules.

The mapping rules are defined in application[.local].properties by specifying a string, for example:

     recipientrewrite.mappings=(.*?)@tocco.ch -> $1@tocco.ch; * -> fallback@tocco.ch
 
The string contains rules separated by semi-colon "`;`". A rule is a simple mapping of type from -> to, where from is a regular expression and to a replacement expression. If no mappings are defined, this processor is simply skipped. Each from part is matched against a single email address of form localpart@domainpart (without personal information). If the regex finds a match in the input, the replacement part is applied to it. The replacement string can refer to matched groups as described in Matcher.appendReplacement(StringBuffer, String). The rules are applied in the order they occur in the string. The first rule whose from part matches the input email address wins and is applied.

The character * is special and expands automatically to the regular expression ^.*$, matching every email address. So to simply redirect every mail to a central "catch-all" address, use this mapping:

     recipientrewrite.mappings=* -> fallback@tocco.ch
 
Every recipient address in the mail is replaced according to this scheme. It applies to all recipient types TO, CC and BCC. The personal information in the original recipient address is retained.

It's possible to map one address to a list of other addresses by separating the addresses by comma "`,`":

     recipientrewrite.mappings=(.*?)@tocco.ch -> $1-mail1@tocco.ch, $1-mail2@tocco.ch; * -> fallback@tocco.ch
 
In the example above, mails to support@tocco.ch would be sent to support-mail1@tocco.ch and support-mail2@tocco.ch.

Group addresses are replaced by their individual addresses. The group information (the name) will be lost.

See Also:
  • Constructor Details

    • RecipientRewriteProcessor

      public RecipientRewriteProcessor()
  • Method Details