charlesb 01/06/14 08:55:41
Modified: proposals/v1.3/conf james-config.xml
proposals/v1.3/java/org/apache/james/smtpserver
SMTPHandler.java
Log:
Combined Matt Pangaro s SizeLimitedSMTPHandler into main SMTPHandler
Revision Changes Path
1.9 +4 -4 jakarta-james/proposals/v1.3/conf/james-config.xml
Index: james-config.xml
===================================================================
RCS file: /home/cvs/jakarta-james/proposals/v1.3/conf/james-config.xml,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- james-config.xml 2001/06/14 13:00:42 1.8
+++ james-config.xml 2001/06/14 15:55:34 1.9
@@ -13,8 +13,8 @@
CONFIRM? comment in the left
margin.
- This is $Revision: 1.8 $
- Committed on $Date: 2001/06/14 13:00:42 $ by: $Author: charlesb $
+ This is $Revision: 1.9 $
+ Committed on $Date: 2001/06/14 15:55:34 $ by: $Author: charlesb $
-->
<config>
@@ -396,9 +396,9 @@
as somebody else -->
<!-- This sets the maximum allowed message size for the smtphandler
- in KBytes. The value defaults to 0, which means no limit.
+ in KBytes. The value defaults to 0, which means no limit. -->
<maxmessagesize>0</maxmessagesize>
- -->
+
</handler>
</smtpserver>
1.3 +67 -10
jakarta-james/proposals/v1.3/java/org/apache/james/smtpserver/SMTPHandler.java
Index: SMTPHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-james/proposals/v1.3/java/org/apache/james/smtpserver/SMTPHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SMTPHandler.java 2001/06/14 13:00:43 1.2
+++ SMTPHandler.java 2001/06/14 15:55:39 1.3
@@ -41,9 +41,10 @@
* @author Serge Knystautas <[EMAIL PROTECTED]>
* @author Federico Barbieri <[EMAIL PROTECTED]>
* @author Jason Borden <[EMAIL PROTECTED]>
+ * @author Matthew Pangaro <[EMAIL PROTECTED]>
*
- * This is $Revision: 1.2 $
- * Committed on $Date: 2001/06/14 13:00:43 $ by: $Author: charlesb $
+ * This is $Revision: 1.3 $
+ * Committed on $Date: 2001/06/14 15:55:39 $ by: $Author: charlesb $
*/
public class SMTPHandler
extends BaseConnectionHandler
@@ -56,10 +57,12 @@
public final static String NAME_GIVEN = "NAME_GIVEN";
public final static String CURRENT_HELO_MODE = "CURRENT_HELO_MODE";
public final static String SENDER = "SENDER_ADDRESS";
+ public final static String MESG_FAILED = "MESG_FAILED";
public final static String RCPT_VECTOR = "RCPT_VECTOR";
public final static String SMTP_ID = "SMTP_ID";
public final static String AUTH = "AUTHENTICATED";
public final static char[] SMTPTerminator = {'\r','\n','.','\r','\n'};
+ private final static boolean DEEP_DEBUG = true;
private Socket socket;
private DataInputStream in;
@@ -74,7 +77,7 @@
private boolean authRequired = false;
private boolean verifyIdentity = false;
- private Configuration conf;
+ // private Configuration conf;
private TimeScheduler scheduler;
private UsersRepository users;
private MailServer mailServer;
@@ -85,6 +88,7 @@
private static long count;
private Hashtable state = new Hashtable();
private Random random = new Random();
+ private long maxmessagesize = 0;
public void configure ( Configuration configuration )
throws ConfigurationException {
@@ -93,6 +97,13 @@
= configuration.getChild("authRequired").getValueAsBoolean(false);
verifyIdentity
= configuration.getChild("verifyIdentity").getValueAsBoolean(false);
+ // get the message size limit from the conf file and multiply
+ // by 1024, to put it in bytes
+ maxmessagesize =
+ configuration.getChild( "maxmessagesize" ).getValueAsLong( 0 ) * 1024;
+ if (DEEP_DEBUG) {
+ getLogger().debug("Max message size is: " + maxmessagesize);
+ }
}
public void compose( final ComponentManager componentManager )
@@ -203,7 +214,9 @@
throws Exception {
if (command == null) return false;
- getLogger().info("Command received: " + command);
+ if (state.get(MESG_FAILED) == null) {
+ getLogger().info("Command received: " + command);
+ }
StringTokenizer commandLine
= new StringTokenizer(command.trim(), " :");
int arguments = commandLine.countTokens();
@@ -261,6 +274,9 @@
}
private void doEHLO(String command,String argument,String argument1) {
doHELO(command,argument,argument1);
+ if (maxmessagesize > 0) {
+ // out.println("250 SIZE " + maxmessagesize);
+ }
}
private void doAUTH(String command,String argument,String argument1)
@@ -447,6 +463,16 @@
// parse headers
InputStream msgIn
= new CharTerminatedInputStream(in, SMTPTerminator);
+ // if the message size limit has been set, we'll
+ // wrap msgIn with a SizeLimitedInputStream
+ if (maxmessagesize > 0) {
+ if (DEEP_DEBUG) {
+ getLogger().debug("Using SizeLimitedInputStream "
+ + " with max message size: "
+ + maxmessagesize);
+ }
+ msgIn = new SizeLimitedInputStream(msgIn, maxmessagesize);
+ }
MailHeaders headers = new MailHeaders(msgIn);
// if headers do not contains minimum REQUIRED headers fields
// add them
@@ -481,14 +507,41 @@
(MailAddress)state.get(SENDER),
(Vector)state.get(RCPT_VECTOR),
new SequenceInputStream(headersIn, msgIn));
+ // if the message size limit has been set, we'll
+ // call mail.getSize() to force the message to be
+ // loaded. Need to do this to limit the size
+ if (maxmessagesize > 0) {
+ mail.getSize();
+ }
mail.setRemoteHost((String)state.get(REMOTE_NAME));
mail.setRemoteAddr((String)state.get(REMOTE_IP));
mailServer.sendMail(mail);
} catch (MessagingException me) {
- out.println("451 Error processing message: "
- + me.getMessage());
- getLogger().error("Error processing message: "
- + me.getMessage());
+ //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) {
+ getLogger().error("552 Error processing message: "
+ + e.getMessage());
+ // Add an item to the state to suppress
+ // logging of extra lines of data
+ // that are sent after the size limit has
+ // been hit.
+ state.put(MESG_FAILED, Boolean.TRUE);
+
+ //then let the client know that the size
+ //limit has been hit.
+ out.println("552 Error processing message: "
+ + e.getMessage());
+ } else {
+ out.println("451 Error processing message: "
+ + me.getMessage());
+ getLogger().error("Error processing message: "
+ + me.getMessage());
+ me.printStackTrace();
+ }
return;
}
getLogger().info("Mail sent to Mail Server");
@@ -501,8 +554,12 @@
+ " Service closing transmission channel");
}
- private void doUnknownCmd(String command,String argument,String argument1) {
- out.println("500 " + state.get(SERVER_NAME) + " Syntax error, command
unrecognized: " +
- command);
+ private void doUnknownCmd(String command,String argument,
+ String argument1) {
+ if (state.get(MESG_FAILED) == null) {
+ out.println("500 " + state.get(SERVER_NAME)
+ + " Syntax error, command unrecognized: " + command);
+ }
}
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]