remove antiquated cruft: please, who use MMDF's nowadays ?!
[apps/madmutt.git] / lib-mx / mbox.c
index 8e75038..57f287a 100644 (file)
@@ -7,7 +7,7 @@
  * please see the file GPL in the top level source directory.
  */
 
-/* This file contains code to parse ``mbox'' and ``mmdf'' style mailboxes */
+/* This file contains code to parse ``mbox'' style mailboxes */
 
 #include <lib-lib/lib-lib.h>
 
@@ -71,122 +71,6 @@ static void mbox_unlock_mailbox (CONTEXT * ctx)
   }
 }
 
-static int mmdf_parse_mailbox (CONTEXT * ctx)
-{
-  char buf[HUGE_STRING];
-  char return_path[LONG_STRING];
-  int count = 0, oldmsgcount = ctx->msgcount;
-  int lines;
-  time_t t, tz;
-  off_t loc, tmploc;
-  HEADER *hdr;
-  struct stat sb;
-
-  if (stat (ctx->path, &sb) == -1) {
-    mutt_perror (ctx->path);
-    return (-1);
-  }
-  ctx->mtime = sb.st_mtime;
-  ctx->size = sb.st_size;
-
-  /* precompute the local timezone to speed up calculation of the
-     received time */
-  tz = mutt_local_tz (0);
-
-  buf[sizeof (buf) - 1] = 0;
-
-  for (;;) {
-    if (fgets (buf, sizeof (buf) - 1, ctx->fp) == NULL)
-      break;
-
-    if (m_strcmp(buf, MMDF_SEP) == 0) {
-      loc = ftello (ctx->fp);
-
-      count++;
-      if (!ctx->quiet && ReadInc && ((count % ReadInc == 0) || count == 1))
-        mutt_message (_("Reading %s... %d (%d%%)"), ctx->path, count,
-                      (int) (loc / (ctx->size / 100 + 1)));
-
-
-      if (ctx->msgcount == ctx->hdrmax)
-        mx_alloc_memory (ctx);
-      ctx->hdrs[ctx->msgcount] = hdr = header_new();
-      hdr->offset = loc;
-      hdr->index = ctx->msgcount;
-
-      if (fgets (buf, sizeof (buf) - 1, ctx->fp) == NULL) {
-        /* TODO: memory leak??? */
-        break;
-      }
-
-      return_path[0] = 0;
-
-      if (!is_from (buf, return_path, sizeof (return_path), &t)) {
-        if (fseeko (ctx->fp, loc, SEEK_SET) != 0) {
-          mutt_error _("Mailbox is corrupt!");
-
-          return (-1);
-        }
-      }
-      else
-        hdr->received = t - tz;
-
-      hdr->env = mutt_read_rfc822_header (ctx->fp, hdr, 0, 0);
-
-      loc = ftello (ctx->fp);
-
-      if (hdr->content->length > 0 && hdr->lines > 0) {
-        tmploc = loc + hdr->content->length;
-
-        if (0 < tmploc && tmploc < ctx->size) {
-          if (fseeko (ctx->fp, tmploc, SEEK_SET) != 0 ||
-              fgets (buf, sizeof (buf) - 1, ctx->fp) == NULL ||
-              m_strcmp(MMDF_SEP, buf) != 0) {
-            fseeko (ctx->fp, loc, SEEK_SET);
-            hdr->content->length = -1;
-          }
-        }
-        else
-          hdr->content->length = -1;
-      }
-      else
-        hdr->content->length = -1;
-
-      if (hdr->content->length < 0) {
-        lines = -1;
-        do {
-          loc = ftello (ctx->fp);
-          if (fgets (buf, sizeof (buf) - 1, ctx->fp) == NULL)
-            break;
-          lines++;
-        } while (m_strcmp(buf, MMDF_SEP) != 0);
-
-        hdr->lines = lines;
-        hdr->content->length = loc - hdr->content->offset;
-      }
-
-      if (!hdr->env->return_path && return_path[0])
-        hdr->env->return_path =
-          rfc822_parse_adrlist (hdr->env->return_path, return_path);
-
-      if (!hdr->env->from)
-        hdr->env->from = address_list_dup (hdr->env->return_path);
-
-      ctx->msgcount++;
-    }
-    else {
-      mutt_error _("Mailbox is corrupt!");
-
-      return (-1);
-    }
-  }
-
-  if (ctx->msgcount > oldmsgcount)
-    mx_update_context (ctx, ctx->msgcount - oldmsgcount);
-
-  return (0);
-}
-
 /* Note that this function is also called when new mail is appended to the
  * currently open folder, and NOT just when the mailbox is initially read.
  *
@@ -340,7 +224,7 @@ static int mbox_parse_mailbox (CONTEXT * ctx)
 
 #undef PREV
 
-/* open a mbox or mmdf style mailbox */
+/* open a mbox style mailbox */
 static int mbox_open_mailbox (CONTEXT * ctx)
 {
   int rc;
@@ -357,8 +241,6 @@ static int mbox_open_mailbox (CONTEXT * ctx)
 
   if (ctx->magic == M_MBOX)
     rc = mbox_parse_mailbox (ctx);
-  else if (ctx->magic == M_MMDF)
-    rc = mmdf_parse_mailbox (ctx);
   else
     rc = -1;
 
@@ -416,13 +298,9 @@ static int _mbox_check_mailbox (CONTEXT * ctx, int *index_hint)
        */
       fseeko (ctx->fp, ctx->size, SEEK_SET);
       if (fgets (buffer, sizeof (buffer), ctx->fp) != NULL) {
-        if ((ctx->magic == M_MBOX && m_strncmp("From ", buffer, 5) == 0)
-            || (ctx->magic == M_MMDF && m_strcmp(MMDF_SEP, buffer) == 0)) {
+        if (ctx->magic == M_MBOX && m_strncmp("From ", buffer, 5) == 0) {
           fseeko (ctx->fp, ctx->size, SEEK_SET);
-          if (ctx->magic == M_MBOX)
-            mbox_parse_mailbox (ctx);
-          else
-            mmdf_parse_mailbox (ctx);
+          mbox_parse_mailbox (ctx);
 
           /* Only unlock the folder if it was locked inside of this routine.
            * It may have been locked elsewhere, like in
@@ -546,7 +424,7 @@ static int mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused))
     return (-1);
 
   /* Create a temporary file to write the new version of the mailbox in. */
-  fp = m_tempfile(tempfile, _POSIX_PATH_MAX, NONULL(Tempdir), NULL);
+  fp = m_tempfile(tempfile, _POSIX_PATH_MAX, NONULL(MCore.tmpdir), NULL);
   if (fp == NULL) {
     mutt_error _("Could not create temporary file!");
     mutt_sleep (5);
@@ -575,12 +453,6 @@ static int mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused))
   /* where to start overwriting */
   offset = ctx->hdrs[i]->offset;
 
-  /* the offset stored in the header does not include the MMDF_SEP, so make
-   * sure we seek to the correct location
-   */
-  if (ctx->magic == M_MMDF)
-    offset -= (sizeof MMDF_SEP - 1);
-
   /* allocate space for the new offsets */
   newOffset = p_new(struct m_update_t, ctx->msgcount - first);
   oldOffset = p_new(struct m_update_t, ctx->msgcount - first);
@@ -603,15 +475,6 @@ static int mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused))
         mutt_message (_("Writing messages... %d (%d%%)"), i,
                       (int) (ftello (ctx->fp) / (ctx->size / 100 + 1)));
 
-      if (ctx->magic == M_MMDF) {
-        if (fputs (MMDF_SEP, fp) == EOF) {
-          mutt_perror (tempfile);
-          mutt_sleep (5);
-          unlink (tempfile);
-          goto bail;
-        }
-      }
-
       /* save the new offset for this message.  we add `offset' because the
        * temporary file only contains saved message which are located after
        * `offset' in the real mailbox
@@ -621,7 +484,7 @@ static int mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused))
       if (mutt_copy_message
           (fp, ctx, ctx->hdrs[i], M_CM_UPDATE,
            CH_FROM | CH_UPDATE | CH_UPDATE_LEN) == -1) {
-        mutt_perror (tempfile);
+        mutt_perror (_("Can't create temporary file"));
         mutt_sleep (5);
         unlink (tempfile);
         goto bail;
@@ -637,29 +500,18 @@ static int mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused))
         ftello (fp) - ctx->hdrs[i]->content->length + offset;
       body_list_wipe(&ctx->hdrs[i]->content->parts);
 
-      switch (ctx->magic) {
-      case M_MMDF:
-        if (fputs (MMDF_SEP, fp) == EOF) {
-          mutt_perror (tempfile);
-          mutt_sleep (5);
-          unlink (tempfile);
-          goto bail;
-        }
-        break;
-      default:
-        if (fputs ("\n", fp) == EOF) {
-          mutt_perror (tempfile);
-          mutt_sleep (5);
-          unlink (tempfile);
-          goto bail;
-        }
+      if (fputs ("\n", fp) == EOF) {
+        mutt_perror (_("Can't create temporary file"));
+        mutt_sleep (5);
+        unlink (tempfile);
+        goto bail;
       }
     }
   }
 
   if (m_fclose(&fp) != 0) {
     unlink (tempfile);
-    mutt_perror (tempfile);
+    mutt_perror (_("Can't create temporary file"));
     mutt_sleep (5);
     goto bail;
   }
@@ -675,16 +527,16 @@ static int mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused))
   if ((fp = fopen (tempfile, "r")) == NULL) {
     mutt_unblock_signals ();
     mx_fastclose_mailbox (ctx);
-    mutt_perror (tempfile);
+    mutt_perror (_("Can't create temporary file"));
     mutt_sleep (5);
     return (-1);
   }
 
-  if (fseeko (ctx->fp, offset, SEEK_SET) != 0 || /* seek the append location */
+  if (fseeko (ctx->fp, offset, SEEK_SET) != 0 /* seek the append location */
       /* do a sanity check to make sure the mailbox looks ok */
-      fgets (buf, sizeof (buf), ctx->fp) == NULL ||
-      (ctx->magic == M_MBOX && m_strncmp("From ", buf, 5) != 0) ||
-      (ctx->magic == M_MMDF && m_strcmp(MMDF_SEP, buf) != 0)) {
+  ||  fgets (buf, sizeof (buf), ctx->fp) == NULL
+  ||  (ctx->magic == M_MBOX && m_strncmp("From ", buf, 5) != 0))
+  {
     i = -1;
   }
   else {
@@ -718,7 +570,7 @@ static int mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused))
     char savefile[_POSIX_PATH_MAX];
 
     snprintf(savefile, sizeof (savefile), "%s/mutt.%s-%u",
-             NONULL(Tempdir), NONULL(Username), (unsigned int)getpid());
+             NONULL(MCore.tmpdir), NONULL(MCore.username), (unsigned int)getpid());
     rename (tempfile, savefile);
     mutt_unblock_signals ();
     mx_fastclose_mailbox (ctx);
