1 package org.ibex.mail.target;
2 import org.ibex.mail.*;
3 import org.ibex.util.*;
4 import org.ibex.mail.*;
10 public abstract class Mailbox extends Target {
12 private static final String STORAGE_ROOT =
13 System.getProperty("ibex.mail.root", File.separatorChar + "var" + File.separatorChar + "org.ibex.mail");
14 public static FileBasedMailbox root = null;
15 public static Transcript transcript = null;
18 root = new FileBasedMailbox(STORAGE_ROOT + File.separatorChar);
19 transcript = new Transcript(STORAGE_ROOT + File.separatorChar + "transcript");
20 } catch (Exception e) {
26 public abstract Mailbox.Iterator iterator(); // only abstract method
27 public Mailbox.Iterator iterator(Query q) throws MailException { return new QueryIterator(q); }
28 public int add(Message message) throws MailException { throw new MailException("not implemented"); }
29 public int delete(Message message) throws MailException { throw new MailException("not implemented"); }
30 public void move(Query q, Mailbox dest, boolean copy) throws MailException { throw new MailException("not implemented"); }
31 public int count(Query q) throws MailException {
33 for(Iterator it = iterator(); it.next(); ) if (q.match(it)) i++;
38 public void rename(String newName) throws MailException { throw new MailException("you cannot rename this mailbox"); }
39 public void destroy() throws MailException { throw new MailException("you cannot destroy this mailbox"); }
40 public Mailbox slash(String name, boolean create) throws MailException { throw new MailException("no submailboxes"); }
41 public Mailbox slash(String name) throws MailException { return slash(name, false); }
43 public abstract int uidNext();
44 public abstract int uidValidity();
47 public abstract String getName();
49 private class QueryIterator extends Iterator {
52 public QueryIterator(Query q) { this.q = q; this.i = Mailbox.this.iterator(); }
53 public Message cur() { return i.cur(); }
54 public boolean next() { do { if (!i.next()) return false; } while(!q.match(i)); return true; }
55 protected int flags() { return i.flags(); }
56 protected void flags(int newFlags) { i.flags(newFlags); }
57 public int uid() { return i.uid(); }
58 public int num() { return i.num(); }
59 public void set(String key, String val) { i.set(key, val); }
60 public String get(String key) { return i.get(key); }
61 public void delete() { i.delete(); }
64 public static abstract class Iterator {
65 public abstract Message cur();
66 public abstract boolean next();
68 // minimal implementation
69 protected abstract int flags();
70 protected abstract void flags(int newFlags);
71 public abstract int uid();
72 public abstract int num();
73 public abstract void delete();
75 public void set(String key, String val) { throw new MailException.MetadataNotSupported(""); }
76 public String get(String key) { throw new MailException.MetadataNotSupported(""); }
78 public final boolean getFlag(int flag) { return ((flags() & flag) == flag); }
79 public final void setFlag(int flag) { flags(flags() | flag); }
80 public final void clearFlag(int flag) { flags(flags() & ~flag); }
82 public final boolean seen() { return getFlag(Flag.SEEN); }
83 public final boolean deleted() { return getFlag(Flag.DELETED); }
84 public final boolean flagged() { return getFlag(Flag.FLAGGED); }
85 public final boolean draft() { return getFlag(Flag.DRAFT); }
86 public final boolean answered() { return getFlag(Flag.ANSWERED); }
87 public final boolean recent() { return getFlag(Flag.RECENT); }
89 public final void seen(boolean on) { setFlag(Flag.SEEN); }
90 public final void deleted(boolean on) { setFlag(Flag.DELETED); }
91 public final void flagged(boolean on) { setFlag(Flag.FLAGGED); }
92 public final void draft(boolean on) { setFlag(Flag.DRAFT); }
93 public final void answered(boolean on) { setFlag(Flag.ANSWERED); }
94 public final void recent(boolean on) { setFlag(Flag.RECENT); }
97 public final void accept(Message m) throws MailException { add(m); }