put to/from on envelopes when sending
authoradam <adam@megacz.com>
Wed, 11 Aug 2004 01:34:32 +0000 (01:34 +0000)
committeradam <adam@megacz.com>
Wed, 11 Aug 2004 01:34:32 +0000 (01:34 +0000)
darcs-hash:20040811013432-5007d-b1eba804153b9eee4b6b7545936cfcf16dad577c.gz

src/org/ibex/mail/target/Script.java

index 42b878b..d2bca1b 100644 (file)
@@ -118,14 +118,19 @@ public class Script extends Target {
                     JS m = (JS)a;
                     StringBuffer headers = new StringBuffer();
                     String body = "";
+                    Address from = null, to = null;
                     for(Enumeration e = m.keys(); e.hasMoreElements();) {
                         String key = (String)e.nextElement();
-                        String val = m.get(key).toString();
-                        if (key.equals("body")) body = val;
+                        String val = m.get(key) == null ? null : m.get(key).toString();
+                        if ("body".equals(key)) body = val;
                         else headers.append(key + ": " + val + "\r\n");
+                        if ("from".equalsIgnoreCase(key)) from = Address.parse(val);
+                        if ("to".equalsIgnoreCase(key)) to = Address.parse(val);
                     }
                     Message message = new Message(new org.ibex.io.Stream(headers.toString() + "\r\n" + body),
-                                                  new Message.Envelope(null, null, new Date()));
+                                                  new Message.Envelope(from,
+                                                                       to,
+                                                                       new Date()));
                     //org.ibex.mail.protocol.SMTP.Outgoing.accept(message);
                     boolean ok = org.ibex.mail.protocol.SMTP.Outgoing.attempt(message);
                     if (!ok) throw new JSExn("SMTP server rejected message");
@@ -157,6 +162,7 @@ public class Script extends Target {
                 }
             } catch (Exception e) {
                 Log.warn(this, "ibex."+name+"() threw: " + e);
+                Log.warn(this, e);
                 if (e instanceof JSExn) throw ((JSExn)e);
                 throw new JSExn("invalid argument for ibex object method "+name+"()");
             }