reshuffling of file locations to make package structure flatter
[org.ibex.mail.git] / src / org / ibex / mail / MailmanArchives.java
diff --git a/src/org/ibex/mail/MailmanArchives.java b/src/org/ibex/mail/MailmanArchives.java
new file mode 100644 (file)
index 0000000..0426967
--- /dev/null
@@ -0,0 +1,66 @@
+// Copyright 2000-2005 the Contributors, as shown in the revision logs.
+// Licensed under the Apache Public Source License 2.0 ("the License").
+// You may not use this file except in compliance with the License
+
+package org.ibex.mail;
+import org.ibex.io.*;
+import org.ibex.mail.*;
+import org.ibex.util.*;
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import java.util.zip.*;
+import java.text.*;
+
+/** designed to make a set of HTTP-accessible Mailman archives appear as a mailbox */
+public class MailmanArchives extends Mailbox.Default {
+
+    public static final String archiveUrl =
+        "http://lists.false-profit.com/mailman/private/us/2004-August.txt.gz?username=adam@false-profit.com&password=bre4kull";
+
+    public MailmanArchives() {
+        try {
+            InputStream is = new java.net.URL(archiveUrl).openConnection().getInputStream();
+            BufferedReader br = new BufferedReader(new InputStreamReader(/*new GZIPInputStream(is)*/is));
+            Vec all = new Vec();
+            StringBuffer acc = null;
+            for(String s = br.readLine(); ; s = br.readLine()) {
+                if (s == null || s.startsWith("From ")) {
+                    if (acc != null) {
+                        Log.warn("[msg]", acc.toString());
+                        all.addElement(Message.newMessage(new Fountain.StringFountain(acc.toString())));
+                    }
+                    if (s == null) break;
+                    acc = new StringBuffer();
+                } else {
+                    acc.append(s);
+                    acc.append("\r\n");
+                }
+            }
+            all.copyInto(messages = new Message[all.size()]);
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException(e);
+        }
+    }
+
+    public void insert(Message m, int i) { throw new RuntimeException("not supported"); }
+
+    public Message[] messages;
+
+    public int              uidValidity()  { return 1; }
+    public Mailbox.Iterator iterator()     { return new Iterator(); }
+    public int              uidNext()      { return messages.length; }
+
+    private class Iterator extends Mailbox.Default.Iterator {
+        int num = 0;
+        public int     uid() { return num; }
+        public int     nntpNumber() { return num; }
+        public int     imapNumber() { return num; }
+        public Message cur() { return messages[num]; }
+        public Headers head() { return messages[num].headers; }
+        public boolean next() { return (++num) < messages.length; }
+        public void    delete() { }
+    }    
+
+}