public static final long MAGIC_DATE = 0;
private static final char slash = File.separatorChar;
- private static final WeakHashMap<String,FileBasedMailbox> instances = new WeakHashMap<String,FileBasedMailbox>();
+ private static final WeakHashMap<String,Mailbox> instances = new WeakHashMap<String,Mailbox>();
public String toString() { return "[FileBasedMailbox " + path.getAbsolutePath() + "]"; }
public Mailbox slash(String name, boolean create) { return getFileBasedMailbox(path.getAbsolutePath()+slash+name, create); }
// FIXME: should be a File()
- public static synchronized FileBasedMailbox getFileBasedMailbox(String path, boolean create) {
+ public static synchronized Mailbox getFileBasedMailbox(String path, boolean create) {
try {
- FileBasedMailbox ret = instances.get(path);
+ Mailbox ret = instances.get(path);
if (ret == null) {
if (!create && !(new File(path).exists())) return null;
- instances.put(path, ret = new FileBasedMailbox(new File(path)));
+ if (new File(new File(path)+"/subscribers").exists()) {
+ ret = new MailingList(new File(path), new FileBasedMailbox(new File(path)));
+ } else {
+ ret = new FileBasedMailbox(new File(path));
+ }
+ instances.put(path, ret);
}
return ret;
} catch (Exception e) {
// acquire lock
File lockfile = new File(this.path.getAbsolutePath() + slash + ".lock");
lock = new RandomAccessFile(lockfile, "rw").getChannel().tryLock();
- if (lock == null) throw new IOException("unable to lock FileBasedMailbox");
+ /*
+ if (lock == null) {
+ Log.warn(this, "warning: blocking waiting for a lock on " + path);
+ lock = new RandomAccessFile(lockfile, "rw").getChannel().lock();
+ if (lock == null) throw new IOException("unable to lock FileBasedMailbox: " + path);
+ }
+ lockfile.deleteOnExit();
+ */
+
uidValidity = (int)(lockfile.lastModified() & 0xffffffff);
uidNext = 0;
String[] files = path.list();
for(int i=0; i<files.length; i++) {
try {
- if (files[i].indexOf('.') != -1) files[i] = files[i].substring(0, files[i].indexOf('.'));
+ if (files[i].indexOf('.') <= 0) continue;
+ files[i] = files[i].substring(0, files[i].indexOf('.'));
int n = Integer.parseInt(files[i]);
if (n>=uidNext) uidNext = n;
} catch(Exception e) { Log.error(this, e); }
};
public Mailbox.Iterator iterator() { return new Iterator(); }
- public synchronized void add(Message message) { add(message, Mailbox.Flag.RECENT); }
public String[] children() {
Vec vec = new Vec();
String[] list = sort(path.list());
public int uidValidity() { return uidValidity; }
public int uidNext() { return uidNext; }
- public synchronized void add(Message message, int flags) {
+ public synchronized void insert(Message message, int flags) {
try {
String name, fullname; File target, f;
for(int i = uidNext; ; i++) {
target = new File(fullname);
f = new File(target.getCanonicalPath() + "-");
if (!f.exists() && !target.exists()) break;
- Log.error(this, "aieeee!!!! target of add() already exists: " + target.getAbsolutePath());
+ Log.error(this, "aieeee!!!! target of insert() already exists: " + target.getAbsolutePath());
}
Stream stream = new Stream(new FileOutputStream(f));
message.getStream().transcribe(stream);
public boolean next() { cur++; return !done(); }
public boolean seen() { return false; }
public boolean recent() { return false; }
- public int num() { return cur+1; } // EUDORA insists that message numbers start at 1, not 0
+ public int nntpNumber() { return cur+1; } // FIXME: lame
+ public int imapNumber() { return cur+1; } // EUDORA insists that message numbers start at 1, not 0
public int uid() { return done() ? -1 : Integer.parseInt(files[cur].substring(0, files[cur].length()-1)); }
public void delete() { File f = file(); if (f != null && f.exists()) f.delete(); }
public void seen(boolean seen) { }
s[0] = (m.from==null?"":m.from.toString(true));
s[1] = m.subject;
s[2] = (m.date + "").trim().replaceAll(" "," ");
- s[3] = it.num() + "";
+ s[3] = it.imapNumber() + "";
msgs.addElement(s);
}
String[][] messages;
int target = Integer.parseInt(request.getParameter("msgnum"));
Mailbox.Iterator it = mbox.iterator();
while(it.next())
- if (it.num() == target)
+ if (it.imapNumber() == target)
break;
if (it.cur() != null) {
pw.println(" <table width=100% border=0 cellspacing=0 style='border: 1px black solid; background-color:#F0F0E0;'>");
private void banner(HttpServletRequest request, HttpServletResponse response) throws IOException {
String basename = request.getServletPath();
String realpath = getServletContext().getRealPath(basename);
+ /*
MailingList list = MailingList.getMailingList(realpath);
list.banner(request, response);
+ */
+ banner(request, response);
}
private void topright(HttpServletRequest request, HttpServletResponse response, String[][] messages) throws IOException {