lowercase the name of the inbox
[org.ibex.mail.git] / src / org / ibex / mail / IMAP.java
index f6a254d..f97e771 100644 (file)
@@ -115,12 +115,11 @@ public class IMAP {
         private Mailbox mailbox(String name, boolean create) { return mailbox(name, create, true); }
         private Mailbox mailbox(String name, boolean create, boolean throwexn) {
             if (name.equalsIgnoreCase("inbox")) return inbox;
+            if (name.equalsIgnoreCase("trash")) name = "trash";
             MailTree mt =  mailboxTree(name, create, throwexn);
-            /* FIXME: throw throwexn here
-            if (mt==null || mt.getMailbox()==null)
-                Log.error("mt==null", name);
-            */
-            return mt==null ? null : mt.getMailbox();
+            Mailbox ret = mt==null ? null : mt.getMailbox();
+            if (ret==null && throwexn) throw new Server.No("no such mailbox " + name);
+            return ret;
         }
         private MailTree mailboxTree(String name, boolean create) { return mailboxTree(name, create, true); }
         private MailTree mailboxTree(String name, boolean create, boolean throwexn) {
@@ -231,7 +230,8 @@ public class IMAP {
             Vec.Int vec = new Vec.Int();
             for(Mailbox.Iterator it = selected().iterator(q); it.next();) {
                 vec.addElement(uid ? it.uid() : it.imapNumber());
-                it.setFlags(it.getFlags() & ~Mailbox.Flag.RECENT);
+                if ((it.getFlags() & Mailbox.Flag.RECENT) != 0)
+                    it.setFlags(it.getFlags() & ~Mailbox.Flag.RECENT);
             }
             return vec.dump();
         }
@@ -254,7 +254,8 @@ public class IMAP {
 
         public void fetch(Query q, int spec, String[] headers, int start, int end, boolean uid) {
             for(Mailbox.Iterator it = selected().iterator(q); it.next(); ) {
-                Message message = ((spec & (BODYSTRUCTURE | ENVELOPE | INTERNALDATE | FIELDS | FIELDSNOT | RFC822 |
+                Message message =
+                    ((spec & (BODYSTRUCTURE | ENVELOPE | INTERNALDATE | FIELDS | FIELDSNOT | RFC822 |
                                             RFC822TEXT | RFC822SIZE | HEADERNOT | HEADER)) != 0) ? it.cur() : null;
                 long size = message == null ? 0 : message.getLength();
                 client.fetch(it.imapNumber(), it.getFlags(), (int)size, message, it.uid());
@@ -293,7 +294,7 @@ public class IMAP {
             } else {
                 Account account = (Account)ret;
                 ((MailboxWrapper)api).root = root = account.getMailbox(IMAP.class);
-                MailTree ibt = root.slash("INBOX", false);
+                MailTree ibt = root.slash("inbox", false);
                 Mailbox ib = ibt==null ? null : ibt.getMailbox();
                 ((MailboxWrapper)api).inbox = inbox = ib;
             }