Yep. I've gotten this same feedback from a few others. Modified
patch (w/ mapping to ^\) is attached.
Thanks,
Steve
Jeremy Blosser wrote:
On Mar 26, Steve Talley [[EMAIL PROTECTED]] wrote:
filter-message (default: )
FWIW, the edit-threads patch, which quite a lot of people use, uses
for one of it's primary functions.
diff -pruN2d mutt-1.3.28.orig/OPS mutt-1.3.28/OPS
--- mutt-1.3.28.orig/OPSSat Jan 27 06:33:53 2001
+++ mutt-1.3.28/OPS Tue Mar 26 10:47:39 2002
@@ -82,4 +82,5 @@ OP_ENTER_MASK enter a file mask
OP_EXIT exit this menu
OP_FILTER filter attachment through a shell command
+OP_FILTER_MESSAGE filter message through a shell command
OP_FIRST_ENTRY move to the first entry
OP_FLAG_MESSAGE toggle a message's 'important' flag
diff -pruN2d mutt-1.3.28.orig/PATCHES mutt-1.3.28/PATCHES
--- mutt-1.3.28.orig/PATCHESMon Nov 26 12:16:52 2001
+++ mutt-1.3.28/PATCHES Tue Mar 26 10:56:38 2002
@@ -0,0 +1 @@
+patch-1.3.28.st.filter_message.1
diff -pruN2d mutt-1.3.28.orig/commands.c mutt-1.3.28/commands.c
--- mutt-1.3.28.orig/commands.c Thu Nov 8 01:56:48 2001
+++ mutt-1.3.28/commands.c Tue Mar 26 10:47:39 2002
@@ -301,5 +301,10 @@ void pipe_msg (HEADER *h, FILE *fp, int
-/* the following code is shared between printing and piping */
+/*
+ * the following code is shared between printing and piping
+ *
+ * fpfout: NULL to direct the command's STDOUT to mutt's STDOUT, or
+ * non-null to redirect.
+ */
static int _mutt_pipe_message (HEADER *h, char *cmd,
@@ -307,5 +312,6 @@ static int _mutt_pipe_message (HEADER *h
int print,
int split,
- char *sep)
+ char *sep,
+ FILE **fpfout)
{
@@ -330,5 +336,5 @@ static int _mutt_pipe_message (HEADER *h
#endif
-if ((thepid = mutt_create_filter (cmd, fpout, NULL, NULL)) 0)
+if ((thepid = mutt_create_filter (cmd, fpout, fpfout, NULL)) 0)
{
mutt_perror _(Can't create filter process);
@@ -369,5 +375,5 @@ static int _mutt_pipe_message (HEADER *h
mutt_message_hook (Context, Context-hdrs[Context-v2r[i]], M_MESSAGEHOOK);
mutt_endwin (NULL);
- if ((thepid = mutt_create_filter (cmd, fpout, NULL, NULL)) 0)
+ if ((thepid = mutt_create_filter (cmd, fpout, fpfout, NULL)) 0)
{
mutt_perror _(Can't create filter process);
@@ -386,5 +392,5 @@ static int _mutt_pipe_message (HEADER *h
{
mutt_endwin (NULL);
- if ((thepid = mutt_create_filter (cmd, fpout, NULL, NULL)) 0)
+ if ((thepid = mutt_create_filter (cmd, fpout, fpfout, NULL)) 0)
{
mutt_perror _(Can't create filter process);
@@ -426,5 +432,6 @@ void mutt_pipe_message (HEADER *h)
0,
option (OPTPIPESPLIT),
- PipeSep);
+ PipeSep,
+ NULL);
}
@@ -447,5 +454,6 @@ void mutt_print_message (HEADER *h)
1,
option (OPTPRINTSPLIT),
- \f) == 0)
+ \f,
+ NULL) == 0)
mutt_message (h ? _(Message printed) : _(Messages printed));
else
@@ -454,4 +462,87 @@ void mutt_print_message (HEADER *h)
}
+/*
+ * Filter a single message through the given command
+ */
+int filter_one_message (CONTEXT *ctx, HEADER *h, char *command)
+{
+ FILE *fpfout;
+ char tmp[_POSIX_PATH_MAX];
+ int omagic;
+ int rc;
+ int oerrno;
+ CONTEXT tmpctx;
+
+ _mutt_pipe_message (h, command,
+ option (OPTPIPEDECODE),
+ 0,
+ option (OPTPIPESPLIT),
+ PipeSep,
+ fpfout);
+
+ /* Create tmp mbox for filter output */
+ mutt_mktemp (tmp);
+ omagic = DefaultMagic;
+ DefaultMagic = M_MBOX;
+ rc = (mx_open_mailbox (tmp, M_APPEND, tmpctx) == NULL) ? -1 : 0;
+ DefaultMagic = omagic;
+
+ if (rc == -1)
+ {
+mutt_error (_(could not create temporary folder: %s), strerror (errno));
+return -1;
+ }
+
+ /* Copy filter output to tmp mbox */
+ rc = mutt_copy_stream (fpfout, tmpctx.fp);
+ oerrno = errno;
+ rc = fflush(tmpctx.fp);
+
+ /* Close stream and tmp mbox */
+ safe_fclose (fpfout);
+ mx_close_mailbox (tmpctx, NULL);
+
+ if (rc == -1)
+ {
+mutt_error (_(could not write temporary mail folder: %s), strerror (errno));
+return -1;
+ }
+
+ /* Replace the selected message with the filter output */
+ return mutt_replace_message (ctx, h, tmp, 0);
+}
+
+/*
+ * Filter a single or tagged messages through a user-specified command
+ */
+int mutt_filter_message (CONTEXT *ctx, HEADER *hdr)
+{
+ int i, j;
+ char buffer[LONG_STRING];
+
+ buffer[0] = 0;
+ if (mutt_get_field (_(Filter command: ), buffer, sizeof (buffer), M_CMD)
+ != 0 || !buffer[0])
+return 0;
+
+ mutt_expand_path (buffer, sizeof (buffer));
+
+ /*