removed Message.Envelope class
[org.ibex.mail.git] / src / org / ibex / mail / protocol / SMTP.java
index b47585f..46b4c6e 100644 (file)
@@ -71,6 +71,10 @@ public class SMTP {
                     conn.flush();
                     try {
                         StringBuffer buf = new StringBuffer();
+                        buf.append("Received: from " + conn.getRemoteHostname() + " (" + remotehost + ")\r\n");
+                        buf.append("          by "+conn.vhost+" ("+SMTP.class.getName()+") with "+(ehlo?"ESMTP":"SMTP") + "\r\n");
+                        buf.append("          for "); for(int i=0; i<to.size(); i++) buf.append(to.elementAt(i) + " ");
+                        buf.append("; " + dateFormat.format(new Date()) + "\r\n");
                         while(true) {
                             String s = conn.readln();
                             if (s == null) throw new RuntimeException("connection closed");
@@ -120,13 +124,13 @@ public class SMTP {
         }
 
         public static boolean attempt(Message m) throws IOException {
-            InetAddress[] mx = getMailExchangerIPs(m.envelope.to.host);
+            InetAddress[] mx = getMailExchangerIPs(m.envelopeTo.host);
             if (mx.length == 0) {
                 Log.warn(SMTP.Outgoing.class, "could not resolve " + m.envelopeTo.host + "; bouncing it\n" + m.summary());
                 accept(m.bounce("could not resolve " + m.envelopeTo.host));
                 return true;
             }
-            if (new Date().getTime() - m.envelope.arrival.getTime() > 1000 * 60 * 60 * 24 * 5) {
+            if (new Date().getTime() - m.arrival.getTime() > 1000 * 60 * 60 * 24 * 5) {
                 Log.warn(SMTP.Outgoing.class, "could not send message after 5 days; bouncing it\n" + m.summary());
                 accept(m.bounce("could not send for 5 days"));
                 return true;
@@ -156,7 +160,17 @@ public class SMTP {
                 conn.println("MAIL FROM:<" + m.envelope.from.user + "@" + m.envelope.from.host+">");  check(conn.readln(), conn);
                 conn.println("RCPT TO:<"   + m.envelope.to.user + "@" + m.envelope.to.host+">");      check(conn.readln(), conn);
                 conn.println("DATA");                          check(conn.readln(), conn);
-                conn.println(m.toString());
+                Stream stream = new Stream(m.toString());
+                boolean inheaders = true;
+                while(true) {
+                    String s = stream.readln();
+                    if (s == null) break;
+                    if (s.length() == 0) inheaders = false;
+                    // quash Return-Path; required by RFC2822
+                    if (inheaders && s.toLowerCase().startsWith("Return-Path:")) continue;
+                    if (s.startsWith(".")) conn.print(".");
+                    conn.println(s);
+                }
                 conn.println(".");
                 check(conn.readln(), conn);
                 Log.warn(SMTP.Outgoing.class, "success: " + mx + " accepted " + m.summary());