]> granicus.if.org Git - mutt/commitdiff
Apply message-hook to more commands, and make it more useful by
authorThomas Roessler <roessler@does-not-exist.org>
Wed, 21 Jun 2000 06:17:00 +0000 (06:17 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Wed, 21 Jun 2000 06:17:00 +0000 (06:17 +0000)
permitting the "~h" and "~b" pattern specifiers.  Bad enough, this
removes message-hook abilities from the receive-attachment menu.

commands.c
hook.c
protos.h
recvattach.c
recvcmd.c
send.c

index 70dfd4c083f301d45274cc4ea07c3293df65eb07..fac63e04510cefbc414e6de64dc2d23adfa9d12f 100644 (file)
@@ -73,7 +73,7 @@ int mutt_display_message (HEADER *cur)
            cur->content->subtype);
 
   mutt_parse_mime_message (Context, cur);
-
+  mutt_message_hook (Context, cur, M_MESSAGEHOOK);
 
 #ifdef HAVE_PGP
   /* see if PGP is needed for this message.  if so, we should exit curses */
@@ -113,8 +113,6 @@ int mutt_display_message (HEADER *cur)
     return (0);
   }
 
-  mutt_message_hook (cur, M_MESSAGEHOOK);
-
   if (DisplayFilter && *DisplayFilter) 
   {
     fpfilterout = fpout;
@@ -305,7 +303,7 @@ int mutt_pipe_message (HEADER *h)
   if (h)
   {
 
-
+    mutt_message_hook (Context, h, M_MESSAGEHOOK);
 
 #ifdef HAVE_PGP
     if (option (OPTPIPEDECODE))
@@ -336,6 +334,7 @@ int mutt_pipe_message (HEADER *h)
       for (i = 0; i < Context->vcount; i++)
        if(Context->hdrs[Context->v2r[i]]->tagged)
        {
+         mutt_message_hook (Context, Context->hdrs[Context->v2r[i]], M_MESSAGEHOOK);
          mutt_parse_mime_message(Context, Context->hdrs[Context->v2r[i]]);
          if (Context->hdrs[Context->v2r[i]]->pgp & PGPENCRYPT &&
              !pgp_valid_passphrase())
@@ -352,6 +351,7 @@ int mutt_pipe_message (HEADER *h)
       {
         if (Context->hdrs[Context->v2r[i]]->tagged)
         {
+         mutt_message_hook (Context, Context->hdrs[Context->v2r[i]], M_MESSAGEHOOK);
          endwin ();
          thepid = mutt_create_filter (buffer, &(s.fpout), NULL, NULL);
           mutt_pipe_message_to_state (Context->hdrs[Context->v2r[i]], &s);
@@ -372,6 +372,7 @@ int mutt_pipe_message (HEADER *h)
       {
         if (Context->hdrs[Context->v2r[i]]->tagged)
         {
+         mutt_message_hook (Context, Context->hdrs[Context->v2r[i]], M_MESSAGEHOOK);
           mutt_pipe_message_to_state (Context->hdrs[Context->v2r[i]], &s);
           /* add the message separator */
           if (PipeSep)
@@ -582,6 +583,7 @@ int mutt_save_message (HEADER *h, int delete,
 
   *redraw = 0;
 
+  
   snprintf (prompt, sizeof (prompt), _("%s%s to mailbox"),
            decode ? (delete ? _("Decode-save") : _("Decode-copy")) :
            (decrypt ? (delete ? _("Decrypt-save") : _("Decrypt-copy")):
@@ -592,6 +594,7 @@ int mutt_save_message (HEADER *h, int delete,
 #ifdef HAVE_PGP
     need_passphrase = h->pgp & PGPENCRYPT;
 #endif
+    mutt_message_hook (Context, h, M_MESSAGEHOOK);
     mutt_default_save (buf, sizeof (buf), h);
   }
   else
@@ -609,6 +612,7 @@ int mutt_save_message (HEADER *h, int delete,
 
     if (h)
     {
+      mutt_message_hook (Context, h, M_MESSAGEHOOK);
       mutt_default_save (buf, sizeof (buf), h);
 #ifdef HAVE_PGP
       need_passphrase |= h->pgp & PGPENCRYPT;
@@ -681,8 +685,11 @@ int mutt_save_message (HEADER *h, int delete,
       for (i = 0; i < Context->vcount; i++)
       {
        if (Context->hdrs[Context->v2r[i]]->tagged)
+       {
+         mutt_message_hook (Context, Context->hdrs[Context->v2r[i]], M_MESSAGEHOOK);
          _mutt_save_message(Context->hdrs[Context->v2r[i]],
                             &ctx, delete, decode, decrypt);
+       }
       }
     }
 
@@ -746,6 +753,7 @@ void mutt_print_message (HEADER *h)
   pid_t thepid;
   FILE *fp;
 
+  
   if (query_quadoption (OPT_PRINT,
                        h ? _("Print message?") : _("Print tagged messages?"))
                        != M_YES)
@@ -755,6 +763,7 @@ void mutt_print_message (HEADER *h)
     return;
   if (h)
   {
+    mutt_message_hook (Context, h, M_MESSAGEHOOK);
     print_msg (fp, Context, h);
     count++;
   }
@@ -764,6 +773,7 @@ void mutt_print_message (HEADER *h)
     {
       if (Context->hdrs[Context->v2r[i]]->tagged)
       {
+       mutt_message_hook (Context, Context->hdrs[Context->v2r[i]], M_MESSAGEHOOK);
        print_msg (fp, Context, Context->hdrs[Context->v2r[i]]);
        /* add a formfeed */
        fputc ('\f', fp);
diff --git a/hook.c b/hook.c
index 5972fcf11da40cdd1ca3a08be68dd73a5eeafcb7..d6e454295a6a608ee07e1b2ec6ce5a2db5fef8a7 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -147,7 +147,7 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
   if (data & (M_SENDHOOK | M_SAVEHOOK | M_FCCHOOK | M_MESSAGEHOOK))
   {
     if ((pat = mutt_pattern_comp (pattern.data,
-          (data & (M_SENDHOOK | M_FCCHOOK | M_MESSAGEHOOK)) ? 0 : M_FULL_MSG,
+          (data & (M_SENDHOOK | M_FCCHOOK)) ? 0 : M_FULL_MSG,
                                  err)) == NULL)
       goto error;
   }
@@ -294,7 +294,7 @@ char *mutt_find_hook (int type, const char *pat)
   return (NULL);
 }
 
-void mutt_message_hook (HEADER *hdr, int type)
+void mutt_message_hook (CONTEXT *ctx, HEADER *hdr, int type)
 {
   BUFFER err, token;
   HOOK *hook;
@@ -309,7 +309,7 @@ void mutt_message_hook (HEADER *hdr, int type)
       continue;
 
     if (hook->type & type)
-      if ((mutt_pattern_exec (hook->pattern, 0, NULL, hdr) > 0) ^ hook->rx.not)
+      if ((mutt_pattern_exec (hook->pattern, 0, ctx, hdr) > 0) ^ hook->rx.not)
        if (mutt_parse_rc_line (hook->command, &token, &err) != 0)
        {
          FREE (&token.data);
index b2683deae126cbf97163f5025eaeeeab6dade7db..1ae0e230251c06b131019ba194512b5ba6da16e8 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -197,7 +197,7 @@ void mutt_score_message (CONTEXT *, HEADER *, int);
 void mutt_select_fcc (char *, size_t, HEADER *);
 #define mutt_select_file(A,B,C) _mutt_select_file(A,B,C,0,NULL,NULL)
 void _mutt_select_file (char *, size_t, int, int, char ***, int *);
-void mutt_message_hook (HEADER *, int);
+void mutt_message_hook (CONTEXT *, HEADER *, int);
 void _mutt_set_flag (CONTEXT *, HEADER *, int, int, int);
 #define mutt_set_flag(a,b,c,d) _mutt_set_flag(a,b,c,d,1)
 void mutt_set_followup_to (ENVELOPE *);
index 11f370f5c1dd3f5549b06e0cfbb4ba359345f12f..30a3b1a1d1fe757c07da6a69eb056ddd14ff1279 100644 (file)
@@ -795,6 +795,8 @@ void mutt_view_attachments (HEADER *hdr)
   /* make sure we have parsed this message */
   mutt_parse_mime_message (Context, hdr);
 
+  mutt_message_hook (Context, hdr, M_MESSAGEHOOK);
+  
   if ((msg = mx_open_message (Context, hdr->msgno)) == NULL)
     return;
 
index 59def2d02e1222aeb41d06c8e3f621b60b0ded5c..52f0e03e04de65ef1c3da11ba9948ae78daf457e 100644 (file)
--- a/recvcmd.c
+++ b/recvcmd.c
@@ -566,7 +566,7 @@ static void attach_forward_msgs (FILE * fp, HEADER * hdr,
     
     if (cur)
     {
-      mutt_message_hook (cur->hdr, M_MESSAGEHOOK);
+      /* mutt_message_hook (cur->hdr, M_MESSAGEHOOK); */ 
       mutt_forward_intro (tmpfp, cur->hdr);
       _mutt_copy_message (tmpfp, fp, cur->hdr, cur->hdr->content, cmflags, chflags);
       mutt_forward_trailer (tmpfp);
@@ -577,7 +577,7 @@ static void attach_forward_msgs (FILE * fp, HEADER * hdr,
       {
        if (idx[i]->content->tagged)
        {
-         mutt_message_hook (idx[i]->content->hdr, M_MESSAGEHOOK);
+         /* mutt_message_hook (idx[i]->content->hdr, M_MESSAGEHOOK); */ 
          mutt_forward_intro (tmpfp, idx[i]->content->hdr);
          _mutt_copy_message (tmpfp, fp, idx[i]->content->hdr,
                              idx[i]->content->hdr->content, cmflags, chflags);
@@ -733,7 +733,7 @@ static void attach_include_reply (FILE *fp, FILE *tmpfp, HEADER *cur, int flags)
   int cmflags = M_CM_PREFIX | M_CM_DECODE | M_CM_CHARCONV;
   int chflags = CH_DECODE;
 
-  mutt_message_hook (cur, M_MESSAGEHOOK);
+  /* mutt_message_hook (cur, M_MESSAGEHOOK); */ 
   
   mutt_make_attribution (Context, cur, tmpfp);
   
diff --git a/send.c b/send.c
index 326928fc7587eaffe330fd5b01c8746216ebb4fd..47666c824a9999b7ba8eb8bbbb2820067a137b96 100644 (file)
--- a/send.c
+++ b/send.c
@@ -337,7 +337,8 @@ static int include_forward (CONTEXT *ctx, HEADER *cur, FILE *out)
 {
   int chflags = CH_DECODE, cmflags = 0;
   
-  mutt_message_hook (cur, M_MESSAGEHOOK);
+  mutt_parse_mime_message (ctx, cur);
+  mutt_message_hook (ctx, cur, M_MESSAGEHOOK);
 
 #ifdef HAVE_PGP
   if ((cur->pgp & PGPENCRYPT) && option (OPTFORWDECODE))
@@ -360,7 +361,7 @@ static int include_forward (CONTEXT *ctx, HEADER *cur, FILE *out)
   }
   if (option (OPTFORWQUOTE))
     cmflags |= M_CM_PREFIX;
-  mutt_parse_mime_message (ctx, cur);
+
   mutt_copy_message (out, ctx, cur, cmflags, chflags);
   mutt_forward_trailer (out);
   return 0;
@@ -404,7 +405,8 @@ static int include_reply (CONTEXT *ctx, HEADER *cur, FILE *out)
   }
 #endif /* HAVE_PGP */
 
-  mutt_message_hook (cur, M_MESSAGEHOOK);
+  mutt_parse_mime_message (ctx, cur);
+  mutt_message_hook (ctx, cur, M_MESSAGEHOOK);
   
   mutt_make_attribution (ctx, cur, out);
   
@@ -416,9 +418,8 @@ static int include_reply (CONTEXT *ctx, HEADER *cur, FILE *out)
     cmflags |= M_CM_WEED;
   }
 
-  mutt_parse_mime_message (ctx, cur);
   mutt_copy_message (out, ctx, cur, cmflags, chflags);
-  
+
   mutt_make_post_indent (ctx, cur, out);
   
   return 0;
@@ -1152,7 +1153,7 @@ ci_send_message (int flags,               /* send mode */
 
     /* change settings based upon recipients */
     
-    mutt_message_hook (msg, M_SENDHOOK);
+    mutt_message_hook (NULL, msg, M_SENDHOOK);
 
     if (killfrom)
     {
@@ -1165,6 +1166,20 @@ ci_send_message (int flags,              /* send mode */
 
 
 
+
+    /* include replies/forwarded messages, unless we are given a template */
+    if (!tempfile && (ctx || !(flags & (SENDREPLY|SENDFORWARD)))
+       && generate_body (tempfp, msg, flags, ctx, cur) == -1)
+      goto cleanup;
+
+    if (! (flags & (SENDMAILX | SENDKEY)) && Editor && mutt_strcmp (Editor, "builtin") != 0)
+      append_signature (tempfp);
+
+    /* 
+     * this wants to be done _after_ generate_body, so message-hooks
+     * can take effect.
+     */
+
 #ifdef HAVE_PGP
     if (! (flags & SENDMAILX))
     {
@@ -1183,13 +1198,6 @@ ci_send_message (int flags,              /* send mode */
 
 
 
-    /* include replies/forwarded messages, unless we are given a template */
-    if (!tempfile && (ctx || !(flags & (SENDREPLY|SENDFORWARD)))
-       && generate_body (tempfp, msg, flags, ctx, cur) == -1)
-      goto cleanup;
-
-    if (! (flags & (SENDMAILX | SENDKEY)) && Editor && mutt_strcmp (Editor, "builtin") != 0)
-      append_signature (tempfp);
   }
   /* wait until now to set the real name portion of our return address so
      that $realname can be set in a send-hook */