org.apache.james.mailet.standard.mailets
Class ReplaceContent

java.lang.Object
  extended by org.apache.mailet.base.GenericMailet
      extended by org.apache.james.mailet.standard.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 String applyPatterns(Pattern[] patterns, String[] substitutions, Integer[] pflags, String text, int debug, GenericMailet logOwner)
           
 String getMailetInfo()
          returns a String describing this mailet.
protected static PatternBean getPattern(String line)
           
protected static PatternList getPatternsFromStream(InputStream stream, String charset)
           
protected static PatternList getPatternsFromString(String pattern)
           
 void init()
          A convenience method which can be overridden so that there's no need to call super.init(config).
 void service(Mail mail)
          Called by the mailet container to allow the mailet to process a message.
 
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 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 PatternBean getPattern(String line)
                                 throws MailetException
Returns:
an array containing Pattern and Substitution of the input stream
Throws:
MailetException

getPatternsFromString

protected static PatternList getPatternsFromString(String pattern)
                                            throws MailetException
Throws:
MailetException

getPatternsFromStream

protected static PatternList getPatternsFromStream(InputStream stream,
                                                   String charset)
                                            throws MailetException,
                                                   IOException
Throws:
MailetException
IOException

applyPatterns

protected static String applyPatterns(Pattern[] patterns,
                                      String[] substitutions,
                                      Integer[] pflags,
                                      String text,
                                      int debug,
                                      GenericMailet logOwner)

init

public void init()
          throws MailetException
Description copied from class: GenericMailet

A convenience method which can be overridden so that there's no need to call super.init(config).

Instead of overriding init(MailetConfig), simply override this method and it will be called by GenericMailet.init(MailetConfig config). The MailetConfig object can still be retrieved via getMailetConfig().

Overrides:
init in class GenericMailet
Throws:
MailetException

service

public void service(Mail mail)
             throws MailetException
Description copied from class: GenericMailet

Called by the mailet container to allow the mailet to process a message.

This method is declared abstract so subclasses must override it.

Specified by:
service in interface Mailet
Specified by:
service in class GenericMailet
Parameters:
mail - - the Mail object that contains the MimeMessage and routing information
Throws:
MailetException


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