bugfix for envelope on ibex.mail.send()
authoradam <adam@megacz.com>
Sat, 15 Jan 2005 10:09:50 +0000 (10:09 +0000)
committeradam <adam@megacz.com>
Sat, 15 Jan 2005 10:09:50 +0000 (10:09 +0000)
darcs-hash:20050115100950-5007d-a2e6ec9a7dfc329bae55ae14640279d1c75ff717.gz

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

index ac94ca9..f3e8adf 100644 (file)
@@ -139,16 +139,23 @@ public class Script extends Target {
                     JS m = (JS)a;
                     StringBuffer headers = new StringBuffer();
                     String body = "";
-                    Address from = null, to = null;
-                    for(JS.Enumeration e = m.keys(); e.hasNext();) {
+                    Address from = null, to = null, envelopeFrom = null, envelopeTo = null;
+                    JS.Enumeration e = m.keys();
+                    for(; e.hasNext();) {
                         JS key = (JS)e.next();
                         JS val = m.get(key) == null ? null : m.get(key);
                         if ("body".equalsIgnoreCase(JSU.toString(key))) body = JSU.toString(val);
-                        else headers.append(key + ": " + val + "\r\n");
+                        else headers.append(JSU.toString(key) + ": " + JSU.toString(val) + "\r\n");
                         if ("from".equalsIgnoreCase(JSU.toString(key))) from = Address.parse(JSU.toString(val));
                         if ("to".equalsIgnoreCase(JSU.toString(key))) to = Address.parse(JSU.toString(val));
+                        if ("envelopeFrom".equalsIgnoreCase(JSU.toString(key))) envelopeFrom = Address.parse(JSU.toString(val));
+                        if ("envelopeTo".equalsIgnoreCase(JSU.toString(key))) envelopeTo = Address.parse(JSU.toString(val));
                     }
-                    Message message = Message.newMessage(new org.ibex.io.Stream(headers.toString() + "\r\n" + body), from, to);
+                    if (envelopeTo == null) envelopeTo = to;
+                    if (envelopeFrom == null) envelopeFrom = from;
+                    Message message = Message.newMessage(new org.ibex.io.Stream(headers.toString() + "\r\n" + body),
+                                                         envelopeFrom,
+                                                         envelopeTo);
                     //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");