X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fmail%2FMailingList.java;h=0a2baa6e9c4ade5519e2415efaf61cef554ad2f6;hb=5d04327679cf286064528beb2d3e9031695679c9;hp=4eca2c1ea3beb17cd56b37b5593c9ecc4de2dcd9;hpb=bc83134e919098665f5027be4b2b11d971270d15;p=org.ibex.mail.git diff --git a/src/org/ibex/mail/MailingList.java b/src/org/ibex/mail/MailingList.java index 4eca2c1..0a2baa6 100644 --- a/src/org/ibex/mail/MailingList.java +++ b/src/org/ibex/mail/MailingList.java @@ -13,12 +13,13 @@ import java.net.*; import javax.servlet.*; import javax.servlet.http.*; -public class MailingList implements Target, Iterable { +public class MailingList extends Mailbox.MailboxWrapper { - // DO NOT move this below the stuff underneath it - private MailingList(File path) throws IOException { + // FIXME + public MailingList(File path, FileBasedMailbox fbm) throws IOException { + super(fbm); this.path = path; - archive = FileBasedMailbox.getFileBasedMailbox(path.getCanonicalPath(), true); + this.mailbox = fbm; properties = new PropertiesFile(new File(path.getCanonicalPath() + File.separatorChar + "properties")); address = new Address(properties.get("address")); homepage = properties.get("homepage"); @@ -111,8 +112,8 @@ public class MailingList implements Target, Iterable { } private final File path; - private final FileBasedMailbox archive; private final PropertiesFile properties; + private final FileBasedMailbox mailbox; private final long secret = new Random().nextLong(); public final Address address; @@ -131,38 +132,41 @@ public class MailingList implements Target, Iterable { // Pooling ////////////////////////////////////////////////////////////////////////////// - - public Iterator iterator() { - final File subdir = new File(path.getAbsolutePath() + File.separatorChar + "subscribers"); - if (!subdir.exists()) subdir.mkdirs(); - final String[] subs = !subdir.isDirectory() ? new String[0] : subdir.list(); - return new Iterator() { - int i=0; - Subscriber prep = null; - public void remove() { - try { - new File(subdir.getAbsolutePath() + File.separatorChar + subs[i++]).delete(); - } catch (Exception e) { - Log.error(MailingList.class, e); - } - } - public boolean hasNext() { if (prep==null) prep = next(); return prep!=null; } - public Subscriber next() { - if (prep!=null) { Subscriber ret = prep; prep = null; return ret; } - while(i subscribers() { + return new Iterable() { + public java.util.Iterator iterator() { + final File subdir = new File(path.getAbsolutePath() + File.separatorChar + "subscribers"); + if (!subdir.exists()) subdir.mkdirs(); + final String[] subs = !subdir.isDirectory() ? new String[0] : subdir.list(); + return new java.util.Iterator() { + int i=0; + Subscriber prep = null; + public void remove() { + try { + new File(subdir.getAbsolutePath() + File.separatorChar + subs[i++]).delete(); + } catch (Exception e) { + Log.error(MailingList.class, e); + } } - } - return null; + public boolean hasNext() { if (prep==null) prep = next(); return prep!=null; } + public Subscriber next() { + if (prep!=null) { Subscriber ret = prep; prep = null; return ret; } + while(i cache = new HashMap(); public static MailingList getMailingList(String path) throws IOException { return getMailingList(new File(path)); } public static MailingList getMailingList(File path) throws IOException { @@ -171,27 +175,35 @@ public class MailingList implements Target, Iterable { if (ret==null) cache.put(path.getCanonicalPath(), ret = new MailingList(path)); return ret; } - + */ // Methods ////////////////////////////////////////////////////////////////////////////// - public Mailbox getArchive() throws IOException { return archive; } - - public void accept(Message m) throws IOException, MailException { - StringBuffer buf = new StringBuffer(); - m.getBody().getStream().transcribe(buf); - Headers head = new Headers.Original(m.headers.getStream()); - head = head.set("List-Id", one_line_description + "<"+address+">"); - head = head.set("Subject", properties.get("prefix") + " " + head.get("Subject")); - - m = Message.newMessage(new Fountain.StringFountain(head.getString()+"\r\n"+buf.toString())); - Log.warn(MailingList.class, "archiving list message " + m.subject); - getArchive().accept(m); - - for(Subscriber s : this) try { - Log.warn(MailingList.class, " trying " + s.address); - SMTP.accept(Message.newMessage(m, m.envelopeFrom, s.address)); - Log.warn("[list]", "successfully sent to " + s); - } catch (Exception e2) { Log.error("[list]", e2); } + public void add(Message message) { + try { + accept(message); + } catch (Exception e) { throw new RuntimeException(e); } + } + public void add(Message message, int flags) { add(message); /* FIXME: flags? */ } + public void accept(Message m) throws MailException { + try { + StringBuffer buf = new StringBuffer(); + m.getBody().getStream().transcribe(buf); + Headers head = new Headers.Original(m.headers.getStream()); + head = head.set("List-Id", one_line_description + "<"+address+">"); + head = head.set("Subject", properties.get("prefix") + " " + head.get("Subject")); + + m = Message.newMessage(Fountain.Util.concat(new Fountain[] { head, + Fountain.Util.create("\r\n"), + Fountain.Util.create(buf.toString()) })); + Log.warn(MailingList.class, "archiving list message " + m.subject); + mailbox.accept(m); + + for(Subscriber s : subscribers()) try { + Log.warn(MailingList.class, " trying " + s.address); + SMTP.enqueue(Message.newMessage(m, m.envelopeFrom, s.address)); + Log.warn("[list]", "successfully sent to " + s); + } catch (Exception e2) { Log.error("[list]", e2); } + } catch (Exception e) { throw new RuntimeException(e); } } //public Filter[] filters = new Filter[0];