You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ie...@apache.org on 2013/03/01 00:31:42 UTC
svn commit: r1451435 [6/9] - in /james/server/trunk: ./ app/
app/src/assemble/ app/src/reporting-site/
cli/src/main/java/org/apache/james/cli/
cli/src/main/java/org/apache/james/cli/probe/impl/
core/src/main/java/org/apache/james/core/ data/data-api/sr...
Modified: james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/BayesianAnalysis.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/BayesianAnalysis.java?rev=1451435&r1=1451434&r2=1451435&view=diff
==============================================================================
--- james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/BayesianAnalysis.java (original)
+++ james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/BayesianAnalysis.java Thu Feb 28 23:31:36 2013
@@ -136,14 +136,13 @@ public class BayesianAnalysis extends Ge
/**
* The JDBCBayesianAnalyzer class that does all the work.
*/
- private JDBCBayesianAnalyzer analyzer = new JDBCBayesianAnalyzer() {
+ private final JDBCBayesianAnalyzer analyzer = new JDBCBayesianAnalyzer() {
protected void delegatedLog(String logString) {
log("BayesianAnalysis: " + logString);
}
};
private DataSource datasource;
- private String repositoryPath;
private static final String MAIL_ATTRIBUTE_NAME = "org.apache.james.spam.probability";
private static final String HEADER_NAME = "X-MessageIsSpamProbability";
@@ -229,7 +228,7 @@ public class BayesianAnalysis extends Ge
* if a problem arises
*/
public void init() throws MessagingException {
- repositoryPath = getInitParameter("repositoryPath");
+ String repositoryPath = getInitParameter("repositoryPath");
if (repositoryPath == null) {
throw new MessagingException("repositoryPath is null");
@@ -237,7 +236,7 @@ public class BayesianAnalysis extends Ge
headerName = getInitParameter("headerName", HEADER_NAME);
- ignoreLocalSender = Boolean.valueOf(getInitParameter("ignoreLocalSender")).booleanValue();
+ ignoreLocalSender = Boolean.valueOf(getInitParameter("ignoreLocalSender"));
if (ignoreLocalSender) {
log("Will ignore messages coming from local senders");
@@ -316,7 +315,7 @@ public class BayesianAnalysis extends Ge
probability = 0.0;
}
- mail.setAttribute(MAIL_ATTRIBUTE_NAME, new Double(probability));
+ mail.setAttribute(MAIL_ATTRIBUTE_NAME, probability);
message.setHeader(headerName, Double.toString(probability));
DecimalFormat probabilityForm = (DecimalFormat) DecimalFormat.getInstance();
@@ -375,7 +374,7 @@ public class BayesianAnalysis extends Ge
}
Iterator<MailAddress> iter = addresses.iterator();
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
sb.append('[');
for (int i = 0; iter.hasNext(); i++) {
sb.append(iter.next());
@@ -413,7 +412,7 @@ public class BayesianAnalysis extends Ge
private static class CorpusLoader extends Thread {
- private BayesianAnalysis analysis;
+ private final BayesianAnalysis analysis;
private CorpusLoader(BayesianAnalysis analysis) {
super("BayesianAnalysis Corpus Loader");
Modified: james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/BayesianAnalysisFeeder.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/BayesianAnalysisFeeder.java?rev=1451435&r1=1451434&r2=1451435&view=diff
==============================================================================
--- james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/BayesianAnalysisFeeder.java (original)
+++ james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/BayesianAnalysisFeeder.java Thu Feb 28 23:31:36 2013
@@ -140,14 +140,13 @@ public class BayesianAnalysisFeeder exte
/**
* The JDBCBayesianAnalyzer class that does all the work.
*/
- private JDBCBayesianAnalyzer analyzer = new JDBCBayesianAnalyzer() {
+ private final JDBCBayesianAnalyzer analyzer = new JDBCBayesianAnalyzer() {
protected void delegatedLog(String logString) {
log("BayesianAnalysisFeeder: " + logString);
}
};
private DataSource datasource;
- private String repositoryPath;
private String feedType;
@@ -205,7 +204,7 @@ public class BayesianAnalysisFeeder exte
* if a problem arises
*/
public void init() throws MessagingException {
- repositoryPath = getInitParameter("repositoryPath");
+ String repositoryPath = getInitParameter("repositoryPath");
if (repositoryPath == null) {
throw new MessagingException("repositoryPath is null");
Modified: james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java?rev=1451435&r1=1451434&r2=1451435&view=diff
==============================================================================
--- james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java (original)
+++ james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java Thu Feb 28 23:31:36 2013
@@ -19,14 +19,13 @@
package org.apache.james.transport.mailets;
-import java.util.Collection;
-import java.util.HashSet;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress;
-
-import org.apache.mailet.Mail;
-import org.apache.mailet.MailAddress;
+import java.util.Collection;
+import java.util.HashSet;
/**
* <p>
@@ -51,11 +50,11 @@ import org.apache.mailet.MailAddress;
* <p>
* Supports the <code>passThrough</code> init parameter (true if missing).
* </p>
- *
+ * <p/>
* <p>
* Sample configuration:
* </p>
- *
+ * <p/>
* <pre>
* <code>
* <mailet match="All" class="Bounce">
@@ -71,12 +70,12 @@ import org.apache.mailet.MailAddress;
* </mailet>
* </code>
* </pre>
- *
+ * <p/>
* <p>
* The behaviour of this mailet is equivalent to using Resend with the following
* configuration:
* </p>
- *
+ * <p/>
* <pre>
* <code>
* <mailet match="All" class="Resend">
@@ -99,31 +98,35 @@ import org.apache.mailet.MailAddress;
* <i>notice</i> and <i>sendingAddress</i> can be used instead of <i>message</i>
* and <i>sender</i>; such names are kept for backward compatibility.
* </p>
- *
+ *
* @since 2.2.0
*/
public class Bounce extends AbstractNotify {
/**
* Return a string describing this mailet.
- *
+ *
* @return a string describing this mailet
*/
+ @Override
public String getMailetInfo() {
return "Bounce Mailet";
}
- /** Gets the expected init parameters. */
+ /**
+ * Gets the expected init parameters.
+ */
+ @Override
protected String[] getAllowedInitParameters() {
- String[] allowedArray = {
+ return new String[]{
// "static",
- "debug", "passThrough", "fakeDomainCheck", "inline", "attachment", "message", "notice", "sender", "sendingAddress", "prefix", "attachError", };
- return allowedArray;
+ "debug", "passThrough", "fakeDomainCheck", "inline", "attachment", "message", "notice", "sender", "sendingAddress", "prefix", "attachError",};
}
/**
* @return <code>SpecialAddress.REVERSE_PATH</code>
*/
+ @Override
protected Collection getRecipients() {
Collection newRecipients = new HashSet();
newRecipients.add(SpecialAddress.REVERSE_PATH);
@@ -133,6 +136,7 @@ public class Bounce extends AbstractNoti
/**
* @return <code>SpecialAddress.REVERSE_PATH</code>
*/
+ @Override
protected InternetAddress[] getTo() {
InternetAddress[] apparentlyTo = new InternetAddress[1];
apparentlyTo[0] = SpecialAddress.REVERSE_PATH.toInternetAddress();
@@ -142,6 +146,7 @@ public class Bounce extends AbstractNoti
/**
* @return <code>SpecialAddress.NULL</code> (the meaning of bounce)
*/
+ @Override
protected MailAddress getReversePath(Mail originalMail) {
return SpecialAddress.NULL;
}
@@ -150,12 +155,11 @@ public class Bounce extends AbstractNoti
* Service does the hard work,and redirects the originalMail in the form
* specified. Checks that the original return path is not empty, and then
* calls super.service(originalMail), otherwise just returns.
- *
- * @param originalMail
- * the mail to process and redirect
- * @throws MessagingException
- * if a problem arises formulating the redirected mail
+ *
+ * @param originalMail the mail to process and redirect
+ * @throws MessagingException if a problem arises formulating the redirected mail
*/
+ @Override
public void service(Mail originalMail) throws MessagingException {
if (originalMail.getSender() == null) {
if (isDebug)
Modified: james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java?rev=1451435&r1=1451434&r2=1451435&view=diff
==============================================================================
--- james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java (original)
+++ james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java Thu Feb 28 23:31:36 2013
@@ -19,6 +19,22 @@
package org.apache.james.transport.mailets;
+import com.google.common.base.Throwables;
+import org.apache.james.core.MailImpl;
+import org.apache.james.protocols.smtp.dsn.DSNStatus;
+import org.apache.james.transport.util.Patterns;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.base.RFC2822Headers;
+import org.apache.mailet.base.RFC822DateFormat;
+import org.apache.mailet.base.mail.MimeMultipartReport;
+
+import javax.mail.MessagingException;
+import javax.mail.SendFailedException;
+import javax.mail.Session;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.ConnectException;
@@ -28,28 +44,11 @@ import java.net.UnknownHostException;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
-import javax.mail.MessagingException;
-import javax.mail.SendFailedException;
-import javax.mail.Session;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeBodyPart;
-import javax.mail.internet.MimeMessage;
-
-import org.apache.james.core.MailImpl;
-import org.apache.james.protocols.smtp.dsn.DSNStatus;
-import org.apache.mailet.Mail;
-import org.apache.mailet.MailAddress;
-import org.apache.mailet.base.RFC2822Headers;
-import org.apache.mailet.base.RFC822DateFormat;
-import org.apache.mailet.base.mail.MimeMultipartReport;
-
/**
- *
* <p>
* Generates a Delivery Status Notification (DSN) Note that this is different
* than a mail-client's reply, which would use the Reply-To or From header.
@@ -66,17 +65,17 @@ import org.apache.mailet.base.mail.MimeM
* <p>
* Supports the <code>passThrough</code> init parameter (true if missing).
* </p>
- *
+ * <p/>
* <p>
* Sample configuration:
* </p>
- *
+ * <p/>
* <pre>
* <code>
* <mailet match="All" class="DSNBounce">
- * <sender><i>an address or postmaster or sender or unaltered,
+ * <sender><i>an address or postmaster or sender or unaltered,
* default=postmaster</i></sender>
- * <prefix><i>optional subject prefix prepended to the original
+ * <prefix><i>optional subject prefix prepended to the original
* message</i></prefix>
* <attachment><i>message, heads or none, default=message</i></attachment>
* <messageString><i>the message sent in the bounce, the first occurrence of the pattern [machine] is replaced with the name of the executing machine, default=Hi. This is the James mail server at [machine] ... </i></messageString>
@@ -85,7 +84,7 @@ import org.apache.mailet.base.mail.MimeM
* </mailet>
* </code>
* </pre>
- *
+ *
* @see org.apache.james.transport.mailets.AbstractNotify
*/
@@ -93,40 +92,21 @@ public class DSNBounce extends AbstractN
private static final RFC822DateFormat rfc822DateFormat = new RFC822DateFormat();
- // regexp pattern for scaning status code from exception message
- private static Pattern statusPattern;
+ public static final String STATUS_PATTERN_STRING = ".*\\s*([245]\\.\\d{1,3}\\.\\d{1,3}).*\\s*";
+ public static final String DIAG_PATTERN_STRING = "^\\d{3}\\s.*$";
- private static Pattern diagPattern;
+ // regexp pattern for scaning status code from exception message
+ private static final Pattern statusPattern = Patterns.compilePatternUncheckedException(STATUS_PATTERN_STRING);
+ private static final Pattern diagPattern = Patterns.compilePatternUncheckedException(DIAG_PATTERN_STRING);
private static final String MACHINE_PATTERN = "[machine]";
private String messageString = null;
- /*
- * Static initializer.<p> Compiles patterns for processing exception
- * messages.<p>
- */
- static {
- String status_pattern_string = ".*\\s*([245]\\.\\d{1,3}\\.\\d{1,3}).*\\s*";
- String diag_pattern_string = "^\\d{3}\\s.*$";
- try {
- statusPattern = Pattern.compile(status_pattern_string);
- } catch (PatternSyntaxException mpe) {
- // this should not happen as the pattern string is hardcoded.
- System.err.println("Malformed pattern: " + status_pattern_string);
- mpe.printStackTrace(System.err);
- }
- try {
- diagPattern = Pattern.compile(diag_pattern_string);
- } catch (PatternSyntaxException mpe) {
- // this should not happen as the pattern string is hardcoded.
- System.err.println("Malformed pattern: " + diag_pattern_string);
- }
- }
-
/**
* Initialize the mailet
*/
+ @Override
public void init() throws MessagingException {
super.init();
messageString = getInitParameter("messageString",
@@ -136,14 +116,12 @@ public class DSNBounce extends AbstractN
/**
* Service does the hard work and bounces the originalMail in the format
* specified by RFC3464.
- *
- * @param originalMail
- * the mail to bounce
- * @throws MessagingException
- * if a problem arises formulating the redirected mail
- *
+ *
+ * @param originalMail the mail to bounce
+ * @throws MessagingException if a problem arises formulating the redirected mail
* @see org.apache.mailet.Mailet#service(org.apache.mailet.Mail)
*/
+ @Override
public void service(Mail originalMail) throws MessagingException {
// duplicates the Mail object, to be able to modify the new mail keeping
@@ -238,7 +216,7 @@ public class DSNBounce extends AbstractN
/**
* Create a MimeBodyPart with a textual description for human readers.
- *
+ *
* @param originalMail
* @return MimeBodyPart
* @throws MessagingException
@@ -247,7 +225,7 @@ public class DSNBounce extends AbstractN
MimeBodyPart part1 = new MimeBodyPart();
StringWriter sout = new StringWriter();
PrintWriter out = new PrintWriter(sout, true);
- String machine = "[unknown]";
+ String machine;
try {
InetAddress me = InetAddress.getLocalHost();
machine = me.getHostName();
@@ -255,15 +233,15 @@ public class DSNBounce extends AbstractN
machine = "[address unknown]";
}
- StringBuffer bounceBuffer = new StringBuffer(128).append(messageString);
+ StringBuilder bounceBuffer = new StringBuilder(128).append(messageString);
int m_idx_begin = messageString.indexOf(MACHINE_PATTERN);
if (m_idx_begin != -1) {
bounceBuffer.replace(m_idx_begin, m_idx_begin + MACHINE_PATTERN.length(), machine);
}
out.println(bounceBuffer.toString());
out.println("Failed recipient(s):");
- for (Iterator<?> i = originalMail.getRecipients().iterator(); i.hasNext();) {
- out.println(i.next());
+ for (MailAddress mailAddress : originalMail.getRecipients()) {
+ out.println(mailAddress);
}
String ex = (String) originalMail.getAttribute("delivery-error");
out.println();
@@ -277,7 +255,7 @@ public class DSNBounce extends AbstractN
/**
* creates the DSN-bodypart for automated processing
- *
+ *
* @param originalMail
* @return MimeBodyPart dsn-bodypart
* @throws MessagingException
@@ -286,7 +264,7 @@ public class DSNBounce extends AbstractN
MimeBodyPart dsn = new MimeBodyPart();
StringWriter sout = new StringWriter();
PrintWriter out = new PrintWriter(sout, true);
- String nameType = null;
+ String nameType;
// //////////////////////
// per message fields //
@@ -330,9 +308,7 @@ public class DSNBounce extends AbstractN
// per recipient fields //
// ////////////////////////
- Iterator<MailAddress> recipients = originalMail.getRecipients().iterator();
- while (recipients.hasNext()) {
- MailAddress rec = (MailAddress) recipients.next();
+ for (MailAddress rec : originalMail.getRecipients()) {
String addressType = "rfc822";
// required: blank line
@@ -364,7 +340,7 @@ public class DSNBounce extends AbstractN
// to which MTA were we talking while the Error occured?
// optional: diagnostic-code
- String diagnosticType = null;
+ String diagnosticType;
// this typically is the return value received during smtp
// (or other transport) communication
// and should be stored as attribute by the smtp handler
@@ -406,7 +382,7 @@ public class DSNBounce extends AbstractN
/**
* Create a MimeBodyPart with the original Mail as Attachment
- *
+ *
* @param originalMail
* @return MimeBodyPart
* @throws MessagingException
@@ -434,17 +410,16 @@ public class DSNBounce extends AbstractN
/**
* Guessing status code by the exception provided. This method should use
* the status attribute when the SMTP-handler somewhen provides it
- *
- * @param me
- * the MessagingException of which the statusCode should be
- * generated
+ *
+ * @param me the MessagingException of which the statusCode should be
+ * generated
* @return status the generated statusCode
*/
protected String getStatus(MessagingException me) {
if (me.getNextException() == null) {
String mess = me.getMessage();
Matcher m = statusPattern.matcher(mess);
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
if (m.matches()) {
sb.append(m.group(1));
return sb.toString();
@@ -463,7 +438,7 @@ public class DSNBounce extends AbstractN
} else {
Exception ex1 = me.getNextException();
Matcher m = statusPattern.matcher(ex1.getMessage());
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
if (m.matches()) {
sb.append(m.group(1));
return sb.toString();
@@ -477,58 +452,58 @@ public class DSNBounce extends AbstractN
switch (smtpCode) {
- // Req mail action not taken: mailbox unavailable
- case 450:
- return DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.MAILBOX_OTHER);
+ // Req mail action not taken: mailbox unavailable
+ case 450:
+ return DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.MAILBOX_OTHER);
// Req action aborted: local error in processing
- case 451:
- return DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.SYSTEM_OTHER);
+ case 451:
+ return DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.SYSTEM_OTHER);
// Req action not taken: insufficient sys storage
- case 452:
- return DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.SYSTEM_FULL);
+ case 452:
+ return DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.SYSTEM_FULL);
// Syntax error, command unrecognized
- case 500:
- return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_SYNTAX);
+ case 500:
+ return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_SYNTAX);
// Syntax error in parameters or arguments
- case 501:
- return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_INVALID_ARG);
+ case 501:
+ return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_INVALID_ARG);
// Command not implemented
- case 502:
- return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_INVALID_CMD);
+ case 502:
+ return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_INVALID_CMD);
// Bad sequence of commands
- case 503:
- return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_INVALID_CMD);
+ case 503:
+ return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_INVALID_CMD);
// Command parameter not implemented
- case 504:
- return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_INVALID_ARG);
+ case 504:
+ return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_INVALID_ARG);
// Req mail action not taken: mailbox unavailable
- case 550:
- return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.MAILBOX_OTHER);
+ case 550:
+ return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.MAILBOX_OTHER);
// User not local; please try <...>
// 5.7.1 Select another host to act as your forwarder
- case 551:
- return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_AUTH);
+ case 551:
+ return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_AUTH);
// Req mail action aborted: exceeded storage alloc
- case 552:
- return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.MAILBOX_FULL);
+ case 552:
+ return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.MAILBOX_FULL);
// Req action not taken: mailbox name not allowed
- case 553:
- return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.ADDRESS_SYNTAX);
+ case 553:
+ return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.ADDRESS_SYNTAX);
// Transaction failed
- case 554:
- return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.UNDEFINED_STATUS);
+ case 554:
+ return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.UNDEFINED_STATUS);
// Not authorized. This is not an SMTP code, but many server
// use it.
- case 571:
- return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_AUTH);
+ case 571:
+ return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_AUTH);
- default:
- // if we get an smtp returncode starting with 4
- // it is an persistent transient error, else permanent
- if (ex1.getMessage().startsWith("4")) {
- return DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.DELIVERY_OTHER);
- } else
- return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_OTHER);
+ default:
+ // if we get an smtp returncode starting with 4
+ // it is an persistent transient error, else permanent
+ if (ex1.getMessage().startsWith("4")) {
+ return DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.DELIVERY_OTHER);
+ } else
+ return DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_OTHER);
}
} else if (ex1 instanceof UnknownHostException) {
@@ -547,13 +522,17 @@ public class DSNBounce extends AbstractN
}
}
+ @Override
public String getMailetInfo() {
return "DSNBounce Mailet";
}
- /** Gets the expected init parameters. */
+ /**
+ * Gets the expected init parameters.
+ */
+ @Override
protected String[] getAllowedInitParameters() {
- String[] allowedArray = { "debug", "passThrough", "messageString", "attachment", "sender", "prefix" };
+ String[] allowedArray = {"debug", "passThrough", "messageString", "attachment", "sender", "prefix"};
return allowedArray;
}
@@ -561,13 +540,15 @@ public class DSNBounce extends AbstractN
* @return the <code>attachment</code> init parameter, or
* <code>MESSAGE</code> if missing
*/
- protected int getAttachmentType() throws MessagingException {
+ @Override
+ protected int getAttachmentType() {
return getTypeCode(getInitParameter("attachment", "message"));
}
/**
* @return <code>SpecialAddress.REVERSE_PATH</code>
*/
+ @Override
protected Collection<MailAddress> getRecipients() {
Collection<MailAddress> newRecipients = new HashSet<MailAddress>();
newRecipients.add(SpecialAddress.REVERSE_PATH);
@@ -577,6 +558,7 @@ public class DSNBounce extends AbstractN
/**
* @return <code>SpecialAddress.REVERSE_PATH</code>
*/
+ @Override
protected InternetAddress[] getTo() {
InternetAddress[] apparentlyTo = new InternetAddress[1];
apparentlyTo[0] = SpecialAddress.REVERSE_PATH.toInternetAddress();
@@ -586,6 +568,7 @@ public class DSNBounce extends AbstractN
/**
* @return <code>SpecialAddress.NULL</code> (the meaning of bounce)
*/
+ @Override
protected MailAddress getReversePath(Mail originalMail) {
return SpecialAddress.NULL;
}
Modified: james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/Forward.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/Forward.java?rev=1451435&r1=1451434&r2=1451435&view=diff
==============================================================================
--- james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/Forward.java (original)
+++ james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/Forward.java Thu Feb 28 23:31:36 2013
@@ -92,21 +92,21 @@ public class Forward extends AbstractRed
/**
* @return UNALTERED
*/
- protected int getInLineType() throws MessagingException {
+ protected int getInLineType() {
return UNALTERED;
}
/**
* @return NONE
*/
- protected int getAttachmentType() throws MessagingException {
+ protected int getAttachmentType() {
return NONE;
}
/**
* @return ""
*/
- protected String getMessage() throws MessagingException {
+ protected String getMessage() {
return "";
}
@@ -124,13 +124,13 @@ public class Forward extends AbstractRed
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" });
+ for (InternetAddress anIaarray : iaarray) {
+ String addressString = anIaarray.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]));
+ newRecipients.add(new MailAddress(anIaarray));
}
}
} catch (Exception e) {
@@ -174,14 +174,14 @@ public class Forward extends AbstractRed
/**
* @return null
*/
- protected String getSubject() throws MessagingException {
+ protected String getSubject() {
return null;
}
/**
* @return ""
*/
- protected String getSubjectPrefix() throws MessagingException {
+ protected String getSubjectPrefix() {
return null;
}
@@ -195,7 +195,7 @@ public class Forward extends AbstractRed
/**
* @return false
*/
- protected boolean isReply() throws MessagingException {
+ protected boolean isReply() {
return false;
}
Modified: james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/FromRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/FromRepository.java?rev=1451435&r1=1451434&r2=1451435&view=diff
==============================================================================
--- james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/FromRepository.java (original)
+++ james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/FromRepository.java Thu Feb 28 23:31:36 2013
@@ -123,9 +123,8 @@ public class FromRepository extends Gene
}
if (delete) {
- Iterator delList = processed.iterator();
- while (delList.hasNext()) {
- repository.remove((String) delList.next());
+ for (Object aProcessed : processed) {
+ repository.remove((String) aProcessed);
}
}
}
Modified: james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/JDBCAlias.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/JDBCAlias.java?rev=1451435&r1=1451434&r2=1451435&view=diff
==============================================================================
--- james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/JDBCAlias.java (original)
+++ james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/JDBCAlias.java Thu Feb 28 23:31:36 2013
@@ -98,13 +98,13 @@ public class JDBCAlias extends GenericMa
// DatabaseMetaInfo.
// Try UPPER, lower, and MixedCase, to see if the table is there.
if (!(theJDBCUtil.tableExists(dbMetaData, tableName))) {
- StringBuffer exceptionBuffer = new StringBuffer(128).append("Could not find table '").append(tableName).append("' in datasource '").append(datasourceName).append("'");
- throw new MailetException(exceptionBuffer.toString());
+ String exceptionBuffer = "Could not find table '" + tableName + "' in datasource '" + datasourceName + "'";
+ throw new MailetException(exceptionBuffer);
}
// Build the query
- StringBuffer queryBuffer = new StringBuffer(128).append("SELECT ").append(getInitParameter("target_column")).append(" FROM ").append(tableName).append(" WHERE ").append(getInitParameter("source_column")).append(" = ?");
- query = queryBuffer.toString();
+ String queryBuffer = "SELECT " + getInitParameter("target_column") + " FROM " + tableName + " WHERE " + getInitParameter("source_column") + " = ?";
+ query = queryBuffer;
} catch (MailetException me) {
throw me;
} catch (Exception e) {
@@ -129,9 +129,9 @@ public class JDBCAlias extends GenericMa
conn = datasource.getConnection();
mappingStmt = conn.prepareStatement(query);
- for (Iterator<MailAddress> i = recipients.iterator(); i.hasNext();) {
+ for (MailAddress recipient : recipients) {
try {
- MailAddress source = i.next();
+ MailAddress source = recipient;
mappingStmt.setString(1, source.toString());
mappingRS = mappingStmt.executeQuery();
if (!mappingRS.next()) {
@@ -149,9 +149,8 @@ public class JDBCAlias extends GenericMa
} catch (ParseException pe) {
// Don't alias this address... there's an invalid
// address mapping here
- StringBuffer exceptionBuffer = new StringBuffer(128).append("There is an invalid alias from ").append(source).append(" to ").append(mappingRS.getString(1));
- log(exceptionBuffer.toString());
- continue;
+ String exceptionBuffer = "There is an invalid alias from " + source + " to " + mappingRS.getString(1);
+ log(exceptionBuffer);
}
} finally {
ResultSet localRS = mappingRS;
Modified: james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/JDBCRecipientRewriteTable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/JDBCRecipientRewriteTable.java?rev=1451435&r1=1451434&r2=1451435&view=diff
==============================================================================
--- james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/JDBCRecipientRewriteTable.java (original)
+++ james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/JDBCRecipientRewriteTable.java Thu Feb 28 23:31:36 2013
@@ -156,8 +156,8 @@ public class JDBCRecipientRewriteTable e
// DatabaseMetaInfo.
// Try UPPER, lower, and MixedCase, to see if the table is there.
if (!(theJDBCUtil.tableExists(dbMetaData, tableName))) {
- StringBuffer exceptionBuffer = new StringBuffer(128).append("Could not find table '").append(tableName).append("' in datasource '").append(datasourceName).append("'");
- throw new MailetException(exceptionBuffer.toString());
+ String exceptionBuffer = "Could not find table '" + tableName + "' in datasource '" + datasourceName + "'";
+ throw new MailetException(exceptionBuffer);
}
// Build the query
@@ -188,10 +188,10 @@ public class JDBCRecipientRewriteTable e
conn = datasource.getConnection();
mappingStmt = conn.prepareStatement(query);
- for (Iterator<MailAddress> i = recipients.iterator(); i.hasNext();) {
+ for (MailAddress recipient : recipients) {
ResultSet mappingRS = null;
try {
- MailAddress source = i.next();
+ MailAddress source = recipient;
mappingStmt.setString(1, source.getLocalPart());
mappingStmt.setString(2, source.getDomain());
mappingStmt.setString(3, source.getDomain());
Modified: james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java?rev=1451435&r1=1451434&r2=1451435&view=diff
==============================================================================
--- james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java (original)
+++ james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java Thu Feb 28 23:31:36 2013
@@ -90,7 +90,7 @@ public class LocalDelivery extends Gener
*/
public void service(Mail mail) throws MessagingException {
recipientRewriteTable.service(mail);
- if (mail.getState() != Mail.GHOST) {
+ if (!mail.getState().equals(Mail.GHOST)) {
sieveMailet.service(mail);
}
}
Modified: james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RecipientRewriteTable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RecipientRewriteTable.java?rev=1451435&r1=1451434&r2=1451435&view=diff
==============================================================================
--- james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RecipientRewriteTable.java (original)
+++ james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RecipientRewriteTable.java Thu Feb 28 23:31:36 2013
@@ -43,7 +43,7 @@ public class RecipientRewriteTable exten
* @param vut
* the vutStore to set, possibly null
*/
- @Inject
+ @Inject
public final void setRecipientRewriteTable(org.apache.james.rrt.api.RecipientRewriteTable vut) {
this.vut = vut;
}
@@ -59,8 +59,8 @@ public class RecipientRewriteTable exten
return handleMappings(mappings, sender, recipient, message);
}
} catch (ErrorMappingException e) {
- StringBuilder errorBuffer = new StringBuilder(128).append("A problem as occoured trying to alias and forward user ").append(recipient).append(": ").append(e.getMessage());
- throw new MessagingException(errorBuffer.toString());
+ String errorBuffer = "A problem as occoured trying to alias and forward user " + recipient + ": " + e.getMessage();
+ throw new MessagingException(errorBuffer);
} catch (RecipientRewriteTableException e) {
throw new MessagingException("Unable to access RecipientRewriteTable", e);
}
Modified: james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java?rev=1451435&r1=1451434&r2=1451435&view=diff
==============================================================================
--- james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java (original)
+++ james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java Thu Feb 28 23:31:36 2013
@@ -306,7 +306,7 @@ public class Redirect extends AbstractRe
/**
* @return the <code>inline</code> init parameter
*/
- protected int getInLineType() throws MessagingException {
+ protected int getInLineType() {
return getTypeCode(getInitParameter("inline", "body"));
}
@@ -329,13 +329,13 @@ public class Redirect extends AbstractRe
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" });
+ for (InternetAddress anIaarray : iaarray) {
+ String addressString = anIaarray.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]));
+ newRecipients.add(new MailAddress(anIaarray));
}
}
} catch (Exception e) {
@@ -357,7 +357,7 @@ public class Redirect extends AbstractRe
* <code>null</code> if also the latter is missing
*/
protected InternetAddress[] getTo() throws MessagingException {
- InternetAddress[] iaarray = null;
+ InternetAddress[] iaarray;
String addressList = getInitParameter("to", getInitParameter("recipients"));
// if nothing was specified, return null meaning no change
Modified: james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java?rev=1451435&r1=1451434&r2=1451435&view=diff
==============================================================================
--- james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java (original)
+++ james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java Thu Feb 28 23:31:36 2013
@@ -19,6 +19,38 @@
package org.apache.james.transport.mailets;
+import org.apache.james.dnsservice.api.DNSService;
+import org.apache.james.dnsservice.api.TemporaryResolutionException;
+import org.apache.james.dnsservice.library.MXHostAddressIterator;
+import org.apache.james.domainlist.api.DomainList;
+import org.apache.james.domainlist.api.DomainListException;
+import org.apache.james.lifecycle.api.LifecycleUtil;
+import org.apache.james.queue.api.MailPrioritySupport;
+import org.apache.james.queue.api.MailQueue;
+import org.apache.james.queue.api.MailQueue.MailQueueException;
+import org.apache.james.queue.api.MailQueue.MailQueueItem;
+import org.apache.james.queue.api.MailQueueFactory;
+import org.apache.james.transport.util.MailetContextLog;
+import org.apache.james.transport.util.Patterns;
+import org.apache.james.util.TimeConverter;
+import org.apache.mailet.HostAddress;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.MailetContext;
+import org.apache.mailet.base.GenericMailet;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.mail.Address;
+import javax.mail.MessagingException;
+import javax.mail.SendFailedException;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+import javax.mail.internet.MimePart;
+import javax.mail.internet.ParseException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -41,69 +73,35 @@ import java.util.Vector;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
-
-import javax.annotation.Resource;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.mail.Address;
-import javax.mail.MessagingException;
-import javax.mail.SendFailedException;
-import javax.mail.Session;
-import javax.mail.Transport;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.MimeMultipart;
-import javax.mail.internet.MimePart;
-import javax.mail.internet.ParseException;
-
-import org.apache.james.dnsservice.api.DNSService;
-import org.apache.james.dnsservice.api.TemporaryResolutionException;
-import org.apache.james.dnsservice.library.MXHostAddressIterator;
-import org.apache.james.domainlist.api.DomainList;
-import org.apache.james.domainlist.api.DomainListException;
-import org.apache.james.lifecycle.api.LifecycleUtil;
-import org.apache.james.queue.api.MailPrioritySupport;
-import org.apache.james.queue.api.MailQueue;
-import org.apache.james.queue.api.MailQueue.MailQueueException;
-import org.apache.james.queue.api.MailQueue.MailQueueItem;
-import org.apache.james.queue.api.MailQueueFactory;
-import org.apache.james.transport.util.MailetContextLog;
-import org.apache.james.util.TimeConverter;
-import org.apache.mailet.HostAddress;
-import org.apache.mailet.Mail;
-import org.apache.mailet.MailAddress;
-import org.apache.mailet.MailetContext;
-import org.apache.mailet.base.GenericMailet;
/**
* <p>The RemoteDelivery mailet delivers messages to a remote SMTP server able to deliver or forward messages to their final
* destination.
- *
- * <p>The remote SMTP server through which each mail is delivered is resolved using MX lookup for each message destination
+ * <p/>
+ * <p>The remote SMTP server through which each mail is delivered is resolved using MX lookup for each message destination
* unless the <code><gateway/></code> parameter is set. The <code><gateway/></code> parameter enables the
* definition of one or more gateway servers through which all messages are sent.
- *
+ * <p/>
* <p>If an attempt to deliver a message fails, a redelivery attempt is scheduled according to the scheme defined
- * by the <code><delayTime/></code> parameter, retrying up to the limit defined
+ * by the <code><delayTime/></code> parameter, retrying up to the limit defined
* by the <code><maxRetries/></code> parameter. When the retry limit is exceeded, delivery failure is processed
- * according to the setting of the <code><bounceProcessor/></code> parameter.
- *
+ * according to the setting of the <code><bounceProcessor/></code> parameter.
+ * <p/>
* <p>These are the parameters that control the operation of the RemoteDelivery mailet:
- *
+ * <p/>
* <ul>
- * <li><b>deliveryThreads</b> (required) - an Integer for the number of threads this mailet will use to deliver mail.</li>
+ * <li><b>deliveryThreads</b> (required) - an Integer for the number of threads this mailet will use to deliver mail.</li>
* <li><b>outgoing</b> (required) - a String containing the URL for the repository that will hold messages being processed by this mailet.</li>
* <li><b>bind</b> (optional) - a String describing the local IP address to which the mailet should be bound while delivering
* emails. This tag is useful for multihomed machines. Default is to bind to the default local address of the machine.<br>
- * Note: The same IP address must be used for all of those RemoteDelivery instances where you explicitly supply a bind address.
+ * Note: The same IP address must be used for all of those RemoteDelivery instances where you explicitly supply a bind address.
* <li><b>delayTime</b> (optional> a String containing a comma separated list of patterns defining the number of and delays between delivery
* attempts. The pattern is <code>[attempts\*]delay [unit]</code> where:
- * <ul>
- * <li><i>attempts</i> (optional) - an Integer for the number of delivery attempts. Default is 1.</li>
- * <li><i>delay</i> (required) - a Long for the delay between attempts.</li>
- * <li><i>unit</i> (optional) - a String with the value of one of 'msec', 'sec', 'minute', 'hour', or 'day'. Default is msec.</li>
- * </ul>
+ * <ul>
+ * <li><i>attempts</i> (optional) - an Integer for the number of delivery attempts. Default is 1.</li>
+ * <li><i>delay</i> (required) - a Long for the delay between attempts.</li>
+ * <li><i>unit</i> (optional) - a String with the value of one of 'msec', 'sec', 'minute', 'hour', or 'day'. Default is msec.</li>
+ * </ul>
* Default is one attempt after 6 hours, which if explicitly declared would be written as <code><delayTime>1 * 6 hour</delayTime></code></li>
* <li><b>maxRetries</b> (optional) an Integer for the number of times an attempt is made to deliver a particular mail.
* Default is the greater of five and the sum of the attempts for each <code><delayTime/></code> specified.
@@ -114,80 +112,78 @@ import org.apache.mailet.base.GenericMai
* <li><b>bounceProcessor</b> (optional) - a String containing the name of the mailet processor to pass messages that cannot
* be delivered to for DSN bounce processing. Default is to send a traditional message containing the bounce details.</li>
* <li><b>startTLS</b> (optional) - a Boolean (true/false) indicating whether the STARTTLS command (if supported by the server)
- * to switch the connection to a TLS-protected connection before issuing any login commands. Default is false.</li>
- * <li><b>sslEnable</b> (optional) - a Boolean (true/false) indicating whether to use SSL to connect and use the SSL port unless
+ * to switch the connection to a TLS-protected connection before issuing any login commands. Default is false.</li>
+ * <li><b>sslEnable</b> (optional) - a Boolean (true/false) indicating whether to use SSL to connect and use the SSL port unless
* explicitly overridden. Default is false.</li>
* <li><b>gateway</b> (optional) - a String containing a comma separated list of patterns defining the gateway servers to be used to
* deliver mail regardless of the recipient address. If multiple gateway servers are defined, each will be tried in definition order
* until delivery is successful. If none are successful, the mail is bounced. The pattern is <code>host[:port]</code> where:
- * <ul>
- * <li><i>host</i> (required) - the FQN of the gateway server.</li>
- * <li><i>port</i> (optional) - the port of the gateway server. Default is the value defined in the <code><gatewayPort/></code>
- * parameter if set, else the default port for the specified connection type.</li>
- * </ul>
+ * <ul>
+ * <li><i>host</i> (required) - the FQN of the gateway server.</li>
+ * <li><i>port</i> (optional) - the port of the gateway server. Default is the value defined in the <code><gatewayPort/></code>
+ * parameter if set, else the default port for the specified connection type.</li>
+ * </ul>
* Default is to resolve the destination SMTP server for each mail using MX lookup.
* </li>
* <li><b>gatewayPort</b> (optional) - an Integer for the gateway port to be used for each defined gateway server for which a
* port is not explicitly defined in the <code><gateway/></code> parameter. Default is the default port for the specified connection type.</li>
* <li><b>gatewayUsername</b> (optional) - a String containing the user name to be used to authenticate the user using the
- * AUTH command. Default is not to issue the AUTH command.
+ * AUTH command. Default is not to issue the AUTH command.
* <li><b>gatewayPassword</b> (required if <code>gatewayUsername</code>) is set - a String representing the password to be used
- * to authenticate the user using the AUTH command.
- * <li><b>heloName</b> (optional) - a String containing the name used in the SMTP HELO and EHLO commands. Default is the default domain,
- * which is typically <code>localhost</code>.</li>
+ * to authenticate the user using the AUTH command.
+ * <li><b>heloName</b> (optional) - a String containing the name used in the SMTP HELO and EHLO commands. Default is the default domain,
+ * which is typically <code>localhost</code>.</li>
* <li><b>mail.*</b> (optional) - Any property beginning with <code>mail.</code> described in the Javadoc for package
- * <a href="http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-summary.html"><code>com.sun.mail.smtp</code></a>
+ * <a href="http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-summary.html"><code>com.sun.mail.smtp</code></a>
* can be set with a parameter of the corresponding name. For example the parameter
- * <code><mail.smtp.ssl.enable>true</mail.smtp.ssl.enable></code> is equivalent to the Java code
- * <code>props.put("mail.smtp.ssl.enable", "true");</code>. Properties set by this facility override settings made
+ * <code><mail.smtp.ssl.enable>true</mail.smtp.ssl.enable></code> is equivalent to the Java code
+ * <code>props.put("mail.smtp.ssl.enable", "true");</code>. Properties set by this facility override settings made
* within the mailet code.<br>
- * Note: This facility should be used with extreme care by expert users with a thorough knowledge of the relevant RFCs and
+ * Note: This facility should be used with extreme care by expert users with a thorough knowledge of the relevant RFCs and
* the ability to perform their own problem resolutions.</li>
* <li><b>debug</b> (optional) - a Boolean (true/false) indicating whether debugging is on. Default is false.</li>
* </ul>
*/
public class RemoteDelivery extends GenericMailet implements Runnable {
- /** Default Delay Time (Default is 6*60*60*1000 Milliseconds (6 hours)). */
+ /**
+ * Default Delay Time (Default is 6*60*60*1000 Milliseconds (6 hours)).
+ */
private static final long DEFAULT_DELAY_TIME = 21600000;
- /** Pattern to match [attempts*]delay[units]. */
+ /**
+ * Pattern to match [attempts*]delay[units].
+ */
private static final String PATTERN_STRING = "\\s*([0-9]*\\s*[\\*])?\\s*([0-9]+)\\s*([a-z,A-Z]*)\\s*";
- /** Compiled pattern of the above String. */
- private static Pattern PATTERN = null;
+ private static final Pattern PATTERN = Patterns.compilePatternUncheckedException(PATTERN_STRING);
- /** The DNSService */
@Inject
private DNSService dnsServer;
/**
- * Static initializer.<br>
- * Compiles pattern for processing delaytime entries.<br>
- * Initializes MULTIPLIERS with the supported unit quantifiers
+ * Flag to define verbose logging messages.
*/
- static {
- try {
- PATTERN = Pattern.compile(PATTERN_STRING);
- } catch (PatternSyntaxException mpe) {
- // this should not happen as the pattern string is hardcoded.
- mpe.printStackTrace(System.err);
- }
- }
-
- /** Flag to define verbose logging messages. */
private boolean isDebug = false;
- /** List of Delay Times. Controls frequency of retry attempts. */
+ /**
+ * List of Delay Times. Controls frequency of retry attempts.
+ */
private long[] delayTimes;
- /** Maximum no. of retries (Defaults to 5). */
+ /**
+ * Maximum no. of retries (Defaults to 5).
+ */
private int maxRetries = 5;
- /** Default number of ms to timeout on smtp delivery */
+ /**
+ * Default number of ms to timeout on smtp delivery
+ */
private long smtpTimeout = 180000;
- /** If false then ANY address errors will cause the transmission to fail */
+ /**
+ * If false then ANY address errors will cause the transmission to fail
+ */
private boolean sendPartial = false;
/**
@@ -196,23 +192,25 @@ public class RemoteDelivery extends Gene
*/
private int connectionTimeout = 60000;
- /** No. of threads used to process messages that should be retried. */
+ /**
+ * No. of threads used to process messages that should be retried.
+ */
private int workersThreadCount = 1;
- /** The server(s) to send all email to */
+ /**
+ * The server(s) to send all email to
+ */
private Collection<String> gatewayServer = null;
- /** Auth for gateway server */
+ /**
+ * Auth for gateway server
+ */
private String authUser = null;
- /** Password for gateway server */
- private String authPass = null;
-
/**
- * JavaMail delivery socket binds to this local address. If null the
- * JavaMail default will be used.
+ * Password for gateway server
*/
- private String bindAddress = null;
+ private String authPass = null;
/**
* True, if the bind configuration parameter is supplied,
@@ -220,19 +218,29 @@ public class RemoteDelivery extends Gene
*/
private boolean isBindUsed = false;
- /** Collection that stores all worker threads. */
- private Collection<Thread> workersThreads = new Vector<Thread>();
+ /**
+ * Collection that stores all worker threads.
+ */
+ private final Collection<Thread> workersThreads = new Vector<Thread>();
- /** Flag used by 'run' method to end itself. */
+ /**
+ * Flag used by 'run' method to end itself.
+ */
private volatile boolean destroyed = false;
- /** the processor for creating Bounces */
+ /**
+ * the processor for creating Bounces
+ */
private String bounceProcessor = null;
- /** Default properties for the JavaMail Session */
- private Properties defprops = new Properties();
+ /**
+ * Default properties for the JavaMail Session
+ */
+ private final Properties defprops = new Properties();
- /** The retry count dnsProblemErrors */
+ /**
+ * The retry count dnsProblemErrors
+ */
private int dnsProblemRetry = 0;
private MailQueueFactory queueFactory;
@@ -244,11 +252,11 @@ public class RemoteDelivery extends Gene
private MailetContextLog logAdapter;
private boolean usePriority;
-
+
private DomainList domainList;
private boolean startTLS = false;
-
+
private boolean isSSLEnable = false;
@Inject
@@ -264,9 +272,8 @@ public class RemoteDelivery extends Gene
/**
* Initializes all arguments based on configuration values specified in the
* James configuration file.
- *
- * @throws MessagingException
- * on failure to initialize attributes.
+ *
+ * @throws MessagingException on failure to initialize attributes.
*/
public void init() throws MessagingException {
// Set isDebug flag.
@@ -317,7 +324,7 @@ public class RemoteDelivery extends Gene
// Add extra attempts to the last delayTime.
if (delayTimesList.size() != 0) {
// Get the last delayTime.
- Delay delay = (Delay) delayTimesList.get(delayTimesList.size() - 1);
+ Delay delay = delayTimesList.get(delayTimesList.size() - 1);
// Increase no. of attempts.
delay.setAttempts(delay.getAttempts() + extra);
@@ -366,9 +373,9 @@ public class RemoteDelivery extends Gene
if (sTLS != null) {
startTLS = Boolean.valueOf(sTLS);
}
-
+
isSSLEnable = (getInitParameter("sslEnable") == null) ? false : Boolean.valueOf(getInitParameter("sslEnable"));
-
+
String gateway = getInitParameter("gateway");
String gatewayPort = getInitParameter("gatewayPort");
@@ -394,7 +401,11 @@ public class RemoteDelivery extends Gene
authPass = getInitParameter("gatewayPassword");
}
- bindAddress = getInitParameter("bind");
+ /*
+ JavaMail delivery socket binds to this local address. If null the
+ JavaMail default will be used.
+ */
+ String bindAddress = getInitParameter("bind");
isBindUsed = bindAddress != null;
try {
if (isBindUsed)
@@ -403,7 +414,7 @@ public class RemoteDelivery extends Gene
log("Invalid bind setting (" + bindAddress + "): " + e.toString());
}
-
+
// deal with <mail.*> attributes, passing them to javamail
Iterator<String> i = getInitParameterNames();
while (i.hasNext()) {
@@ -423,7 +434,7 @@ public class RemoteDelivery extends Gene
String prio = getInitParameter("usePriority");
if (prio != null) {
- usePriority = Boolean.valueOf(prio);
+ usePriority = Boolean.valueOf(prio);
}
// Start Workers Threads.
@@ -442,16 +453,13 @@ public class RemoteDelivery extends Gene
/**
* Calculates Total no. of attempts for the specified delayList.
- *
- * @param delayList
- * list of 'Delay' objects
+ *
+ * @param delayList list of 'Delay' objects
* @return total no. of retry attempts
*/
private int calcTotalAttempts(ArrayList<Delay> delayList) {
int sum = 0;
- Iterator<Delay> i = delayList.iterator();
- while (i.hasNext()) {
- Delay delay = i.next();
+ for (Delay delay : delayList) {
sum += delay.getAttempts();
}
return sum;
@@ -462,21 +470,20 @@ public class RemoteDelivery extends Gene
* This method expands an ArrayList containing Delay objects into an array
* holding the only delaytime in the order.
* </p>
- * <p>
+ * <p/>
* So if the list has 2 Delay objects the first having attempts=2 and
* delaytime 4000 the second having attempts=1 and delaytime=300000 will be
* expanded into this array:
- *
+ * <p/>
* <pre>
* long[0] = 4000
* long[1] = 4000
* long[2] = 300000
* </pre>
- *
- * @param list
- * the list to expand
+ *
+ * @param list the list to expand
* @return the expanded list
- **/
+ */
private long[] expandDelays(ArrayList<Delay> list) {
long[] delays = new long[calcTotalAttempts(list)];
Iterator<Delay> i = list.iterator();
@@ -492,11 +499,10 @@ public class RemoteDelivery extends Gene
/**
* This method returns, given a retry-count, the next delay time to use.
- *
- * @param retry_count
- * the current retry_count.
+ *
+ * @param retry_count the current retry_count.
* @return the next delay time to use, given the retry count
- **/
+ */
private long getNextDelay(int retry_count) {
if (retry_count > delayTimes.length) {
return DEFAULT_DELAY_TIME;
@@ -507,7 +513,7 @@ public class RemoteDelivery extends Gene
/**
* This class is used to hold a delay time and its corresponding number of
* retries.
- **/
+ */
private final static class Delay {
private int attempts = 1;
@@ -527,10 +533,9 @@ public class RemoteDelivery extends Gene
* The constructor multiplies the delaytime by the relevant multiplier
* for the unit, so the delayTime instance variable is always in msec.
* </p>
- *
- * @param initString
- * the string to initialize this Delay object from
- **/
+ *
+ * @param initString the string to initialize this Delay object from
+ */
public Delay(String initString) throws MessagingException {
// Default unit value to 'msec'.
String unit = "msec";
@@ -571,40 +576,41 @@ public class RemoteDelivery extends Gene
/**
* This constructor makes a default Delay object with attempts = 1 and
* delayTime = DEFAULT_DELAY_TIME.
- **/
+ */
public Delay() {
}
/**
* @return the delayTime for this Delay
- **/
+ */
public long getDelayTime() {
return delayTime;
}
/**
* @return the number attempts this Delay should be used.
- **/
+ */
public int getAttempts() {
return attempts;
}
/**
* Set the number attempts this Delay should be used.
- **/
+ */
public void setAttempts(int value) {
attempts = value;
}
/**
* Pretty prints this Delay
- **/
+ */
+ @Override
public String toString() {
- String message = getAttempts() + "*" + getDelayTime() + "msecs";
- return message;
+ return getAttempts() + "*" + getDelayTime() + "msecs";
}
}
+ @Override
public String getMailetInfo() {
return "RemoteDelivery Mailet";
}
@@ -615,10 +621,10 @@ public class RemoteDelivery extends Gene
* and then call the deliver (messagecontainer) method for each
* server-specific messagecontainer ... that will handle storing it in the
* outgoing queue if needed.
- *
- * @param mail
- * org.apache.mailet.Mail
+ *
+ * @param mail org.apache.mailet.Mail
*/
+ @Override
public void service(Mail mail) throws MessagingException {
// Do I want to give the internal key, or the message's Message ID
if (isDebug) {
@@ -627,7 +633,7 @@ public class RemoteDelivery extends Gene
Collection<MailAddress> recipients = mail.getRecipients();
if (usePriority) {
-
+
// Use highest prio for new emails. See JAMES-1311
mail.setAttribute(MailPrioritySupport.MAIL_PRIORITY, MailPrioritySupport.HIGH_PRIORITY);
}
@@ -635,8 +641,7 @@ public class RemoteDelivery extends Gene
// Must first organize the recipients into distinct servers (name
// made case insensitive)
Hashtable<String, Collection<MailAddress>> targets = new Hashtable<String, Collection<MailAddress>>();
- for (Iterator<MailAddress> i = recipients.iterator(); i.hasNext();) {
- MailAddress target = i.next();
+ for (MailAddress target : recipients) {
String targetServer = target.getDomain().toLowerCase(Locale.US);
Collection<MailAddress> temp = targets.get(targetServer);
if (temp == null) {
@@ -656,12 +661,12 @@ public class RemoteDelivery extends Gene
String name = mail.getName();
for (Map.Entry<String, Collection<MailAddress>> entry : targets.entrySet()) {
if (isDebug) {
- StringBuilder logMessageBuffer = new StringBuilder(128).append("Sending mail to ").append(entry.getValue()).append(" on host ").append(entry.getKey());
- log(logMessageBuffer.toString());
+ String logMessageBuffer = "Sending mail to " + entry.getValue() + " on host " + entry.getKey();
+ log(logMessageBuffer);
}
mail.setRecipients(entry.getValue());
- StringBuilder nameBuffer = new StringBuilder(128).append(name).append("-to-").append(entry.getKey());
- mail.setName(nameBuffer.toString());
+ String nameBuffer = name + "-to-" + entry.getKey();
+ mail.setName(nameBuffer);
try {
queue.enQueue(mail);
} catch (MailQueueException e) {
@@ -671,8 +676,8 @@ public class RemoteDelivery extends Gene
} else {
// Store the mail unaltered for processing by the gateway server(s)
if (isDebug) {
- StringBuilder logMessageBuffer = new StringBuilder(128).append("Sending mail to ").append(mail.getRecipients()).append(" via ").append(gatewayServer);
- log(logMessageBuffer.toString());
+ String logMessageBuffer = "Sending mail to " + mail.getRecipients() + " via " + gatewayServer;
+ log(logMessageBuffer);
}
// Set it to try to deliver (in a separate thread) immediately
@@ -691,13 +696,13 @@ public class RemoteDelivery extends Gene
* is called by the Mailet container before taking this Mailet out of
* service.
*/
+ @Override
public synchronized void destroy() {
// Mark flag so threads from this Mailet stop themselves
destroyed = true;
// Wake up all threads from waiting for an accept
- for (Iterator<Thread> i = workersThreads.iterator(); i.hasNext();) {
- Thread t = i.next();
+ for (Thread t : workersThreads) {
t.interrupt();
}
notifyAll();
@@ -707,6 +712,7 @@ public class RemoteDelivery extends Gene
* Handles checking the outgoing spool for new mail and delivering them if
* there are any
*/
+ @Override
public void run() {
// Checks the pool and delivers a mail message
@@ -735,7 +741,7 @@ public class RemoteDelivery extends Gene
// handle starttls
props.put("mail.smtp.starttls.enable", String.valueOf(startTLS));
-
+
// handle SSLEnable
props.put("mail.smtp.ssl.enable", String.valueOf(isSSLEnable));
@@ -797,7 +803,7 @@ public class RemoteDelivery extends Gene
}
long delay = getNextDelay(retries);
-
+
if (usePriority) {
// Use lowest priority for retries. See JAMES-1311
mail.setAttribute(MailPrioritySupport.MAIL_PRIORITY, MailPrioritySupport.LOW_PRIORITY);
@@ -854,11 +860,9 @@ public class RemoteDelivery extends Gene
* same mail server. We will now rely on the DNS server to do DNS MX record
* lookup and try to deliver to the multiple mail servers. If it fails, it
* should throw an exception.
- *
- * @param mail
- * org.apache.james.core.MailImpl
- * @param session
- * javax.mail.Session
+ *
+ * @param mail org.apache.james.core.MailImpl
+ * @param session javax.mail.Session
* @return boolean Whether the delivery was successful and the message can
* be deleted
*/
@@ -885,9 +889,9 @@ public class RemoteDelivery extends Gene
// Figure out which servers to try to send to. This collection
// will hold all the possible target servers
- Iterator<HostAddress> targetServers = null;
+ Iterator<HostAddress> targetServers;
if (gatewayServer == null) {
- MailAddress rcpt = (MailAddress) recipients.iterator().next();
+ MailAddress rcpt = recipients.iterator().next();
String host = rcpt.getDomain();
// Lookup the possible targets
@@ -895,14 +899,14 @@ public class RemoteDelivery extends Gene
targetServers = new MXHostAddressIterator(dnsServer.findMXRecords(host).iterator(), dnsServer, false, logAdapter);
} catch (TemporaryResolutionException e) {
log("Temporary problem looking up mail server for host: " + host);
- StringBuilder exceptionBuffer = new StringBuilder(128).append("Temporary problem looking up mail server for host: ").append(host).append(". I cannot determine where to send this message.");
+ String exceptionBuffer = "Temporary problem looking up mail server for host: " + host + ". I cannot determine where to send this message.";
// temporary problems
- return failMessage(mail, new MessagingException(exceptionBuffer.toString()), false);
+ return failMessage(mail, new MessagingException(exceptionBuffer), false);
}
if (!targetServers.hasNext()) {
log("No mail server found for: " + host);
- StringBuilder exceptionBuffer = new StringBuilder(128).append("There are no DNS entries for the hostname ").append(host).append(". I cannot determine where to send this message.");
+ String exceptionBuffer = "There are no DNS entries for the hostname " + host + ". I cannot determine where to send this message.";
int retry = 0;
try {
@@ -913,9 +917,9 @@ public class RemoteDelivery extends Gene
if (retry == 0 || retry > dnsProblemRetry) {
// The domain has no dns entry.. Return a permanent
// error
- return failMessage(mail, new MessagingException(exceptionBuffer.toString()), true);
+ return failMessage(mail, new MessagingException(exceptionBuffer), true);
} else {
- return failMessage(mail, new MessagingException(exceptionBuffer.toString()), false);
+ return failMessage(mail, new MessagingException(exceptionBuffer), false);
}
}
} else {
@@ -966,7 +970,7 @@ public class RemoteDelivery extends Gene
// MX record. Just log the exception. We'll worry
// about
// failing the message at the end of the loop.
-
+
// Also include the stacktrace if debug is enabled. See JAMES-1257
if (isDebug) {
log(me.getMessage(), me.getCause());
@@ -980,8 +984,8 @@ public class RemoteDelivery extends Gene
if (transport.getClass().getName().endsWith(".SMTPTransport")) {
boolean supports8bitmime = false;
try {
- Method supportsExtension = transport.getClass().getMethod("supportsExtension", new Class[] { String.class });
- supports8bitmime = ((Boolean) supportsExtension.invoke(transport, new Object[] { "8BITMIME" })).booleanValue();
+ Method supportsExtension = transport.getClass().getMethod("supportsExtension", new Class[]{String.class});
+ supports8bitmime = (Boolean) supportsExtension.invoke(transport, "8BITMIME");
} catch (NoSuchMethodException nsme) {
// An SMTPAddressFailedException with no
// getAddress method.
@@ -1051,8 +1055,8 @@ public class RemoteDelivery extends Gene
if (sfe.getValidSentAddresses() != null) {
Address[] validSent = sfe.getValidSentAddresses();
if (validSent.length > 0) {
- StringBuilder logMessageBuffer = new StringBuilder(256).append("Mail (").append(mail.getName()).append(") sent successfully for ").append(Arrays.asList(validSent));
- log(logMessageBuffer.toString());
+ String logMessageBuffer = "Mail (" + mail.getName() + ") sent successfully for " + Arrays.asList(validSent);
+ log(logMessageBuffer);
}
}
@@ -1062,7 +1066,7 @@ public class RemoteDelivery extends Gene
*/
if (sfe.getClass().getName().endsWith(".SMTPSendFailedException")) {
try {
- int returnCode = ((Integer) invokeGetter(sfe, "getReturnCode")).intValue();
+ int returnCode = (Integer) invokeGetter(sfe, "getReturnCode");
// if 5xx, terminate this delivery attempt by
// re-throwing the exception.
if (returnCode >= 500 && returnCode <= 599)
@@ -1076,7 +1080,6 @@ public class RemoteDelivery extends Gene
if (isDebug)
log("Send failed, " + sfe.getValidUnsentAddresses().length + " valid addresses remain, continuing with any other servers");
lastError = sfe;
- continue;
} else {
// There are no valid addresses left to send, so rethrow
throw sfe;
@@ -1084,8 +1087,8 @@ public class RemoteDelivery extends Gene
} catch (MessagingException me) {
// MessagingException are horribly difficult to figure out
// what actually happened.
- StringBuilder exceptionBuffer = new StringBuilder(256).append("Exception delivering message (").append(mail.getName()).append(") - ").append(me.getMessage());
- log(exceptionBuffer.toString());
+ String exceptionBuffer = "Exception delivering message (" + mail.getName() + ") - " + me.getMessage();
+ log(exceptionBuffer);
if ((me.getNextException() != null) && (me.getNextException() instanceof java.io.IOException)) {
// This is more than likely a temporary failure
@@ -1105,12 +1108,12 @@ public class RemoteDelivery extends Gene
throw me;
}
} // end while
- // If we encountered an exception while looping through,
- // throw the last MessagingException we caught. We only
- // do this if we were unable to send the message to any
- // server. If sending eventually succeeded, we exit
- // deliver() though the return at the end of the try
- // block.
+ // If we encountered an exception while looping through,
+ // throw the last MessagingException we caught. We only
+ // do this if we were unable to send the message to any
+ // server. If sending eventually succeeded, we exit
+ // deliver() though the return at the end of the try
+ // block.
if (lastError != null) {
throw lastError;
}
@@ -1146,7 +1149,7 @@ public class RemoteDelivery extends Gene
*/
try {
if (sfe.getClass().getName().endsWith(".SMTPSendFailedException")) {
- int returnCode = ((Integer) invokeGetter(sfe, "getReturnCode")).intValue();
+ int returnCode = (Integer) invokeGetter(sfe, "getReturnCode");
// If we got an SMTPSendFailedException, use its RetCode to
// determine default permanent/temporary failure
deleteMessage = (returnCode >= 500 && returnCode <= 599);
@@ -1159,7 +1162,7 @@ public class RemoteDelivery extends Gene
while ((ne = me.getNextException()) != null && ne instanceof MessagingException) {
me = (MessagingException) ne;
if (me.getClass().getName().endsWith(".SMTPAddressFailedException")) {
- int returnCode = ((Integer) invokeGetter(me, "getReturnCode")).intValue();
+ int returnCode = (Integer) invokeGetter(me, "getReturnCode");
deleteMessage = (returnCode >= 500 && returnCode <= 599);
}
}
@@ -1180,9 +1183,9 @@ public class RemoteDelivery extends Gene
Address[] address = sfe.getInvalidAddresses();
if (address.length > 0) {
recipients.clear();
- for (int i = 0; i < address.length; i++) {
+ for (Address addres : address) {
try {
- recipients.add(new MailAddress(address[i].toString()));
+ recipients.add(new MailAddress(addres.toString()));
} catch (ParseException pe) {
// this should never happen ... we should have
// caught malformed addresses long before we
@@ -1192,7 +1195,7 @@ public class RemoteDelivery extends Gene
}
// Set the recipients for the mail
mail.setRecipients(recipients);
-
+
if (isDebug)
log("Invalid recipients: " + recipients);
deleteMessage = failMessage(mail, sfe, true);
@@ -1203,9 +1206,9 @@ public class RemoteDelivery extends Gene
Address[] address = sfe.getValidUnsentAddresses();
if (address.length > 0) {
recipients.clear();
- for (int i = 0; i < address.length; i++) {
+ for (Address addres : address) {
try {
- recipients.add(new MailAddress(address[i].toString()));
+ recipients.add(new MailAddress(addres.toString()));
} catch (ParseException pe) {
// this should never happen ... we should have
// caught malformed addresses long before we
@@ -1218,15 +1221,15 @@ public class RemoteDelivery extends Gene
if (isDebug)
log("Unsent recipients: " + recipients);
if (sfe.getClass().getName().endsWith(".SMTPSendFailedException")) {
- int returnCode = ((Integer) invokeGetter(sfe, "getReturnCode")).intValue();
+ int returnCode = (Integer) invokeGetter(sfe, "getReturnCode");
deleteMessage = failMessage(mail, sfe, returnCode >= 500 && returnCode <= 599);
} else {
deleteMessage = failMessage(mail, sfe, false);
}
}
}
-
-
+
+
return deleteMessage;
} catch (MessagingException ex) {
// We should do a better job checking this... if the failure is a
@@ -1261,9 +1264,8 @@ public class RemoteDelivery extends Gene
/**
* Try to return a usefull logString created of the Exception which was
* given. Return null if nothing usefull could be done
- *
- * @param e
- * The MessagingException to use
+ *
+ * @param e The MessagingException to use
* @return logString
*/
private String exceptionToLogString(Exception e) {
@@ -1287,7 +1289,7 @@ public class RemoteDelivery extends Gene
if (ex.getClass().getName().endsWith(".SMTPAddressFailedException")) {
try {
InternetAddress ia = (InternetAddress) invokeGetter(ex, "getAddress");
- sb.append(" ( " + ia + " - [" + ex.getMessage().replaceAll("\\n", "") + "] )");
+ sb.append(" ( ").append(ia).append(" - [").append(ex.getMessage().replaceAll("\\n", "")).append("] )");
smtpExFound = true;
} catch (IllegalStateException ise) {
// Error invoking the getAddress method
@@ -1306,7 +1308,7 @@ public class RemoteDelivery extends Gene
invalidAddr = true;
}
if (exception.getValidUnsentAddresses().length > 0) {
- if (invalidAddr == true)
+ if (invalidAddr)
sb.append(" ");
sb.append(Arrays.toString(exception.getValidUnsentAddresses()));
}
@@ -1322,14 +1324,11 @@ public class RemoteDelivery extends Gene
/**
* Utility method used to invoke getters for javamail implementation
* specific classes.
- *
- * @param target
- * the object whom method will be invoked
- * @param getter
- * the no argument method name
+ *
+ * @param target the object whom method will be invoked
+ * @param getter the no argument method name
* @return the result object
- * @throws IllegalStateException
- * on invocation error
+ * @throws IllegalStateException on invocation error
*/
private Object invokeGetter(Object target, String getter) {
try {
@@ -1399,7 +1398,7 @@ public class RemoteDelivery extends Gene
/**
* Converts a message to 7 bit.
- *
+ *
* @param part
*/
private void convertTo7Bit(MimePart part) throws MessagingException, IOException {
@@ -1430,11 +1429,9 @@ public class RemoteDelivery extends Gene
/**
* Insert the method's description here.
- *
- * @param mail
- * org.apache.james.core.MailImpl
- * @param ex
- * javax.mail.MessagingException
+ *
+ * @param mail org.apache.james.core.MailImpl
+ * @param ex javax.mail.MessagingException
* @param permanent
* @return boolean Whether the message failed fully and can be deleted
*/
@@ -1523,9 +1520,8 @@ public class RemoteDelivery extends Gene
/**
* Utility method for getting the error message from the (nested) exception.
- *
- * @param me
- * MessagingException
+ *
+ * @param me MessagingException
* @return error message
*/
protected String getErrorMsg(MessagingException me) {
@@ -1540,22 +1536,22 @@ public class RemoteDelivery extends Gene
private void bounce(Mail mail, Exception ex) {
StringWriter sout = new StringWriter();
PrintWriter out = new PrintWriter(sout, true);
- String machine = "[unknown]";
+ String machine;
try {
machine = getHeloName();
} catch (Exception e) {
machine = "[address unknown]";
}
- StringBuilder bounceBuffer = new StringBuilder(128).append("Hi. This is the James mail server at ").append(machine).append(".");
- out.println(bounceBuffer.toString());
+ String bounceBuffer = "Hi. This is the James mail server at " + machine + ".";
+ out.println(bounceBuffer);
out.println("I'm afraid I wasn't able to deliver your message to the following addresses.");
out.println("This is a permanent error; I've given up. Sorry it didn't work out. Below");
out.println("I include the list of recipients and the reason why I was unable to deliver");
out.println("your message.");
out.println();
- for (Iterator<MailAddress> i = mail.getRecipients().iterator(); i.hasNext();) {
- out.println(i.next());
+ for (MailAddress mailAddress : mail.getRecipients()) {
+ out.println(mailAddress);
}
if (ex instanceof MessagingException) {
if (((MessagingException) ex).getNextException() == null) {
@@ -1591,7 +1587,7 @@ public class RemoteDelivery extends Gene
/**
* Returns the javamail Session object.
- *
+ *
* @param props
* @return the java mail session
*/
@@ -1607,12 +1603,10 @@ public class RemoteDelivery extends Gene
* hasNext() will return false. The Iterator is a nested iterator: the outer
* iteration is over each gateway, and the inner iteration is over
* potentially multiple A records for each gateway.
- *
- * @see org.apache.james.DNSServer#getSMTPHostAddresses(String)
- * @since v2.2.0a16-unstable
- * @param gatewayServers
- * - Collection of host[:port] Strings
+ *
+ * @param gatewayServers - Collection of host[:port] Strings
* @return an Iterator over HostAddress instances, sorted by priority
+ * @since v2.2.0a16-unstable
*/
private Iterator<HostAddress> getGatewaySMTPHostAddresses(final Collection<String> gatewayServers) {
Iterator<String> gateways = gatewayServers.iterator();
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org