]> granicus.if.org Git - mutt/commitdiff
patch-1.2.bbell.display_filter.2.
authorThomas Roessler <roessler@does-not-exist.org>
Thu, 15 Jun 2000 21:15:51 +0000 (21:15 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Thu, 15 Jun 2000 21:15:51 +0000 (21:15 +0000)
commands.c
globals.h
init.h

index c8264f4dc2e5714b7f56b739dcef5e094c969372..322e6c34b5450af3810fde9090a4cb0ac9780ca0 100644 (file)
@@ -25,6 +25,9 @@
 #include "copy.h"
 #include "mx.h"
 #include "pager.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 #ifdef USE_IMAP
 #include "imap.h"
@@ -61,7 +64,10 @@ int mutt_display_message (HEADER *cur)
   char tempfile[_POSIX_PATH_MAX], buf[LONG_STRING];
   int rc = 0, builtin = 0;
   int cmflags = M_CM_DECODE | M_CM_DISPLAY | M_CM_CHARCONV;
-  FILE *fpout;
+  FILE *fpout = NULL;
+  FILE *fpfilterout = NULL;
+  pid_t filterpid;
+  int res;
 
   snprintf (buf, sizeof (buf), "%s/%s", TYPE (cur->content),
            cur->content->subtype);
@@ -107,7 +113,23 @@ int mutt_display_message (HEADER *cur)
     return (0);
   }
 
-   mutt_message_hook (cur, M_DISPLAYHOOK);
+  mutt_message_hook (cur, M_DISPLAYHOOK);
+
+  if (DisplayFilter && *DisplayFilter) 
+  {
+    fpfilterout = fpout;
+    fpout = NULL;
+    endwin ();
+    filterpid = mutt_create_filter_fd (DisplayFilter, &fpout, NULL, NULL,
+                                      -1, fileno(fpfilterout), -1);
+    if (filterpid < 0)
+    {
+      mutt_error (_("Cannot create display filter"));
+      fclose (fpfilterout);
+      unlink (tempfile);
+      return 0;
+    }
+  }
 
   if (!Pager || mutt_strcmp (Pager, "builtin") == 0)
     builtin = 1;
@@ -118,20 +140,19 @@ int mutt_display_message (HEADER *cur)
     fputs ("\n\n", fpout);
   }
 
-  if (mutt_copy_message (fpout, Context, cur, cmflags,
-                        (option (OPTWEED) ? (CH_WEED | CH_REORDER) : 0) | CH_DECODE | CH_FROM) == -1)
+  res = mutt_copy_message (fpout, Context, cur, cmflags,
+               (option (OPTWEED) ? (CH_WEED | CH_REORDER) : 0) | CH_DECODE | CH_FROM);
+  if ((fclose (fpout) != 0 && errno != EPIPE) || res == -1)
   {
-    fclose (fpout);
-    unlink (tempfile);
+    mutt_error (_("Could not copy message"));
+    if (fpfilterout != NULL)
+      mutt_wait_filter (filterpid);
+    mutt_unlink (tempfile);
     return 0;
   }
 
-  if (fclose (fpout) != 0 && errno != EPIPE)
-  {
-    mutt_perror ("fclose");
-    mutt_unlink (tempfile);
-    return (0);
-  }
+  if (fpfilterout != NULL && mutt_wait_filter (filterpid) != 0)
+    mutt_any_key_to_continue (NULL);
 
 #ifdef HAVE_PGP
   /* update PGP information for this message */
index 429c746e15446b868f44b6a4cd28625f7e21171f..e47e714b9a85696fa7f4f69fe46c41904ae43fbf 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -37,6 +37,7 @@ WHERE char *Charset;
 WHERE char *ComposeFormat;
 WHERE char *DefaultHook;
 WHERE char *DateFmt;
+WHERE char *DisplayFilter;
 WHERE char *DsnNotify;
 WHERE char *DsnReturn;
 WHERE char *Editor;
diff --git a/init.h b/init.h
index 734c04fe77c07bdd0361d989dde413007841b5c8..5e55a10bb802f2d4cf51433132b57531a9b231a0 100644 (file)
--- a/init.h
+++ b/init.h
@@ -367,6 +367,13 @@ struct option_t MuttVars[] = {
   ** for deletion.  This applies when you either explicitly delete a message,
   ** or when you save it to another folder.
   */
+  { "display_filter",  DT_PATH, R_PAGER, UL &DisplayFilter, "" },
+  /*
+  ** .pp
+  ** When set, specifies a command used to filter messages.  When a message
+  ** is viewed it is passed as standard input to $$display_filter, and the
+  ** filtered message is read from the standard output.
+  */
 #if defined(DL_STANDALONE) && defined(USE_DOTLOCK)
   { "dotlock_program",  DT_PATH, R_NONE, UL &MuttDotlock, UL BINDIR "/mutt_dotlock" },
   /*