change num() to imapNumber() and nntpNumber(), add comments about semantics
[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 add(Message m) { throw new RuntimeException("not supported"); }
48     public void add(Message m, int i) { throw new RuntimeException("not supported"); }
49
50     public Message[] messages;
51
52     public int              uidValidity()  { return 1; }
53     public Mailbox.Iterator iterator()     { return new Iterator(); }
54     public int              uidNext()      { return messages.length; }
55
56     private class Iterator extends Mailbox.Default.Iterator {
57         int num = 0;
58
59         public int     uid() { return num; }
60         public int     nntpNumber() { return num; }
61         public int     imapNumber() { return num; }
62         public Message cur() { return messages[num]; }
63         public Headers head() { return messages[num].headers; }
64         public boolean next() { return (++num) < messages.length; }
65         public void    delete() { }
66
67         public void    set(String key, String val) { }
68         public String  get(String key) { return null; }
69         public boolean seen() { return false; }
70         public boolean deleted() { return false; }
71         public boolean flagged() { return false; }
72         public boolean draft() { return false; }
73         public boolean answered() { return false; }
74         public boolean recent() { return false; }
75         public void    seen(boolean on) { }
76         public void    deleted(boolean on) { }
77         public void    flagged(boolean on) { }
78         public void    draft(boolean on) { }
79         public void    answered(boolean on) { }
80         public void    recent(boolean on) { }
81         public int     flags() { return 0; }
82     }    
83
84 }