From 8531aa831228edc504315761146a557c78dbe060 Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 3 Aug 2004 07:16:21 +0000 Subject: [PATCH] added List.java darcs-hash:20040803071621-5007d-7fdbc5b7ee79094933abc8f88f0179a094b98410.gz --- src/org/ibex/mail/List.java | 116 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 src/org/ibex/mail/List.java diff --git a/src/org/ibex/mail/List.java b/src/org/ibex/mail/List.java new file mode 100644 index 0000000..fd9ef09 --- /dev/null +++ b/src/org/ibex/mail/List.java @@ -0,0 +1,116 @@ +package org.ibex.mail; +import org.ibex.util.*; +import org.ibex.mail.target.*; +import java.util.*; +import java.io.*; +import org.prevayler.*; +import org.prevayler.Query; + +// FEATURE: umbrella structure to mailing lists +public class List implements Serializable { + + 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;} + + public Hashtable subscribers = new Hashtable(); + public Filter[] filters = new Filter[0]; + + public String homepage = ""; + public String one_line_description = ""; + public String long_description = ""; + public String message_footer = ""; + + public Visibility listVisibility = Visibility.Nobody; + public Visibility membershipVisibility = Visibility.Nobody; + public Visibility archiveVisibility = Visibility.Members; + public Action defaultPostingType = Action.Hold; + + public int bounceThreshhold = 10; + + public static List getList(Object all, String listName) { return (List)((Hashtable)all).get(listName); } + public synchronized Subscriber getSubscriber(Address subscriber) { + Subscriber s = (Subscriber)subscribers.get(subscriber.toString(false)); + if (s == null) subscribers.put(subscriber, s = new Subscriber()); + return s; + } + + public static class Subscriber implements Serializable { + public Address address; + public Action posting; + public UserType type; + public SubscriptionType subscription; + public boolean send_copy_of_own_post; + public boolean filter_duplicates_when_ccd; + } + + //public static class Filter { + // public class EmergencyModerationFilter { } + // public class MaximumLengthFilter { } + // public class SpamFilter { } + // public class MIMETypes { } + // public class MungeReplyTo { } + // public class AnonymizeSender { public boolean uncorrelated; } + //} + + // Transactions /////////////////////////////////////////////////////////////////////////// + + + ////////////////////////////////////////////////////////////////////////////// + + public static final String ROOT = System.getProperty("ibex.mail.list.root", Mailbox.STORAGE_ROOT+File.separatorChar+"lists"); + public static Prevayler p; + static { try { p = PrevaylerFactory.createPrevayler(new Hashtable(), ROOT); } + catch (Exception e) { Log.error(List.class, e); } } + + public static Transaction subscribeNewUser(final Address user, final String list) { + return new Transaction() { public void executeOn(final Object o, final Date now) { + try { + new AlterSubscription(user, + now.getTime() + 1000*60*60*24, + list, + SubscriptionType.All).signAndSend(getList(o, list).secret); + } catch (Exception e) { + Log.error(List.class, e); + } + } }; } + + public static Transaction create(final Address address, final Mailbox pending, final Mailbox archive) { + final long random = new Random().nextLong(); + return new Transaction() { public void executeOn(Object all, Date now) { + ((Hashtable)all).put(address.toString(false), new List(address, pending, archive, random)); } }; + } + + public static Transaction delete(final Address address) { + return new Transaction() { public void executeOn(Object o,Date now) { + ((Hashtable)o).remove(address.toString(false)); } }; } + + public static Query all() { return new Query() { public Object query(Object o, Date now) { + Hashtable all = (Hashtable)o; + List[] ret = new List[all.size()]; + Enumeration e = all.elements(); + for(int i=0; i