public Cache(File dir) { this.dir = dir; }
- public void init(Prevayler prevayler) throws IOException {
+ public void init(final Prevayler prevayler) throws IOException {
dir.mkdirs();
Log.info(this, "initializing maildir " + dir.getParent());
boolean invalid = false;
if (file.charAt(0)!='.' && !(new File(dir.getParent() + slash + file).isDirectory()))
if (get(file) == null) new Entry(this, prevayler, file);
Log.info(this, " done initializing maildir " + dir.getParent());
- prevayler.takeSnapshot();
+ new Thread() { public void run() {
+ try { prevayler.takeSnapshot(); } catch (Exception e) { Log.error(this, e); }
+ } }.start();
}
public static class Drop implements Transaction {
}
public static class Entry implements Serializable {
- public final MIME.Headers headers;
+ private final byte[] header;
public final String name;
private int uid;
private boolean seen;
+ public MIME.Headers headers() { return new MIME.Headers(new Stream(new ByteArrayInputStream(header)), true); }
public Entry(Cache cache, Prevayler prevayler, String name) throws IOException {
File f = new File(cache.dir.getParent()+slash+name);
seen = f.lastModified() == MAGIC_DATE;
this.name = name;
- headers = new MIME.Headers(new Stream(new FileInputStream(f)), true);
+ header = new MIME.Headers(new Stream(new FileInputStream(f)), true).toString().getBytes();
prevayler.execute(new Transaction() {
public void executeOn(Object o, Date now) {
Cache cache = (Cache)o;
private class Iterator extends Mailbox.Default.Iterator {
int cur = -1;
private Cache.Entry entry() { return cache.getLinear(cur); }
- public MIME.Headers head() { return done() ? null : entry().headers; }
+ public MIME.Headers head() { return done() ? null : entry().headers(); }
public boolean done() { return cur >= cache.size(); }
public boolean next() { cur++; return !done(); }
public boolean seen() { return done() ? false : entry().seen(); }