implemented bounce messages
[org.ibex.mail.git] / src / org / ibex / mail / target / Script.java
index 912c732..d68d91e 100644 (file)
@@ -115,6 +115,8 @@ public class Script extends Target {
             case "mail.forward": return METHOD;
             case "mail.forward2": return METHOD;
             case "mail.send": return METHOD;
+            case "mail.drop": return Drop.instance;
+            case "mail.bounce": return METHOD;
             case "mail.my": return getSub("mail.my");
             case "mail.my.prefs": try {
                     return new org.ibex.js.Directory(new File("/etc/org.ibex.mail.prefs"));
@@ -163,6 +165,18 @@ public class Script extends Target {
                     if (!ok) throw new JSExn("SMTP server rejected message");
                     return JSU.T;
                 }
+                if (name.equals("mail.bounce")) {
+                    return new Target() {
+                            public void accept(Message m) throws MailException {
+                                try {
+                                    Message m2 = m.bounce(JSU.toString(a));
+                                    org.ibex.mail.protocol.SMTP.Outgoing.accept(m2);
+                                    Log.error(this, "BOUNCING! " + m2.summary());
+                                } catch (Exception e) {
+                                    Log.warn(this, e);
+                                }
+                            } };
+                }
                 if (name.equals("mail.forward2") || name.equals("forward2")) {
                     try {
                         Message m2 = Message.newMessage(new org.ibex.io.Fountain.StringFountain(m.toString()),
@@ -175,16 +189,12 @@ public class Script extends Target {
                     }
                     return null;
                 }
-                if (name.equals("mail.forward") || name.equals("forward")) { return new Target() {
-                        public void accept(Message m) throws MailException {
-                            try {
-                                Message m2 = Message.newMessage(m, m.envelopeFrom, new Address(JSU.toString(a)));
-                                org.ibex.mail.protocol.SMTP.Outgoing.accept(m2);
-                            } catch (Exception e) {
-                                throw new MailException(e.toString());
-                            }
-                        }
-                    }; }
+                if (name.equals("mail.forward") || name.equals("forward")) {
+                    Message m = (Message)a;
+                    Message m2 = Message.newMessage(m, m.envelopeFrom, new Address(JSU.toString(a)));
+                    org.ibex.mail.protocol.SMTP.Outgoing.attempt(m2);
+                    return Drop.instance;
+                }
                 if (name.equals("log.debug") || name.equals("debug")) {    JSU.debug(a== null ? "**null**" : JSU.toString(a)); return null; }
                 if (name.equals("log.info") || name.equals("info")) {     JSU.info(a== null ? "**null**" : JSU.toString(a)); return null; }
                 if (name.equals("log.warn") || name.equals("warn")) {     JSU.warn(a== null ? "**null**" : JSU.toString(a)); return null; }