added GMail
[org.ibex.mail.git] / src / org / ibex / mail / protocol / GMail.java
1 package org.ibex.mail.protocol;
2 import org.ibex.io.*;
3 import org.ibex.crypto.*;
4 import org.ibex.jinetd.Listener;
5 import org.ibex.jinetd.Worker;
6 import org.ibex.mail.*;
7 import org.ibex.util.*;
8 import org.ibex.mail.target.*;
9 import java.util.*;
10 import java.net.*;
11 import java.text.*;
12 import java.io.*;
13
14 public class GMail extends Account {
15     public Mailbox getMailbox(Class protocol) { return this.root; }
16     public GMail(String user, String pass) {
17         super(user, Address.parse(user + "@gmail.com"));
18         Log.warn(GMail.class, "logging in " + user + "@gmail.com...");
19         try {
20             Process p =
21                 Runtime.getRuntime().exec(new String[] {
22                     "/usr/bin/python",
23                     "/usr/local/libgmail/demos/archive.py",
24                     user,
25                     pass
26                     });
27             final Mailbox inbox = new MessageArrayMailbox(Mbox.parse(new Stream(p.getInputStream())));
28             this.root =
29                 new Mailbox.Default() {
30                         public void add(Message m) { throw new RuntimeException("not supported"); }
31                         public void add(Message m, int i) { throw new RuntimeException("not supported"); }
32                         public int              uidValidity()  { return 1; }
33                         public Mailbox.Iterator iterator()     { return new Mailbox.Iterator.NullIterator(); }
34                         public int              uidNext()      { return 500; }
35                         public String[] children() { return new String[] { "gmail" }; }
36                         public Mailbox slash(String name, boolean create) { return inbox; }
37                     };
38             p.waitFor();
39             Log.warn(GMail.class, "    succeeded for " + user + "@gmail.com!");
40         } catch (Exception e) {
41             Log.error(GMail.class, e);
42         }
43     }
44 }