Hello all,
I've attacheched a diff for a patch to the SMTPHandler that will allow
it to handle the SIZE= extension to the MAIL FROM. It's not
particularly complicated, but it works, and should also make the
server a little more forgiving, in that it will now swallow any
unexpected command after the email address. If we want to support more
commands, we can just add them to this code block. I haven't been able
to find anything about other extensions to MAIL FROM, but I guess we
should keep looking. Overall, it seems like the size limiting will
work pretty well now, after this fix and the patch serge committed
yesterday to MimeMessageWrapper, which fixed the basic functionality.

I also removed the DEEP_DEBUG parameter, which was set locally, and
not configurable. Seemed like this could just follow the normal log
setting pattern from the conf file.

The other two patches are related to serge's fix of MimeMessageWrapper
from yesterday. I just found all the instances where an exception was
being caught in a try block, and the root cause wasn't being wrapped
in the MessagingException. Seems like it's always a good idea to
include that original exception, since it allows the caller to get
more information, if they need it (like in the case of SMTPHandler).

Matt Pangaro
Loki Technologies
http://www.lokitech.com

----- Original Message -----
From: "Serge Knystautas" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, December 05, 2001 6:49 PM
Subject: MAIL FROM and spaces


> Ok, after saying that all those messages didn't put a space between
MAIL
> FROM: and the <>, I'm seeing in EHLO mode the commands are a bit
different.
> I recently turned on the SIZE limit in SMTP, which means JAMES
acknowledges
> with an EHLO and a 250-SIZE line.  Remote servers are noticing this,
so
> they're sending the complementary SIZE parameter in the MAIL FROM.
This
> means they send the following:
>
> MAIL FROM:<username@domain> SIZE=2148
>
> Where 2148 is the number of bytes of the message.  Note there is now
no
> space between "...FROM:" and "<username...".  Incidentally, this
size is
> sent so as while it gives a series of RCPT TO commands, our server
can see
> if any of those users have a quota that this message would exceed,
and then
> reject receiving the message for that user, using a 452 reply code.
>
> Anyway, James is failing on this MAIL FROM format, so the size
limitation
> code isn't 100% just yet.  I'm not sure quite how many emails we're
> rejecting at this point, but I'm either going to patch this or turn
off the
> size limit setting on my server soon.

Index: smtpserver/SMTPHandler.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-james/src/java/org/apache/james/smtpserver/SMTPHandler.java,v
retrieving revision 1.12
diff -r1.12 SMTPHandler.java
61a62
>     public final static String MESG_SIZE = "MESG_SIZE";
66d66
<     private final static boolean DEEP_DEBUG = true;
105,107c105
<         if (DEEP_DEBUG) {
<             getLogger().debug("Max message size is: " + maxmessagesize);
<         }
---
>         getLogger().debug("Max message size is: " + maxmessagesize);
356a355,379
>             int lastChar = sender.lastIndexOf('>');
>             if (sender.length() > lastChar+1) {
>                 //handle a SIZE=### command if it's sent
>                 String cmdString = sender.substring(lastChar+1).trim();
>                 if (cmdString.toUpperCase().startsWith("SIZE")) {
>                     try {
>                         int size = 
>Integer.parseInt(cmdString.substring(cmdString.indexOf('=')+1));
>                         if (maxmessagesize > 0 && size > maxmessagesize) {
>                             getLogger().error("552 Message size exceeds fixed 
>maximum message size");
>
>                             //let the client know that the size limit has been hit.
>                             out.println("552 Message size exceeds fixed maximum 
>message size");
>                             return;
>                         } else {
>                             //put the message size in the message state so it can be 
>used
>                             //  later to restrict messages for user quotas, etc.
>                             state.put(MESG_SIZE, new Integer(size));
>                         }
>                     } catch (Exception e) {
>                     }
>                 }
>                 //cut off the extra bit in the sender string
>                 sender = sender.substring(0, lastChar+1);
>             }
>
489,493c512,514
<                     if (DEEP_DEBUG) {
<                         getLogger().debug("Using SizeLimitedInputStream "
<                                   + " with max message size: "
<                                   + maxmessagesize);
<                     }
---
>                     getLogger().debug("Using SizeLimitedInputStream "
>                               + " with max message size: "
>                               + maxmessagesize);
Index: core/MimeMessageWrapper.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-james/src/java/org/apache/james/core/MimeMessageWrapper.java,v
retrieving revision 1.5
diff -r1.5 MimeMessageWrapper.java
69c69
<             throw new MessagingException("Unable to parse headers from stream: " + 
ioe.getMessage());
---
>             throw new MessagingException("Unable to parse headers from stream: " + 
>ioe.getMessage(), ioe);
93c93
<             throw new MessagingException("Unable to parse stream: " + 
ioe.getMessage());
---
>             throw new MessagingException("Unable to parse stream: " + 
>ioe.getMessage(), ioe);
Index: James.java
===================================================================
RCS file: /home/cvspublic/jakarta-james/src/java/org/apache/james/James.java,v
retrieving revision 1.14
diff -r1.14 James.java
267c267
<             throw new MessagingException("Exception spooling message: " + 
e.getMessage());
---
>             throw new MessagingException("Exception spooling message: " + 
>e.getMessage(), e);
384c384
<             throw new MessagingException("Unable to create multipart body");
---
>             throw new MessagingException("Unable to create multipart body", ioe);

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to