@@ -838,9 +690,9 @@ static int mbox_reopen_mailbox (CONTEXT * ctx, int *index_hint)
 
   /* simulate a close */
   if (ctx->id_hash)
-    hash_destroy (&ctx->id_hash, NULL);
+    hash_delete (&ctx->id_hash, NULL);
   if (ctx->subj_hash)
-    hash_destroy (&ctx->subj_hash, NULL);
+    hash_delete (&ctx->subj_hash, NULL);
   mutt_clear_threads (ctx);
   p_delete(&ctx->v2r);
   if (ctx->readonly) {
@@ -867,24 +719,11 @@ static int mbox_reopen_mailbox (CONTEXT * ctx, int *index_hint)
   ctx->id_hash = NULL;
   ctx->subj_hash = NULL;
 
-  switch (ctx->magic) {
-  case M_MBOX:
-  case M_MMDF:
-    if (fseeko (ctx->fp, 0, SEEK_SET) != 0) {
-      rc = -1;
-    }
-    else {
-      cmp_headers = mutt_cmp_header;
-      if (ctx->magic == M_MBOX)
-        rc = mbox_parse_mailbox (ctx);
-      else
-        rc = mmdf_parse_mailbox (ctx);
-    }
-    break;
-
-  default:
+  if (ctx->magic == M_MBOX && !fseeko(ctx->fp, 0, SEEK_SET)) {
+    cmp_headers = mutt_cmp_header;
+    rc = mbox_parse_mailbox (ctx);
+  } else {
     rc = -1;
-    break;
   }
 
   if (rc == -1) {
@@ -983,7 +822,8 @@ int mbox_check_empty (const char *path)
   return ((st.st_size == 0));
 }
 
-int mbox_is_magic (const char* path, struct stat* st) {
+int mbox_is_magic (const char* path, struct stat* st)
+{
   int magic = -1;
   FILE* f;
   char tmp[_POSIX_PATH_MAX];
@@ -992,11 +832,7 @@ int mbox_is_magic (const char* path, struct stat* st) {
     return (-1);
 
   if (st->st_size == 0) {
-    /* hard to tell what zero-length files are, so assume the default magic */
-    if (DefaultMagic == M_MBOX || DefaultMagic == M_MMDF)
-      return (DefaultMagic);
-    else
-      return (M_MBOX);
+    return M_MBOX;
   }
   else if ((f = fopen (path, "r")) != NULL) {
     struct utimbuf times;
@@ -1004,8 +840,6 @@ int mbox_is_magic (const char* path, struct stat* st) {
     fgets (tmp, sizeof (tmp), f);
     if (m_strncmp("From ", tmp, 5) == 0)
       magic = M_MBOX;
-    else if (m_strcmp(MMDF_SEP, tmp) == 0)
-      magic = M_MMDF;
     m_fclose(&f);
 
     /* need to restore the times here, the file was not really accessed,
@@ -1025,23 +859,14 @@ int mbox_is_magic (const char* path, struct stat* st) {
   return (magic);
 }
 
-static int commit_message (MESSAGE* msg, CONTEXT* ctx __attribute__ ((unused)), int mbox) {
-  if ((mbox && fputc ('\n', msg->fp) == EOF) ||
-      (!mbox && fputs (MMDF_SEP, msg->fp) == EOF))
-    return (-1);
+static int mbox_commit_message (MESSAGE* msg, CONTEXT* ctx) {
+  if (fputc ('\n', msg->fp) == EOF)
+    return -1;
   if ((fflush (msg->fp) == EOF || fsync (fileno (msg->fp)) == -1)) {
     mutt_perror (_("Can't write message"));
-    return (-1);
+    return -1;
   }
-  return (0);
-}
-
-static int mbox_commit_message (MESSAGE* msg, CONTEXT* ctx) {
-  return (commit_message (msg, ctx, 1));
-}
-
-static int mmdf_commit_message (MESSAGE* msg, CONTEXT* ctx) {
-  return (commit_message (msg, ctx, 0));
+  return 0;
 }
 
 mx_t const mbox_mx = {
@@ -1059,17 +884,3 @@ mx_t const mbox_mx = {
     mbox_commit_message,
 };
 
-mx_t const mmdf_mx = {
-    M_MMDF,
-    1,
-    mbox_is_magic,
-    mbox_check_empty,
-    access,
-    mbox_open_mailbox,
-    mbox_open_new_message,
-    NULL,
-    mbox_check_mailbox,
-    NULL,
-    mbox_sync_mailbox,
-    mmdf_commit_message,
-};