[PATCH] fix segfault in maildir new mail detection with hcache enabled
# HG changeset patch
# User Michael Elkins <me@xxxxxxxx>
# Date 1197069362 28800
# Branch HEAD
# Node ID 90aeea22bdf2bf73e2d27c093d208e2af1c82037
# Parent 468b9c86b0df05d30245ed54d76b9437ef73cfe1
Skip over messages which were previously parsed after sorting the tail of the
list. Avoids a segmentation fault when rescanning the new/ subdir of a maildir
when messages were left over from a previous scan.
diff -r 468b9c86b0df -r 90aeea22bdf2 mh.c
--- a/mh.c Fri Dec 07 13:09:32 2007 +0100
+++ b/mh.c Fri Dec 07 15:16:02 2007 -0800
@@ -954,6 +954,25 @@ static void mh_sort_natural (CONTEXT *ct
*md = maildir_sort (*md, (size_t) -1, md_cmp_path);
}
+static struct maildir *skip_duplicates (struct maildir *p, struct maildir
**last)
+{
+ /*
+ * Skip ahead to the next non-duplicate message.
+ *
+ * p should never reach NULL, because we couldn't have reached this point
unless
+ * there was a message that needed to be parsed.
+ *
+ * the check for p->header_parsed is likely unnecessary since the dupes will
most
+ * likely be at the head of the list. but it is present for consistency with
+ * the check at the top of the for() loop in maildir_delayed_parsing().
+ */
+ while (!p->h || p->header_parsed) {
+ *last = p;
+ p = p->next;
+ }
+ return p;
+}
+
/*
* This function does the second parsing pass
*/
@@ -1011,6 +1030,9 @@ void maildir_delayed_parsing (CONTEXT *
else
last->next = p;
sort = 1;
+
+ p = skip_duplicates(p, &last);
+
snprintf (fn, sizeof (fn), "%s/%s", ctx->path, p->h->path);
}
#endif
@@ -1039,6 +1061,9 @@ void maildir_delayed_parsing (CONTEXT *
else
last->next = p;
sort = 1;
+
+ p = skip_duplicates(p, &last);
+
snprintf (fn, sizeof (fn), "%s/%s", ctx->path, p->h->path);
}
#endif
@@ -1058,7 +1083,7 @@ void maildir_delayed_parsing (CONTEXT *
FREE (&data);
#endif
last = p;
- }
+ }
#if USE_HCACHE
mutt_hcache_close (hc);
#endif