📄 abstractredirect.java
字号:
* 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(MailImpl newMail, MailAddress reversePath, Mail originalMail) throws MessagingException { if(reversePath != null) { if (reversePath == SpecialAddress.NULL) { reversePath = null; } newMail.setSender(reversePath); 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 { 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 { return (isStatic()) ? this.subject : getSubject(); } /** * 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 { 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 { return (isStatic()) ? this.subjectPrefix : getSubjectPrefix(); } /** * 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 { return (isStatic()) ? this.attachError : 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 { return (isStatic()) ? this.isReply : 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 = new Boolean(getInitParameter("debug","false")).booleanValue(); isStatic = new Boolean(getInitParameter("static","false")).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(); subjectPrefix = getSubjectPrefix(); apparentlyTo = getTo(); attachError = attachError(); isReply = isReply(); if (isDebug) { StringBuffer logBuffer = new StringBuffer(1024) .append("static") .append(", passThrough=").append(passThrough) .append(", fakeDomainCheck=").append(fakeDomainCheck) .append(", sender=").append(sender) .append(", replyTo=").append(replyTo) .append(", reversePath=").append(reversePath)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -