KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > transport > mailets > Resend


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

270
271 public class Resend extends AbstractRedirect {
272
273     /**
274      * Returns a string describing this mailet.
275      *
276      * @return a string describing this mailet
277      */

278     public String JavaDoc getMailetInfo() {
279         return "Redirect Mailet";
280     }
281
282     /** Gets the expected init parameters. */
283     protected String JavaDoc[] getAllowedInitParameters() {
284         String JavaDoc[] allowedArray = {
285 // "static",
286
"debug",
287             "passThrough",
288             "fakeDomainCheck",
289             "inline",
290             "attachment",
291             "message",
292             "recipients",
293             "to",
294             "replyTo",
295             "replyto",
296             "reversePath",
297             "sender",
298             "subject",
299             "prefix",
300             "attachError",
301             "isReply"
302         };
303         return allowedArray;
304     }
305
306     /* ******************************************************************** */
307     /* ****************** Begin of getX and setX methods ****************** */
308     /* ******************************************************************** */
309
310     /* ******************************************************************** */
311     /* ******************* End of getX and setX methods ******************* */
312     /* ******************************************************************** */
313
314 }
315
Popular Tags