]> granicus.if.org Git - mutt/commitdiff
Experimental support for the so-called "kendra" mail folder format.
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 10 Nov 1998 21:02:18 +0000 (21:02 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 10 Nov 1998 21:02:18 +0000 (21:02 +0000)
This seems to be used on OS/2 and is, actually, a slibhtly modified
version of the MMDF format.

attach.c
buffy.c
commands.c
copy.c
init.c
mbox.c
mx.c
mx.h
sendlib.c

index b6a613e70b7b576d0ecd9610e58f2161f40083cd..029fdac53470eeec1535b9ed1c52dfee2840dade 100644 (file)
--- a/attach.c
+++ b/attach.c
@@ -631,7 +631,7 @@ int mutt_save_attachment (FILE *fp, BODY *m, char *path, int flags, HEADER *hdr)
        mx_close_mailbox(&ctx);
        return -1;
       }
-      if (ctx.magic == M_MBOX || ctx.magic == M_MMDF)
+      if (ctx.magic == M_MBOX || ctx.magic == M_MMDF || ctx.magic == M_KENDRA)
        chflags = CH_FROM;
       chflags |= (ctx.magic == M_MAILDIR ? CH_NOSTATUS : CH_UPDATE);
       if ((r = _mutt_copy_message (msg->fp, fp, hn, hn->content, 0, chflags)) == 0)
