<<< Date Index >>>     <<< Thread Index >>>

[PATCH] bug#463: mailbox sort order for MH folders is not MH sort order



--- mh.c~       2004-04-25 14:59:19.000000000 -0400
+++ mh.c        2004-04-25 14:59:23.000000000 -0400
@@ -663,6 +663,24 @@
     else
       h->path = safe_strdup (fname);
 
+    /* In MH folders, mailbox order is defined by the numerical value
+     * of the filename. -pkv */
+    h->index = -1;
+    if (ctx->magic == M_MH)
+    {
+      const char *p;
+
+      p = fname;
+      if (*(p = fname))
+      {
+        while ((*p) && isdigit(*p)) p++;
+        if ((*p) == 0) /* all digits */
+        {
+          h->index = atoi(fname);
+        }
+      }
+    }
+
     entry = safe_calloc (sizeof (struct maildir), 1);
     entry->h = h;
     entry->header_parsed = (ctx->magic == M_MH);
@@ -752,7 +770,16 @@
        mx_alloc_memory (ctx);
 
       ctx->hdrs[ctx->msgcount] = md->h;
-      ctx->hdrs[ctx->msgcount]->index = ctx->msgcount;
+      if (ctx->hdrs[ctx->msgcount]->index == -1)
+      {
+        /* assign unique indices to messages for
+           which one was not already available */
+        /* make them negative and these will sort
+           before every message whose index actually
+           was discernable */
+        /* -pkv */
+        ctx->hdrs[ctx->msgcount]->index = INT_MIN + ctx->msgcount;
+      }
       ctx->size +=
        md->h->content->length + md->h->content->offset -
        md->h->content->hdr_offset;
--- PATCHES~    2004-04-25 14:59:19.000000000 -0400
+++ PATCHES     2004-04-25 14:59:23.000000000 -0400
@@ -1,0 +1 @@
+patch-1.5.5.1.pkv.bug463_mhorder.1