View Javadoc

1   /************************************************************************
2    * Copyright (c) 2000-2006 The Apache Software Foundation.             *
3    * All rights reserved.                                                *
4    * ------------------------------------------------------------------- *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you *
6    * may not use this file except in compliance with the License. You    *
7    * may obtain a copy of the License at:                                *
8    *                                                                     *
9    *     http://www.apache.org/licenses/LICENSE-2.0                      *
10   *                                                                     *
11   * Unless required by applicable law or agreed to in writing, software *
12   * distributed under the License is distributed on an "AS IS" BASIS,   *
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
14   * implied.  See the License for the specific language governing       *
15   * permissions and limitations under the License.                      *
16   ***********************************************************************/
17  
18  package org.apache.james.transport.mailets;
19  
20  /***
21   * <P>A mailet providing configurable redirection services.</P>
22   * <P>Can produce listserver, forward and notify behaviour, with the original
23   * message intact, attached, appended or left out altogether.
24   * Can be used as a replacement to {@link Redirect}, having more consistent defaults,
25   * and new options available.<BR>
26   * Use <CODE>Resend</CODE> if you need full control, <CODE>Redirect</CODE> if
27   * the more automatic behaviour of some parameters is appropriate.</P>
28   * <P>This built in functionality is controlled by the configuration as laid out below.
29   * In the table please note that the parameters controlling message headers
30   * accept the <B>&quot;unaltered&quot;</B> value, whose meaning is to keep the associated
31   * header unchanged and, unless stated differently, corresponds to the assumed default
32   * if the parameter is missing.</P>
33   * <P>The configuration parameters are:</P>
34   * <TABLE width="75%" border="1" cellspacing="2" cellpadding="2">
35   * <TR valign=top>
36   * <TD width="20%">&lt;recipients&gt;</TD>
37   * <TD width="80%">
38   * A comma delimited list of addresses for recipients of this message.<BR>
39   * Such addresses can contain &quot;full names&quot;, like
40   * <I>Mr. John D. Smith &lt;john.smith@xyz.com&gt;</I>.<BR>
41   * The list can include constants &quot;sender&quot;, &quot;from&quot;, &quot;replyTo&quot;, &quot;postmaster&quot;, &quot;reversePath&quot;, &quot;recipients&quot;, &quot;to&quot;, &quot;null&quot; and &quot;unaltered&quot;;
42   * &quot;replyTo&quot; uses the ReplyTo header if available, otherwise the
43   * From header if available, otherwise the Sender header if available, otherwise the return-path;
44   * &quot;from&quot; is made equivalent to &quot;sender&quot;, and &quot;to&quot; is made equivalent to &quot;recipients&quot;;
45   * &quot;null&quot; is ignored.
46   * Default: &quot;unaltered&quot;.
47   * </TD>
48   * </TR>
49   * <TR valign=top>
50   * <TD width="20%">&lt;to&gt;</TD>
51   * <TD width="80%">
52   * A comma delimited list of addresses to appear in the To: header.<BR>
53   * Such addresses can contain &quot;full names&quot;, like
54   * <I>Mr. John D. Smith &lt;john.smith@xyz.com&gt;</I>.<BR>
55   * The list can include constants &quot;sender&quot;, &quot;from&quot;, &quot;replyTo&quot;, &quot;postmaster&quot;, &quot;reversePath&quot;, &quot;recipients&quot;, &quot;to&quot;, &quot;null&quot; and &quot;unaltered&quot;;
56   * &quot;from&quot; uses the From header if available, otherwise the Sender header if available,
57   * otherwise the return-path;
58   * &quot;replyTo&quot; uses the ReplyTo header if available, otherwise the
59   * From header if available, otherwise the Sender header if available, otherwise the return-path;
60   * &quot;recipients&quot; is made equivalent to &quot;to&quot;;
61   * if &quot;null&quot; is specified alone it will remove this header.
62   * Default: &quot;unaltered&quot;.
63   * </TD>
64   * </TR>
65   * <TR valign=top>
66   * <TD width="20%">&lt;sender&gt;</TD>
67   * <TD width="80%">
68   * A single email address to appear in the From: header and become the sender.<BR>
69   * It can include constants &quot;sender&quot;, &quot;postmaster&quot; and &quot;unaltered&quot;;
70   * &quot;sender&quot; is equivalent to &quot;unaltered&quot;.<BR>
71   * Default: &quot;unaltered&quot;.
72   * </TD>
73   * </TR>
74   * <TR valign=top>
75   * <TD width="20%">&lt;message&gt;</TD>
76   * <TD width="80%">
77   * A text message to insert into the body of the email.<BR>
78   * Default: no message is inserted.
79   * </TD>
80   * </TR>
81   * <TR valign=top>
82   * <TD width="20%">&lt;inline&gt;</TD>
83   * <TD width="80%">
84   * <P>One of the following items:</P>
85   * <UL>
86   * <LI>unaltered &nbsp;&nbsp;&nbsp;&nbsp;The original message is the new
87   * message, for forwarding/aliasing</LI>
88   * <LI>heads&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The
89   * headers of the original message are appended to the message</LI>
90   * <LI>body&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The
91   * body of the original is appended to the new message</LI>
92   * <LI>all&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Both
93   * headers and body are appended</LI>
94   * <LI>none&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Neither
95   * body nor headers are appended</LI>
96   * </UL>
97   * Default: &quot;unaltered&quot;.
98   * </TD>
99   * </TR>
100  * <TR valign=top>
101  * <TD width="20%">&lt;attachment&gt;</TD>
102  * <TD width="80%">
103  * <P>One of the following items:</P>
104  * <UL>
105  * <LI>heads&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The headers of the original
106  * are attached as text</LI>
107  * <LI>body&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The body of the original
108  * is attached as text</LI>
109  * <LI>all&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Both
110  * headers and body are attached as a single text file</LI>
111  * <LI>none&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Nothing is attached</LI>
112  * <LI>message &nbsp;The original message is attached as type message/rfc822,
113  * this means that it can, in many cases, be opened, resent, fw'd, replied
114  * to etc by email client software.</LI>
115  * </UL>
116  * Default: &quot;none&quot;.
117  * </TD>
118  * </TR>
119  * <TR valign=top>
120  * <TD width="20%">&lt;passThrough&gt;</TD>
121  * <TD width="80%">
122  * true or false, if true the original message continues in the
123  * mailet processor after this mailet is finished. False causes the original
124  * to be stopped.<BR>
125  * Default: false.
126  * </TD>
127  * </TR>
128  * <TR valign=top>
129  * <TD width="20%">&lt;fakeDomainCheck&gt;</TD>
130  * <TD width="80%">
131  * true or false, if true will check if the sender domain is valid.<BR>
132  * Default: true.
133  * </TD>
134  * </TR>
135  * <TR valign=top>
136  * <TD width="20%">&lt;attachError&gt;</TD>
137  * <TD width="80%">
138  * true or false, if true any error message available to the
139  * mailet is appended to the message body (except in the case of inline ==
140  * unaltered).<BR>
141  * Default: false.
142  * </TD>
143  * </TR>
144  * <TR valign=top>
145  * <TD width="20%">&lt;replyTo&gt;</TD>
146  * <TD width="80%">
147  * A single email address to appear in the Reply-To: header.<BR>
148  * It can include constants &quot;sender&quot;, &quot;postmaster&quot; &quot;null&quot; and &quot;unaltered&quot;;
149  * if &quot;null&quot; is specified it will remove this header.<BR>
150  * Default: &quot;unaltered&quot;.
151  * </TD>
152  * </TR>
153  * <TR valign=top>
154  * <TD width="20%">&lt;reversePath&gt;</TD>
155  * <TD width="80%">
156  * A single email address to appear in the Return-Path: header.<BR>
157  * It can include constants &quot;sender&quot;, &quot;postmaster&quot; &quot;null&quot; and &quot;unaltered&quot;;
158  * if &quot;null&quot; is specified then it will set it to <>, meaning &quot;null return path&quot;.<BR>
159  * Default: &quot;unaltered&quot;.
160  * </TD>
161  * </TR>
162  * <TR valign=top>
163  * <TD width="20%">&lt;subject&gt;</TD>
164  * <TD width="80%">
165  * An optional string to use as the subject.<BR>
166  * Default: keep the original message subject.
167  * </TD>
168  * </TR>
169  * <TR valign=top>
170  * <TD width="20%">&lt;prefix&gt;</TD>
171  * <TD width="80%">
172  * An optional subject prefix prepended to the original message
173  * subject, or to a new subject specified with the <I>&lt;subject&gt;</I> parameter.<BR>
174  * For example: <I>[Undeliverable mail]</I>.<BR>
175  * Default: &quot;&quot;.
176  * </TD>
177  * </TR>
178  * <TR valign=top>
179  * <TD width="20%">&lt;isReply&gt;</TD>
180  * <TD width="80%">
181  * true or false, if true the IN_REPLY_TO header will be set to the
182  * id of the current message.<BR>
183  * Default: false.
184  * </TD>
185  * </TR>
186  * <TR valign=top>
187  * <TD width="20%">&lt;debug&gt;</TD>
188  * <TD width="80%">
189  * true or false.  If this is true it tells the mailet to write some debugging
190  * information to the mailet log.<BR>
191  * Default: false.
192  * </TD>
193  * </TR>
194  * </TABLE>
195  *
196  * <P>Example:</P>
197  * <PRE><CODE>
198  *  &lt;mailet match=&quot;RecipientIs=test@localhost&quot; class=&quot;Resend&quot;&gt;
199  *    &lt;recipients&gt;x@localhost, y@localhost, z@localhost&lt;/recipients&gt;
200  *    &lt;to&gt;list@localhost&lt;/to&gt;
201  *    &lt;sender&gt;owner@localhost&lt;/sender&gt;
202  *    &lt;message&gt;sent on from James&lt;/message&gt;
203  *    &lt;inline&gt;unaltered&lt;/inline&gt;
204  *    &lt;passThrough&gt;FALSE&lt;/passThrough&gt;
205  *    &lt;replyTo&gt;postmaster&lt;/replyTo&gt;
206  *    &lt;prefix xml:space="preserve"&gt;[test mailing] &lt;/prefix&gt;
207  *    &lt;!-- note the xml:space="preserve" to preserve whitespace --&gt;
208  *    &lt;static&gt;TRUE&lt;/static&gt;
209  * &lt;/mailet&gt;
210  * </CODE></PRE>
211  * 
212  * <P>and:</P>
213  *
214  * <PRE><CODE>
215  *  &lt;mailet match=&quot;All&quot; class=&quot;Resend&quot;&gt;
216  *    &lt;recipients&gt;x@localhost&lt;/recipients&gt;
217  *    &lt;sender&gt;postmaster&lt;/sender&gt;
218  *    &lt;message xml:space="preserve"&gt;Message marked as spam:&lt;/message&gt;
219  *    &lt;inline&gt;heads&lt;/inline&gt;
220  *    &lt;attachment&gt;message&lt;/attachment&gt;
221  *    &lt;passThrough&gt;FALSE&lt;/passThrough&gt;
222  *    &lt;attachError&gt;TRUE&lt;/attachError&gt;
223  *    &lt;replyTo&gt;postmaster&lt;/replyTo&gt;
224  *    &lt;prefix&gt;[spam notification]&lt;/prefix&gt;
225  *  &lt;/mailet&gt;
226  * </CODE></PRE>
227  *
228  * <P>The following example forwards the message without any modification, based on the defaults:</P>
229  * <PRE><CODE>
230  *  &lt;mailet match=&quot;All&quot; class=&quot;Resend&quot/;&gt;
231  * </CODE></PRE>
232  * <P><I>replyto</I> can be used instead of
233  * <I>replyTo</I>; such name is kept for backward compatibility.</P>
234  * <P><B>WARNING: as the message (or a copy of it) is reinjected in the spool without any modification,
235  * the preceding example is very likely to cause a "configuration loop" in your system,
236  * unless some other mailet has previously modified something (a header for instance) that could force the resent
237  * message follow a different path so that it does not return here unchanged.</B></P>
238  *
239  * @version CVS $Revision: 382444 $ $Date: 2006-03-02 16:56:32 +0000 (gio, 02 mar 2006) $
240  * @since 2.2.0
241  */
242 
243 public class Resend extends AbstractRedirect {
244 
245     /***
246      * Returns a string describing this mailet.
247      *
248      * @return a string describing this mailet
249      */
250     public String getMailetInfo() {
251         return "Redirect Mailet";
252     }
253 
254     /*** Gets the expected init parameters. */
255     protected  String[] getAllowedInitParameters() {
256         String[] allowedArray = {
257 //            "static",
258             "debug",
259             "passThrough",
260             "fakeDomainCheck",
261             "inline",
262             "attachment",
263             "message",
264             "recipients",
265             "to",
266             "replyTo",
267             "replyto",
268             "reversePath",
269             "sender",
270             "subject",
271             "prefix",
272             "attachError",
273             "isReply"
274         };
275         return allowedArray;
276     }
277 
278     /* ******************************************************************** */
279     /* ****************** Begin of getX and setX methods ****************** */
280     /* ******************************************************************** */
281 
282     /* ******************************************************************** */
283     /* ******************* End of getX and setX methods ******************* */
284     /* ******************************************************************** */
285 
286 }