001: /****************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one *
003: * or more contributor license agreements. See the NOTICE file *
004: * distributed with this work for additional information *
005: * regarding copyright ownership. The ASF licenses this file *
006: * to you under the Apache License, Version 2.0 (the *
007: * "License"); you may not use this file except in compliance *
008: * with the License. You may obtain a copy of the License at *
009: * *
010: * http://www.apache.org/licenses/LICENSE-2.0 *
011: * *
012: * Unless required by applicable law or agreed to in writing, *
013: * software distributed under the License is distributed on an *
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
015: * KIND, either express or implied. See the License for the *
016: * specific language governing permissions and limitations *
017: * under the License. *
018: ****************************************************************/package org.apache.james.transport.mailets;
019:
020: import org.apache.mailet.MailAddress;
021:
022: import javax.mail.MessagingException;
023: import javax.mail.internet.InternetAddress;
024: import java.util.HashSet;
025: import java.util.Collection;
026:
027: /**
028: * <P>Sends a notification message to the sender of a message.</P>
029: * <P>A sender of the notification message can optionally be specified.
030: * If one is not specified, the postmaster's address will be used.<BR>
031: * The "To:" header of the notification message can be set to "unaltered";
032: * if missing will be set to the sender of the notified message.<BR>
033: * A notice text can be specified, and in such case will be inserted into the
034: * notification inline text.<BR>
035: * If the notified message has an "error message" set, it will be inserted into the
036: * notification inline text. If the <CODE>attachStackTrace</CODE> init parameter
037: * is set to true, such error message will be attached to the notification message.<BR>
038: * The notified messages are attached in their entirety (headers and
039: * content) and the resulting MIME part type is "message/rfc822".</P>
040: * <P>Supports the <CODE>passThrough</CODE> init parameter (true if missing).</P>
041: *
042: * <P>Sample configuration:</P>
043: * <PRE><CODE>
044: * <mailet match="All" class="NotifySender">
045: * <sender><I>an address or postmaster or sender or unaltered, default=postmaster</I></sender>
046: * <attachError><I>true or false, default=false</I></attachError>
047: * <prefix><I>optional subject prefix prepended to the original message</I></prefix>
048: * <inline><I>see {@link Resend}, default=none</I></inline>
049: * <attachment><I>see {@link Resend}, default=message</I></attachment>
050: * <passThrough><I>true or false, default=true</I></passThrough>
051: * <fakeDomainCheck><I>true or false, default=true</I></fakeDomainCheck>
052: * <to><I>unaltered or sender or from(optional, defaults to sender)</I></to>
053: * <debug><I>true or false, default=false</I></debug>
054: * </mailet>
055: * </CODE></PRE>
056: *
057: * <P>The behaviour of this mailet is equivalent to using Resend with the following
058: * configuration:</P>
059: * <PRE><CODE>
060: * <mailet match="All" class="Resend">
061: * <sender><I>an address or postmaster or sender or unaltered</I></sender>
062: * <attachError><I>true or false</I></attachError>
063: * <message><I><B>dynamically built</B></I></message>
064: * <prefix><I>a string</I></prefix>
065: * <passThrough>true</passThrough>
066: * <fakeDomainCheck><I>true or false</I></fakeDomainCheck>
067: * <to><I>unaltered or sender or from<</I>;/to>
068: * <recipients><B>sender</B></recipients>
069: * <inline>none</inline>
070: * <attachment>message</attachment>
071: * <isReply>true</isReply>
072: * <debug><I>true or false</I></debug>
073: * </mailet>
074: * </CODE></PRE>
075: * <P><I>notice</I>, <I>sendingAddress</I> and <I>attachStackTrace</I> can be used instead of
076: * <I>message</I>, <I>sender</I> and <I>attachError</I>; such names are kept for backward compatibility.</P>
077: *
078: * @version CVS $Revision: 494012 $ $Date: 2007-01-08 11:23:58 +0100 (Mo, 08 Jan 2007) $
079: */
080: public class NotifySender extends AbstractNotify {
081:
082: /**
083: * Return a string describing this mailet.
084: *
085: * @return a string describing this mailet
086: */
087: public String getMailetInfo() {
088: return "NotifySender Mailet";
089: }
090:
091: /** Gets the expected init parameters. */
092: protected String[] getAllowedInitParameters() {
093: String[] allowedArray = {
094: // "static",
095: "debug", "passThrough", "fakeDomainCheck", "inline",
096: "attachment", "message", "notice", "sender",
097: "sendingAddress", "prefix", "attachError",
098: "attachStackTrace", "to" };
099: return allowedArray;
100: }
101:
102: /* ******************************************************************** */
103: /* ****************** Begin of getX and setX methods ****************** */
104: /* ******************************************************************** */
105:
106: /**
107: * @return <CODE>SpecialAddress.SENDER</CODE>, indicating the sender of the current mail
108: */
109: protected Collection getRecipients() {
110: Collection newRecipients = new HashSet();
111: newRecipients.add(SpecialAddress.SENDER);
112: return newRecipients;
113: }
114:
115: /**
116: * @return <CODE>SpecialAddress.UNALTERED</CODE> if specified or <CODE>SpecialAddress.SENDER</CODE> if missing
117: */
118: protected InternetAddress[] getTo() throws MessagingException {
119: String addressList = getInitParameter("to");
120: InternetAddress[] iaarray = new InternetAddress[1];
121: iaarray[0] = SpecialAddress.SENDER.toInternetAddress();
122: if (addressList != null) {
123: MailAddress specialAddress = getSpecialAddress(addressList,
124: new String[] { "sender", "unaltered", "from" });
125: if (specialAddress != null) {
126: iaarray[0] = specialAddress.toInternetAddress();
127: } else {
128: log("\"to\" parameter ignored, set to sender");
129: }
130: }
131: return iaarray;
132: }
133:
134: /**
135: * @return the <CODE>attachStackTrace</CODE> init parameter,
136: * or the <CODE>attachError</CODE> init parameter if missing,
137: * or false if missing
138: */
139: protected boolean attachError() throws MessagingException {
140: String parameter = getInitParameter("attachStackTrace");
141: if (parameter == null) {
142: return super .attachError();
143: }
144: return new Boolean(parameter).booleanValue();
145: }
146:
147: /* ******************************************************************** */
148: /* ******************* End of getX and setX methods ******************* */
149: /* ******************************************************************** */
150:
151: }
|