]> granicus.if.org Git - mutt/commitdiff
Cleaning up attachment counting. This takes away some of the
authorThomas Roessler <roessler@does-not-exist.org>
Fri, 28 Apr 2006 19:52:44 +0000 (19:52 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Fri, 28 Apr 2006 19:52:44 +0000 (19:52 +0000)
worst aberrations, but the feature is still a performance hog.

hdrline.c
mutt.h
parse.c
pattern.c
protos.h

index a5b973482c8678e9774b4702a43ac3cdaf194c0c..10d3840960ce76121e545a6261e1e7dc2380554b 100644 (file)
--- 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 105d368746f8f3fbc7c828fd0207b936b436416a..0523109e4f66647c5b084b149bd3034437f5abf7 100644 (file)
--- 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 d87f556b61cc3cac4e76747b035aefcc1f6add60..8676b793827a7a6efa0b11f40e1399afcc35cef9 100644 (file)
--- 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;
 }
index ea3a7a9c4f8178df7f8c4297ba7ef3219e0f09e6..6e6d3ff96d455a9e4658b9f1aead6e5718a909c4 100644 (file)
--- 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)));
       }
index 12610365b0dcdffb7a2b10a938316afc042cbcf4..211cb65601b60b62974ddc6e1f877c0231608b45 100644 (file)
--- 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 *);