Author: norman Date: Sat Nov 26 21:48:13 2011 New Revision: 1206615 URL: http://svn.apache.org/viewvc?rev=1206615&view=rev Log: Adjustments for java 5 support. Thanks again to Felix!
Modified: james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/AuthCmdHandler.java 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=1206615&r1=1206614&r2=1206615&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 Nov 26 21:48:13 2011 @@ -18,6 +18,7 @@ ****************************************************************/ package org.apache.james.protocols.smtp.core; +import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.util.Collection; import java.util.Date; @@ -32,7 +33,7 @@ import org.apache.mailet.base.RFC822Date public class ReceivedDataLineFilter implements DataLineFilter { - private final static Charset CHARSET = Charset.forName("US-ASCII"); + private final static String CHARSET = "US-ASCII"; private final static String SOFTWARE_TYPE = "JAMES SMTP Server "; @@ -64,86 +65,84 @@ public class ReceivedDataLineFilter impl } @SuppressWarnings("unchecked") - private Response addNewReceivedMailHeaders(SMTPSession session, LineHandler<SMTPSession> next) { - StringBuilder headerLineBuffer = new StringBuilder(); + private Response addNewReceivedMailHeaders(SMTPSession session, LineHandler<SMTPSession> next) { + try { + StringBuilder headerLineBuffer = new StringBuilder(); - String heloMode = (String) session.getConnectionState().get( - SMTPSession.CURRENT_HELO_MODE); - String heloName = (String) session.getConnectionState().get( - SMTPSession.CURRENT_HELO_NAME); - - // Put our Received header first - headerLineBuffer.append(RFC2822Headers.RECEIVED + ": from ").append( - session.getRemoteAddress().getHostName()); - - if (heloName != null) { - headerLineBuffer.append(" (").append(heloMode).append(" ").append( - heloName).append(") "); - } - - headerLineBuffer.append(" ([").append(session.getRemoteAddress().getAddress().getHostAddress()) - .append("])").append("\r\n"); - - Response response = next.onLine(session, headerLineBuffer.toString().getBytes(CHARSET)); - if (response != null) { - return response; - } - headerLineBuffer.delete(0, headerLineBuffer.length()); + String heloMode = (String) session.getConnectionState().get(SMTPSession.CURRENT_HELO_MODE); + String heloName = (String) session.getConnectionState().get(SMTPSession.CURRENT_HELO_NAME); - headerLineBuffer.append(" by ").append(session.getHelloName()) - .append(" (").append(SOFTWARE_TYPE).append(") with "); + // Put our Received header first + headerLineBuffer.append(RFC2822Headers.RECEIVED + ": from ").append(session.getRemoteAddress().getHostName()); - // Check if EHLO was used - if ("EHLO".equals(heloMode)) { - // Not successful auth - if (session.getUser() == null) { - headerLineBuffer.append("ESMTP"); - } else { - // See RFC3848 - // The new keyword "ESMTPA" indicates the use of ESMTP when the - // SMTP - // AUTH [3] extension is also used and authentication is - // successfully - // achieved. - headerLineBuffer.append("ESMTPA"); + if (heloName != null) { + headerLineBuffer.append(" (").append(heloMode).append(" ").append(heloName).append(") "); } - } else { - headerLineBuffer.append("SMTP"); - } - headerLineBuffer.append(" ID ").append(session.getSessionID()); + headerLineBuffer.append(" ([").append(session.getRemoteAddress().getAddress().getHostAddress()).append("])").append("\r\n"); - if (((Collection<?>) session.getState().get(SMTPSession.RCPT_LIST)).size() == 1) { - // Only indicate a recipient if they're the only recipient - // (prevents email address harvesting and large headers in - // bulk email) - headerLineBuffer.append("\r\n"); - next.onLine(session, headerLineBuffer.toString().getBytes(CHARSET)); - headerLineBuffer.delete(0, headerLineBuffer.length()); - - headerLineBuffer.delete(0, headerLineBuffer.length()); - headerLineBuffer.append(" for <").append(((List<MailAddress>) session.getState().get(SMTPSession.RCPT_LIST)).get(0).toString()).append(">;").append("\r\n"); - response = next.onLine(session, headerLineBuffer.toString().getBytes(CHARSET)); - + Response response = next.onLine(session, headerLineBuffer.toString().getBytes(CHARSET)); if (response != null) { - return response; + return response; } headerLineBuffer.delete(0, headerLineBuffer.length()); - headerLineBuffer.delete(0, headerLineBuffer.length()); - - } else { - // Put the ; on the end of the 'by' line - headerLineBuffer.append(";"); - headerLineBuffer.append("\r\n"); - response = next.onLine(session, headerLineBuffer.toString().getBytes(CHARSET)); - if (response != null) { - return response; + headerLineBuffer.append(" by ").append(session.getHelloName()).append(" (").append(SOFTWARE_TYPE).append(") with "); + + // Check if EHLO was used + if ("EHLO".equals(heloMode)) { + // Not successful auth + if (session.getUser() == null) { + headerLineBuffer.append("ESMTP"); + } else { + // See RFC3848 + // The new keyword "ESMTPA" indicates the use of ESMTP when + // the + // SMTP + // AUTH [3] extension is also used and authentication is + // successfully + // achieved. + headerLineBuffer.append("ESMTPA"); + } + } else { + headerLineBuffer.append("SMTP"); } - headerLineBuffer.delete(0, headerLineBuffer.length()); - } - headerLineBuffer = null; - return next.onLine(session, (" " + rfc822DateFormat.format(new Date()) + "\r\n").getBytes(CHARSET)); + headerLineBuffer.append(" ID ").append(session.getSessionID()); + + if (((Collection<?>) session.getState().get(SMTPSession.RCPT_LIST)).size() == 1) { + // Only indicate a recipient if they're the only recipient + // (prevents email address harvesting and large headers in + // bulk email) + headerLineBuffer.append("\r\n"); + next.onLine(session, headerLineBuffer.toString().getBytes(CHARSET)); + headerLineBuffer.delete(0, headerLineBuffer.length()); + + headerLineBuffer.delete(0, headerLineBuffer.length()); + headerLineBuffer.append(" for <").append(((List<MailAddress>) session.getState().get(SMTPSession.RCPT_LIST)).get(0).toString()).append(">;").append("\r\n"); + response = next.onLine(session, headerLineBuffer.toString().getBytes(CHARSET)); + + if (response != null) { + return response; + } + headerLineBuffer.delete(0, headerLineBuffer.length()); + headerLineBuffer.delete(0, headerLineBuffer.length()); + + } else { + // Put the ; on the end of the 'by' line + headerLineBuffer.append(";"); + headerLineBuffer.append("\r\n"); + + response = next.onLine(session, headerLineBuffer.toString().getBytes(CHARSET)); + if (response != null) { + return response; + } + headerLineBuffer.delete(0, headerLineBuffer.length()); + } + headerLineBuffer = null; + return next.onLine(session, (" " + rfc822DateFormat.format(new Date()) + "\r\n").getBytes(CHARSET)); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException("No US-ASCII support ?"); + } } } Modified: james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/AuthCmdHandler.java URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/AuthCmdHandler.java?rev=1206615&r1=1206614&r2=1206615&view=diff ============================================================================== --- james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/AuthCmdHandler.java (original) +++ james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/AuthCmdHandler.java Sat Nov 26 21:48:13 2011 @@ -21,7 +21,7 @@ package org.apache.james.protocols.smtp.core.esmtp; -import java.nio.charset.Charset; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -62,11 +62,15 @@ public class AuthCmdHandler private static final String[] MAIL_PARAMS = { "AUTH" }; private static final List<String> ESMTP_FEATURES = Collections.unmodifiableList(Arrays.asList("AUTH LOGIN PLAIN", "AUTH=LOGIN PLAIN")); - private final static Charset CHARSET = Charset.forName("US-ASCII"); + private final static String CHARSET = "US-ASCII"; private abstract class AbstractSMTPLineHandler implements LineHandler<SMTPSession> { public Response onLine(SMTPSession session, byte[] l) { - return handleCommand(session, new String(l, CHARSET)); + try { + return handleCommand(session, new String(l, CHARSET)); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException("No " + CHARSET + " support!"); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org