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 2006/08/04 17:08:23 UTC
svn commit: r428748 [1/3] - in /james/server/sandbox/handlerapi2/src:
java/org/apache/james/smtpserver/ java/org/apache/james/smtpserver/core/
java/org/apache/james/smtpserver/core/filter/
java/org/apache/james/smtpserver/core/filter/fastfail/ test/org...
Author: norman
Date: Fri Aug 4 08:08:20 2006
New Revision: 428748
URL: http://svn.apache.org/viewvc?rev=428748&view=rev
Log:
Commit some changes to show for new handler api
Added:
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/IOState.java
Removed:
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/Chain.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/IOObject.java
Modified:
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/CommandHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/ConnectHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/SMTPHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/SMTPSession.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/AuthCmdHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/EhloCmdHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/ExpnCmdHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/HeloCmdHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/HelpCmdHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/MailCmdHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/NoopCmdHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/POP3BeforeSMTPHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/QuitCmdHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/RcptCmdHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/RsetCmdHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/SendMailHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/SetMimeHeaderHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/UnknownCmdHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/VrfyCmdHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/filter/DataFilterCmdHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/filter/EhloHeloFilterCmdHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/filter/MailFilterCmdHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/filter/RcptFilterCmdHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/filter/fastfail/ResolvableEhloHeloHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/filter/fastfail/ReverseEqualsEhloHeloHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/filter/fastfail/SpamAssassinHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/filter/fastfail/TarpitHandler.java
james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java
james/server/sandbox/handlerapi2/src/test/org/apache/james/smtpserver/AbstractSMTPSession.java
james/server/sandbox/handlerapi2/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java
james/server/sandbox/handlerapi2/src/test/org/apache/james/smtpserver/POP3BeforeSMTPHandlerTest.java
james/server/sandbox/handlerapi2/src/test/org/apache/james/smtpserver/ResolvableEhloHeloHandlerTest.java
james/server/sandbox/handlerapi2/src/test/org/apache/james/smtpserver/SPFHandlerTest.java
james/server/sandbox/handlerapi2/src/test/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
james/server/sandbox/handlerapi2/src/test/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
james/server/sandbox/handlerapi2/src/test/org/apache/james/smtpserver/TarpitHandlerTest.java
james/server/sandbox/handlerapi2/src/test/org/apache/james/smtpserver/ValidSenderDomainHandlerTest.java
Modified: james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/CommandHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/CommandHandler.java?rev=428748&r1=428747&r2=428748&view=diff
==============================================================================
--- james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/CommandHandler.java (original)
+++ james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/CommandHandler.java Fri Aug 4 08:08:20 2006
@@ -17,24 +17,21 @@
* under the License. *
****************************************************************/
-
-
package org.apache.james.smtpserver;
import java.util.Collection;
-
/**
* Custom command handlers must implement this interface
* The command handlers will be Server wide common to all the SMTPHandlers,
* therefore the command handlers must store all the state information
* in the SMTPSession object
*/
- public interface CommandHandler {
-
+public interface CommandHandler {
+
/**
* Handle the command
- **/
+ **/
void onCommand(SMTPSession session);
/**
@@ -43,5 +40,5 @@
* @return Collection which contains implemented commands
*/
Collection getImplCommands();
-
+
}
Modified: james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/ConnectHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/ConnectHandler.java?rev=428748&r1=428747&r2=428748&view=diff
==============================================================================
--- james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/ConnectHandler.java (original)
+++ james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/ConnectHandler.java Fri Aug 4 08:08:20 2006
@@ -29,9 +29,9 @@
* in the SMTPSession object
*/
public interface ConnectHandler {
- /*
+ /**
* Handle connection
- **/
+ **/
void onConnect(SMTPSession session);
}
Added: james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/IOState.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/IOState.java?rev=428748&view=auto
==============================================================================
--- james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/IOState.java (added)
+++ james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/IOState.java Fri Aug 4 08:08:20 2006
@@ -0,0 +1,24 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.smtpserver;
+
+public interface IOState {
+ void readResponse(SMTPSession session, String data);
+}
Modified: james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/SMTPHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/SMTPHandler.java?rev=428748&r1=428747&r2=428748&view=diff
==============================================================================
--- james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/SMTPHandler.java (original)
+++ james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/SMTPHandler.java Fri Aug 4 08:08:20 2006
@@ -42,10 +42,12 @@
/**
* Provides SMTP functionality by carrying out the server side of the SMTP
* interaction.
- *
- * @version CVS $Revision$ $Date$
+ *
+ * @version CVS $Revision$ $Date: 2006-08-03 05:55:20 +0000 (Do, 03 Aug
+ * 2006) $
*/
-public class SMTPHandler extends AbstractJamesHandler implements SMTPSession {
+public class SMTPHandler extends AbstractJamesHandler implements SMTPSession,
+ IOState {
/**
* The constants to indicate the current processing mode of the session
@@ -105,7 +107,8 @@
private boolean sessionEnded = false;
/**
- * The user name of the authenticated user associated with this SMTP transaction.
+ * The user name of the authenticated user associated with this SMTP
+ * transaction.
*/
private String authenticatedUser;
@@ -120,7 +123,7 @@
private boolean relayingAllowed;
/**
- * Whether the remote Server must send HELO/EHLO
+ * Whether the remote Server must send HELO/EHLO
*/
private boolean heloEhloEnforcement;
@@ -140,16 +143,19 @@
private SMTPHandlerConfigurationData theConfigData;
/**
- * The hash map that holds variables for the SMTP message transfer in progress.
- *
- * This hash map should only be used to store variable set in a particular
- * set of sequential MAIL-RCPT-DATA commands, as described in RFC 2821. Per
- * connection values should be stored as member variables in this class.
+ * The hash map that holds variables for the SMTP message transfer in
+ * progress.
+ *
+ * This hash map should only be used to store variable set in a
+ * particular set of sequential MAIL-RCPT-DATA commands, as described in
+ * RFC 2821. Per connection values should be stored as member variables
+ * in this class.
*/
private HashMap state = new HashMap();
/**
- * The hash map holds states which should be used in the whole connection
+ * The hash map holds states which should be used in the whole
+ * connection
*/
private HashMap connectionState = new HashMap();
@@ -162,17 +168,17 @@
private final static String DEFAULT_SMTP_RESPONSE = "Unexpected Error";
- private SMTPResponse response = new SMTPResponse(DEFAULT_SMTP_CODE,
- DEFAULT_SMTP_RESPONSE);
+ private SMTPResponse response = null;
- private List ioObject = new ArrayList(2);
+ private List ioState = new ArrayList(2);
- private boolean blockSMTPResponse = false;
+ private boolean doChain = false;
/**
* Set the configuration data for the handler
- *
- * @param theData the per-service configuration data for this handler
+ *
+ * @param theData
+ * the per-service configuration data for this handler
*/
public void setConfigurationData(Object theData) {
if (theData instanceof SMTPHandlerConfigurationData) {
@@ -187,6 +193,9 @@
* @see org.apache.james.core.AbstractJamesHandler#handleProtocol()
*/
protected void handleProtocol() throws IOException {
+
+ ioState.add((IOState) this);
+
smtpID = random.nextInt(1024) + "";
relayingAllowed = theConfigData.isRelayingAllowed(remoteIP);
authRequired = theConfigData.isAuthRequired(remoteIP);
@@ -195,11 +204,12 @@
smtpGreeting = theConfigData.getSMTPGreeting();
resetState();
resetConnectionState();
+ response = null;
// if no greeting was configured use a default
if (smtpGreeting == null) {
// Initially greet the connector
- // Format is: Sat, 24 Jan 1998 13:16:09 -0500
+ // Format is: Sat, 24 Jan 1998 13:16:09 -0500
responseBuffer.append("220 ").append(theConfigData.getHelloName())
.append(" SMTP Server (").append(SOFTWARE_TYPE).append(
@@ -211,72 +221,53 @@
String responseString = clearResponseBuffer();
writeLoggedFlushedResponse(responseString);
- //the core in-protocol handling logic
- //run all the connection handlers, if it fast fails, end the session
- //parse the command command, look up for the list of command handlers
- //Execute each of the command handlers. If any command handlers writes
- //response then, End the subsequent command handler processing and
- //start parsing new command. Once the message is received, run all
- //the message handlers. The message handlers can either terminate
- //message or terminate session
-
- //At the beginning
- //mode = command_mode
- //once the commandHandler writes response, the mode is changed to RESPONSE_MODE.
- //This will cause to skip the subsequent command handlers configured for that command.
- //For instance:
- //There are 2 commandhandlers MailAddressChecker and MailCmdHandler for
- //MAIL command. If MailAddressChecker validation of the MAIL FROM
- //address is successful, the MailCmdHandlers will be executed.
- //Incase it fails, it has to write response. Once we write response
- //there is no need to execute the MailCmdHandler.
- //Next, Once MAIL message is received the DataCmdHandler and any other
- //equivalent commandHandler will call setMail method. this will change
- //he mode to MAIL_RECEIVED_MODE. This mode will trigger the message
- //handlers to be execute. Message handlers can abort message. In that case,
- //message will not spooled.
+ // the core in-protocol handling logic
+ // run all the connection handlers, if it fast fails, end the session
+ // parse the command command, look up for the list of command handlers
+ // Execute each of the command handlers. If any command handlers writes
+ // response then, End the subsequent command handler processing and
+ // start parsing new command. Once the message is received, run all
+ // the message handlers. The message handlers can either terminate
+ // message or terminate session
+
+ // At the beginning
+ // mode = command_mode
+ // once the commandHandler writes response, the mode is changed to
+ // RESPONSE_MODE.
+ // This will cause to skip the subsequent command handlers configured
+ // for that command.
+ // For instance:
+ // There are 2 commandhandlers MailAddressChecker and MailCmdHandler for
+ // MAIL command. If MailAddressChecker validation of the MAIL FROM
+ // address is successful, the MailCmdHandlers will be executed.
+ // Incase it fails, it has to write response. Once we write response
+ // there is no need to execute the MailCmdHandler.
+ // Next, Once MAIL message is received the DataCmdHandler and any other
+ // equivalent commandHandler will call setMail method. this will change
+ // he mode to MAIL_RECEIVED_MODE. This mode will trigger the message
+ // handlers to be execute. Message handlers can abort message. In that
+ // case,
+ // message will not spooled.
- //Session started - RUN all connect handlers
+ // Session started - RUN all connect handlers
List connectHandlers = handlerChain.getConnectHandlers();
if (connectHandlers != null) {
+ for (int i = 0; i < connectHandlers.size(); i++) {
+ doChain = false;
- pushIOObject(new Chain(connectHandlers.iterator()));
- process();
- popIOObject();
+ ((ConnectHandler) connectHandlers.get(i)).onConnect(this);
+
+ if (doChain == false)
+ break;
+ }
}
theWatchdog.start();
while (!sessionEnded) {
- // Reset the current command values
- curCommandName = null;
- curCommandArgument = null;
- mode = COMMAND_MODE;
-
- // parse the command
- String cmdString = readCommandLine();
- if (cmdString == null) {
- break;
- }
- int spaceIndex = cmdString.indexOf(" ");
- if (spaceIndex > 0) {
- curCommandName = cmdString.substring(0, spaceIndex);
- curCommandArgument = cmdString.substring(spaceIndex + 1);
- } else {
- curCommandName = cmdString;
- }
- curCommandName = curCommandName.toUpperCase(Locale.US);
- // fetch the command handlers registered to the command
- List commandHandlers = handlerChain
- .getCommandHandlers(curCommandName);
- if (commandHandlers == null) {
- // end the session
- break;
- } else {
- pushIOObject(new Chain(commandHandlers.iterator()));
- process();
- popIOObject();
+ process(readCommandLine());
+ if (response != null) {
writeCompleteResponse(getSMTPResponse());
}
@@ -286,10 +277,20 @@
List messageHandlers = handlerChain.getMessageHandlers();
if (messageHandlers != null) {
- pushIOObject(new Chain(messageHandlers.iterator()));
- process();
- popIOObject();
- writeCompleteResponse(getSMTPResponse());
+
+ for (int i = 0; i < messageHandlers.size(); i++) {
+ doChain = false;
+
+ ((MessageHandler) messageHandlers.get(i))
+ .onMessage(this);
+
+ if (doChain == false)
+ break;
+
+ }
+
+ if (response != null)
+ writeCompleteResponse(response);
}
}
@@ -314,6 +315,43 @@
getLogger().debug("Closing socket.");
}
+ public void readResponse(SMTPSession session, String data) {
+
+ // Reset the current command values
+ curCommandName = null;
+ curCommandArgument = null;
+ mode = COMMAND_MODE;
+
+ // parse the command
+ String cmdString = data;
+ if (cmdString == null) {
+ endSession();
+ }
+ int spaceIndex = cmdString.indexOf(" ");
+ if (spaceIndex > 0) {
+ curCommandName = cmdString.substring(0, spaceIndex);
+ curCommandArgument = cmdString.substring(spaceIndex + 1);
+ } else {
+ curCommandName = cmdString;
+ }
+ curCommandName = curCommandName.toUpperCase(Locale.US);
+
+ // fetch the command handlers registered to the command
+ List commandHandlers = handlerChain.getCommandHandlers(curCommandName);
+ if (commandHandlers == null) {
+ // end the session
+ endSession();
+ } else {
+ for (int i = 0; i < commandHandlers.size(); i++) {
+ doChain = false;
+ ((CommandHandler) commandHandlers.get(i)).onCommand(this);
+
+ if (doChain == false)
+ break;
+ }
+ }
+ }
+
/**
* Write a Collection of responseString to the client
*
@@ -344,6 +382,10 @@
}
}
resetSMTPResponse();
+
+ if (mode == COMMAND_MODE) {
+ mode = RESPONSE_MODE;
+ }
}
/**
@@ -360,7 +402,7 @@
remoteIP = null;
authenticatedUser = null;
smtpID = null;
- resetSMTPResponse();
+ response = null;
}
/**
@@ -379,7 +421,7 @@
public void writeResponse(String respString) {
writeLoggedFlushedResponse(respString);
- //TODO Explain this well
+ // TODO Explain this well
if (mode == COMMAND_MODE) {
mode = RESPONSE_MODE;
}
@@ -475,7 +517,8 @@
}
/**
- * @see org.apache.james.smtpserver.SMTPSession#setRelayingAllowed(boolean relayingAllowed)
+ * @see org.apache.james.smtpserver.SMTPSession#setRelayingAllowed(boolean
+ * relayingAllowed)
*/
public void setRelayingAllowed(boolean relayingAllowed) {
this.relayingAllowed = relayingAllowed;
@@ -605,6 +648,10 @@
* @see org.apache.james.smtpserver.SMTPSession#getSMTPResponse()
*/
public SMTPResponse getSMTPResponse() {
+ if (response == null) {
+ setSMTPResponse(new SMTPResponse(DEFAULT_SMTP_CODE,
+ DEFAULT_SMTP_RESPONSE));
+ }
return response;
}
@@ -623,20 +670,23 @@
getSMTPResponse().setSMTPResponse(DEFAULT_SMTP_RESPONSE);
}
- public void pushIOObject(IOObject io) {
- ioObject.add(0, io);
+ public void pushIOState(IOState io) {
+ ioState.add(0, io);
}
- public void popIOObject() {
- ioObject.remove(0);
+ public void popIOState() {
+ ioState.remove(0);
}
- public IOObject getIOObject() {
- return (IOObject) ioObject.get(0);
+ public IOState getIOState() {
+ return (IOState) ioState.get(0);
}
- public SMTPResponse process() {
- return getIOObject().nextHandler(this);
+ public void doChain() {
+ doChain = true;
}
+ private void process(String data) {
+ getIOState().readResponse(this, data);
+ }
}
Modified: james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/SMTPSession.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/SMTPSession.java?rev=428748&r1=428747&r2=428748&view=diff
==============================================================================
--- james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/SMTPSession.java (original)
+++ james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/SMTPSession.java Fri Aug 4 08:08:20 2006
@@ -242,12 +242,12 @@
void writeResponse(String resp);
- public void pushIOObject(IOObject io);
+ public void pushIOState(IOState io);
- public void popIOObject();
+ public void popIOState();
- public IOObject getIOObject();
+ public IOState getIOState();
- public SMTPResponse process();
+ public void doChain();
}
Modified: james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/AuthCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/AuthCmdHandler.java?rev=428748&r1=428747&r2=428748&view=diff
==============================================================================
--- james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/AuthCmdHandler.java (original)
+++ james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/AuthCmdHandler.java Fri Aug 4 08:08:20 2006
@@ -21,7 +21,6 @@
package org.apache.james.smtpserver.core;
-import org.apache.james.smtpserver.Chain;
import org.apache.james.smtpserver.CommandHandler;
import org.apache.james.smtpserver.SMTPSession;
import org.apache.james.util.mail.dsn.DSNStatus;
@@ -57,7 +56,7 @@
*
* @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
*/
- public void onCommand(SMTPSession session,Chain chain) {
+ public void onCommand(SMTPSession session) {
//deviation from the Main code
//Instead of throwing exception just end the session
try{
Modified: james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java?rev=428748&r1=428747&r2=428748&view=diff
==============================================================================
--- james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java (original)
+++ james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java Fri Aug 4 08:08:20 2006
@@ -17,8 +17,6 @@
* under the License. *
****************************************************************/
-
-
package org.apache.james.smtpserver.core;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
@@ -26,7 +24,6 @@
import org.apache.james.core.MailHeaders;
import org.apache.james.core.MailImpl;
import org.apache.james.fetchmail.ReaderInputStream;
-import org.apache.james.smtpserver.Chain;
import org.apache.james.smtpserver.CommandHandler;
import org.apache.james.smtpserver.MessageSizeException;
import org.apache.james.smtpserver.SMTPSession;
@@ -52,16 +49,14 @@
import java.util.Enumeration;
import java.util.List;
-
/**
- * handles DATA command
+ * handles DATA command
*/
-public class DataCmdHandler
- extends AbstractLogEnabled
- implements CommandHandler {
+public class DataCmdHandler extends AbstractLogEnabled implements
+ CommandHandler {
private final static String SOFTWARE_TYPE = "JAMES SMTP Server "
- + Constants.SOFTWARE_VERSION;
+ + Constants.SOFTWARE_VERSION;
/**
* Static RFC822DateFormat used to generate date headers
@@ -90,11 +85,10 @@
*
* @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
*/
- public void onCommand(SMTPSession session,Chain chain) {
- doDATA(session, session.getCommandArgument());
+ public void onCommand(SMTPSession session) {
+ doDATA(session, session.getCommandArgument());
}
-
/**
* Handler method called upon receipt of a DATA command.
* Reads in message data, creates header, and delivers to
@@ -105,153 +99,147 @@
*/
private void doDATA(SMTPSession session, String argument) {
- String responseString = null;
- responseString = "354 Ok Send data ending with <CRLF>.<CRLF>";
+ String responseString = null;
+ responseString = "354 Ok Send data ending with <CRLF>.<CRLF>";
+ session.writeResponse(responseString);
+ session.getSMTPResponse().setRawSMTPResponse(responseString);
+ InputStream msgIn = new CharTerminatedInputStream(session
+ .getInputStream(), SMTPTerminator);
+ try {
+ msgIn = new BytesReadResetInputStream(msgIn, session.getWatchdog(),
+ session.getConfigurationData().getResetLength());
+
+ // if the message size limit has been set, we'll
+ // wrap msgIn with a SizeLimitedInputStream
+ long maxMessageSize = session.getConfigurationData()
+ .getMaxMessageSize();
+ if (maxMessageSize > 0) {
+ if (getLogger().isDebugEnabled()) {
+ StringBuffer logBuffer = new StringBuffer(128).append(
+ "Using SizeLimitedInputStream ").append(
+ " with max message size: ").append(maxMessageSize);
+ getLogger().debug(logBuffer.toString());
+ }
+ msgIn = new SizeLimitedInputStream(msgIn, maxMessageSize);
+ }
+ // Removes the dot stuffing
+ msgIn = new DotStuffingInputStream(msgIn);
+ // Parse out the message headers
+ MailHeaders headers = new MailHeaders(msgIn);
+ headers = processMailHeaders(session, headers);
+ processMail(session, headers, msgIn);
+ headers = null;
+ } catch (MessagingException me) {
+ // Grab any exception attached to this one.
+ Exception e = me.getNextException();
+ // If there was an attached exception, and it's a
+ // MessageSizeException
+ if (e != null && e instanceof MessageSizeException) {
+ // Add an item to the state to suppress
+ // logging of extra lines of data
+ // that are sent after the size limit has
+ // been hit.
+ session.getState().put(SMTPSession.MESG_FAILED, Boolean.TRUE);
+ // then let the client know that the size
+ // limit has been hit.
+ responseString = "552 "
+ + DSNStatus.getStatus(DSNStatus.PERMANENT,
+ DSNStatus.SYSTEM_MSG_TOO_BIG)
+ + " Error processing message: " + e.getMessage();
+ StringBuffer errorBuffer = new StringBuffer(256).append(
+ "Rejected message from ").append(
+ session.getState().get(SMTPSession.SENDER).toString())
+ .append(" from host ").append(session.getRemoteHost())
+ .append(" (").append(session.getRemoteIPAddress())
+ .append(") exceeding system maximum message size of ")
+ .append(
+ session.getConfigurationData()
+ .getMaxMessageSize());
+ getLogger().error(errorBuffer.toString());
+ } else {
+ responseString = "451 "
+ + DSNStatus.getStatus(DSNStatus.TRANSIENT,
+ DSNStatus.UNDEFINED_STATUS)
+ + " Error processing message: " + me.getMessage();
+ getLogger().error(
+ "Unknown error occurred while processing DATA.", me);
+ }
session.writeResponse(responseString);
-
- InputStream msgIn = new CharTerminatedInputStream(session
- .getInputStream(), SMTPTerminator);
+ return;
+ } finally {
+ if (msgIn != null) {
try {
- msgIn = new BytesReadResetInputStream(msgIn, session.getWatchdog(),
- session.getConfigurationData().getResetLength());
-
- // if the message size limit has been set, we'll
- // wrap msgIn with a SizeLimitedInputStream
- long maxMessageSize = session.getConfigurationData()
- .getMaxMessageSize();
- if (maxMessageSize > 0) {
- if (getLogger().isDebugEnabled()) {
- StringBuffer logBuffer = new StringBuffer(128).append(
- "Using SizeLimitedInputStream ").append(
- " with max message size: ").append(maxMessageSize);
- getLogger().debug(logBuffer.toString());
- }
- msgIn = new SizeLimitedInputStream(msgIn, maxMessageSize);
- }
- // Removes the dot stuffing
- msgIn = new DotStuffingInputStream(msgIn);
- // Parse out the message headers
- MailHeaders headers = new MailHeaders(msgIn);
- headers = processMailHeaders(session, headers);
- processMail(session, headers, msgIn);
- headers = null;
- } catch (MessagingException me) {
- // Grab any exception attached to this one.
- Exception e = me.getNextException();
- // If there was an attached exception, and it's a
- // MessageSizeException
- if (e != null && e instanceof MessageSizeException) {
- // Add an item to the state to suppress
- // logging of extra lines of data
- // that are sent after the size limit has
- // been hit.
- session.getState().put(SMTPSession.MESG_FAILED, Boolean.TRUE);
- // then let the client know that the size
- // limit has been hit.
- responseString = "552 "
- + DSNStatus.getStatus(DSNStatus.PERMANENT,
- DSNStatus.SYSTEM_MSG_TOO_BIG)
- + " Error processing message: " + e.getMessage();
- StringBuffer errorBuffer = new StringBuffer(256).append(
- "Rejected message from ").append(
- session.getState().get(SMTPSession.SENDER).toString())
- .append(" from host ").append(session.getRemoteHost())
- .append(" (").append(session.getRemoteIPAddress())
- .append(") exceeding system maximum message size of ")
- .append(
- session.getConfigurationData()
- .getMaxMessageSize());
- getLogger().error(errorBuffer.toString());
- } else {
- responseString = "451 "
- + DSNStatus.getStatus(DSNStatus.TRANSIENT,
- DSNStatus.UNDEFINED_STATUS)
- + " Error processing message: " + me.getMessage();
- getLogger().error(
- "Unknown error occurred while processing DATA.", me);
- }
- session.writeResponse(responseString);
- return;
- } finally {
- if (msgIn != null) {
- try {
- msgIn.close();
- } catch (Exception e) {
- // Ignore close exception
- }
- msgIn = null;
- }
+ msgIn.close();
+ } catch (Exception e) {
+ // Ignore close exception
+ }
+ msgIn = null;
}
-
}
+ }
-
-
-
-
-
- private MailHeaders processMailHeaders(SMTPSession session, MailHeaders headers)
- throws MessagingException {
- // If headers do not contains minimum REQUIRED headers fields,
- // add them
- if (!headers.isSet(RFC2822Headers.DATE)) {
- headers.setHeader(RFC2822Headers.DATE, rfc822DateFormat.format(new Date()));
- }
- if (!headers.isSet(RFC2822Headers.FROM) && session.getState().get(SMTPSession.SENDER) != null) {
- headers.setHeader(RFC2822Headers.FROM, session.getState().get(SMTPSession.SENDER).toString());
- }
- // RFC 2821 says that we cannot examine the message to see if
- // Return-Path headers are present. If there is one, our
- // Received: header may precede it, but the Return-Path header
- // should be removed when making final delivery.
- // headers.removeHeader(RFC2822Headers.RETURN_PATH);
- StringBuffer headerLineBuffer = new StringBuffer(512);
- // We will rebuild the header object to put our Received header at the top
- Enumeration headerLines = headers.getAllHeaderLines();
- MailHeaders newHeaders = new MailHeaders();
- // Put our Received header first
- headerLineBuffer.append(RFC2822Headers.RECEIVED + ": from ")
- .append(session.getRemoteHost())
- .append(" ([")
- .append(session.getRemoteIPAddress())
- .append("])");
-
+ private MailHeaders processMailHeaders(SMTPSession session,
+ MailHeaders headers) throws MessagingException {
+ // If headers do not contains minimum REQUIRED headers fields,
+ // add them
+ if (!headers.isSet(RFC2822Headers.DATE)) {
+ headers.setHeader(RFC2822Headers.DATE, rfc822DateFormat
+ .format(new Date()));
+ }
+ if (!headers.isSet(RFC2822Headers.FROM)
+ && session.getState().get(SMTPSession.SENDER) != null) {
+ headers.setHeader(RFC2822Headers.FROM, session.getState().get(
+ SMTPSession.SENDER).toString());
+ }
+ // RFC 2821 says that we cannot examine the message to see if
+ // Return-Path headers are present. If there is one, our
+ // Received: header may precede it, but the Return-Path header
+ // should be removed when making final delivery.
+ // headers.removeHeader(RFC2822Headers.RETURN_PATH);
+ StringBuffer headerLineBuffer = new StringBuffer(512);
+ // We will rebuild the header object to put our Received header at the top
+ Enumeration headerLines = headers.getAllHeaderLines();
+ MailHeaders newHeaders = new MailHeaders();
+ // Put our Received header first
+ headerLineBuffer.append(RFC2822Headers.RECEIVED + ": from ").append(
+ session.getRemoteHost()).append(" ([").append(
+ session.getRemoteIPAddress()).append("])");
+
+ newHeaders.addHeaderLine(headerLineBuffer.toString());
+ headerLineBuffer.delete(0, headerLineBuffer.length());
+
+ headerLineBuffer.append(" by ").append(
+ session.getConfigurationData().getHelloName()).append(" (")
+ .append(SOFTWARE_TYPE).append(") with SMTP 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)
newHeaders.addHeaderLine(headerLineBuffer.toString());
headerLineBuffer.delete(0, headerLineBuffer.length());
-
- headerLineBuffer.append(" by ")
- .append(session.getConfigurationData().getHelloName())
- .append(" (")
- .append(SOFTWARE_TYPE)
- .append(") with SMTP 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)
- newHeaders.addHeaderLine(headerLineBuffer.toString());
- headerLineBuffer.delete(0, headerLineBuffer.length());
- headerLineBuffer.append(" for <")
- .append(((List) session.getState().get(SMTPSession.RCPT_LIST)).get(0).toString())
- .append(">;");
- newHeaders.addHeaderLine(headerLineBuffer.toString());
- headerLineBuffer.delete(0, headerLineBuffer.length());
- } else {
- // Put the ; on the end of the 'by' line
- headerLineBuffer.append(";");
- newHeaders.addHeaderLine(headerLineBuffer.toString());
- headerLineBuffer.delete(0, headerLineBuffer.length());
- }
- headerLineBuffer = null;
- newHeaders.addHeaderLine(" " + rfc822DateFormat.format(new Date()));
-
- // Add all the original message headers back in next
- while (headerLines.hasMoreElements()) {
- newHeaders.addHeaderLine((String) headerLines.nextElement());
- }
- return newHeaders;
+ headerLineBuffer.append(" for <").append(
+ ((List) session.getState().get(SMTPSession.RCPT_LIST)).get(
+ 0).toString()).append(">;");
+ newHeaders.addHeaderLine(headerLineBuffer.toString());
+ headerLineBuffer.delete(0, headerLineBuffer.length());
+ } else {
+ // Put the ; on the end of the 'by' line
+ headerLineBuffer.append(";");
+ newHeaders.addHeaderLine(headerLineBuffer.toString());
+ headerLineBuffer.delete(0, headerLineBuffer.length());
+ }
+ headerLineBuffer = null;
+ newHeaders.addHeaderLine(" "
+ + rfc822DateFormat.format(new Date()));
+
+ // Add all the original message headers back in next
+ while (headerLines.hasMoreElements()) {
+ newHeaders.addHeaderLine((String) headerLines.nextElement());
+ }
+ return newHeaders;
}
/**
@@ -262,61 +250,63 @@
* @param headers the headers of the mail being read
* @param msgIn the stream containing the message content
*/
- private void processMail(SMTPSession session, MailHeaders headers, InputStream msgIn)
- throws MessagingException {
- ByteArrayInputStream headersIn = null;
- MailImpl mail = null;
- List recipientCollection = null;
+ private void processMail(SMTPSession session, MailHeaders headers,
+ InputStream msgIn) throws MessagingException {
+ ByteArrayInputStream headersIn = null;
+ MailImpl mail = null;
+ List recipientCollection = null;
+ try {
+ headersIn = new ByteArrayInputStream(headers.toByteArray());
+ recipientCollection = (List) session.getState().get(
+ SMTPSession.RCPT_LIST);
+ mail = new MailImpl(session.getConfigurationData().getMailServer()
+ .getId(), (MailAddress) session.getState().get(
+ SMTPSession.SENDER), recipientCollection,
+ new SequenceInputStream(new SequenceInputStream(headersIn,
+ msgIn), new ReaderInputStream(new StringReader(
+ "\r\n"))));
+ // Call mail.getSize() to force the message to be
+ // loaded. Need to do this to enforce the size limit
+ if (session.getConfigurationData().getMaxMessageSize() > 0) {
+ mail.getMessageSize();
+ }
+ mail.setRemoteHost(session.getRemoteHost());
+ mail.setRemoteAddr(session.getRemoteIPAddress());
+ if (session.getUser() != null) {
+ mail.setAttribute(SMTP_AUTH_USER_ATTRIBUTE_NAME, session
+ .getUser());
+ }
+
+ if (session.isRelayingAllowed()) {
+ mail.setAttribute(SMTP_AUTH_NETWORK_NAME, "true");
+ }
+
+ session.setMail(mail);
+ } finally {
+ if (recipientCollection != null) {
+ recipientCollection.clear();
+ }
+ recipientCollection = null;
+ if (headersIn != null) {
try {
- headersIn = new ByteArrayInputStream(headers.toByteArray());
- recipientCollection = (List) session.getState().get(SMTPSession.RCPT_LIST);
- mail =
- new MailImpl(session.getConfigurationData().getMailServer().getId(),
- (MailAddress) session.getState().get(SMTPSession.SENDER),
- recipientCollection,
- new SequenceInputStream(new SequenceInputStream(headersIn, msgIn),
- new ReaderInputStream(new StringReader("\r\n"))));
- // Call mail.getSize() to force the message to be
- // loaded. Need to do this to enforce the size limit
- if (session.getConfigurationData().getMaxMessageSize() > 0) {
- mail.getMessageSize();
- }
- mail.setRemoteHost(session.getRemoteHost());
- mail.setRemoteAddr(session.getRemoteIPAddress());
- if (session.getUser() != null) {
- mail.setAttribute(SMTP_AUTH_USER_ATTRIBUTE_NAME, session.getUser());
- }
-
- if (session.isRelayingAllowed()) {
- mail.setAttribute(SMTP_AUTH_NETWORK_NAME,"true");
- }
-
- session.setMail(mail);
- } finally {
- if (recipientCollection != null) {
- recipientCollection.clear();
- }
- recipientCollection = null;
- if (headersIn != null) {
- try {
- headersIn.close();
- } catch (IOException ioe) {
- // Ignore exception on close.
- }
- }
- headersIn = null;
+ headersIn.close();
+ } catch (IOException ioe) {
+ // Ignore exception on close.
}
+ }
+ headersIn = null;
+ }
}
-
+
/**
* @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
*/
public Collection getImplCommands() {
- Collection implCommands = new ArrayList();
- implCommands.add("DATA");
-
- return implCommands;
+ Collection implCommands = new ArrayList();
+ implCommands.add("DATA");
+
+ return implCommands;
}
}
Modified: james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/EhloCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/EhloCmdHandler.java?rev=428748&r1=428747&r2=428748&view=diff
==============================================================================
--- james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/EhloCmdHandler.java (original)
+++ james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/EhloCmdHandler.java Fri Aug 4 08:08:20 2006
@@ -17,15 +17,12 @@
* under the License. *
****************************************************************/
-
-
package org.apache.james.smtpserver.core;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.james.smtpserver.Chain;
import org.apache.james.smtpserver.CommandHandler;
import org.apache.james.smtpserver.SMTPSession;
@@ -33,7 +30,7 @@
* Handles EHLO command
*/
public class EhloCmdHandler extends AbstractLogEnabled implements
- CommandHandler {
+ CommandHandler {
/**
* The name of the command handled by the command handler
@@ -42,71 +39,74 @@
/*
* processes EHLO command
- *
+ *
* @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
- **/
- public void onCommand(SMTPSession session,Chain chain) {
- doEHLO(session);
+ */
+ public void onCommand(SMTPSession session) {
+ doEHLO(session);
}
/**
- * Handler method called upon receipt of a EHLO command.
- * Responds with a greeting and informs the client whether
- * client authentication is required.
- *
- * @param session SMTP session object
- * @param argument the argument passed in with the command by the SMTP client
+ * Handler method called upon receipt of a EHLO command. Responds with a
+ * greeting and informs the client whether client authentication is
+ * required.
+ *
+ * @param session
+ * SMTP session object
+ * @param argument
+ * the argument passed in with the command by the SMTP
+ * client
*/
private void doEHLO(SMTPSession session) {
- String argument = session.getCommandArgument();
- session.getConnectionState().put(SMTPSession.CURRENT_HELO_MODE,
- COMMAND_NAME);
-
- ArrayList esmtpextensions = new ArrayList();
-
- esmtpextensions.add(new StringBuffer(session.getConfigurationData()
- .getHelloName()).append(" Hello ").append(argument)
- .append(" (").append(session.getRemoteHost()).append(" [")
- .append(session.getRemoteIPAddress()).append("])").toString());
-
- // Extension defined in RFC 1870
- long maxMessageSize = session.getConfigurationData()
- .getMaxMessageSize();
- if (maxMessageSize > 0) {
- esmtpextensions.add("SIZE " + maxMessageSize);
- }
-
- if (session.isAuthRequired()) {
- esmtpextensions.add("AUTH LOGIN PLAIN");
- esmtpextensions.add("AUTH=LOGIN PLAIN");
- }
-
- esmtpextensions.add("PIPELINING");
- esmtpextensions.add("ENHANCEDSTATUSCODES");
- // see http://issues.apache.org/jira/browse/JAMES-419
- // esmtpextensions.add("8BITMIME");
-
- // Iterator i = esmtpextensions.iterator();
- for (int i = 0; i < esmtpextensions.size(); i++) {
- if (i == 0) {
- session.getSMTPResponse().setSMTPCode(250);
- session.getSMTPResponse().setSMTPResponse(
- (String) esmtpextensions.get(i));
-
- } else {
- session.getSMTPResponse().addSMTPResponse(
- (String) esmtpextensions.get(i));
- }
- }
+ String argument = session.getCommandArgument();
+ session.getConnectionState().put(SMTPSession.CURRENT_HELO_MODE,
+ COMMAND_NAME);
+
+ ArrayList esmtpextensions = new ArrayList();
+
+ esmtpextensions.add(new StringBuffer(session.getConfigurationData()
+ .getHelloName()).append(" Hello ").append(argument)
+ .append(" (").append(session.getRemoteHost()).append(" [")
+ .append(session.getRemoteIPAddress()).append("])").toString());
+
+ // Extension defined in RFC 1870
+ long maxMessageSize = session.getConfigurationData()
+ .getMaxMessageSize();
+ if (maxMessageSize > 0) {
+ esmtpextensions.add("SIZE " + maxMessageSize);
}
-
+
+ if (session.isAuthRequired()) {
+ esmtpextensions.add("AUTH LOGIN PLAIN");
+ esmtpextensions.add("AUTH=LOGIN PLAIN");
+ }
+
+ esmtpextensions.add("PIPELINING");
+ esmtpextensions.add("ENHANCEDSTATUSCODES");
+ // see http://issues.apache.org/jira/browse/JAMES-419
+ // esmtpextensions.add("8BITMIME");
+
+ // Iterator i = esmtpextensions.iterator();
+ for (int i = 0; i < esmtpextensions.size(); i++) {
+ if (i == 0) {
+ session.getSMTPResponse().setSMTPCode(250);
+ session.getSMTPResponse().setSMTPResponse(
+ (String) esmtpextensions.get(i));
+
+ } else {
+ session.getSMTPResponse().addSMTPResponse(
+ (String) esmtpextensions.get(i));
+ }
+ }
+ }
+
/**
- * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
- */
+ * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
+ */
public Collection getImplCommands() {
- Collection implCommands = new ArrayList();
- implCommands.add("EHLO");
-
- return implCommands;
+ Collection implCommands = new ArrayList();
+ implCommands.add("EHLO");
+
+ return implCommands;
}
}
Modified: james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/ExpnCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/ExpnCmdHandler.java?rev=428748&r1=428747&r2=428748&view=diff
==============================================================================
--- james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/ExpnCmdHandler.java (original)
+++ james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/ExpnCmdHandler.java Fri Aug 4 08:08:20 2006
@@ -17,28 +17,25 @@
* under the License. *
****************************************************************/
-
-
package org.apache.james.smtpserver.core;
import java.util.ArrayList;
import java.util.Collection;
-import org.apache.james.smtpserver.Chain;
import org.apache.james.smtpserver.CommandHandler;
import org.apache.james.smtpserver.SMTPSession;
import org.apache.james.util.mail.dsn.DSNStatus;
/**
- * Handles EXPN command
- */
+ * Handles EXPN command
+ */
public class ExpnCmdHandler implements CommandHandler {
/**
* The name of the command handled by the command handler
*/
private final static String COMMAND_NAME = "EXPN";
-
+
/**
* Handler method called upon receipt of a EXPN command.
* This method informs the client that the command is
@@ -46,23 +43,25 @@
*
* @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
*/
- public void onCommand(SMTPSession session,Chain chain) {
- int code = 502;
- String responseString = DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SYSTEM_NOT_CAPABLE)+" EXPN is not supported";
-
- // Set the response
- session.getSMTPResponse().setSMTPCode(code);
- session.getSMTPResponse().setSMTPResponse(responseString);
+ public void onCommand(SMTPSession session) {
+ int code = 502;
+ String responseString = DSNStatus.getStatus(DSNStatus.PERMANENT,
+ DSNStatus.SYSTEM_NOT_CAPABLE)
+ + " EXPN is not supported";
+
+ // Set the response
+ session.getSMTPResponse().setSMTPCode(code);
+ session.getSMTPResponse().setSMTPResponse(responseString);
}
-
+
/**
* @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
*/
public Collection getImplCommands() {
- Collection implCommands = new ArrayList();
- implCommands.add("EXPN");
-
- return implCommands;
+ Collection implCommands = new ArrayList();
+ implCommands.add("EXPN");
+
+ return implCommands;
}
}
Modified: james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/HeloCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/HeloCmdHandler.java?rev=428748&r1=428747&r2=428748&view=diff
==============================================================================
--- james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/HeloCmdHandler.java (original)
+++ james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/HeloCmdHandler.java Fri Aug 4 08:08:20 2006
@@ -17,41 +17,37 @@
* under the License. *
****************************************************************/
-
-
package org.apache.james.smtpserver.core;
-
import java.util.ArrayList;
import java.util.Collection;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.james.smtpserver.Chain;
import org.apache.james.smtpserver.CommandHandler;
import org.apache.james.smtpserver.SMTPSession;
-
/**
- * Handles HELO command
- */
-public class HeloCmdHandler extends AbstractLogEnabled implements CommandHandler {
+ * Handles HELO command
+ */
+public class HeloCmdHandler extends AbstractLogEnabled implements
+ CommandHandler {
/**
* The name of the command handled by the command handler
*/
- private final static String COMMAND_NAME = "HELO";
-
+ private final static String COMMAND_NAME = "HELO";
+
/**
* process HELO command
*
* @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
- **/
- public void onCommand(SMTPSession session,Chain chain) {
- String response = doHELO(session);
-
- if (response != null) {
- session.getSMTPResponse().setRawSMTPResponse(response);
- }
+ **/
+ public void onCommand(SMTPSession session) {
+ String response = doHELO(session);
+
+ if (response != null) {
+ session.getSMTPResponse().setRawSMTPResponse(response);
+ }
}
/**
@@ -60,26 +56,27 @@
*/
private String doHELO(SMTPSession session) {
String argument = session.getCommandArgument();
- String responseString = null;
+ String responseString = null;
+
+ session.getConnectionState().put(SMTPSession.CURRENT_HELO_MODE,
+ COMMAND_NAME);
+ session.getResponseBuffer().append("250 ").append(
+ session.getConfigurationData().getHelloName())
+ .append(" Hello ").append(argument).append(" (").append(
+ session.getRemoteHost()).append(" [").append(
+ session.getRemoteIPAddress()).append("])");
+ responseString = session.clearResponseBuffer();
- session.getConnectionState().put(SMTPSession.CURRENT_HELO_MODE, COMMAND_NAME);
- session.getResponseBuffer().append("250 ").append(
- session.getConfigurationData().getHelloName())
- .append(" Hello ").append(argument).append(" (").append(
- session.getRemoteHost()).append(" [").append(
- session.getRemoteIPAddress()).append("])");
- responseString = session.clearResponseBuffer();
-
- return responseString;
+ return responseString;
}
-
+
/**
* @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
*/
public Collection getImplCommands() {
- Collection implCommands = new ArrayList();
- implCommands.add("HELO");
-
- return implCommands;
- }
+ Collection implCommands = new ArrayList();
+ implCommands.add("HELO");
+
+ return implCommands;
+ }
}
Modified: james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/HelpCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/HelpCmdHandler.java?rev=428748&r1=428747&r2=428748&view=diff
==============================================================================
--- james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/HelpCmdHandler.java (original)
+++ james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/HelpCmdHandler.java Fri Aug 4 08:08:20 2006
@@ -24,7 +24,6 @@
import java.util.ArrayList;
import java.util.Collection;
-import org.apache.james.smtpserver.Chain;
import org.apache.james.smtpserver.CommandHandler;
import org.apache.james.smtpserver.SMTPSession;
import org.apache.james.util.mail.dsn.DSNStatus;
@@ -44,7 +43,7 @@
*
* @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
**/
- public void onCommand(SMTPSession session, Chain chain) {
+ public void onCommand(SMTPSession session) {
String responseString = "502 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SYSTEM_NOT_CAPABLE)+" HELP is not supported";
session.getSMTPResponse().setRawSMTPResponse(responseString);
}
Modified: james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/MailCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/MailCmdHandler.java?rev=428748&r1=428747&r2=428748&view=diff
==============================================================================
--- james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/MailCmdHandler.java (original)
+++ james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/MailCmdHandler.java Fri Aug 4 08:08:20 2006
@@ -17,38 +17,33 @@
* under the License. *
****************************************************************/
-
-
package org.apache.james.smtpserver.core;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.james.smtpserver.Chain;
import org.apache.james.smtpserver.CommandHandler;
import org.apache.james.smtpserver.SMTPSession;
import org.apache.james.util.mail.dsn.DSNStatus;
import org.apache.mailet.MailAddress;
/**
- * Handles MAIL command
- */
-public class MailCmdHandler
- extends AbstractLogEnabled
- implements CommandHandler {
+ * Handles MAIL command
+ */
+public class MailCmdHandler extends AbstractLogEnabled implements
+ CommandHandler {
-
/**
* handles MAIL command
*
* @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
*/
- public void onCommand(SMTPSession session,Chain chain) {
- session.getSMTPResponse().setRawSMTPResponse(doMAIL(session, session.getCommandArgument()));
+ public void onCommand(SMTPSession session) {
+ session.getSMTPResponse().setRawSMTPResponse(
+ doMAIL(session, session.getCommandArgument()));
}
-
/**
* Handler method called upon receipt of a MAIL command.
* Sets up handler to deliver mail as the stated sender.
@@ -57,29 +52,29 @@
* @param argument the argument passed in with the command by the SMTP client
*/
private String doMAIL(SMTPSession session, String argument) {
-
- StringBuffer responseBuffer = session.getResponseBuffer();
- String responseString = null;
-
- MailAddress sender = (MailAddress) session.getState().get(
- SMTPSession.SENDER);
- responseBuffer.append(
- "250 "
- + DSNStatus.getStatus(DSNStatus.SUCCESS,
- DSNStatus.ADDRESS_OTHER) + " Sender <").append(
- sender).append("> OK");
- responseString = session.clearResponseBuffer();
- return responseString;
-
+
+ StringBuffer responseBuffer = session.getResponseBuffer();
+ String responseString = null;
+
+ MailAddress sender = (MailAddress) session.getState().get(
+ SMTPSession.SENDER);
+ responseBuffer.append(
+ "250 "
+ + DSNStatus.getStatus(DSNStatus.SUCCESS,
+ DSNStatus.ADDRESS_OTHER) + " Sender <").append(
+ sender).append("> OK");
+ responseString = session.clearResponseBuffer();
+ return responseString;
+
}
-
+
/**
* @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
*/
public Collection getImplCommands() {
- Collection implCommands = new ArrayList();
- implCommands.add("MAIL");
-
- return implCommands;
+ Collection implCommands = new ArrayList();
+ implCommands.add("MAIL");
+
+ return implCommands;
}
}
Modified: james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/NoopCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/NoopCmdHandler.java?rev=428748&r1=428747&r2=428748&view=diff
==============================================================================
--- james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/NoopCmdHandler.java (original)
+++ james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/NoopCmdHandler.java Fri Aug 4 08:08:20 2006
@@ -17,21 +17,18 @@
* under the License. *
****************************************************************/
-
-
package org.apache.james.smtpserver.core;
import java.util.ArrayList;
import java.util.Collection;
-import org.apache.james.smtpserver.Chain;
import org.apache.james.smtpserver.CommandHandler;
import org.apache.james.smtpserver.SMTPSession;
import org.apache.james.util.mail.dsn.DSNStatus;
/**
- * Handles NOOP command
- */
+ * Handles NOOP command
+ */
public class NoopCmdHandler implements CommandHandler {
/**
@@ -45,18 +42,20 @@
*
* @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
*/
- public void onCommand(SMTPSession session, Chain chain) {
- String responseString = "250 "+DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.UNDEFINED_STATUS)+" OK";
- session.getSMTPResponse().setRawSMTPResponse(responseString);
+ public void onCommand(SMTPSession session) {
+ String responseString = "250 "
+ + DSNStatus.getStatus(DSNStatus.SUCCESS,
+ DSNStatus.UNDEFINED_STATUS) + " OK";
+ session.getSMTPResponse().setRawSMTPResponse(responseString);
}
-
+
/**
* @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
*/
public Collection getImplCommands() {
- Collection implCommands = new ArrayList();
- implCommands.add("NOOP");
-
- return implCommands;
+ Collection implCommands = new ArrayList();
+ implCommands.add("NOOP");
+
+ return implCommands;
}
}
Modified: james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/POP3BeforeSMTPHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/POP3BeforeSMTPHandler.java?rev=428748&r1=428747&r2=428748&view=diff
==============================================================================
--- james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/POP3BeforeSMTPHandler.java (original)
+++ james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/POP3BeforeSMTPHandler.java Fri Aug 4 08:08:20 2006
@@ -17,13 +17,11 @@
* under the License. *
****************************************************************/
-
package org.apache.james.smtpserver.core;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.james.smtpserver.Chain;
import org.apache.james.smtpserver.ConnectHandler;
import org.apache.james.smtpserver.SMTPSession;
import org.apache.james.util.POP3BeforeSMTPHelper;
@@ -43,18 +41,18 @@
* @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
*/
public void configure(Configuration arg0) throws ConfigurationException {
- Configuration config = arg0.getChild("expireTime", false);
+ Configuration config = arg0.getChild("expireTime", false);
- if (config != null) {
- try {
- setExpireTime(config.getValue(null));
- } catch (NumberFormatException e) {
- throw new ConfigurationException(
- "Please configure a valid expireTime: "
- + e.getMessage());
- }
+ if (config != null) {
+ try {
+ setExpireTime(config.getValue(null));
+ } catch (NumberFormatException e) {
+ throw new ConfigurationException(
+ "Please configure a valid expireTime: "
+ + e.getMessage());
}
}
+ }
/**
* Set the time after which an ipAddresses should be handled as expired
@@ -63,28 +61,29 @@
* The time
*/
public void setExpireTime(String rawExpireTime) {
- if (rawExpireTime != null) {
- this.expireTime = TimeConverter.getMilliSeconds(rawExpireTime);
- }
+ if (rawExpireTime != null) {
+ this.expireTime = TimeConverter.getMilliSeconds(rawExpireTime);
+ }
}
/**
* @see org.apache.james.smtpserver.ConnectHandler#onConnect(SMTPSession)
*/
- public void onConnect(SMTPSession session,Chain chain) {
+ public void onConnect(SMTPSession session) {
- // some kind of random cleanup process
- if (Math.random() > 0.99) {
- POP3BeforeSMTPHelper.removeExpiredIP(expireTime);
- }
+ // some kind of random cleanup process
+ if (Math.random() > 0.99) {
+ POP3BeforeSMTPHelper.removeExpiredIP(expireTime);
+ }
- // Check if the ip is allowed to relay
- if (!session.isRelayingAllowed()
- && POP3BeforeSMTPHelper.isAuthorized(session.getRemoteIPAddress())) {
- session.setRelayingAllowed(true);
- }
-
- chain.doChain(session);
+ // Check if the ip is allowed to relay
+ if (!session.isRelayingAllowed()
+ && POP3BeforeSMTPHelper.isAuthorized(session
+ .getRemoteIPAddress())) {
+ session.setRelayingAllowed(true);
+ }
+
+ session.doChain();
}
}
Modified: james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/QuitCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/QuitCmdHandler.java?rev=428748&r1=428747&r2=428748&view=diff
==============================================================================
--- james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/QuitCmdHandler.java (original)
+++ james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/QuitCmdHandler.java Fri Aug 4 08:08:20 2006
@@ -17,21 +17,18 @@
* under the License. *
****************************************************************/
-
-
package org.apache.james.smtpserver.core;
import java.util.ArrayList;
import java.util.Collection;
-import org.apache.james.smtpserver.Chain;
import org.apache.james.smtpserver.CommandHandler;
import org.apache.james.smtpserver.SMTPSession;
import org.apache.james.util.mail.dsn.DSNStatus;
/**
- * Handles QUIT command
- */
+ * Handles QUIT command
+ */
public class QuitCmdHandler implements CommandHandler {
/**
@@ -44,13 +41,12 @@
*
* @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
*/
- public void onCommand(SMTPSession session, Chain chain) {
- session.getSMTPResponse().setRawSMTPResponse(doQUIT(session));
- session.endSession();
+ public void onCommand(SMTPSession session) {
+ session.getSMTPResponse().setRawSMTPResponse(doQUIT(session));
+ session.endSession();
}
-
/**
* Handler method called upon receipt of a QUIT command.
* This method informs the client that the connection is
@@ -60,18 +56,24 @@
* @param argument the argument passed in with the command by the SMTP client
*/
private String doQUIT(SMTPSession session) {
- String responseString = "";
- String argument = session.getCommandArgument();
-
- if ((argument == null) || (argument.length() == 0)) {
- session.getResponseBuffer().append("221 "+DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.UNDEFINED_STATUS)+" ")
- .append(session.getConfigurationData().getHelloName())
- .append(" Service closing transmission channel");
- responseString = session.clearResponseBuffer();
- } else {
- responseString = "500 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Unexpected argument provided with QUIT command";
- }
- return responseString;
+ String responseString = "";
+ String argument = session.getCommandArgument();
+
+ if ((argument == null) || (argument.length() == 0)) {
+ session.getResponseBuffer().append(
+ "221 "
+ + DSNStatus.getStatus(DSNStatus.SUCCESS,
+ DSNStatus.UNDEFINED_STATUS) + " ").append(
+ session.getConfigurationData().getHelloName()).append(
+ " Service closing transmission channel");
+ responseString = session.clearResponseBuffer();
+ } else {
+ responseString = "500 "
+ + DSNStatus.getStatus(DSNStatus.PERMANENT,
+ DSNStatus.DELIVERY_INVALID_ARG)
+ + " Unexpected argument provided with QUIT command";
+ }
+ return responseString;
}
@@ -79,12 +81,9 @@
* @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
*/
public Collection getImplCommands() {
- Collection implCommands = new ArrayList();
- implCommands.add("QUIT");
-
- return implCommands;
+ Collection implCommands = new ArrayList();
+ implCommands.add("QUIT");
+
+ return implCommands;
}
}
-
-
-
Modified: james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/RcptCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/RcptCmdHandler.java?rev=428748&r1=428747&r2=428748&view=diff
==============================================================================
--- james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/RcptCmdHandler.java (original)
+++ james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/RcptCmdHandler.java Fri Aug 4 08:08:20 2006
@@ -17,36 +17,32 @@
* under the License. *
****************************************************************/
-
-
package org.apache.james.smtpserver.core;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.james.smtpserver.Chain;
import org.apache.james.smtpserver.CommandHandler;
import org.apache.james.smtpserver.SMTPSession;
import org.apache.james.util.mail.dsn.DSNStatus;
import org.apache.mailet.MailAddress;
/**
- * Handles RCPT command
- */
+ * Handles RCPT command
+ */
public class RcptCmdHandler extends AbstractLogEnabled implements
- CommandHandler {
+ CommandHandler {
/**
* handles RCPT command
*
* @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
- **/
- public void onCommand(SMTPSession session,Chain chain) {
- session.getSMTPResponse().setRawSMTPResponse(doRCPT(session));
+ **/
+ public void onCommand(SMTPSession session) {
+ session.getSMTPResponse().setRawSMTPResponse(doRCPT(session));
}
-
/**
* Handler method called upon receipt of a RCPT command.
* Reads recipient. Does some connection validation.
@@ -56,37 +52,37 @@
* @param argument the argument passed in with the command by the SMTP client
*/
private String doRCPT(SMTPSession session) {
-
- String responseString = null;
- StringBuffer responseBuffer = session.getResponseBuffer();
-
- Collection rcptColl = (Collection) session.getState().get(
- SMTPSession.RCPT_LIST);
- if (rcptColl == null) {
- rcptColl = new ArrayList();
- }
- MailAddress recipientAddress = (MailAddress) session.getState().get(
- SMTPSession.CURRENT_RECIPIENT);
- rcptColl.add(recipientAddress);
- session.getState().put(SMTPSession.RCPT_LIST, rcptColl);
- responseBuffer.append(
- "250 "
- + DSNStatus.getStatus(DSNStatus.SUCCESS,
- DSNStatus.ADDRESS_VALID) + " Recipient <")
- .append(recipientAddress).append("> OK");
- responseString = session.clearResponseBuffer();
- return responseString;
-
+
+ String responseString = null;
+ StringBuffer responseBuffer = session.getResponseBuffer();
+
+ Collection rcptColl = (Collection) session.getState().get(
+ SMTPSession.RCPT_LIST);
+ if (rcptColl == null) {
+ rcptColl = new ArrayList();
}
-
+ MailAddress recipientAddress = (MailAddress) session.getState().get(
+ SMTPSession.CURRENT_RECIPIENT);
+ rcptColl.add(recipientAddress);
+ session.getState().put(SMTPSession.RCPT_LIST, rcptColl);
+ responseBuffer.append(
+ "250 "
+ + DSNStatus.getStatus(DSNStatus.SUCCESS,
+ DSNStatus.ADDRESS_VALID) + " Recipient <")
+ .append(recipientAddress).append("> OK");
+ responseString = session.clearResponseBuffer();
+ return responseString;
+
+ }
+
/**
* @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
*/
public Collection getImplCommands() {
- Collection implCommands = new ArrayList();
- implCommands.add("RCPT");
-
- return implCommands;
+ Collection implCommands = new ArrayList();
+ implCommands.add("RCPT");
+
+ return implCommands;
}
}
Modified: james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/RsetCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/RsetCmdHandler.java?rev=428748&r1=428747&r2=428748&view=diff
==============================================================================
--- james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/RsetCmdHandler.java (original)
+++ james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/RsetCmdHandler.java Fri Aug 4 08:08:20 2006
@@ -17,21 +17,18 @@
* under the License. *
****************************************************************/
-
-
package org.apache.james.smtpserver.core;
import java.util.ArrayList;
import java.util.Collection;
-import org.apache.james.smtpserver.Chain;
import org.apache.james.smtpserver.CommandHandler;
import org.apache.james.smtpserver.SMTPSession;
import org.apache.james.util.mail.dsn.DSNStatus;
/**
- * Handles RSET command
- */
+ * Handles RSET command
+ */
public class RsetCmdHandler implements CommandHandler {
/**
* The name of the command handled by the command handler
@@ -42,12 +39,12 @@
* handles RSET command
*
* @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
- **/
- public void onCommand(SMTPSession session, Chain chain) {
- session.getSMTPResponse().setRawSMTPResponse(doRSET(session, session.getCommandArgument()));
+ **/
+ public void onCommand(SMTPSession session) {
+ session.getSMTPResponse().setRawSMTPResponse(
+ doRSET(session, session.getCommandArgument()));
}
-
/**
* Handler method called upon receipt of a RSET command.
* Resets message-specific, but not authenticated user, state.
@@ -56,26 +53,31 @@
* @param argument the argument passed in with the command by the SMTP client
*/
private String doRSET(SMTPSession session, String argument) {
- String responseString = "";
- if ((argument == null) || (argument.length() == 0)) {
+ String responseString = "";
+ if ((argument == null) || (argument.length() == 0)) {
- session.resetState();
+ session.resetState();
- responseString = "250 "+DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.UNDEFINED_STATUS)+" OK";
- } else {
- responseString = "500 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Unexpected argument provided with RSET command";
- }
- return responseString;
+ responseString = "250 "
+ + DSNStatus.getStatus(DSNStatus.SUCCESS,
+ DSNStatus.UNDEFINED_STATUS) + " OK";
+ } else {
+ responseString = "500 "
+ + DSNStatus.getStatus(DSNStatus.PERMANENT,
+ DSNStatus.DELIVERY_INVALID_ARG)
+ + " Unexpected argument provided with RSET command";
+ }
+ return responseString;
}
/**
* @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
*/
public Collection getImplCommands() {
- Collection implCommands = new ArrayList();
- implCommands.add("RSET");
-
- return implCommands;
+ Collection implCommands = new ArrayList();
+ implCommands.add("RSET");
+
+ return implCommands;
}
-
+
}
Modified: james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/SendMailHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/SendMailHandler.java?rev=428748&r1=428747&r2=428748&view=diff
==============================================================================
--- james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/SendMailHandler.java (original)
+++ james/server/sandbox/handlerapi2/src/java/org/apache/james/smtpserver/core/SendMailHandler.java Fri Aug 4 08:08:20 2006
@@ -17,8 +17,6 @@
* under the License. *
****************************************************************/
-
-
package org.apache.james.smtpserver.core;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
@@ -26,7 +24,6 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.james.services.MailServer;
-import org.apache.james.smtpserver.Chain;
import org.apache.james.smtpserver.MessageHandler;
import org.apache.james.smtpserver.MessageSizeException;
import org.apache.james.smtpserver.SMTPSession;
@@ -37,13 +34,11 @@
import java.util.Collection;
-
/**
- * Adds the header to the message
- */
-public class SendMailHandler
- extends AbstractLogEnabled
- implements MessageHandler, Serviceable {
+ * Adds the header to the message
+ */
+public class SendMailHandler extends AbstractLogEnabled implements
+ MessageHandler, Serviceable {
private MailServer mailServer;
@@ -51,7 +46,7 @@
* @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
*/
public void service(ServiceManager serviceManager) throws ServiceException {
- mailServer = (MailServer) serviceManager.lookup(MailServer.ROLE);
+ mailServer = (MailServer) serviceManager.lookup(MailServer.ROLE);
}
/**
@@ -59,71 +54,74 @@
*
* @see org.apache.james.smtpserver#onMessage(SMTPSession)
*/
- public void onMessage(SMTPSession session, Chain chain) {
- session.getSMTPResponse().setRawSMTPResponse(processMail(session));
+ public void onMessage(SMTPSession session) {
+ session.getSMTPResponse().setRawSMTPResponse(processMail(session));
}
-
+
private String processMail(SMTPSession session) {
- getLogger().debug("sending mail");
+ getLogger().debug("sending mail");
+
+ Mail mail = session.getMail();
+
+ String responseString = null;
+ try {
+ mailServer.sendMail(mail);
+ Collection theRecipients = mail.getRecipients();
+ String recipientString = "";
+ if (theRecipients != null) {
+ recipientString = theRecipients.toString();
+ }
+ if (getLogger().isInfoEnabled()) {
+ StringBuffer infoBuffer = new StringBuffer(256).append(
+ "Successfully spooled mail ").append(mail.getName())
+ .append(" from ").append(mail.getSender()).append(
+ " on ").append(session.getRemoteIPAddress())
+ .append(" for ").append(recipientString);
+ getLogger().info(infoBuffer.toString());
+ }
+ } catch (MessagingException me) {
+ // Grab any exception attached to this one.
+ Exception e = me.getNextException();
+ // If there was an attached exception, and it's a
+ // MessageSizeException
+ if (e != null && e instanceof MessageSizeException) {
+ // Add an item to the state to suppress
+ // logging of extra lines of data
+ // that are sent after the size limit has
+ // been hit.
+ session.getState().put(SMTPSession.MESG_FAILED, Boolean.TRUE);
+ // then let the client know that the size
+ // limit has been hit.
+ responseString = "552 "
+ + DSNStatus.getStatus(DSNStatus.PERMANENT,
+ DSNStatus.SYSTEM_MSG_TOO_BIG)
+ + " Error processing message.";
+ StringBuffer errorBuffer = new StringBuffer(256).append(
+ "Rejected message from ").append(
+ session.getState().get(SMTPSession.SENDER).toString())
+ .append(" from host ").append(session.getRemoteHost())
+ .append(" (").append(session.getRemoteIPAddress())
+ .append(") exceeding system maximum message size of ")
+ .append(
+ session.getConfigurationData()
+ .getMaxMessageSize());
+ getLogger().error(errorBuffer.toString());
+ } else {
+ responseString = "451 "
+ + DSNStatus.getStatus(DSNStatus.TRANSIENT,
+ DSNStatus.UNDEFINED_STATUS)
+ + " Error processing message.";
+ getLogger().error(
+ "Unknown error occurred while processing DATA.", me);
+ }
+ return responseString;
+ }
+ responseString = "250 "
+ + DSNStatus.getStatus(DSNStatus.SUCCESS,
+ DSNStatus.CONTENT_OTHER) + " Message received";
+ return responseString;
- Mail mail = session.getMail();
-
- String responseString = null;
- try {
- mailServer.sendMail(mail);
- Collection theRecipients = mail.getRecipients();
- String recipientString = "";
- if (theRecipients != null) {
- recipientString = theRecipients.toString();
- }
- if (getLogger().isInfoEnabled()) {
- StringBuffer infoBuffer =
- new StringBuffer(256)
- .append("Successfully spooled mail ")
- .append(mail.getName())
- .append(" from ")
- .append(mail.getSender())
- .append(" on ")
- .append(session.getRemoteIPAddress())
- .append(" for ")
- .append(recipientString);
- getLogger().info(infoBuffer.toString());
- }
- } catch (MessagingException me) {
- // Grab any exception attached to this one.
- Exception e = me.getNextException();
- // If there was an attached exception, and it's a
- // MessageSizeException
- if (e != null && e instanceof MessageSizeException) {
- // Add an item to the state to suppress
- // logging of extra lines of data
- // that are sent after the size limit has
- // been hit.
- session.getState().put(SMTPSession.MESG_FAILED, Boolean.TRUE);
- // then let the client know that the size
- // limit has been hit.
- responseString = "552 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SYSTEM_MSG_TOO_BIG)+" Error processing message.";
- StringBuffer errorBuffer =
- new StringBuffer(256)
- .append("Rejected message from ")
- .append(session.getState().get(SMTPSession.SENDER).toString())
- .append(" from host ")
- .append(session.getRemoteHost())
- .append(" (")
- .append(session.getRemoteIPAddress())
- .append(") exceeding system maximum message size of ")
- .append(session.getConfigurationData().getMaxMessageSize());
- getLogger().error(errorBuffer.toString());
- } else {
- responseString = "451 "+DSNStatus.getStatus(DSNStatus.TRANSIENT,DSNStatus.UNDEFINED_STATUS)+" Error processing message.";
- getLogger().error("Unknown error occurred while processing DATA.", me);
- }
- return responseString;
- }
- responseString = "250 "+DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.CONTENT_OTHER)+" Message received";
- return responseString;
-
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org