redirect.java

来自「java 开发的邮件服务器平台。支持以下协议。 协议可以修改为自己的专门标识」· Java 代码 · 共 466 行 · 第 1/2 页

JAVA
466
字号
 * <TD width="80%"> * true or false.  If this is true it tells the mailet that it can * reuse all the initial parameters (to, from, etc) without re-calculating * their values.  This will boost performance where a redirect task * doesn't contain any dynamic values.  If this is false, it tells the * mailet to recalculate the values for each e-mail processed.<BR> * Default: false. * </TD> * </TR> * </TABLE> * * <P>Example:</P> * <PRE><CODE> *  &lt;mailet match=&quot;RecipientIs=test@localhost&quot; class=&quot;Redirect&quot;&gt; *    &lt;recipients&gt;x@localhost, y@localhost, z@localhost&lt;/recipients&gt; *    &lt;to&gt;list@localhost&lt;/to&gt; *    &lt;sender&gt;owner@localhost&lt;/sender&gt; *    &lt;message&gt;sent on from James&lt;/message&gt; *    &lt;inline&gt;unaltered&lt;/inline&gt; *    &lt;passThrough&gt;FALSE&lt;/passThrough&gt; *    &lt;replyTo&gt;postmaster&lt;/replyTo&gt; *    &lt;prefix xml:space="preserve"&gt;[test mailing] &lt;/prefix&gt; *    &lt;!-- note the xml:space="preserve" to preserve whitespace --&gt; *    &lt;static&gt;TRUE&lt;/static&gt; * &lt;/mailet&gt; * </CODE></PRE> *  * <P>and:</P> * * <PRE><CODE> *  &lt;mailet match=&quot;All&quot; class=&quot;Redirect&quot;&gt; *    &lt;recipients&gt;x@localhost&lt;/recipients&gt; *    &lt;sender&gt;postmaster&lt;/sender&gt; *    &lt;message xml:space="preserve"&gt;Message marked as spam:&lt;/message&gt; *    &lt;inline&gt;heads&lt;/inline&gt; *    &lt;attachment&gt;message&lt;/attachment&gt; *    &lt;passThrough&gt;FALSE&lt;/passThrough&gt; *    &lt;attachError&gt;TRUE&lt;/attachError&gt; *    &lt;replyTo&gt;postmaster&lt;/replyTo&gt; *    &lt;prefix&gt;[spam notification]&lt;/prefix&gt; *    &lt;static&gt;TRUE&lt;/static&gt; *  &lt;/mailet&gt; * </CODE></PRE> * <P><I>replyto</I> can be used instead of * <I>replyTo</I>; such name is kept for backward compatibility.</P> * * @version CVS $Revision: 1.18.4.19 $ $Date: 2004/03/15 03:54:19 $ */public class Redirect extends AbstractRedirect {    /**     * Returns a string describing this mailet.     *     * @return a string describing this mailet     */    public String getMailetInfo() {        return "Redirect Mailet";    }    /** Gets the expected init parameters. */    protected  String[] getAllowedInitParameters() {        String[] allowedArray = {            "static",            "debug",            "passThrough",            "fakeDomainCheck",            "inline",            "attachment",            "message",            "recipients",            "to",            "replyTo",            "replyto",            "reversePath",            "sender",            "subject",            "prefix",            "attachError",            "isReply"        };        return allowedArray;    }    /* ******************************************************************** */    /* ****************** Begin of getX and setX methods ****************** */    /* ******************************************************************** */    /**     * @return the <CODE>static</CODE> init parameter    */    protected boolean isStatic() {        return isStatic;    }    /**     * @return the <CODE>inline</CODE> init parameter     */    protected int getInLineType() throws MessagingException {        if(getInitParameter("inline") == null) {            return BODY;        } else {            return getTypeCode(getInitParameter("inline"));        }    }    /**     * @return the <CODE>recipients</CODE> init parameter     * or the postmaster address     * or <CODE>SpecialAddress.SENDER</CODE>     * or <CODE>SpecialAddress.REVERSE_PATH</CODE>     * or <CODE>SpecialAddress.UNALTERED</CODE>     * or the <CODE>to</CODE> init parameter if missing     * or <CODE>null</CODE> if also the latter is missing     */    protected Collection getRecipients() throws MessagingException {        Collection newRecipients = new HashSet();        String addressList = (getInitParameter("recipients") == null)                                 ? getInitParameter("to")                                 : getInitParameter("recipients");                                         // if nothing was specified, return <CODE>null</CODE> meaning no change        if (addressList == null) {            return null;        }        try {            InternetAddress[] iaarray = InternetAddress.parse(addressList, false);            for (int i = 0; i < iaarray.length; i++) {                String addressString = iaarray[i].getAddress();                MailAddress specialAddress = getSpecialAddress(addressString,                new String[] {"postmaster", "sender", "from", "replyTo", "reversePath", "unaltered", "recipients", "to", "null"});                if (specialAddress != null) {                    newRecipients.add(specialAddress);                } else {                    newRecipients.add(new MailAddress(iaarray[i]));                }            }        } catch (Exception e) {            throw new MessagingException("Exception thrown in getRecipients() parsing: " + addressList, e);        }        if (newRecipients.size() == 0) {            throw new MessagingException("Failed to initialize \"recipients\" list; empty <recipients> init parameter found.");        }        return newRecipients;    }    /**     * @return the <CODE>to</CODE> init parameter     * or the postmaster address     * or <CODE>SpecialAddress.SENDER</CODE>     * or <CODE>SpecialAddress.REVERSE_PATH</CODE>     * or <CODE>SpecialAddress.UNALTERED</CODE>     * or the <CODE>recipients</CODE> init parameter if missing     * or <CODE>null</CODE> if also the latter is missing     */    protected InternetAddress[] getTo() throws MessagingException {        InternetAddress[] iaarray = null;        String addressList = (getInitParameter("to") == null)                                 ? getInitParameter("recipients")                                 : getInitParameter("to");        // if nothing was specified, return null meaning no change        if (addressList == null) {            return null;        }        try {            iaarray = InternetAddress.parse(addressList, false);            for(int i = 0; i < iaarray.length; ++i) {                String addressString = iaarray[i].getAddress();                MailAddress specialAddress = getSpecialAddress(addressString,                                                new String[] {"postmaster", "sender", "from", "replyTo", "reversePath", "unaltered", "recipients", "to", "null"});                if (specialAddress != null) {                    iaarray[i] = specialAddress.toInternetAddress();                }            }        } catch (Exception e) {            throw new MessagingException("Exception thrown in getTo() parsing: " + addressList, e);        }        if (iaarray.length == 0) {            throw new MessagingException("Failed to initialize \"to\" list; empty <to> init parameter found.");        }        return iaarray;    }    /**     * @return the <CODE>reversePath</CODE> init parameter      * or the postmaster address     * or <CODE>SpecialAddress.SENDER</CODE>     * or <CODE>SpecialAddress.NULL</CODE>     * or <CODE>null</CODE> if missing     */    protected MailAddress getReversePath() throws MessagingException {        String addressString = getInitParameter("reversePath");        if(addressString != null) {            MailAddress specialAddress = getSpecialAddress(addressString,                                            new String[] {"postmaster", "sender", "null"});            if (specialAddress != null) {                return specialAddress;            }            try {                return new MailAddress(addressString);            } catch(Exception e) {                throw new MessagingException("Exception thrown in getReversePath() parsing: " + addressString, e);            }        }        return null;    }    /**     * @return {@link AbstractRedirect#getReversePath()};     * if null return {@link AbstractRedirect#getSender(Mail)},     * meaning the new requested sender if any     */    protected MailAddress getReversePath(Mail originalMail) throws MessagingException {        MailAddress reversePath = super.getReversePath(originalMail);        if (reversePath == null) {            reversePath = getSender(originalMail);        }        return reversePath;    }    /* ******************************************************************** */    /* ******************* End of getX and setX methods ******************* */    /* ******************************************************************** */}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?