+
+static int mh_is_magic (const char* path, struct stat* st) {
+ char tmp[_POSIX_PATH_MAX];
+
+ if (S_ISDIR (st->st_mode)) {
+ snprintf (tmp, sizeof (tmp), "%s/.mh_sequences", path);
+ if (access (tmp, F_OK) == 0)
+ return (M_MH);
+
+ snprintf (tmp, sizeof (tmp), "%s/.xmhcache", path);
+ if (access (tmp, F_OK) == 0)
+ return (M_MH);
+
+ snprintf (tmp, sizeof (tmp), "%s/.mew_cache", path);
+ if (access (tmp, F_OK) == 0)
+ return (M_MH);
+
+ snprintf (tmp, sizeof (tmp), "%s/.mew-cache", path);
+ if (access (tmp, F_OK) == 0)
+ return (M_MH);
+
+ snprintf (tmp, sizeof (tmp), "%s/.sylpheed_cache", path);
+ if (access (tmp, F_OK) == 0)
+ return (M_MH);
+
+ /*
+ * ok, this isn't an mh folder, but mh mode can be used to read
+ * Usenet news from the spool. ;-)
+ */
+
+ snprintf (tmp, sizeof (tmp), "%s/.overview", path);
+ if (access (tmp, F_OK) == 0)
+ return (M_MH);
+ }
+ return (-1);
+}
+
+static int maildir_is_magic (const char* path, struct stat* st) {
+ struct stat sb;
+ char tmp[_POSIX_PATH_MAX];
+
+ if (S_ISDIR (st->st_mode)) {
+ snprintf (tmp, sizeof (tmp), "%s/cur", path);
+ if (stat (tmp, &sb) == 0 && S_ISDIR (sb.st_mode))
+ return (M_MAILDIR);
+ }
+ return (-1);
+}
+
+/* routines common to maildir and mh */
+static mx_t* reg_mx (void) {
+ mx_t* fmt = mem_calloc (1, sizeof (mx_t));
+ fmt->local = 1;
+ fmt->mx_access = access;
+ fmt->mx_sync_mailbox = mh_sync_mailbox;
+ return (fmt);
+}
+
+static int mh_commit (MESSAGE* msg, CONTEXT* ctx) {
+ return (mh_commit_message (msg, ctx, NULL));
+}
+
+static int maildir_commit (MESSAGE* msg, CONTEXT* ctx) {
+ return (maildir_commit_message (msg, ctx, NULL));
+}
+
+mx_t* mh_reg_mx (void) {
+ mx_t* fmt = reg_mx ();
+ fmt->type = M_MH;
+ fmt->mx_check_empty = mh_check_empty;
+ fmt->mx_is_magic = mh_is_magic;
+ fmt->mx_open_mailbox = mh_read_dir;
+ fmt->mx_open_new_message = mh_open_new_message;
+ fmt->mx_check_mailbox = mh_check_mailbox;
+ fmt->mx_commit_message = mh_commit;
+ return (fmt);
+}
+
+mx_t* maildir_reg_mx (void) {
+ mx_t* fmt = reg_mx ();
+ fmt->type = M_MAILDIR;
+ fmt->mx_check_empty = maildir_check_empty;
+ fmt->mx_is_magic = maildir_is_magic;
+ fmt->mx_open_mailbox = maildir_read_dir;
+ fmt->mx_open_new_message = maildir_open_new_message;
+ fmt->mx_check_mailbox = maildir_check_mailbox;
+ fmt->mx_commit_message = maildir_commit;
+ return (fmt);
+}