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 Subscriber(Address a) { this.address = a; }
41 public Address address;
42 public Action posting = Action.Accept;
43 public UserType type = UserType.Member;
44 public SubscriptionType subscription = SubscriptionType.All;
45 public boolean send_copy_of_own_post = false;
46 public boolean filter_duplicates_when_ccd = true;
50 // Pooling //////////////////////////////////////////////////////////////////////////////
52 private MailingList(File path) { super(path); }
53 public static MailingList getMailingList(String path) { return getMailingList(new File(path)); }
54 public static MailingList getMailingList(File path) {
55 if (!path.exists()) path.mkdirs();
56 path = new File(path.getAbsolutePath() + File.separatorChar + ".mailinglist");
58 if (path.exists()) return (MailingList)Persistent.read(path);
59 MailingList ret = new MailingList(path);
62 } catch (Exception e) {
63 Log.error(MailingList.class, e);
68 // Methods //////////////////////////////////////////////////////////////////////////////
70 public Mailbox getArchive() { return FileBasedMailbox.getFileBasedMailbox(file.getParent(), true); }
72 public void accept(Message m) throws IOException, MailException {
73 StringBuffer buf = new StringBuffer();
74 m.getBody().getStream().transcribe(buf);
75 Headers head = new Headers(m.headers.getStream());
76 head.put("list-id", one_line_description + "<"+address+">");
78 m = Message.newMessage(new Fountain.StringFountain(head.getString()+"\r\n"+buf.toString()));
79 Log.warn(MailingList.class, "archiving list message " + m.subject);
80 getArchive().accept(m);
82 for(java.util.Enumeration e = subscribers.elements(); e.hasMoreElements();) try {
83 Subscriber s = (Subscriber)e.nextElement();
84 Log.warn(MailingList.class, " trying " + s.address);
85 SMTP.accept(Message.newMessage(m, m.envelopeFrom, s.address));
86 Log.warn("[list]", "successfully sent to " + s);
87 } catch (Exception e2) { Log.error("[list]", e2); }
90 //public Filter[] filters = new Filter[0];
91 //public static class Filter {
92 // public class EmergencyModerationFilter { }
93 // public class MaximumLengthFilter { }
94 // public class SpamFilter { }
95 // public class MIMETypes { }
96 // public class MungeReplyTo { }
97 // public class AnonymizeSender { public boolean uncorrelated; }