65c874c92622ad6a6a0c377d76fd8d14a542ba09
[org.ibex.mail.git] / src / org / ibex / mail / target / MailmanArchives.java
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.
4
5 package org.ibex.mail.target;
6 import org.ibex.io.*;
7 import org.ibex.mail.*;
8 import org.ibex.util.*;
9 import java.io.*;
10 import java.net.*;
11 import java.util.*;
12 import java.util.zip.*;
13 import java.text.*;
14
15 /** designed to make a set of HTTP-accessible Mailman archives appear as a mailbox */
16 public class MailmanArchives extends Mailbox.Default {
17
18     public static final String archiveUrl =
19         "http://lists.false-profit.com/mailman/private/us/2004-August.txt.gz?username=adam@false-profit.com&password=bre4kull";
20
21     public MailmanArchives() {
22         try {
23             InputStream is = new java.net.URL(archiveUrl).openConnection().getInputStream();
24             BufferedReader br = new BufferedReader(new InputStreamReader(/*new GZIPInputStream(is)*/is));
25             Vec all = new Vec();
26             StringBuffer acc = null;
27             for(String s = br.readLine(); ; s = br.readLine()) {
28                 if (s == null || s.startsWith("From ")) {
29                     if (acc != null) {
30                         Log.warn("[msg]", acc.toString());
31                         all.addElement(Message.newMessage(new Fountain.StringFountain(acc.toString())));
32                     }
33                     if (s == null) break;
34                     acc = new StringBuffer();
35                 } else {
36                     acc.append(s);
37                     acc.append("\r\n");
38                 }
39             }
40             all.copyInto(messages = new Message[all.size()]);
41         } catch (Exception e) {
42             e.printStackTrace();
43             throw new RuntimeException(e);
44         }
45     }
46
47     public void insert(Message m, int i) { throw new RuntimeException("not supported"); }
48
49     public Message[] messages;
50
51     public int              uidValidity()  { return 1; }
52     public Mailbox.Iterator iterator()     { return new Iterator(); }
53     public int              uidNext()      { return messages.length; }
54
55     private class Iterator extends Mailbox.Default.Iterator {
56         int num = 0;
57         public int     uid() { return num; }
58         public int     nntpNumber() { return num; }
59         public int     imapNumber() { return num; }
60         public Message cur() { return messages[num]; }
61         public Headers head() { return messages[num].headers; }
62         public boolean next() { return (++num) < messages.length; }
63         public void    delete() { }
64     }    
65
66 }