From: Thomas Roessler Date: Thu, 15 Jun 2000 21:15:51 +0000 (+0000) Subject: patch-1.2.bbell.display_filter.2. X-Git-Tag: mutt-1-3-4-rel~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e93492141eb952d9a09ed8a8d6738cd09372a162;p=mutt patch-1.2.bbell.display_filter.2. --- diff --git a/commands.c b/commands.c index c8264f4d..322e6c34 100644 --- a/commands.c +++ b/commands.c @@ -25,6 +25,9 @@ #include "copy.h" #include "mx.h" #include "pager.h" +#include +#include +#include #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 */ diff --git a/globals.h b/globals.h index 429c746e..e47e714b 100644 --- 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 734c04fe..5e55a10b 100644 --- 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" }, /*