diff --git a/buffy.c b/buffy.c
index 0a2ccce9f14e14608279721c3440c148385d5a81..09955835b2dc592756d765c83560a24a52af8405 100644 (file)
--- a/buffy.c
+++ b/buffy.c
@@ -46,10 +46,11 @@ static short BuffyNotify = 0;       /* # of unnotified new boxes */
 int fseek_last_message (FILE * f)
 {
   long int pos;
-  char buffer[BUFSIZ + 7];     /* 7 for "\n\nFrom " */
+  char buffer[BUFSIZ + 9];     /* 7 for "\n\nFrom " */
   int bytes_read;
   int i;                       /* Index into `buffer' for scanning.  */
-  memset (buffer, 0, BUFSIZ+7);
+
+  memset (buffer, 0, sizeof(buffer));
   fseek (f, 0, SEEK_END);
   pos = ftell (f);
 
@@ -63,7 +64,7 @@ int fseek_last_message (FILE * f)
   while ((pos -= bytes_read) >= 0)
   {
     /* we save in the buffer at the end the first 7 chars from the last read */
-    strncpy (buffer + BUFSIZ, buffer, 7);
+    strncpy (buffer + BUFSIZ, buffer, 5+2); /* 2 == 2 * strlen(CRLF) */
     fseek (f, pos, SEEK_SET);
     bytes_read = fread (buffer, sizeof (char), bytes_read, f);
     if (bytes_read == -1)
@@ -113,7 +114,7 @@ int test_new_folder (const char *path)
 
   typ = mx_get_magic (path);
 
-  if (typ != M_MBOX && typ != M_MMDF)
+  if (typ != M_MBOX && typ != M_MMDF && typ != M_KENDRA)
     return 0;
 
   f = fopen (path, "rb");
@@ -277,6 +278,7 @@ int mutt_buffy_check (int force)
       {
       case M_MBOX:
       case M_MMDF:
+      case M_KENDRA:
 
        if (STAT_CHECK)
        {
index c7a08923ee0a397d09010458d52da8fbbb90b635..eb9c9949dd5570a837206ef8105cc2778f392f6e 100644 (file)
@@ -657,7 +657,7 @@ int mutt_save_message (HEADER *h, int delete, int decode, int decrypt, int *redr
       }
     }
 
-    need_buffy_cleanup = (ctx.magic == M_MBOX || ctx.magic == M_MMDF);
+    need_buffy_cleanup = (ctx.magic == M_MBOX || ctx.magic == M_MMDF || ctx.magic == M_KENDRA);
 
     mx_close_mailbox (&ctx);
 
diff --git a/copy.c b/copy.c
index 4e2b61b5340c7f3bd772848f20cc8100e559d424..f04de42217806ae8f381990d56bdc07535aa4cd4 100644 (file)
--- a/copy.c
+++ b/copy.c
@@ -515,9 +515,9 @@ _mutt_append_message (CONTEXT *dest, FILE *fpin, CONTEXT *src, HEADER *hdr,
   MESSAGE *msg;
   int r;
 
-  if ((msg = mx_open_new_message (dest, hdr, (src->magic == M_MBOX || src->magic == M_MMDF) ? 0 : M_ADD_FROM)) == NULL)
+  if ((msg = mx_open_new_message (dest, hdr, (src->magic == M_MBOX || src->magic == M_MMDF || src->magic == M_KENDRA) ? 0 : M_ADD_FROM)) == NULL)
     return -1;
-  if (dest->magic == M_MBOX || dest->magic == M_MMDF)
+  if (dest->magic == M_MBOX || dest->magic == M_MMDF || dest->magic == M_KENDRA)
     chflags |= CH_FROM;
   chflags |= (dest->magic == M_MAILDIR ? CH_NOSTATUS : CH_UPDATE);
   r = _mutt_copy_message (msg->fp, fpin, hdr, body, flags, chflags);
diff --git a/init.c b/init.c
index 87c3bf4b99dc2963304fe57323a44b1c8072e610..601fd758588a9e0d89937f87d7cbc991fea2760a 100644 (file)
--- a/init.c
+++ b/init.c
@@ -907,6 +907,9 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
          case M_MMDF:
            p = "MMDF";
            break;
+         case M_KENDRA:
+           p = "KENDRA";
+           break;
          case M_MH:
            p = "MH";
            break;
diff --git a/mbox.c b/mbox.c
index 8bf1686b84016c4e48016986acab121fdef20174..37aea877fbe4f7f0cd23a861c203355e2be0f0dc 100644 (file)
--- a/mbox.c
+++ b/mbox.c
@@ -19,6 +19,10 @@ static const char rcsid[]="$Id$";
 
 /* This file contains code to parse ``mbox'' and ``mmdf'' style mailboxes */
 
+/* OS/2's "kendra" mail folder format is also supported.  It's a slightly
+ * modified version of MMDF.
+ */
+
 #include "mutt.h"
 #include "mailbox.h"
 #include "mx.h"
@@ -106,12 +110,13 @@ int mmdf_parse_mailbox (CONTEXT *ctx)
   tz = mutt_local_tz ();
 
   buf[sizeof (buf) - 1] = 0;
+  
   FOREVER
   {
     if (fgets (buf, sizeof (buf) - 1, ctx->fp) == NULL)
       break;
 
-    if (strcmp (buf, MMDF_SEP) == 0)
+    if (strcmp (buf, ctx->magic == M_MMDF ? MMDF_SEP : KENDRA_SEP) == 0)
     {
       loc = ftell (ctx->fp);
 
@@ -154,7 +159,7 @@ int mmdf_parse_mailbox (CONTEXT *ctx)
        {
          if (fseek (ctx->fp, tmploc, SEEK_SET) != 0 ||
              fgets (buf, sizeof (buf) - 1, ctx->fp) == NULL ||
-             strcmp (MMDF_SEP, buf) != 0)
+             strcmp (ctx->magic == M_MMDF ? MMDF_SEP : KENDRA_SEP, buf) != 0)
          {
            if (fseek (ctx->fp, loc, SEEK_SET) != 0)
              dprint (1, (debugfile, "mmdf_parse_mailbox: fseek() failed\n"));
@@ -175,7 +180,7 @@ int mmdf_parse_mailbox (CONTEXT *ctx)
          if (fgets (buf, sizeof (buf) - 1, ctx->fp) == NULL)
            break;
          lines++;
-       } while (strcmp (buf, MMDF_SEP) != 0);
+       } while (strcmp (buf, ctx->magic == M_MMDF ? MMDF_SEP : KENDRA_SEP) != 0);
 
        hdr->lines = lines;
        hdr->content->length = loc - hdr->content->offset;
@@ -188,6 +193,8 @@ int mmdf_parse_mailbox (CONTEXT *ctx)
        hdr->env->from = rfc822_cpy_adr (hdr->env->return_path);
 
       mx_update_context (ctx);
+      if(ctx->magic == M_KENDRA && feof(ctx->fp))
+       break;
     }
     else
     {
@@ -402,7 +409,7 @@ int mbox_open_mailbox (CONTEXT *ctx)
 
   if (ctx->magic == M_MBOX)
     rc = mbox_parse_mailbox (ctx);
-  else if (ctx->magic == M_MMDF)
+  else if (ctx->magic == M_MMDF || ctx->magic == M_KENDRA)
     rc = mmdf_parse_mailbox (ctx);
   else
     rc = -1;
@@ -586,7 +593,8 @@ int mbox_check_mailbox (CONTEXT *ctx, int *index_hint)
       if (fgets (buffer, sizeof (buffer), ctx->fp) != NULL)
       {
        if ((ctx->magic == M_MBOX && strncmp ("From ", buffer, 5) == 0) ||
-           (ctx->magic == M_MMDF && strcmp (MMDF_SEP, buffer) == 0))
+           (ctx->magic == M_MMDF && strcmp (MMDF_SEP, buffer) == 0) ||
+           (ctx->magic == M_KENDRA && strcmp(KENDRA_SEP, buffer) == 0))
        {
          if (fseek (ctx->fp, ctx->size, SEEK_SET) != 0)
            dprint (1, (debugfile, "mbox_check_mailbox: fseek() failed\n"));
@@ -650,7 +658,7 @@ int mbox_check_mailbox (CONTEXT *ctx, int *index_hint)
 int mbox_sync_mailbox (CONTEXT *ctx)
 {
   char tempfile[_POSIX_PATH_MAX];
-  char buf[16];
+  char buf[32];
   int i, j, save_sort = SORT_ORDER;
   int need_sort = 0; /* flag to resort mailbox if new mail arrives */
   int first;   /* first message to be written */
@@ -732,15 +740,19 @@ int mbox_sync_mailbox (CONTEXT *ctx)
     goto bail;
   }
 
+    /* save the index of the first changed/deleted message */
+  first = i; 
+  /* where to start overwriting */
+  offset = ctx->hdrs[i]->offset; 
 
-  first = i; /* save the index of the first changed/deleted message */
-  offset = ctx->hdrs[i]->offset; /* where to start overwriting */
   /* 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 -= strlen (MMDF_SEP);
-
+  else if (ctx->magic == M_KENDRA)
+    offset -= strlen(KENDRA_SEP);
+  
   /* allocate space for the new offsets */
   newOffset = safe_calloc (ctx->msgcount - first, sizeof (struct m_update_t));
 
@@ -758,6 +770,11 @@ int mbox_sync_mailbox (CONTEXT *ctx)
        if (fputs (MMDF_SEP, fp) == EOF)
          goto bail;
       }
+      else if (ctx->magic == M_KENDRA)
+      {
+       if (fputs (KENDRA_SEP, fp) == EOF)
+         goto bail;
+      }
 
       /* save the new offset for this message.  we add `offset' because the
        * temporary file only contains saved message which are located after
@@ -777,11 +794,20 @@ int mbox_sync_mailbox (CONTEXT *ctx)
       newOffset[i - first].body = ftell (fp) - ctx->hdrs[i]->content->length + offset;
       mutt_free_body (&ctx->hdrs[i]->content->parts);
 
-      if (fputs (ctx->magic == M_MMDF ? MMDF_SEP : "\n", fp) == EOF)
-       goto bail;
+      switch(ctx->magic)
+      {
+       case M_MMDF: 
+         if(fputs(MMDF_SEP, fp) == EOF) goto bail; 
+         break;
+       case M_KENDRA:
+         if(fputs(KENDRA_SEP, fp) == EOF) goto bail;
+         break;
+       default:
+         if(fputs("\n", fp) == EOF) goto bail;
+      }
     }
   }
-
+  
   if (fclose (fp) != 0)
   {
     fp = NULL;
@@ -811,7 +837,8 @@ int mbox_sync_mailbox (CONTEXT *ctx)
       /* do a sanity check to make sure the mailbox looks ok */
       fgets (buf, sizeof (buf), ctx->fp) == NULL ||
       (ctx->magic == M_MBOX && strncmp ("From ", buf, 5) != 0) ||
-      (ctx->magic == M_MMDF && strcmp (MMDF_SEP, buf) != 0))
+      (ctx->magic == M_MMDF && strcmp (MMDF_SEP, buf) != 0) ||
+      (ctx->magic == M_KENDRA && strcmp (KENDRA_SEP, buf) != 0))
   {
     dprint (1, (debugfile, "mbox_sync_mailbox: message not in expected position."));
     dprint (1, (debugfile, "\tLINE: %s\n", buf));
@@ -1001,6 +1028,7 @@ int mutt_reopen_mailbox (CONTEXT *ctx, int *index_hint)
   {
     case M_MBOX:
     case M_MMDF:
+    case M_KENDRA:
       if (fseek (ctx->fp, 0, SEEK_SET) != 0)
       {
         dprint (1, (debugfile, "mutt_reopen_mailbox: fseek() failed\n"));
diff --git a/mx.c b/mx.c
index b1ed5c019538cbbca041db73a976be9b89bb4bf1..4469812171a20e453757124f0b4a936529b45058 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -392,6 +392,8 @@ int mx_set_magic (const char *s)
     DefaultMagic = M_MH;
   else if (strcasecmp (s, "maildir") == 0)
     DefaultMagic = M_MAILDIR;
+  else if (strcasecmp (s, "kendra") == 0)
+    DefaultMagic = M_KENDRA;
   else
     return (-1);
 
diff --git a/mx.h b/mx.h
index 6501744c284ec917b54c35356bdba5632791ec7f..b97a985f0bc32a448b34225c262be75abcb60d04 100644 (file)
--- a/mx.h
+++ b/mx.h
@@ -27,6 +27,7 @@ enum
 {
   M_MBOX = 1,
   M_MMDF,
+  M_KENDRA,
   M_MH,
   M_MAILDIR
 #ifdef USE_IMAP
@@ -37,6 +38,7 @@ enum
 WHERE short DefaultMagic INITVAL (M_MBOX);
 
 #define MMDF_SEP "\001\001\001\001\n"
+#define KENDRA_SEP "\001\001\001\001\001\001\001\001\001\001\001\001\001\001\001\001\001\001\001\001\n"
 #define MAXLOCKATTEMPT 5
 
 int mbox_sync_mailbox (CONTEXT *);
index 4f7a1dd5aa27e1735686625bf663b5f966c37fda..11170c3ea1310c5905cf48995d4809ed003427a0 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -1911,7 +1911,7 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post,
   /* We need to add a Content-Length field to avoid problems where a line in
    * the message body begins with "From "   
    */
-  if (f.magic == M_MMDF || f.magic == M_MBOX)
+  if (f.magic == M_MMDF || f.magic == M_MBOX || f.magic == M_KENDRA)
   {
     mutt_mktemp (tempfile);
     if ((tempfp = safe_fopen (tempfile, "w+")) == NULL)