]> granicus.if.org Git - mutt/commitdiff
somewhat cleaner in-band-signalling between the handlers and the
authorThomas Roessler <roessler@does-not-exist.org>
Thu, 8 Nov 2001 10:55:55 +0000 (10:55 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Thu, 8 Nov 2001 10:55:55 +0000 (10:55 +0000)
pager.  In particular, it's more difficult now to get fake PGP and
other mutt-generated "[-- " messages colored.

globals.h
handler.c
init.c
mutt.h
muttlib.c
pager.c
pgp.c

index a9f080810a21d1fab592f6f636754933f3b98a8b..f50da8b249108e399138dc12ee5c716381e459ad 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -22,6 +22,7 @@ WHERE void (*mutt_message) (const char *, ...);
 WHERE CONTEXT *Context;
 
 WHERE char Errorbuf[STRING];
+WHERE char AttachmentMarker[STRING];
 
 #if defined(DL_STANDALONE) && defined(USE_DOTLOCK)
 WHERE char *MuttDotlock;
index be9e23f6782a8af779d5ea24ddd21c76e1f4c3f3..a27a2d20d95936329c25c183d5cae2949ead246b 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -1316,6 +1316,7 @@ static void alternative_handler (BODY *a, STATE *s)
   else if (s->flags & M_DISPLAY)
   {
     /* didn't find anything that we could display! */
+    state_mark_attach (s);
     state_puts(_("[-- Error:  Could not display any parts of Multipart/Alternative! --]\n"), s);
   }
 }
