X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fmail%2FFileBasedMailbox.java;h=e13e22dea9a4632b482d54af885473af023eed8f;hb=8397e490c28796bcc303fb1dfab82d707daa9f22;hp=062168998e634986a14556a9055588d33fb18501;hpb=73c4f25fcc07bcee4e3dde4539a9776094fe5187;p=org.ibex.mail.git diff --git a/src/org/ibex/mail/FileBasedMailbox.java b/src/org/ibex/mail/FileBasedMailbox.java index 0621689..e13e22d 100644 --- a/src/org/ibex/mail/FileBasedMailbox.java +++ b/src/org/ibex/mail/FileBasedMailbox.java @@ -123,7 +123,10 @@ public class FileBasedMailbox extends Mailbox.Default { } public int uidValidity() { return uidValidity; } - public int uidNext() { return uidNext; } + + // UGLY: Apple Mail doesn't like UID=0, so we add one + public int uidNext() { return uidNext+1; } + public synchronized void insert(Message message, int flags) { try { String name, fullname; File target, f; @@ -141,11 +144,14 @@ public class FileBasedMailbox extends Mailbox.Default { f.renameTo(new File(fullname)); uidNext++; f = new File(fullname); - if ((flags & Mailbox.Flag.SEEN) == Mailbox.Flag.SEEN) f.setLastModified(MAGIC_DATE); + if ((flags & Mailbox.Flag.SEEN) == 0) f.setLastModified(MAGIC_DATE); + else if (f.lastModified()==MAGIC_DATE) f.setLastModified(System.currentTimeMillis()); } catch (IOException e) { throw new MailException.IOException(e); } Log.info(this, path + " <= " + message.summary()); } + + private static FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith("."); @@ -157,29 +163,25 @@ public class FileBasedMailbox extends Mailbox.Default { private File file() { return new File(path.getAbsolutePath() + slash + files[cur]); } public boolean done() { return cur >= files.length; } public boolean next() { cur++; return !done(); } - public boolean seen() { return false; } public boolean recent() { return false; } 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)); } + + // UGLY: Apple Mail doesn't like UID=0, so we add one + public int uid() { return done() ? -1 : 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) { } - public Headers head() { - if (done()) return null; - FileInputStream fis = null; - try { - return new Headers.Original(new Stream(new FileInputStream(file()))); - } catch (IOException e) { throw new MailException.IOException(e); - } finally { if (fis != null) try { fis.close(); } catch (Exception e) { /* DELIBERATE */ } } + public int getFlags() { + return file().lastModified()==MAGIC_DATE ? 0 : Flag.SEEN; } - public Message cur() { - FileInputStream fis = null; - try { - return Message.newMessage(new Fountain.File(file())); - //} catch (IOException e) { throw new MailException.IOException(e); - } catch (Message.Malformed e) { throw new MailException(e.getMessage()); - } finally { if (fis != null) try { fis.close(); } catch (Exception e) { /* DELIBERATE */ } } + public void setFlags(int flags) { + File f = file(); + if ((flags & Mailbox.Flag.SEEN) == 0) f.setLastModified(MAGIC_DATE); + else if (f.lastModified()==MAGIC_DATE) f.setLastModified(System.currentTimeMillis()); + // FIXME } + public Headers head() { return done() ? null : new Headers(new Fountain.File(file())); } + public Message cur() { return Message.newMessage(new Fountain.File(file())); } } public static class Servlet extends HttpServlet {