abstractredirect.java

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

JAVA
1,620
字号
     *     * @return the <CODE>reversePath</CODE> init parameter      * or the postmaster address     * or <CODE>SpecialAddress.SENDER</CODE>     * or <CODE>SpecialAddress.NULL</CODE>     * or <CODE>SpecialAddress.UNALTERED</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", "unaltered"});            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;    }    /**     * Gets the <CODE>reversePath</CODE> property,     * built dynamically using the original Mail object.     * Is a "getX(Mail)" method.     *     * @return {@link #getReversePath()},     * replacing <CODE>SpecialAddress.SENDER</CODE> if applicable with null,     * replacing <CODE>SpecialAddress.UNALTERED</CODE>     * and <CODE>SpecialAddress.REVERSE_PATH</CODE> if applicable with null,     * but not replacing <CODE>SpecialAddress.NULL</CODE>     * that will be handled by {@link #setReversePath}     */    protected MailAddress getReversePath(Mail originalMail) throws MessagingException {        MailAddress reversePath = (isStatic()) ? this.reversePath : getReversePath();        if (reversePath != null) {            if (reversePath == SpecialAddress.UNALTERED || reversePath == SpecialAddress.REVERSE_PATH) {                reversePath = null;            }            else if (reversePath == SpecialAddress.SENDER) {                reversePath = null;            }        }        return reversePath;    }    /**     * Sets the "reverse-path" of <I>newMail</I> to <I>reversePath</I>.     * If the requested value is <CODE>SpecialAddress.NULL</CODE> sets it to "<>".     * If the requested value is null does nothing.     * Is a "setX(Mail, Tx, Mail)" method.     */    protected void setReversePath(Mail newMail, MailAddress reversePath, Mail originalMail) throws MessagingException {        if(reversePath != null) {            String reversePathString;            if (reversePath == SpecialAddress.NULL) {                reversePath = null;                reversePathString = "";            } else {                reversePathString = reversePath.toString();            }            ((MailImpl) newMail).setSender(reversePath);            newMail.getMessage().setHeader(RFC2822Headers.RETURN_PATH, "<" + reversePathString + ">");            if (isDebug) {                log("reversePath set to: " + reversePath);            }        }    }    /**     * Gets the <CODE>sender</CODE> property.     * Returns the new sender as a MailAddress,     * or null if no change is requested.     * Is a "getX()" method.     *     * @return the <CODE>sender</CODE> init parameter     * or the postmaster address     * or <CODE>SpecialAddress.SENDER</CODE>     * or <CODE>SpecialAddress.UNALTERED</CODE>     * or <CODE>null</CODE> if missing     */    protected MailAddress getSender() throws MessagingException {        String addressString = getInitParameter("sender");        if(addressString != null) {            MailAddress specialAddress = getSpecialAddress(addressString,                                            new String[] {"postmaster", "sender", "unaltered"});            if (specialAddress != null) {                return specialAddress;            }            try {                return new MailAddress(addressString);            } catch(Exception e) {                throw new MessagingException("Exception thrown in getSender() parsing: " + addressString, e);            }        }        return null;    }    /**     * Gets the <CODE>sender</CODE> property,     * built dynamically using the original Mail object.     * Is a "getX(Mail)" method.     *     * @return {@link #getSender()}     * replacing <CODE>SpecialAddress.UNALTERED</CODE>     * and <CODE>SpecialAddress.SENDER</CODE> if applicable with null     */    protected MailAddress getSender(Mail originalMail) throws MessagingException {        MailAddress sender = (isStatic()) ? this.sender : getSender();        if (sender != null) {            if (sender == SpecialAddress.UNALTERED || sender == SpecialAddress.SENDER) {                sender = null;            }        }        return sender;    }    /**     * Sets the "From:" header of <I>newMail</I> to <I>sender</I>.     * If the requested value is null does nothing.     * Is a "setX(Mail, Tx, Mail)" method.     */    protected void setSender(Mail newMail, MailAddress sender, Mail originalMail) throws MessagingException {        if (sender != null) {            newMail.getMessage().setFrom(sender.toInternetAddress());                        if (isDebug) {                log("sender set to: " + sender);            }        }    }        /**     * Gets the <CODE>subject</CODE> property.     * Returns a string for the new message subject.     * Is a "getX()" method.     *     * @return the <CODE>subject</CODE> init parameter or null if missing     */    protected String getSubject() throws MessagingException {        if(getInitParameter("subject") == null) {            return null;        } else {            return getInitParameter("subject");        }    }    /**     * Gets the <CODE>subject</CODE> property,     * built dynamically using the original Mail object.     * Is a "getX(Mail)" method.     *     * @return {@link #getSubject()}     */    protected String getSubject(Mail originalMail) throws MessagingException {        String subject = (isStatic()) ? this.subject : getSubject();        return subject;    }    /**     * Gets the <CODE>prefix</CODE> property.     * Returns a prefix for the new message subject.     * Is a "getX()" method.     *     * @return the <CODE>prefix</CODE> init parameter or an empty string if missing     */    protected String getSubjectPrefix() throws MessagingException {        if(getInitParameter("prefix") == null) {            return null;        } else {            return getInitParameter("prefix");        }    }    /**     * Gets the <CODE>subjectPrefix</CODE> property,     * built dynamically using the original Mail object.     * Is a "getX(Mail)" method.     *     * @return {@link #getSubjectPrefix()}     */    protected String getSubjectPrefix(Mail originalMail) throws MessagingException {        String subjectPrefix = (isStatic()) ? this.subjectPrefix : getSubjectPrefix();        return subjectPrefix;    }    /**     * Builds the subject of <I>newMail</I> appending the subject     * of <I>originalMail</I> to <I>subjectPrefix</I>.     * Is a "setX(Mail, Tx, Mail)" method.     */    protected void setSubjectPrefix(Mail newMail, String subjectPrefix, Mail originalMail) throws MessagingException {        String subject = getSubject(originalMail);        if ((subjectPrefix != null && subjectPrefix.length() > 0) || subject != null) {            if (subject == null) {                subject = originalMail.getMessage().getSubject();            } else {                // replacing the subject                if (isDebug) {                    log("subject set to: " + subject);                }            }            // Was null in original?            if (subject == null) {                subject = "";            }                        if (subjectPrefix != null) {                subject = subjectPrefix + subject;                // adding a prefix                if (isDebug) {                    log("subjectPrefix set to: " + subjectPrefix);                }            }//            newMail.getMessage().setSubject(subject);            changeSubject(newMail.getMessage(), subject);        }    }    /**     * Gets the <CODE>attachError</CODE> property.     * Returns a boolean indicating whether to append a description of any error to the main body part     * of the new message, if getInlineType does not return "UNALTERED".     * Is a "getX()" method.     *     * @return the <CODE>attachError</CODE> init parameter; false if missing     */    protected boolean attachError() throws MessagingException {        return new Boolean(getInitParameter("attachError")).booleanValue();    }    /**     * Gets the <CODE>attachError</CODE> property,     * built dynamically using the original Mail object.     * Is a "getX(Mail)" method.     *     * @return {@link #attachError()}     */    protected boolean attachError(Mail originalMail) throws MessagingException {        boolean attachError = (isStatic()) ? this.attachError : attachError();        return attachError;    }    /**     * Gets the <CODE>isReply</CODE> property.     * Returns a boolean indicating whether the new message must be considered     * a reply to the original message, setting the IN_REPLY_TO header of the new     * message to the id of the original message.     * Is a "getX()" method.     *     * @return the <CODE>isReply</CODE> init parameter; false if missing     */    protected boolean isReply() throws MessagingException {        return new Boolean(getInitParameter("isReply")).booleanValue();    }    /**     * Gets the <CODE>isReply</CODE> property,     * built dynamically using the original Mail object.     * Is a "getX(Mail)" method.     *     * @return {@link #isReply()}     */    protected boolean isReply(Mail originalMail) throws MessagingException {        boolean isReply = (isStatic()) ? this.isReply : isReply();        return isReply;    }    /**     * Sets the "In-Reply-To:" header of <I>newMail</I> to the "Message-Id:" of     * <I>originalMail</I>, if <I>isReply</I> is true.     */    protected void setIsReply(Mail newMail, boolean isReply, Mail originalMail) throws MessagingException {        if (isReply) {            String messageId = originalMail.getMessage().getMessageID();            if (messageId != null) {                newMail.getMessage().setHeader(RFC2822Headers.IN_REPLY_TO, messageId);                if (isDebug) {                    log("IN_REPLY_TO set to: " + messageId);                }            }        }    }    /* ******************************************************************** */    /* ******************* End of getX and setX methods ******************* */    /* ******************************************************************** */    /**     * Mailet initialization routine.     * Will setup static values for each "x" initialization parameter in config.xml,     * using getX(), if {@link #isStatic()} returns true.     */    public void init() throws MessagingException {        isDebug = (getInitParameter("debug") == null) ? false : new Boolean(getInitParameter("debug")).booleanValue();        isStatic = (getInitParameter("static") == null) ? false : new Boolean(getInitParameter("static")).booleanValue();        if (isDebug) {            log("Initializing");        }                // check that all init parameters have been declared in allowedInitParameters        checkInitParameters(getAllowedInitParameters());                if(isStatic()) {            passThrough         = getPassThrough();            fakeDomainCheck     = getFakeDomainCheck();            attachmentType      = getAttachmentType();            inLineType          = getInLineType();            messageText         = getMessage();            recipients          = getRecipients();            replyTo             = getReplyTo();            reversePath         = getReversePath();            sender              = getSender();            subject             = getSubject();

⌨️ 快捷键说明

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