better .sqlite mailbox autodetection
[org.ibex.mail.git] / src / org / ibex / mail / FileBasedMailbox.java
index dd41566..48e0853 100644 (file)
@@ -41,12 +41,19 @@ public class FileBasedMailbox extends Mailbox.Default implements MailTree {
 
     // FIXME: should be a File()
     public static synchronized MailTree getFileBasedMailbox(String path, boolean create) {
+        if (path.endsWith(".sqlite")) path = path.substring(0, path.length()-".sqlite".length());
         try {
             MailTree ret = instances.get(path);
             if (ret == null) {
-                if (!create && !(new File(path).exists())) return null;
-                ret = new FileBasedMailbox(new File(path));
-                instances.put(path, (FileBasedMailbox)ret);
+                Log.error("n", "no match for " + path + " in " + instances.hashCode());
+                if (new File(path+".sqlite").exists())
+                    ret = new SqliteMailbox(path+".sqlite");
+                else {
+                    if (!create && !(new File(path).exists())) return null;
+                    ret = new FileBasedMailbox(new File(path));
+                }
+                instances.put(path, (MailTree)ret);
+                Log.error("n", "filling " + path + " with " + instances.get(path));
             }
             return ret;
         } catch (Exception e) {
@@ -129,6 +136,8 @@ public class FileBasedMailbox extends Mailbox.Default implements MailTree {
         for(int i=0; i<list.length; i++) {
             File f = new File(path.getAbsolutePath() + slash + list[i]);
             if (f.isDirectory() && f.getName().charAt(0) != '.') vec.addElement(list[i]);
+            if (!f.isDirectory() && f.getName().endsWith(".sqlite"))
+                vec.addElement(list[i].substring(0, list[i].length()-".sqlite".length()));
         }
         return (String[])vec.copyInto(new String[vec.size()]);
     }