drop connection after too many bad recipients
authoradam <adam@megacz.com>
Thu, 5 Jul 2007 01:43:28 +0000 (01:43 +0000)
committeradam <adam@megacz.com>
Thu, 5 Jul 2007 01:43:28 +0000 (01:43 +0000)
darcs-hash:20070705014328-5007d-98673b8388a11a5cbd529b763c73d880612a0d55.gz

src/org/ibex/mail/SMTP.java

index ba4069f..0ae8890 100644 (file)
@@ -94,6 +94,7 @@ public class SMTP {
             boolean ehlo = false;
             String remotehost = null;
             String authenticatedAs = null;
+            int failedRcptCount = 0;
             for(String command = conn.readln(); ; command = conn.readln()) try {
                 if (command == null) return;
                 Log.warn("**"+conn.getRemoteAddress()+"**", command);
@@ -178,21 +179,32 @@ public class SMTP {
                     command = command.substring(8).trim();
                     if(command.indexOf(' ') != -1) command = command.substring(0, command.indexOf(' '));
                     Address addr = new Address(command);
-                    if (addr.isLocal()) {
-                        // FEATURE: should check the address further and give 550 if undeliverable
-                        conn.println("250 " + addr + " is on this machine; I will deliver it");
-                        to.addElement(addr);
-                    } else if (conn.getRemoteAddress().isLoopbackAddress() || (from!=null&&from.toString().indexOf("johnw")!=-1)) {
+                    if (conn.getRemoteAddress().isLoopbackAddress() || (from!=null&&from.toString().indexOf("johnw")!=-1)) {
                         conn.println("250 you are connected locally, so I will let you send");
                         to.addElement(addr);
-                        whitelist.addWhitelist(addr);
+                        if (!whitelist.isWhitelisted(addr))
+                            whitelist.addWhitelist(addr);
                     } else if (authenticatedAs!=null) {
                         conn.println("250 you are authenticated as "+authenticatedAs+", so I will let you send");
                         to.addElement(addr);
-                        whitelist.addWhitelist(addr);
+                        if (!whitelist.isWhitelisted(addr))
+                            whitelist.addWhitelist(addr);
+                    } else if (addr.isLocal()) {
+                        if (to.size() > 3) {
+                            conn.println("536 sorry, limit on 3 RCPT TO's per DATA");
+                        } else {
+                            // FEATURE: should check the address further and give 550 if undeliverable
+                            conn.println("250 " + addr + " is on this machine; I will deliver it");
+                            to.addElement(addr);
+                        }
                     } else {
                         conn.println("535 sorry, " + addr + " is not on this machine, you are not connected from localhost, and I will not relay without SMTP AUTH");
                         Log.warn("","535 sorry, " + addr + " is not on this machine, you are not connected from localhost, and I will not relay without SMTP AUTH");
+                        failedRcptCount++;
+                        if (failedRcptCount > 3) {
+                            conn.close();
+                            return;
+                        }
                     }
                     conn.flush();
                 } else if (c.startsWith("DATA")) {