serge 2003/01/09 10:57:59
Modified: src/java/org/apache/james/smtpserver Tag: branch_2_1_fcs
SMTPHandler.java
Log:
Uses the underlying inputstream rather than the wrappers of an InputStreamReader and
a BufferedReader, both which introduce extra buffers (one of which is not
controllable).
This could use more testing on alternate platforms, and this also allows a
non-compliant client to send messages to James again. Will discuss if/how to enforce
client protocol compliance on the list.
Revision Changes Path
No revision
No revision
1.35.4.1 +43 -29
jakarta-james/src/java/org/apache/james/smtpserver/SMTPHandler.java
Index: SMTPHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/smtpserver/SMTPHandler.java,v
retrieving revision 1.35
retrieving revision 1.35.4.1
diff -u -r1.35 -r1.35.4.1
--- SMTPHandler.java 2 Nov 2002 09:03:51 -0000 1.35
+++ SMTPHandler.java 9 Jan 2003 18:57:59 -0000 1.35.4.1
@@ -52,7 +52,7 @@
// Keys used to store/lookup data in the internal state hash map
private final static String CURRENT_HELO_MODE = "CURRENT_HELO_MODE"; // HELO or
EHLO
- private final static String SENDER = "SENDER_ADDRESS"; // Sender's email
address
+ private final static String SENDER = "SENDER_ADDRESS"; // Sender's email
address
private final static String MESG_FAILED = "MESG_FAILED"; // Message failed
flag
private final static String MESG_SIZE = "MESG_SIZE"; // The size of the
message
private final static String RCPT_LIST = "RCPT_LIST"; // The message recipients
@@ -148,12 +148,12 @@
private final static String MAIL_OPTION_SIZE = "SIZE";
/**
- * The thread executing this handler
+ * The thread executing this handler
*/
private Thread handlerThread;
/**
- * The TCP/IP socket over which the SMTP
+ * The TCP/IP socket over which the SMTP
* dialogue is occurring.
*/
private Socket socket;
@@ -169,11 +169,6 @@
private PrintWriter out;
/**
- * A Reader wrapper for the incoming stream of bytes coming from the socket.
- */
- private BufferedReader inReader;
-
- /**
* The remote host name obtained by lookup on the socket.
*/
private String remoteHost;
@@ -284,16 +279,12 @@
handlerThread = Thread.currentThread();
}
in = new BufferedInputStream(socket.getInputStream(), 1024);
- // An ASCII encoding can be used because all transmissions other
- // that those in the DATA command are guaranteed
- // to be ASCII
- inReader = new BufferedReader(new InputStreamReader(in, "ASCII"), 512);
remoteIP = socket.getInetAddress().getHostAddress();
remoteHost = socket.getInetAddress().getHostName();
smtpID = random.nextInt(1024) + "";
resetState();
} catch (Exception e) {
- StringBuffer exceptionBuffer =
+ StringBuffer exceptionBuffer =
new StringBuffer(256)
.append("Cannot open connection from ")
.append(remoteHost)
@@ -307,7 +298,7 @@
}
if (getLogger().isInfoEnabled()) {
- StringBuffer infoBuffer =
+ StringBuffer infoBuffer =
new StringBuffer(128)
.append("Connection from ")
.append(remoteHost)
@@ -341,7 +332,7 @@
getLogger().debug("Closing socket.");
} catch (SocketException se) {
if (getLogger().isDebugEnabled()) {
- StringBuffer errorBuffer =
+ StringBuffer errorBuffer =
new StringBuffer(64)
.append("Socket to ")
.append(remoteHost)
@@ -352,7 +343,7 @@
}
} catch ( InterruptedIOException iioe ) {
if (getLogger().isDebugEnabled()) {
- StringBuffer errorBuffer =
+ StringBuffer errorBuffer =
new StringBuffer(64)
.append("Socket to ")
.append(remoteHost)
@@ -363,7 +354,7 @@
}
} catch ( IOException ioe ) {
if (getLogger().isDebugEnabled()) {
- StringBuffer errorBuffer =
+ StringBuffer errorBuffer =
new StringBuffer(256)
.append("Exception handling socket to ")
.append(remoteHost)
@@ -391,7 +382,6 @@
clearResponseBuffer();
in = null;
- inReader = null;
out = null;
remoteHost = null;
remoteIP = null;
@@ -436,7 +426,7 @@
}
/**
- * This method logs at a "DEBUG" level the response string that
+ * This method logs at a "DEBUG" level the response string that
* was sent to the SMTP client. The method is provided largely
* as syntactic sugar to neaten up the code base. It is declared
* private and final to encourage compiler inlining.
@@ -463,7 +453,7 @@
}
/**
- * Write a response string. The response is also logged.
+ * Write a response string. The response is also logged.
* Used for multi-line responses.
*
* @param responseString the response string sent to the client
@@ -480,7 +470,31 @@
* @throws IOException if an exception is generated reading in the input
characters
*/
final String readCommandLine() throws IOException {
- return inReader.readLine().trim();
+ //Read through for \r or \n
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ byte b = -1;
+ while (true) {
+ in.mark(1);
+ b = (byte) in.read();
+ if (b == 13) {
+ //We're done, but we want to see if \n is next
+ b = (byte) in.read();
+ if (b != 10) {
+ in.reset();
+ }
+ break;
+ } else if (b == 10) {
+ //We're done
+ break;
+ } else if (b == -1) {
+ break;
+ }
+ bout.write(b);
+ }
+ // An ASCII encoding can be used because all transmissions other
+ // that those in the DATA command are guaranteed
+ // to be ASCII
+ return bout.toString("ASCII").trim();
}
/**
@@ -868,7 +882,7 @@
} else {
// Unexpected option attached to the Mail command
if (getLogger().isDebugEnabled()) {
- StringBuffer debugBuffer =
+ StringBuffer debugBuffer =
new StringBuffer(128)
.append("MAIL command had
unrecognized/unexpected option ")
.append(mailOptionName)
@@ -907,7 +921,7 @@
responseString = "501 Syntax error in sender address";
writeLoggedFlushedResponse(responseString);
if (getLogger().isErrorEnabled()) {
- StringBuffer errorBuffer =
+ StringBuffer errorBuffer =
new StringBuffer(256)
.append("Error parsing sender address: ")
.append(sender)
@@ -945,7 +959,7 @@
return false;
}
if (getLogger().isDebugEnabled()) {
- StringBuffer debugBuffer =
+ StringBuffer debugBuffer =
new StringBuffer(128)
.append("MAIL command option SIZE received with value ")
.append(size)
@@ -1029,7 +1043,7 @@
}
// Unexpected option attached to the RCPT command
if (getLogger().isDebugEnabled()) {
- StringBuffer debugBuffer =
+ StringBuffer debugBuffer =
new StringBuffer(128)
.append("RCPT command had unrecognized/unexpected
option ")
.append(rcptOptionName)
@@ -1044,7 +1058,7 @@
responseString = "501 Syntax error in parameters or arguments";
writeLoggedFlushedResponse(responseString);
if (getLogger().isErrorEnabled()) {
- StringBuffer errorBuffer =
+ StringBuffer errorBuffer =
new StringBuffer(192)
.append("Error parsing recipient address: ")
.append(recipient)
@@ -1066,7 +1080,7 @@
writeLoggedFlushedResponse(responseString);
if (getLogger().isErrorEnabled()) {
- StringBuffer errorBuffer =
+ StringBuffer errorBuffer =
new StringBuffer(192)
.append("Error parsing recipient address: ")
.append(recipient)
@@ -1183,7 +1197,7 @@
long maxMessageSize = theConfigData.getMaxMessageSize();
if (maxMessageSize > 0) {
if (getLogger().isDebugEnabled()) {
- StringBuffer logBuffer =
+ StringBuffer logBuffer =
new StringBuffer(128)
.append("Using SizeLimitedInputStream ")
.append(" with max message size: ")
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>