1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
6 import org.ibex.util.*;
8 import org.ibex.mail.target.*;
9 import org.ibex.mail.protocol.*;
12 import org.prevayler.*;
13 import org.prevayler.Query;
15 public class MailingList extends Persistent implements Target {
17 public static enum UserType { Administrator, Moderator, Member }
18 public static enum SubscriptionType { All, None, Digest, MimeDigest }
19 public static enum Visibility { Members, Public, Nobody }
20 public static enum Action { Accept, Hold, Reject }
22 public Address address;
23 private final long secret = new Random().nextLong();
25 public Hashtable subscribers = new Hashtable();
27 public String homepage = "";
28 public String one_line_description = "";
29 public String long_description = "";
30 public String message_footer = "";
32 public Visibility listVisibility = Visibility.Nobody;
33 public Visibility membershipVisibility = Visibility.Nobody;
34 public Visibility archiveVisibility = Visibility.Members;
35 public Action defaultPostingType = Action.Hold;
37 public int bounceThreshhold = 10;
39 public static class Subscriber {
40 public Address address;
41 public Action posting;
43 public SubscriptionType subscription;
44 public boolean send_copy_of_own_post;
45 public boolean filter_duplicates_when_ccd;
49 // Pooling //////////////////////////////////////////////////////////////////////////////
51 private MailingList(File path) { super(path); }
52 public static MailingList getMailingList(String path) { return getMailingList(new File(path)); }
53 public static MailingList getMailingList(File path) {
54 if (!path.exists()) path.mkdirs();
55 File f = new File(path.getAbsolutePath() + File.separatorChar + ".mailinglist");
57 if (f.exists()) return (MailingList)Persistent.read(f);
58 MailingList ret = new MailingList(path);
61 } catch (Exception e) {
62 Log.error(MailingList.class, e);
67 // Methods //////////////////////////////////////////////////////////////////////////////
69 public Mailbox getArchive() { return FileBasedMailbox.getFileBasedMailbox(path, true); }
71 public void accept(Message m) throws IOException, MailException {
72 StringBuffer buf = new StringBuffer();
73 m.getBody().getStream().transcribe(buf);
74 Headers head = new Headers(m.headers.getStream());
75 head.put("list-id", one_line_description + "<"+address+">");
77 m = Message.newMessage(new Fountain.StringFountain(head.getString()+"\r\n"+buf.toString()));
78 Log.warn(MailingList.class, "archiving list message " + m.subject);
79 getArchive().accept(m);
81 for(java.util.Enumeration e = subscribers.elements(); e.hasMoreElements();) try {
82 Subscriber s = (Subscriber)e.nextElement();
83 Log.warn(MailingList.class, " trying " + s.address);
84 SMTP.accept(Message.newMessage(m, m.envelopeFrom, s.address));
85 Log.warn("[list]", "successfully sent to " + s);
86 } catch (Exception e2) { Log.error("[list]", e2); }
89 //public Filter[] filters = new Filter[0];
90 //public static class Filter {
91 // public class EmergencyModerationFilter { }
92 // public class MaximumLengthFilter { }
93 // public class SpamFilter { }
94 // public class MIMETypes { }
95 // public class MungeReplyTo { }
96 // public class AnonymizeSender { public boolean uncorrelated; }