]> granicus.if.org Git - mutt/commitdiff
Add caching for a message's flags.
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 29 Sep 1998 06:58:08 +0000 (06:58 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 29 Sep 1998 06:58:08 +0000 (06:58 +0000)
hdrline.c
init.c
mutt.h

index dba84304a639596038e6d83e549efaf402db0203..ad17877f5e430af55c76844e6a1bd252683df6e9 100644 (file)
--- a/hdrline.c
+++ b/hdrline.c
@@ -145,7 +145,7 @@ static void make_from_addr (ENVELOPE *hdr, char *buf, size_t len, int do_lists)
     *buf = 0;
 }
 
-int mutt_user_is_recipient (ADDRESS *a)
+static int user_in_addr (ADDRESS *a)
 {
   for (; a; a = a->next)
     if (mutt_addr_is_user (a))
@@ -160,23 +160,32 @@ int mutt_user_is_recipient (ADDRESS *a)
  * 3: user is in the CC list
  * 4: user is originator
  */
-static int user_is_recipient (ENVELOPE *hdr)
+static int user_is_recipient (HEADER *h)
 {
-  if (mutt_addr_is_user (hdr->from))
-    return 4;
+  ENVELOPE *hdr = h->env;
 
-  if (mutt_user_is_recipient (hdr->to))
+  if(!h->recip_valid)
   {
-    if (hdr->to->next || hdr->cc)
-      return 2; /* non-unique recipient */
-    else
-      return 1; /* unique recipient */
-  }
-
-  if (mutt_user_is_recipient (hdr->cc))
-    return 3;
+    h->recip_valid = 1;
+    
+    if (mutt_addr_is_user (hdr->from))
+      h->recipient = 4;
 
-  return (0);
+    if (user_in_addr (hdr->to))
+    {
+      if (hdr->to->next || hdr->cc)
+       h->recipient = 2; /* non-unique recipient */
+      else
+       h->recipient = 1; /* unique recipient */
+    }
+    
+    if (user_in_addr (hdr->cc))
+      h->recipient = 3;
+    
+    h->recipient = 0;
+  }
+  
+  return h->recipient;
 }
 
 /* %a = address of author
@@ -526,7 +535,7 @@ hdr_format_str (char *dest,
     case 'T':
       snprintf (fmt, sizeof (fmt), "%%%sc", prefix);
       snprintf (dest, destlen, fmt,
-               (Tochars && ((i = user_is_recipient (hdr->env))) < strlen (Tochars)) ? Tochars[i] : ' ');
+               (Tochars && ((i = user_is_recipient (hdr))) < strlen (Tochars)) ? Tochars[i] : ' ');
       break;
 
     case 'u':
@@ -569,7 +578,7 @@ hdr_format_str (char *dest,
                hdr->deleted ? 'D' : (hdr->attach_del ? 'd' : ch),
                hdr->tagged ? '*' :
                (hdr->flagged ? '!' :
-                (Tochars && ((i = user_is_recipient (hdr->env)) < strlen (Tochars)) ? Tochars[user_is_recipient (hdr->env)] : ' ')));
+                (Tochars && ((i = user_is_recipient (hdr)) < strlen (Tochars)) ? Tochars[i] : ' ')));
       snprintf (dest, destlen, fmt, buf2);
       break;
 
diff --git a/init.c b/init.c
index b18f2fc4726d106907db61a02ab64118027b6571..94f9ec4c3f214291cb512e5123f5a46e00ce1a3f 100644 (file)
--- a/init.c
+++ b/init.c
@@ -806,6 +806,14 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
        break;
       }
 
+      if (option(OPTATTACHMSG) && (!strcmp(MuttVars[idx].option, "alternates")
+                                  || !strcmp(MuttVars[idx].option, "reply_regexp")))
+      {
+       snprintf (err->data, err->dsize, "Operation not permitted when in attach-message mode.");
+       r = -1;
+       break;
+      }
+      
       s->dptr++;
 
       /* copy the value of the string */
@@ -853,7 +861,8 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
        ptr->rx = rx;
        ptr->not = not;
 
-       /* $reply_regexp requires special treatment */
+       /* $reply_regexp and $alterantes require special treatment */
+       
        if (Context && Context->msgcount &&
            strcmp (MuttVars[idx].option, "reply_regexp") == 0)
        {
@@ -873,6 +882,15 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
          }
 #undef CUR_ENV
        }
+       
+       if(Context && Context->msgcount &&
+          strcmp(MuttVars[idx].option, "alternates") == 0)
+       {
+         int i;
+         
+         for(i = 0; i < Context->msgcount; i++)
+           Context->hdrs[i]->recip_valid = 0;
+       }
       }
     }
     else if (DTYPE(MuttVars[idx].type) == DT_MAGIC)
diff --git a/mutt.h b/mutt.h
index 8986bce8bf46f4520170d0cbf4588f0bf34e86c7..0a88c226cd0527a202682514aae8cfc914e72f00 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -497,8 +497,8 @@ typedef struct header
   unsigned int display_subject : 1; /* used for threading */
   unsigned int fake_thread : 1;     /* no ref matched, but subject did */
   unsigned int threaded : 1;        /* message has been threaded */
-
-  unsigned int active : 1;
+  unsigned int recip_valid : 1;  /* is_recipient is valid */
+  unsigned int active : 1;         /* message is not to be removed */
   
   /* timezone of the sender of this message */
   unsigned int zhours : 5;
@@ -514,6 +514,8 @@ typedef struct header
   unsigned int limited : 1;   /* is this message in a limited view?  */
   size_t num_hidden;          /* number of hidden messages in this view */
 
+  short recipient;     /* user_is_recipient()'s return value, cached */
+  
   int pair; /* color-pair to use when displaying in the index */
 
   time_t date_sent;     /* time when the message was sent (UTC) */