From: adam Date: Thu, 23 Sep 2004 07:03:30 +0000 (+0000) Subject: List can now send messages X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=88ee94f69d25a1d257de5a8a0f6283174c618a4b;p=org.ibex.mail.git List can now send messages darcs-hash:20040923070330-5007d-edbc7c4f5679bde4acdde4a201e01c1c8140f946.gz --- diff --git a/src/org/ibex/mail/List.java b/src/org/ibex/mail/List.java index 8b54d9a..5686f0f 100644 --- a/src/org/ibex/mail/List.java +++ b/src/org/ibex/mail/List.java @@ -1,26 +1,25 @@ package org.ibex.mail; import org.ibex.util.*; +import org.ibex.io.*; import org.ibex.mail.target.*; +import org.ibex.mail.protocol.*; import java.util.*; import java.io.*; -//import org.prevayler.*; -//import org.prevayler.Query; +import org.prevayler.*; +import org.prevayler.Query; // FEATURE: umbrella structure to mailing lists -public class List implements Serializable { +public class List extends Target implements Serializable { - // disabled until we figure out how to cope with the Prevayler dependency - /* public static enum UserType { Administrator, Moderator, Member } public static enum SubscriptionType { All, None, Digest, MimeDigest } public static enum Visibility { Members, Public, Nobody } public static enum Action { Accept, Hold, Reject } public Address address; - public Mailbox pending; public Mailbox archive; private final long secret; - private List(Address a, Mailbox p, Mailbox ar, long s) {this.address=a;this.pending=p;this.archive=ar;this.secret=s;} + private List(Address a, Mailbox ar, long s) { this.address=a; this.archive=ar; this.secret=s; } public Hashtable subscribers = new Hashtable(); public Filter[] filters = new Filter[0]; @@ -38,6 +37,15 @@ public class List implements Serializable { public int bounceThreshhold = 10; public static List getList(Object all, String listName) { return (List)((Hashtable)all).get(listName); } + public static List getList(final String listName) { + try { + return (List)p.execute(new Query() { public Object query(Object o, Date now) { return getList(o, listName); } }); + } catch (Exception e) { + Log.error(List.class, e); + return null; + } + } + public synchronized Subscriber getSubscriber(Address subscriber) { Subscriber s = (Subscriber)subscribers.get(subscriber.toString(false)); if (s == null) subscribers.put(subscriber, s = new Subscriber()); @@ -62,6 +70,40 @@ public class List implements Serializable { // public class AnonymizeSender { public boolean uncorrelated; } //} + + public void accept(Message m) throws IOException, MailException { + try { + m = new Message(new Stream("List-Id: " + one_line_description + "<"+address+">\r\n" + + m.toString() + + "--\r\n" + + message_footer + "\r\n" + + "to unsubscribe, go to " + homepage + "\r\n"), + null); + } catch (Exception e2) { + Log.error("[list]", e2); + throw new IOException(e2.toString()); + } + Log.warn(List.class, "got message " + m.subject); + archive.accept(m); + try { + String[] subscribers = (String[])p.execute(subscribers()); + Log.warn("**", "length is " + subscribers.length); + for(int i=0; i