diff --git a/samples/debug.js b/samples/debug.js new file mode 100644 index 0000000..f426ac5 --- /dev/null +++ b/samples/debug.js @@ -0,0 +1,21 @@ +// The contents of this file are subject to the Mozilla Public License Version 1.1 +// (the "License"); you may not use this file except in compliance with the License. +// You may obtain a copy of the License at . +// +// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT +// WARRANTY OF ANY KIND, either express or implied. See the License for the specific +// language governing rights and limitations under the License. +// +// The Original Code is the Venice Web Communities System - Generic Mail Gateway. +// +// The Initial Developer of the Original Code is Eric J. Bowersox , +// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are +// Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. +// +// Contributor(s): + +importPackage(Packages.com.silverwrist.mailgate); + +// get the message, dump it +message = bsf.lookupBean("message"); +message.dump(); diff --git a/samples/debug.properties b/samples/debug.properties new file mode 100644 index 0000000..dbef285 --- /dev/null +++ b/samples/debug.properties @@ -0,0 +1,29 @@ +# The contents of this file are subject to the Mozilla Public License Version 1.1 +# (the "License"); you may not use this file except in compliance with the License. +# You may obtain a copy of the License at . +# +# Software distributed under the License is distributed on an "AS IS" basis, WITHOUT +# WARRANTY OF ANY KIND, either express or implied. See the License for the specific +# language governing rights and limitations under the License. +# +# The Original Code is the Venice Web Communities System - Generic Mail Gateway. +# +# The Initial Developer of the Original Code is Eric J. Bowersox , +# for Silverwrist Design Studios. Portions created by Eric J. Bowersox are +# Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. +# +# Contributor(s): + +# The script to be run by the gateway for each received message. +mailgate.script=debug.js + +# Temporary directory for script engines. +mailgate.script.tmpdir=/tmp + +# Configuration parameters +# (none) + +# Properties used by the mail session object. +mail.transport.protocol=smtp +mail.smtp.host=localhost + diff --git a/samples/debug.sh b/samples/debug.sh new file mode 100755 index 0000000..78bf2d9 --- /dev/null +++ b/samples/debug.sh @@ -0,0 +1,3 @@ +#!/bin/sh +exec java -cp "mailgate.jar:bsf.jar:js.jar:jacl.jar:tcljava.jar:xmlrpc.jar" \ + com.silverwrist.mailgate.Main debug.properties \ No newline at end of file diff --git a/samples/mailgate.js b/samples/mailgate.js index d95ab32..6abf37a 100644 --- a/samples/mailgate.js +++ b/samples/mailgate.js @@ -45,6 +45,7 @@ my_topic = lib.castInteger(lib.getConfigParam("topic")); parms.add(my_topic); parms.add(message.subject); parms.add(lib.castString(text)); +parms.add("email"); ndx = lib.castInteger(rpc.execute("venice:conferencing.topic.postMessage",parms)); if (message.hasAttachments()) @@ -61,6 +62,7 @@ if (message.hasAttachments()) parms.add(my_topic); parms.add(message.subject); parms.add(lib.castString(new_text)); + parms.add("email"); ndx = lib.castInteger(rpc.execute("venice:conferencing.topic.postMessage",parms)); } // end if diff --git a/src/com/silverwrist/mailgate/AttachmentData.java b/src/com/silverwrist/mailgate/AttachmentData.java index 864fa10..4a80199 100644 --- a/src/com/silverwrist/mailgate/AttachmentData.java +++ b/src/com/silverwrist/mailgate/AttachmentData.java @@ -84,4 +84,10 @@ public class AttachmentData } // end getData + public final void dump() + { + System.out.println("\tName: " + name + " Type: " + type + " Length: " + data.length); + + } // end dump + } // end class AttachmentData diff --git a/src/com/silverwrist/mailgate/Library.java b/src/com/silverwrist/mailgate/Library.java index 53b91d7..dad4a69 100644 --- a/src/com/silverwrist/mailgate/Library.java +++ b/src/com/silverwrist/mailgate/Library.java @@ -85,4 +85,16 @@ public class Library } // end createVector + public final void failPermanent(String message) throws PermanentExit + { + throw new PermanentExit("failPermanent: " + message); + + } // end failPermanent + + public final void failTemporary(String message) throws TemporaryExit + { + throw new TemporaryExit("failTemporary: " + message); + + } // end failTemporary + } // end class Library diff --git a/src/com/silverwrist/mailgate/MessageData.java b/src/com/silverwrist/mailgate/MessageData.java index fbb0275..21ddd15 100644 --- a/src/com/silverwrist/mailgate/MessageData.java +++ b/src/com/silverwrist/mailgate/MessageData.java @@ -32,6 +32,7 @@ public class MessageData private Set recipients; // the set of addresses the message was sent to private String sender; // the sender private String subject; // the message subject + private Map headers; // the headers private String text = null; // the message text private ArrayList attachments = new ArrayList(); // the attachments @@ -47,13 +48,14 @@ public class MessageData Address[] tmp_array = msg.getAllRecipients(); HashSet tmp_set = new HashSet(); int i; - for (i=0; i0) - buf.append(", "); - buf.append(addr.toUnicodeString()); + if (tmp_array!=null) + for (i=0; i0) + buf.append(", "); + buf.append(addr.toUnicodeString()); - } // end for + } // end for and if sender = buf.toString(); // Get the subject line. subject = msg.getSubject(); + if (subject==null) + subject = ""; + + // Get all the message headers. + Map tmp_headers = new HashMap(); + Enumeration hdr_enum = msg.getAllHeaders(); + if (hdr_enum!=null) + { // get out all the headers + while (hdr_enum.hasMoreElements()) + { // get each header in turn + Header hdr = (Header)(hdr_enum.nextElement()); + String label = hdr.getName().toLowerCase(); + int n = label.indexOf(':'); + if (n>=0) + label = label.substring(0,n); + List val_list = (List)(tmp_headers.get(label)); + if (val_list==null) + { // create new list + val_list = new ArrayList(); + tmp_headers.put(label,val_list); + + } // end if + + val_list.add(hdr.getValue()); + + } // end while + + } // end if + + if (tmp_headers.isEmpty()) + headers = Collections.EMPTY_MAP; + else + headers = Collections.unmodifiableMap(tmp_headers); if (msg.getContentType().toLowerCase().startsWith("multipart/")) { // we need to break up the multipart object @@ -188,6 +224,24 @@ public class MessageData } // end getSubject + public final boolean headerContains(String name, String value) + { + List foo = (List)(headers.get(name.trim().toLowerCase())); + if (foo==null) + return false; + Iterator it = foo.iterator(); + while (it.hasNext()) + { // look for a matching string value + String s = (String)(it.next()); + if (s.indexOf(value)>=0) + return true; + + } // end while + + return false; + + } // end headerContains + public final String getText() { return text; @@ -212,4 +266,41 @@ public class MessageData } // end getAttachment + public final void dump() + { + System.out.println("==== Begin Message Data ===="); + System.out.println(recipients.size() + " recipients"); + Iterator it = recipients.iterator(); + while (it.hasNext()) + System.out.println("\t" + it.next().toString()); + System.out.println("Sender: " + sender); + System.out.println("Subject: " + subject); + System.out.println(headers.size() + " distinct headers"); + it = headers.entrySet().iterator(); + while (it.hasNext()) + { // get each map entry + Map.Entry ntry = (Map.Entry)(it.next()); + String name = ntry.getKey().toString(); + List values = (List)(ntry.getValue()); + System.out.println("\tName: " + name + " [" + values.size() + " entries]"); + Iterator it2 = values.iterator(); + while (it2.hasNext()) + System.out.println("\t\t" + it2.next().toString()); + + } // end while + + System.out.println("Message text: " + text.length() + " characters"); + System.out.println(attachments.size() + " attachments"); + it = attachments.iterator(); + while (it.hasNext()) + { // dump the attachments, too + AttachmentData ad = (AttachmentData)(it.next()); + ad.dump(); + + } // end while + + System.out.println("===== End Message Data ====="); + + } // end dump + } // end class MessageData