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 no...@apache.org on 2011/12/31 23:02:55 UTC
svn commit: r1226195 - in
/james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core:
AbstractAddHeadersFilter.java ReceivedDataLineFilter.java
Author: norman
Date: Sat Dec 31 22:02:54 2011
New Revision: 1226195
URL: http://svn.apache.org/viewvc?rev=1226195&view=rev
Log:
Small code improvements.
Modified:
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractAddHeadersFilter.java
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java
Modified: james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractAddHeadersFilter.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractAddHeadersFilter.java?rev=1226195&r1=1226194&r2=1226195&view=diff
==============================================================================
--- james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractAddHeadersFilter.java (original)
+++ james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractAddHeadersFilter.java Sat Dec 31 22:02:54 2011
@@ -96,12 +96,17 @@ public abstract class AbstractAddHeaders
protected abstract Collection<Header> headers(SMTPSession session);
public final static class Header {
+ public static final String MULTI_LINE_PREFIX = " ";
+
public final String name;
public final String value;
-
+
+ private final String[] lines;
+
public Header(String name, String value) {
this.name = name;
this.value = value;
+ this.lines = toString().split("\r\n");
}
public String toString() {
@@ -120,7 +125,6 @@ public abstract class AbstractAddHeaders
*/
public Response transferTo(SMTPSession session, LineHandler<SMTPSession> handler) {
try {
- String[] lines = toString().split("\r\n");
Response response = null;
for (int i = 0; i < lines.length; i++) {
response = handler.onLine(session, ByteBuffer.wrap((lines[i] + "\r\n").getBytes("US-ASCII")));
Modified: james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java?rev=1226195&r1=1226194&r2=1226195&view=diff
==============================================================================
--- james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java (original)
+++ james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java Sat Dec 31 22:02:54 2011
@@ -37,6 +37,11 @@ import org.apache.james.protocols.smtp.S
*/
public class ReceivedDataLineFilter extends AbstractAddHeadersFilter {
+ private static final String EHLO ="EHLO";
+ private static final String SMTP = "SMTP";
+ private static final String ESMTPA = "ESMTPA";
+ private static final String ESMTP = "ESMTP";
+
private static final ThreadLocal<DateFormat> DATEFORMAT = new ThreadLocal<DateFormat>() {
@Override
@@ -58,10 +63,10 @@ public class ReceivedDataLineFilter exte
*/
protected String getServiceType(SMTPSession session, String heloMode) {
// Check if EHLO was used
- if ("EHLO".equals(heloMode)) {
+ if (EHLO.equals(heloMode)) {
// Not successful auth
if (session.getUser() == null) {
- return "ESMTP";
+ return ESMTP;
} else {
// See RFC3848
// The new keyword "ESMTPA" indicates the use of ESMTP when
@@ -70,10 +75,10 @@ public class ReceivedDataLineFilter exte
// AUTH [3] extension is also used and authentication is
// successfully
// achieved.
- return "ESMTPA";
+ return ESMTPA;
}
} else {
- return "SMTP";
+ return SMTP;
}
}
@@ -105,7 +110,7 @@ public class ReceivedDataLineFilter exte
headerLineBuffer.append(" ([").append(session.getRemoteAddress().getAddress().getHostAddress()).append("])").append("\r\n");
headerLineBuffer.delete(0, headerLineBuffer.length());
- headerLineBuffer.append(" by ").append(session.getConfiguration().getHelloName()).append(" (").append(session.getConfiguration().getSoftwareName()).append(") with ").append(getServiceType(session, heloMode));
+ headerLineBuffer.append(Header.MULTI_LINE_PREFIX).append("by ").append(session.getConfiguration().getHelloName()).append(" (").append(session.getConfiguration().getSoftwareName()).append(") with ").append(getServiceType(session, heloMode));
headerLineBuffer.append(" ID ").append(session.getSessionID());
if (((Collection<?>) session.getAttachment(SMTPSession.RCPT_LIST, State.Transaction)).size() == 1) {
@@ -113,12 +118,12 @@ public class ReceivedDataLineFilter exte
// (prevents email address harvesting and large headers in
// bulk email)
headerLineBuffer.append("\r\n");
- headerLineBuffer.append(" for <").append(((List<MailAddress>) session.getAttachment(SMTPSession.RCPT_LIST, State.Transaction)).get(0).toString()).append(">;");
+ headerLineBuffer.append(Header.MULTI_LINE_PREFIX).append("for <").append(((List<MailAddress>) session.getAttachment(SMTPSession.RCPT_LIST, State.Transaction)).get(0).toString()).append(">;");
} else {
// Put the ; on the end of the 'by' line
headerLineBuffer.append(";");
}
- headerLineBuffer.append(" " + DATEFORMAT.get().format(new Date()));
+ headerLineBuffer.append(Header.MULTI_LINE_PREFIX).append(DATEFORMAT.get().format(new Date()));
return Arrays.asList(new Header("Received", headerLineBuffer.toString()));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org