From: Thomas Roessler Date: Fri, 28 Apr 2006 19:52:44 +0000 (+0000) Subject: Cleaning up attachment counting. This takes away some of the X-Git-Tag: mutt-1-5-12-rel~95 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8ffb3c72d0468b58d37b70c6b2b92d5409170bd8;p=mutt Cleaning up attachment counting. This takes away some of the worst aberrations, but the feature is still a performance hog. --- diff --git a/hdrline.c b/hdrline.c index a5b97348..10d38409 100644 --- a/hdrline.c +++ b/hdrline.c @@ -657,16 +657,7 @@ hdr_format_str (char *dest, case 'X': { - int count; - - if (hdr->content->parts) - count = mutt_count_body_parts(hdr, 0); - else - { - mutt_parse_mime_message(ctx, hdr); - count = mutt_count_body_parts(hdr, 0); - mutt_free_body(&hdr->content->parts); - } + int count = mutt_count_body_parts (ctx, hdr); /* The recursion allows messages without depth to return 0. */ if (optional) diff --git a/mutt.h b/mutt.h index 105d3687..0523109e 100644 --- a/mutt.h +++ b/mutt.h @@ -921,9 +921,7 @@ typedef struct regex_t minor_rx; } ATTACH_MATCH; -/* Flags for mutt_count_body_parts() */ #define M_PARTS_TOPLEVEL (1<<0) /* is the top-level part */ -#define M_PARTS_RECOUNT (1<<1) /* force recount */ #include "ascii.h" #include "protos.h" diff --git a/parse.c b/parse.c index d87f556b..8676b793 100644 --- a/parse.c +++ b/parse.c @@ -928,7 +928,6 @@ static char *extract_message_id (const char *s) void mutt_parse_mime_message (CONTEXT *ctx, HEADER *cur) { MESSAGE *msg; - int flags = 0; do { if (cur->content->type != TYPEMESSAGE && @@ -949,7 +948,7 @@ void mutt_parse_mime_message (CONTEXT *ctx, HEADER *cur) } } while (0); - mutt_count_body_parts(cur, flags|M_PARTS_RECOUNT); + cur->attach_valid = 0; } int mutt_parse_rfc822_line (ENVELOPE *e, HEADER *hdr, char *line, char *p, short user_hdrs, short weed, @@ -1599,16 +1598,27 @@ int count_body_parts (BODY *body, int flags) return count < 0 ? 0 : count; } -int mutt_count_body_parts (HEADER *hdr, int flags) +int mutt_count_body_parts (CONTEXT *ctx, HEADER *hdr) { - if (hdr->attach_valid && !(flags & M_PARTS_RECOUNT)) - return hdr->attach_total; + short keep_parts = 0; + if (hdr->attach_valid) + return hdr->attach_total; + + if (hdr->content->parts) + keep_parts = 1; + else + mutt_parse_mime_message (ctx, hdr); + if (AttachAllow || AttachExclude || InlineAllow || InlineExclude) - hdr->attach_total = count_body_parts(hdr->content, flags | M_PARTS_TOPLEVEL); + hdr->attach_total = count_body_parts(hdr->content, M_PARTS_TOPLEVEL); else hdr->attach_total = 0; hdr->attach_valid = 1; + + if (!keep_parts) + mutt_free_body (&hdr->content->parts); + return hdr->attach_total; } diff --git a/pattern.c b/pattern.c index ea3a7a9c..6e6d3ff9 100644 --- a/pattern.c +++ b/pattern.c @@ -1132,17 +1132,7 @@ mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags, CONTEXT *ctx, return (pat->not ^ (h->thread && h->thread->duplicate_thread)); case M_MIMEATTACH: { - int count; - - if (h->content->parts) - count = mutt_count_body_parts(h, 0); - else - { - mutt_parse_mime_message(ctx, h); - count = mutt_count_body_parts(h, 0); - mutt_free_body(&h->content->parts); - } - + int count = mutt_count_body_parts (ctx, h); return (pat->not ^ (count >= pat->min && (pat->max == M_MAXRANGE || count <= pat->max))); } diff --git a/protos.h b/protos.h index 12610365..211cb656 100644 --- a/protos.h +++ b/protos.h @@ -168,7 +168,7 @@ void mutt_break_thread (HEADER *); void mutt_buffy (char *, size_t); int mutt_buffy_list (void); void mutt_canonical_charset (char *, size_t, const char *); -int mutt_count_body_parts (HEADER *hdr, int flags); +int mutt_count_body_parts (CONTEXT *, HEADER *); void mutt_check_rescore (CONTEXT *); void mutt_clear_error (void); void mutt_create_alias (ENVELOPE *, ADDRESS *);