better DCC interface
[org.ibex.mail.git] / src / org / ibex / mail / Script.java
index f3a189c..f7b259d 100644 (file)
@@ -147,8 +147,8 @@ public class Script extends JS.Obj implements Target {
             } catch (IOException e) { throw new JSExn(e.toString()); }
             case "mail.whitelist": return JSReflection.wrap(org.ibex.mail.SMTP.whitelist);
             case "mail.my.mailbox":
-                Mailbox root = FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT, true);
-                return root.slash("user", true).slash("megacz", true);
+                MailTree root = FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT, true);
+                return (JS)root.slash("user", true).slash("megacz", true);
             case "mail.list": return METHOD;
                 //#end
                 return super.get(name);
@@ -243,7 +243,37 @@ public class Script extends JS.Obj implements Target {
                    StringBuffer ret = new StringBuffer();
                    new Stream(p.getInputStream()).transcribe(ret);
                    p.waitFor();
-                   return JSU.S(ret.toString());
+                    String result = ret.toString();
+                    Log.warn("dcc", ((Message)args[0]).summary() + ":\n  " + result);
+                    int body = 0;
+                    int fuz1 = 0;
+                    int fuz2 = 0;
+                    int i_body = result.indexOf("Body=");
+                    int i_fuz1 = result.indexOf("Fuz1=");
+                    int i_fuz2 = result.indexOf("Fuz2=");
+                    if (i_body != -1) try {
+                        String s = result.substring(i_body+5);
+                        if (s.indexOf(' ') != -1) s = s.substring(0, s.indexOf(' '));
+                        if (s.indexOf('\n') != -1) s = s.substring(0, s.indexOf('\n'));
+                        body = s.equals("many") ? 999 : Integer.parseInt(s.trim());
+                    } catch (Exception e) { Log.error("", e); }
+                    if (i_fuz1 != -1) try {
+                        String s = result.substring(i_fuz1+5);
+                        if (s.indexOf(' ') != -1) s = s.substring(0, s.indexOf(' '));
+                        if (s.indexOf('\n') != -1) s = s.substring(0, s.indexOf('\n'));
+                        fuz1 = s.equals("many") ? 999 : Integer.parseInt(s.trim());
+                    } catch (Exception e) { Log.error("", e); }
+                    if (i_fuz2 != -1) try {
+                        String s = result.substring(i_fuz2+5);
+                        if (s.indexOf(' ') != -1) s = s.substring(0, s.indexOf(' '));
+                        if (s.indexOf('\n') != -1) s = s.substring(0, s.indexOf('\n'));
+                        fuz2 = s.equals("many") ? 999 : Integer.parseInt(s.trim());
+                    } catch (Exception e) { Log.error("", e); }
+                    JSArray jsa = new JSArray();
+                    jsa.put(JSU.N(0), JSU.N(body));
+                    jsa.put(JSU.N(1), JSU.N(fuz1));
+                    jsa.put(JSU.N(2), JSU.N(fuz2));
+                   return jsa;
                }
                 if (name.equals("mail.drop")) {
                     return args.length==0 ? new Drop() : new Drop(JSU.toString(args[0]));