major revamp due to new Message constructors
[org.ibex.mail.git] / src / org / ibex / mail / SMTP.java
index 0ae8890..c3975ed 100644 (file)
@@ -14,6 +14,8 @@ import java.text.*;
 import javax.naming.*;
 import javax.naming.directory.*;
 
+// FIXME: inbound throttling/ratelimiting
+
 // RFC's implemented
 // RFC2554: SMTP Service Extension for Authentication
 //     - did not implement section 5, though
@@ -174,6 +176,7 @@ public class SMTP {
                     command = command.substring(10).trim();
                     from = command.equals("<>") ? null : new Address(command);
                     conn.println("250 " + from + " is syntactically correct");
+                    // FEATURE: perform SMTP validation on the address, reject if invalid
                 } else if (c.startsWith("RCPT TO:")) {
                     // some clients are broken and put RCPT first; we will tolerate this
                     command = command.substring(8).trim();
@@ -249,7 +252,7 @@ public class SMTP {
                             if (s.equals(".")) break;
                             if (s.startsWith(".")) s = s.substring(1);
                             buf.append(s + "\r\n");
-                            if (MAX_MESSAGE_SIZE != -1 && buf.length() > MAX_MESSAGE_SIZE) {
+                            if (MAX_MESSAGE_SIZE != -1 && buf.length() > MAX_MESSAGE_SIZE && (from+"").indexOf("paperless")==-1) {
                                 Log.error("**"+conn.getRemoteAddress()+"**",
                                           "sorry, this mail server only accepts messages of less than " +
                                           ByteSize.toString(MAX_MESSAGE_SIZE));
@@ -257,12 +260,10 @@ public class SMTP {
                                                                   ByteSize.toString(MAX_MESSAGE_SIZE));
                             }
                         }
-                        String body = buf.toString();
+                        String message = buf.toString();
                         Message m = null;
-                        for(int i=0; i<to.size(); i++) {
-                           m = Message.newMessage(Fountain.Util.create(body), from, (Address)to.elementAt(i));
-                            enqueue(m);
-                       }
+                        for(int i=0; i<to.size(); i++)
+                            enqueue(m = Message.newMessage(Fountain.Util.create(message)).withEnvelope(from, (Address)to.elementAt(i)));
                         if (m != null) Log.info(SMTP.class, "accepted message: " + m.summary());
                         conn.println("250 message accepted");
                         conn.flush();
@@ -331,7 +332,7 @@ public class SMTP {
             }
             for(int i=0; i<mx.length; i++) {
                 //if (deadHosts.contains(mx[i])) continue;
-                if (attempt(m, mx[i])) { return true; }
+                if (attempt(m, mx[i])) return true;
             }
             return false;
         }
@@ -391,6 +392,8 @@ public class SMTP {
                 Log.warn(SMTP.Outgoing.class, "    unable to send; error=" + e);
                 Log.warn(SMTP.Outgoing.class, "      message: " + m.summary());
                 Log.warn(SMTP.Outgoing.class, e);
+                /*
+                  // FIXME: we should not be bouncing here!
                 if (e.code >= 500 && e.code <= 599) {
                     try {
                         attempt(m.bounce("unable to deliver: " + e), true);
@@ -400,6 +403,7 @@ public class SMTP {
                     }
                     return true;
                 }
+                */
                 return false;
             } catch (Exception e) {
                 if (accepted) return true;