@@ -1433,6 +1434,7 @@ void multipart_handler (BODY *a, STATE *s)
   {
     if (s->flags & M_DISPLAY)
     {
+      state_mark_attach (s);
       state_printf (s, _("[-- Attachment #%d"), count);
       if (p->description || p->filename || p->form_name)
       {
@@ -1444,6 +1446,7 @@ void multipart_handler (BODY *a, STATE *s)
 
       mutt_pretty_size (length, sizeof (length), p->length);
       
+      state_mark_attach (s);
       state_printf (s, _("[-- Type: %s/%s, Encoding: %s, Size: %s --]\n"),
                    TYPE (p), p->subtype, ENCODING (p->encoding), length);
       if (!option (OPTWEED))
@@ -1503,6 +1506,7 @@ void autoview_handler (BODY *a, STATE *s)
 
     if (s->flags & M_DISPLAY)
     {
+      state_mark_attach (s);
       state_printf (s, _("[-- Autoview using %s --]\n"), command);
       mutt_message(_("Invoking autoview command: %s"),command);
     }
@@ -1534,7 +1538,10 @@ void autoview_handler (BODY *a, STATE *s)
     {
       mutt_perror _("Can't create filter");
       if (s->flags & M_DISPLAY)
+      {
+       state_mark_attach (s);
        state_printf (s, _("[-- Can't run %s. --]\n"), command);
+      }
       goto bail;
     }
     
@@ -1548,8 +1555,11 @@ void autoview_handler (BODY *a, STATE *s)
       /* check for data on stderr */
       if (fgets (buffer, sizeof(buffer), fperr)) 
       {
-       if (s->flags & M_DISPLAY) 
+       if (s->flags & M_DISPLAY)
+       {
+         state_mark_attach (s);
          state_printf (s, _("[-- Autoview stderr of %s --]\n"), command);
+       }
 
        state_puts (s->prefix, s);
        state_puts (buffer, s);
@@ -1567,8 +1577,11 @@ void autoview_handler (BODY *a, STATE *s)
       if (fgets (buffer, sizeof(buffer), fperr))
       {
        if (s->flags & M_DISPLAY)
+       {
+         state_mark_attach (s);
          state_printf (s, _("[-- Autoview stderr of %s --]\n"), 
                        command);
+       }
        
        state_puts (buffer, s);
        mutt_copy_stream (fperr, s->fpout);
@@ -1601,7 +1614,10 @@ static void external_body_handler (BODY *b, STATE *s)
   if (!access_type)
   {
     if (s->flags & M_DISPLAY)
+    {
+      state_mark_attach (s);
       state_puts (_("[-- Error: message/external-body has no access-type parameter --]\n"), s);
+    }
     return;
   }
 
@@ -1617,7 +1633,8 @@ static void external_body_handler (BODY *b, STATE *s)
     {
       char *length;
       char pretty_size[10];
-
+      
+      state_mark_attach (s);
       state_printf (s, _("[-- This %s/%s attachment "),
               TYPE(b->parts), b->parts->subtype);
       length = mutt_get_parameter ("length", b->parameter);
@@ -1630,9 +1647,15 @@ static void external_body_handler (BODY *b, STATE *s)
       state_puts (_("has been deleted --]\n"), s);
 
       if (expire != -1)
+      {
+       state_mark_attach (s);
        state_printf (s, _("[-- on %s --]\n"), expiration);
+      }
       if (b->parts->filename)
+      {
+       state_mark_attach (s);
        state_printf (s, _("[-- name: %s --]\n"), b->parts->filename);
+      }
 
       mutt_copy_hdr (s->fpin, s->fpout, ftell (s->fpin), b->parts->offset,
                     (option (OPTWEED) ? (CH_WEED | CH_REORDER) : 0) |
@@ -1643,10 +1666,12 @@ static void external_body_handler (BODY *b, STATE *s)
   {
     if (s->flags & M_DISPLAY)
     {
-      state_printf (s, _("[-- This %s/%s attachment is not included, --]\n"
-                        "[-- and the indicated external source has --]\n"
-                        "[-- expired. --]\n"),
+      state_mark_attach (s);
+      state_printf (s, _("[-- This %s/%s attachment is not included, --]\n"),
                    TYPE(b->parts), b->parts->subtype);
+      state_attach_puts (_("[-- and the indicated external source has --]\n"), s);
+      state_attach_puts (_("[-- expired. --]\n"), s);
+
       mutt_copy_hdr(s->fpin, s->fpout, ftell (s->fpin), b->parts->offset,
                    (option (OPTWEED) ? (CH_WEED | CH_REORDER) : 0) |
                    CH_DECODE, NULL);
@@ -1656,10 +1681,14 @@ static void external_body_handler (BODY *b, STATE *s)
   {
     if (s->flags & M_DISPLAY)
     {
+      state_mark_attach (s);
       state_printf (s,
-              _("[-- This %s/%s attachment is not included, --]\n"
-                "[-- and the indicated access-type %s is unsupported --]\n"),
-              TYPE(b->parts), b->parts->subtype, access_type);
+                   _("[-- This %s/%s attachment is not included, --]\n"),
+                   TYPE (b->parts), b->parts->subtype);
+      state_mark_attach (s);
+      state_printf (s, 
+                   _("[-- and the indicated access-type %s is unsupported --]\n"),
+                   access_type);
       mutt_copy_hdr (s->fpin, s->fpout, ftell (s->fpin), b->parts->offset,
                     (option (OPTWEED) ? (CH_WEED | CH_REORDER) : 0) |
                     CH_DECODE , NULL);
@@ -1894,6 +1923,7 @@ void mutt_body_handler (BODY *b, STATE *s)
   }
   else if (s->flags & M_DISPLAY)
   {
+    state_mark_attach (s);
     state_printf (s, _("[-- %s/%s is unsupported "), TYPE (b), b->subtype);
     if (!option (OPTVIEWATTACH))
     {
diff --git a/init.c b/init.c
index 752e09e92b68a1e9b874a3449b64f563bed15540..efc5279029855a7dba6b3161e7bbbac122f300d2 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1699,6 +1699,12 @@ void mutt_init (int skip_sys_rc, LIST *commands)
   err.data = error;
   err.dsize = sizeof (error);
 
+  /* 
+   * XXX - use something even more difficult to predict?
+   */
+  snprintf (AttachmentMarker, sizeof (AttachmentMarker),
+           "\033]9;%ld\a", (long) time (NULL));
+  
   /* on one of the systems I use, getcwd() does not return the same prefix
      as is listed in the passwd file */
   if ((p = getenv ("HOME")))
diff --git a/mutt.h b/mutt.h
index f90ade9619b4959913873cc741b25b8b284fba44..7f68bf11828dd457dc6e08a9445cfb2ab8621259 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -799,7 +799,9 @@ typedef struct
 #define state_puts(x,y) fputs(x,(y)->fpout)
 #define state_putc(x,y) fputc(x,(y)->fpout)
 
-void state_prefix_putc(char, STATE *);
+void state_mark_attach (STATE *);
+void state_attach_puts (const char *, STATE *);
+void state_prefix_putc (char, STATE *);
 int  state_printf(STATE *, const char *, ...);
 
 #include "ascii.h"
index a5cc61d78556d58a33ed75428cda3fe2904fb5b6..0cb386563d28ab770eb0cdceef33cdc5aa44d1a5 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -1215,6 +1215,18 @@ int state_printf(STATE *s, const char *fmt, ...)
   return rv;
 }
 
+void state_mark_attach (STATE *s)
+{
+  if ((s->flags & M_DISPLAY) && !mutt_strcmp (Pager, "builtin"))
+    state_puts (AttachmentMarker, s);
+}
+
+void state_attach_puts (const char *t, STATE *s)
+{
+  state_mark_attach (s);
+  state_puts (t, s);
+}
+
 void mutt_display_sanitize (char *s)
 {
   for (; *s; s++)
diff --git a/pager.c b/pager.c
index 393006cc6cea16a0cf138708f699ef8250290871..643d46bf80f8829d60522d5982a95a9a90fe364a 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -698,6 +698,8 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr,
   return class;
 }
 
+static int check_attachment_marker (char *);
+
 static void
 resolve_types (char *buf, char *raw, struct line_t *lineInfo, int n, int last,
                struct q_class_t **QuoteList, int *q_level, int *force_redraw,
@@ -734,8 +736,13 @@ resolve_types (char *buf, char *raw, struct line_t *lineInfo, int n, int last,
   }
   else if (mutt_strncmp ("\033[0m", raw, 4) == 0)      /* a little hack... */
     lineInfo[n].type = MT_COLOR_NORMAL;
+#if 0
   else if (mutt_strncmp ("[-- ", buf, 4) == 0)
     lineInfo[n].type = MT_COLOR_ATTACHMENT;
+#else
+  else if (check_attachment_marker ((char *) raw) == 0)
+    lineInfo[n].type = MT_COLOR_ATTACHMENT;
+#endif
   else if (mutt_strcmp ("-- \n", buf) == 0 || mutt_strcmp ("-- \r\n", buf) == 0)
   {
     i = n + 1;
@@ -859,11 +866,19 @@ resolve_types (char *buf, char *raw, struct line_t *lineInfo, int n, int last,
 
 static int is_ansi (unsigned char *buf)
 {
-  while (buf && (isdigit(*buf) || *buf == ';'))
+  while (*buf && (isdigit(*buf) || *buf == ';'))
     buf++;
   return (*buf == 'm');
 }
 
+static int check_attachment_marker (char *p)
+{
+  char *q = AttachmentMarker;
+  
+  for (;*p == *q && *q && *p && *q != '\a' && *p != '\a'; p++, q++)
+    ;
+  return (int) (*p - *q);
+}
 
 static int grok_ansi(unsigned char *buf, int pos, ansi_attr *a)
 {
@@ -986,9 +1001,17 @@ fill_buffer (FILE *f, long *last_pos, long offset, unsigned char *buf,
        else                    /* ^H */
          *fmt++ = *p++;
       }
-      else if (*p == '\033' && *(p+1) == '[' && is_ansi (p + 2))       /* skip ANSI sequence */
-       while (*p++ != 'm')
+      else if (*p == '\033' && *(p+1) == '[' && is_ansi (p + 2))
+      {
+       while (*p++ != 'm')     /* skip ANSI sequence */
+         ;
+      }
+      else if (*p == '\033' && *(p+1) == ']' && check_attachment_marker ((char *) p) == 0)
+      {
+       dprint (2, (debugfile, "fill_buffer: Seen attachment marker.\n"));
+       while (*p++ != '\a')    /* skip pseudo-ANSI sequence */
          ;
+      }
       else
        *fmt++ = *p++;
     }
@@ -1017,7 +1040,14 @@ static int format_line (struct line_t **lineInfo, int n, unsigned char *buf,
     while (cnt-ch >= 2 && buf[ch] == '\033' && buf[ch+1] == '[' &&
           is_ansi (buf+ch+2))
       ch = grok_ansi (buf, ch+2, pa) + 1;
-    
+
+    while (cnt-ch >= 2 && buf[ch] == '\033' && buf[ch+1] == ']' &&
+          check_attachment_marker ((char *) buf+ch) == 0)
+    {
+      while (buf[ch++] != '\a')
+       ;
+    }
+
     k = mbrtowc (&wc, (char *)buf+ch, cnt-ch, &mbstate);
     if (k == -2 || k == -1)
     {
diff --git a/pgp.c b/pgp.c
index 265fa30e0465d137e60f61c883d04651f7ca788e..ff421f1aee497e09fe0c5c3b7e56a328b8a85fc9 100644 (file)
--- a/pgp.c
+++ b/pgp.c
@@ -142,7 +142,7 @@ static void pgp_current_time (STATE *s)
            _("[-- PGP output follows (current time: %c) --]\n"),
            localtime (&t));
   setlocale (LC_TIME, "C");
-  state_puts (p, s);
+  state_attach_puts (p, s);
 }
 
 
@@ -363,7 +363,7 @@ void pgp_application_pgp_handler (BODY *m, STATE *s)
          pgpin = NULL;
          pgperr = NULL;
          
-         state_puts (_("[-- Error: unable to create PGP subprocess! --]\n"), s);
+         state_attach_puts (_("[-- Error: unable to create PGP subprocess! --]\n"), s);
        }
        else
        {
@@ -397,18 +397,18 @@ void pgp_application_pgp_handler (BODY *m, STATE *s)
          safe_fclose (&pgperr);
          
          if (s->flags & M_DISPLAY)
-           state_puts (_("\n[-- End of PGP output --]\n\n"), s);
+           state_attach_puts (_("\n[-- End of PGP output --]\n\n"), s);
        }
       }
     
       if(s->flags & M_DISPLAY)
       {
        if (needpass)
-         state_puts (_("[-- BEGIN PGP MESSAGE --]\n\n"), s);
+         state_attach_puts (_("[-- BEGIN PGP MESSAGE --]\n\n"), s);
        else if (pgp_keyblock)
-         state_puts (_("[-- BEGIN PGP PUBLIC KEY BLOCK --]\n"), s);
+         state_attach_puts (_("[-- BEGIN PGP PUBLIC KEY BLOCK --]\n"), s);
        else
-         state_puts (_("[-- BEGIN PGP SIGNED MESSAGE --]\n\n"), s);
+         state_attach_puts (_("[-- BEGIN PGP SIGNED MESSAGE --]\n\n"), s);
       }
 
       /* Use PGP's output if there was no clearsig signature. */
@@ -449,11 +449,11 @@ void pgp_application_pgp_handler (BODY *m, STATE *s)
       if (s->flags & M_DISPLAY)
       {
        if (needpass)
-         state_puts (_("\n[-- END PGP MESSAGE --]\n"), s);
+         state_attach_puts (_("\n[-- END PGP MESSAGE --]\n"), s);
        else if (pgp_keyblock)
-         state_puts (_("[-- END PGP PUBLIC KEY BLOCK --]\n"), s);
+         state_attach_puts (_("[-- END PGP PUBLIC KEY BLOCK --]\n"), s);
        else
-         state_puts (_("\n[-- END PGP SIGNED MESSAGE --]\n"), s);
+         state_attach_puts (_("\n[-- END PGP SIGNED MESSAGE --]\n"), s);
       }
     }
     else
@@ -468,7 +468,7 @@ void pgp_application_pgp_handler (BODY *m, STATE *s)
 
   if (needpass == -1)
   {
-    state_puts (_("[-- Error: could not find beginning of PGP message! --]\n\n"), s);
+    state_attach_puts (_("[-- Error: could not find beginning of PGP message! --]\n\n"), s);
     return;
   }
 }
@@ -742,7 +742,7 @@ static int pgp_verify_one (BODY *sigbdy, STATE *s, const char *tempfile)
      dprint (1, (debugfile, "pgp_verify_one: mutt_wait_filter returned %d.\n", rv));
   }
   
-  state_puts (_("[-- End of PGP output --]\n\n"), s);
+  state_attach_puts (_("[-- End of PGP output --]\n\n"), s);
   
   mutt_unlink (sigfile);
   mutt_unlink (pgperrfile);
@@ -792,7 +792,7 @@ void pgp_signed_handler (BODY *a, STATE *s)
   if (!(a && a->next && a->next->type == protocol_major && 
       !ascii_strcasecmp(a->next->subtype, protocol_minor)))
   {
-    state_puts(_("[-- Error: Inconsistent multipart/signed structure! --]\n\n"), s);
+    state_attach_puts(_("[-- Error: Inconsistent multipart/signed structure! --]\n\n"), s);
     mutt_body_handler (a, s);
     return;
   }
@@ -800,6 +800,7 @@ void pgp_signed_handler (BODY *a, STATE *s)
   if(!(protocol_major == TYPEAPPLICATION && !ascii_strcasecmp(protocol_minor, "pgp-signature"))
      && !(protocol_major == TYPEMULTIPART && !ascii_strcasecmp(protocol_minor, "mixed")))
   {
+    state_mark_attach (s);
     state_printf(s, _("[-- Error: Unknown multipart/signed protocol %s! --]\n\n"), protocol);
     mutt_body_handler (a, s);
     return;
@@ -824,8 +825,11 @@ void pgp_signed_handler (BODY *a, STATE *s)
              goodsig = 0;
          }
          else
+         {
+           state_mark_attach (s);
            state_printf (s, _("[-- Warning: We can't verify %s/%s signatures. --]\n\n"),
                          TYPE(signatures[i]), signatures[i]->subtype);
+         }
        }
       }
       
@@ -836,19 +840,19 @@ void pgp_signed_handler (BODY *a, STATE *s)
       dprint (2, (debugfile, "pgp_signed_handler: goodsig = %d\n", goodsig));
       
       /* Now display the signed body */
-      state_puts (_("[-- The following data is signed --]\n\n"), s);
+      state_attach_puts (_("[-- The following data is signed --]\n\n"), s);
 
 
       safe_free((void **) &signatures);
     }
     else
-      state_puts (_("[-- Warning: Can't find any signatures. --]\n\n"), s);
+      state_attach_puts (_("[-- Warning: Can't find any signatures. --]\n\n"), s);
   }
   
   mutt_body_handler (a, s);
   
   if (s->flags & M_DISPLAY && sigcnt)
-    state_puts (_("\n[-- End of signed data --]\n"), s);
+    state_attach_puts (_("\n[-- End of signed data --]\n"), s);
 }
 
 /* Extract pgp public keys from messages or attachments */
@@ -1008,7 +1012,7 @@ BODY *pgp_decrypt_part (BODY *a, STATE *s, FILE *fpout, BODY *p)
     fclose (pgperr);
     unlink (pgptmpfile);
     if (s->flags & M_DISPLAY)
-      state_puts (_("[-- Error: could not create a PGP subprocess! --]\n\n"), s);
+      state_attach_puts (_("[-- Error: could not create a PGP subprocess! --]\n\n"), s);
     return (NULL);
   }
 
@@ -1038,7 +1042,7 @@ BODY *pgp_decrypt_part (BODY *a, STATE *s, FILE *fpout, BODY *p)
     rewind (pgperr);
     if (pgp_copy_checksig (pgperr, s->fpout) == 0 && p)
       p->goodsig = 1;
-    state_puts (_("[-- End of PGP output --]\n\n"), s);
+    state_attach_puts (_("[-- End of PGP output --]\n\n"), s);
   }
   fclose (pgperr);
 
@@ -1104,7 +1108,7 @@ void pgp_encrypted_handler (BODY *a, STATE *s)
       ascii_strcasecmp ("octet-stream", a->next->subtype) != 0)
   {
     if (s->flags & M_DISPLAY)
-      state_puts (_("[-- Error: malformed PGP/MIME message! --]\n\n"), s);
+      state_attach_puts (_("[-- Error: malformed PGP/MIME message! --]\n\n"), s);
     return;
   }
 
@@ -1117,7 +1121,7 @@ void pgp_encrypted_handler (BODY *a, STATE *s)
   if ((fpout = safe_fopen (tempfile, "w+")) == NULL)
   {
     if (s->flags & M_DISPLAY)
-      state_puts (_("[-- Error: could not create temporary file! --]\n"), s);
+      state_attach_puts (_("[-- Error: could not create temporary file! --]\n"), s);
     return;
   }
 
@@ -1126,7 +1130,7 @@ void pgp_encrypted_handler (BODY *a, STATE *s)
   if ((tattach = pgp_decrypt_part (a, s, fpout, p)) != NULL)
   {
     if (s->flags & M_DISPLAY)
-      state_puts (_("[-- The following data is PGP/MIME encrypted --]\n\n"), s);
+      state_attach_puts (_("[-- The following data is PGP/MIME encrypted --]\n\n"), s);
 
     fpin = s->fpin;
     s->fpin = fpout;
@@ -1144,7 +1148,7 @@ void pgp_encrypted_handler (BODY *a, STATE *s)
       p->goodsig |= tattach->goodsig;
     
     if (s->flags & M_DISPLAY)
-      state_puts (_("\n[-- End of PGP/MIME encrypted data --]\n"), s);
+      state_attach_puts (_("\n[-- End of PGP/MIME encrypted data --]\n"), s);
 
     mutt_free_body (&tattach);
   }