fix horrible SMTP exception code bug
[org.ibex.mail.git] / src / org / ibex / mail / SMTP.java
index bf162fb..ba4069f 100644 (file)
@@ -185,6 +185,11 @@ public class SMTP {
                     } else 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);
+                    } else if (authenticatedAs!=null) {
+                        conn.println("250 you are authenticated as "+authenticatedAs+", so I will let you send");
+                        to.addElement(addr);
+                        whitelist.addWhitelist(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");
@@ -322,7 +327,8 @@ public class SMTP {
         private static void check(String s, Connection conn) {
             if (s==null) return;
             while (s.length() > 3 && s.charAt(3) == '-') s = conn.readln();
-            if (s.startsWith("4")||s.startsWith("5")) throw new SMTPException(s);
+            //if (s.startsWith("4")||s.startsWith("5")) throw new SMTPException(s);
+            if (!s.startsWith("2")&&!s.startsWith("3")) throw new SMTPException(s);
         }
         private static boolean attempt(final Message m, final InetAddress mx) {
             boolean accepted = false;
@@ -339,18 +345,16 @@ public class SMTP {
                     conn.println("HELO " + conn.vhost);
                     check(conn.readln(), conn);
                 }
-                if (m.envelopeFrom==null) {
-                    Log.warn("", "MAIL FROM:<>");
-                    conn.println("MAIL FROM:<>");  check(conn.readln(), conn);
-                } else {
-                    Log.warn("", "MAIL FROM:<" + m.envelopeFrom.toString()+">");
-                    conn.println("MAIL FROM:<" + m.envelopeFrom.toString()+">");  check(conn.readln(), conn);
-                }
-                conn.println("RCPT TO:<"   + m.envelopeTo.toString()+">");      check(conn.readln(), conn);
-                conn.println("DATA");                          check(conn.readln(), conn);
-                Headers head = m.headers;
-                head = head.remove("return-path");
-                head = head.remove("bcc");
+                String envelopeFrom = m.envelopeFrom==null ? "" : m.envelopeFrom.toString();
+                conn.println("MAIL FROM:<" + envelopeFrom +">");            check(conn.readln(), conn);
+                conn.println("RCPT TO:<"   + m.envelopeTo.toString()+">");  check(conn.readln(), conn);
+                conn.println("DATA");                                       check(conn.readln(), conn);
+
+                Headers head = new Headers(m.headers,
+                                           new String[] {
+                                               "return-path", null,
+                                               "bcc", null
+                                           });
                 Stream stream = head.getStream();
                 for(String s = stream.readln(); s!=null; s=stream.readln()) {
                     if (s.startsWith(".")) conn.print(".");