2 import org.ibex.util.*;
3 import org.ibex.mail.target.*;
6 import org.prevayler.*;
7 import org.prevayler.Query;
9 // FEATURE: umbrella structure to mailing lists
10 public class List implements Serializable {
12 public static enum UserType { Administrator, Moderator, Member }
13 public static enum SubscriptionType { All, None, Digest, MimeDigest }
14 public static enum Visibility { Members, Public, Nobody }
15 public static enum Action { Accept, Hold, Reject }
17 public Address address;
18 public Mailbox pending;
19 public Mailbox archive;
20 private final long secret;
21 private List(Address a, Mailbox p, Mailbox ar, long s) {this.address=a;this.pending=p;this.archive=ar;this.secret=s;}
23 public Hashtable subscribers = new Hashtable();
24 public Filter[] filters = new Filter[0];
26 public String homepage = "";
27 public String one_line_description = "";
28 public String long_description = "";
29 public String message_footer = "";
31 public Visibility listVisibility = Visibility.Nobody;
32 public Visibility membershipVisibility = Visibility.Nobody;
33 public Visibility archiveVisibility = Visibility.Members;
34 public Action defaultPostingType = Action.Hold;
36 public int bounceThreshhold = 10;
38 public static List getList(Object all, String listName) { return (List)((Hashtable)all).get(listName); }
39 public synchronized Subscriber getSubscriber(Address subscriber) {
40 Subscriber s = (Subscriber)subscribers.get(subscriber.toString(false));
41 if (s == null) subscribers.put(subscriber, s = new Subscriber());
45 public static class Subscriber implements Serializable {
46 public Address address;
47 public Action posting;
49 public SubscriptionType subscription;
50 public boolean send_copy_of_own_post;
51 public boolean filter_duplicates_when_ccd;
54 //public static class Filter {
55 // public class EmergencyModerationFilter { }
56 // public class MaximumLengthFilter { }
57 // public class SpamFilter { }
58 // public class MIMETypes { }
59 // public class MungeReplyTo { }
60 // public class AnonymizeSender { public boolean uncorrelated; }
63 // Transactions ///////////////////////////////////////////////////////////////////////////
66 //////////////////////////////////////////////////////////////////////////////
68 public static final String ROOT = System.getProperty("ibex.mail.list.root", Mailbox.STORAGE_ROOT+File.separatorChar+"lists");
69 public static Prevayler p;
70 static { try { p = PrevaylerFactory.createPrevayler(new Hashtable(), ROOT); }
71 catch (Exception e) { Log.error(List.class, e); } }
73 public static Transaction subscribeNewUser(final Address user, final String list) {
74 return new Transaction() { public void executeOn(final Object o, final Date now) {
76 new AlterSubscription(user,
77 now.getTime() + 1000*60*60*24,
79 SubscriptionType.All).signAndSend(getList(o, list).secret);
80 } catch (Exception e) {
81 Log.error(List.class, e);
85 public static Transaction create(final Address address, final Mailbox pending, final Mailbox archive) {
86 final long random = new Random().nextLong();
87 return new Transaction() { public void executeOn(Object all, Date now) {
88 ((Hashtable)all).put(address.toString(false), new List(address, pending, archive, random)); } };
91 public static Transaction delete(final Address address) {
92 return new Transaction() { public void executeOn(Object o,Date now) {
93 ((Hashtable)o).remove(address.toString(false)); } }; }
95 public static Query all() { return new Query() { public Object query(Object o, Date now) {
96 Hashtable all = (Hashtable)o;
97 List[] ret = new List[all.size()];
98 Enumeration e = all.elements();
99 for(int i=0; i<ret.length; i++) ret[i] = (List)e.nextElement();
103 public static Query forAddress(final Address a) { return new Query() {
104 public Object query(Object o, Date now) {
105 return ((Hashtable)o).get(a.toString(false)); } }; }
107 public static class AlterSubscription extends Confirmation {
108 public transient SubscriptionType newType = SubscriptionType.All;
110 protected AlterSubscription(Address who, long expiration, String list, SubscriptionType newType) {
111 super(who, expiration); this.newType = newType; this.list = list; }
112 public String getDescription() { return "change your subscription"; }
113 public void executeOn(Object all, Date now) { getList(all, list).getSubscriber(who).subscription = newType; }