default magic is useless: only _create_ mboxes and maildirs.
[apps/madmutt.git] / lib-mx / mx.c
index b41a079..38edb8a 100644 (file)
@@ -157,23 +157,6 @@ int mx_is_local (int m) {
   return (mxfmts[m]->local);
 }
 
-/*
- * set DefaultMagic to the given value
- */
-int mx_set_magic (const char *s)
-{
-  if (ascii_strcasecmp (s, "mbox") == 0)
-    DefaultMagic = M_MBOX;
-  else if (ascii_strcasecmp (s, "mh") == 0)
-    DefaultMagic = M_MH;
-  else if (ascii_strcasecmp (s, "maildir") == 0)
-    DefaultMagic = M_MAILDIR;
-  else
-    return (-1);
-
-  return 0;
-}
-
 /* mx_access: Wrapper for access, checks permissions on a given mailbox.
  *   We may be interested in using ACL-style flags at some point, currently
  *   we use the normal access() flags. */
@@ -212,9 +195,8 @@ static int mx_open_mailbox_append (CONTEXT * ctx, int flags)
     }
   }
   else if (errno == ENOENT) {
-    ctx->magic = DefaultMagic;
-
-    if (ctx->magic == M_MH || ctx->magic == M_MAILDIR) {
+    int len = m_strlen(ctx->path);
+    if (len > 0 && ctx->path[len - 1] == '/') {
       char tmp[_POSIX_PATH_MAX];
 
       if (mkdir (ctx->path, S_IRWXU)) {
@@ -222,47 +204,36 @@ static int mx_open_mailbox_append (CONTEXT * ctx, int flags)
         return (-1);
       }
 
-      if (ctx->magic == M_MAILDIR) {
-        snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
-        if (mkdir (tmp, S_IRWXU)) {
-          mutt_perror (tmp);
-          rmdir (ctx->path);
-          return (-1);
-        }
-
-        snprintf (tmp, sizeof (tmp), "%s/new", ctx->path);
-        if (mkdir (tmp, S_IRWXU)) {
-          mutt_perror (tmp);
-          snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
-          rmdir (tmp);
-          rmdir (ctx->path);
-          return (-1);
-        }
-        snprintf (tmp, sizeof (tmp), "%s/tmp", ctx->path);
-        if (mkdir (tmp, S_IRWXU)) {
-          mutt_perror (tmp);
-          snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
-          rmdir (tmp);
-          snprintf (tmp, sizeof (tmp), "%s/new", ctx->path);
-          rmdir (tmp);
-          rmdir (ctx->path);
-          return (-1);
-        }
+      snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
+      if (mkdir (tmp, S_IRWXU)) {
+        mutt_perror (tmp);
+        rmdir (ctx->path);
+        return (-1);
       }
-      else {
-        int i;
 
-        snprintf (tmp, sizeof (tmp), "%s/.mh_sequences", ctx->path);
-        if ((i = creat (tmp, S_IRWXU)) == -1) {
-          mutt_perror (tmp);
-          rmdir (ctx->path);
-          return (-1);
-        }
-        close (i);
+      snprintf (tmp, sizeof (tmp), "%s/new", ctx->path);
+      if (mkdir (tmp, S_IRWXU)) {
+        mutt_perror (tmp);
+        snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
+        rmdir (tmp);
+        rmdir (ctx->path);
+        return (-1);
       }
+      snprintf (tmp, sizeof (tmp), "%s/tmp", ctx->path);
+      if (mkdir (tmp, S_IRWXU)) {
+        mutt_perror (tmp);
+        snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
+        rmdir (tmp);
+        snprintf (tmp, sizeof (tmp), "%s/new", ctx->path);
+        rmdir (tmp);
+        rmdir (ctx->path);
+        return (-1);
+      }
+      ctx->magic = M_MAILDIR;
+    } else {
+      ctx->magic = M_MBOX;
     }
-  }
-  else {
+  } else {
     mutt_perror (ctx->path);
     return (-1);
   }