b5e0a38bef5f9cd0f2b90b60609ff1f162b8f712
[org.ibex.mail.git] / src / org / ibex / mail / target / MailmanArchives.java
1 package org.ibex.mail.target;
2 import org.ibex.io.*;
3 import org.ibex.mail.*;
4 import org.ibex.util.*;
5 import java.io.*;
6 import java.net.*;
7 import java.util.*;
8 import java.util.zip.*;
9 import java.text.*;
10
11 public class MailmanArchives extends Mailbox.Default {
12
13     public static final String archiveUrl =
14         "http://lists.false-profit.com/mailman/private/us/2004-August.txt.gz?username=adam@false-profit.com&password=bre4kull";
15
16     public MailmanArchives() {
17         try {
18             InputStream is = new java.net.URL(archiveUrl).openConnection().getInputStream();
19             BufferedReader br = new BufferedReader(new InputStreamReader(/*new GZIPInputStream(is)*/is));
20             Vec all = new Vec();
21             StringBuffer acc = null;
22             for(String s = br.readLine(); ; s = br.readLine()) {
23                 if (s == null || s.startsWith("From ")) {
24                     if (acc != null) {
25                         Log.warn("[msg]", acc.toString());
26                         all.addElement(Message.newMessage(new Stream(acc.toString())));
27                     }
28                     if (s == null) break;
29                     acc = new StringBuffer();
30                 } else {
31                     acc.append(s);
32                     acc.append("\r\n");
33                 }
34             }
35             all.copyInto(messages = new Message[all.size()]);
36         } catch (Exception e) {
37             e.printStackTrace();
38             throw new RuntimeException(e);
39         }
40     }
41
42     public void add(Message m) { throw new RuntimeException("not supported"); }
43     public void add(Message m, int i) { throw new RuntimeException("not supported"); }
44
45     public Message[] messages;
46
47     public int              uidValidity()  { return 1; }
48     public Mailbox.Iterator iterator()     { return new Iterator(); }
49     public int              uidNext()      { return messages.length; }
50
51     private class Iterator extends Mailbox.Default.Iterator {
52         int num = 0;
53
54         public int     uid() { return num; }
55         public int     num() { return num; }
56
57         public Message cur() { return messages[num]; }
58         public MIME.Headers head() { return messages[num].headers; }
59         public boolean next() { return (++num) < messages.length; }
60         public void    delete() { }
61
62         public void    set(String key, String val) { }
63         public String  get(String key) { return null; }
64         public boolean seen() { return false; }
65         public boolean deleted() { return false; }
66         public boolean flagged() { return false; }
67         public boolean draft() { return false; }
68         public boolean answered() { return false; }
69         public boolean recent() { return false; }
70         public void    seen(boolean on) { }
71         public void    deleted(boolean on) { }
72         public void    flagged(boolean on) { }
73         public void    draft(boolean on) { }
74         public void    answered(boolean on) { }
75         public void    recent(boolean on) { }
76         public int     flags() { return 0; }
77     }    
78
79 }