org.apache.james.transport.mailets
Class ReplaceContent

java.lang.Object
  extended by org.apache.mailet.base.GenericMailet
      extended by org.apache.james.transport.mailets.ReplaceContent
All Implemented Interfaces:
Mailet, MailetConfig

public class ReplaceContent
extends GenericMailet

Replace text contents

This mailet allow to specific regular expression to replace text in subject and content.

Each expression is defined as: /REGEX_PATTERN/SUBSTITUTION_PATTERN/FLAGS/

REGEX_PATTERN is a regex used for the match
SUBSTITUTION_PATTERN is a substitution pattern
FLAGS flags supported for the pattern:
i: case insensitive
m: multi line
x: extended (N/A)
r: repeat - keep matching until a substitution is possible

To identify subject and body pattern we use the tags <subjectPattern> and <bodyPattern>

Rules can be specified in external files. Lines must be CRLF terminated and lines starting with # are considered commments. Tags used to include external files are <subjectPatternFile> and <bodyPatternFile> If file path starts with # then the file is loaded as a reasource.

Use of both files and direct patterns at the same time is allowed.

This mailet allow also to enforce the resulting charset for messages processed. To do that the tag <charset> must be specified.

NOTE: Regexp rules must be escaped by regexp excaping rules and applying this 2 additional rules:
- "/" char inside an expression must be prefixed with "\": e.g: "/\//-//" replaces "/" with "-"
- when the rules are specified using <subjectPattern> or <bodyPattern> and "/,/" has to be used in a pattern string it must be prefixed with a "\". E.g: "/\/\/,//" replaces "/" with "," (the rule would be "/\//,//" but the "/,/" must be escaped.


Field Summary
static int FLAG_REPEAT
           
 
Constructor Summary
ReplaceContent()
           
 
Method Summary
protected static java.lang.String applyPatterns(java.util.regex.Pattern[] patterns, java.lang.String[] substitutions, java.lang.Integer[] pflags, java.lang.String text, int debug, GenericMailet logOwner)
           
 java.lang.String getMailetInfo()
          returns a String describing this mailet.
protected static java.lang.Object[] getPattern(java.lang.String line)
           
protected static java.util.List[] getPatternsFromStream(java.io.InputStream stream, java.lang.String charset)
           
protected static java.util.List[] getPatternsFromString(java.lang.String pattern)
           
 void init()
           
 void service(Mail mail)
           
 
Methods inherited from class org.apache.mailet.base.GenericMailet
arrayToString, checkInitParameters, destroy, getInitParameter, getInitParameter, 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
 

Field Detail

FLAG_REPEAT

public static final int FLAG_REPEAT
See Also:
Constant Field Values
Constructor Detail

ReplaceContent

public ReplaceContent()
Method Detail

getMailetInfo

public java.lang.String getMailetInfo()
returns a String describing this mailet.

Specified by:
getMailetInfo in interface Mailet
Overrides:
getMailetInfo in class GenericMailet
Returns:
A desciption of this mailet

getPattern

protected static java.lang.Object[] getPattern(java.lang.String line)
                                        throws MailetException
Returns:
an array containing Pattern and Substitution of the input stream
Throws:
MailetException

getPatternsFromString

protected static java.util.List[] getPatternsFromString(java.lang.String pattern)
                                                 throws MailetException
Throws:
MailetException

getPatternsFromStream

protected static java.util.List[] getPatternsFromStream(java.io.InputStream stream,
                                                        java.lang.String charset)
                                                 throws MailetException,
                                                        java.io.IOException
Throws:
MailetException
java.io.IOException

applyPatterns

protected static java.lang.String applyPatterns(java.util.regex.Pattern[] patterns,
                                                java.lang.String[] substitutions,
                                                java.lang.Integer[] pflags,
                                                java.lang.String text,
                                                int debug,
                                                GenericMailet logOwner)

init

public void init()
          throws MailetException
Overrides:
init in class GenericMailet
Throws:
MailetException

service

public void service(Mail mail)
             throws MailetException
Specified by:
service in interface Mailet
Specified by:
service in class GenericMailet
Throws:
MailetException


Copyright © 2008-2009 The Apache Software Foundation. All Rights Reserved.