]> granicus.if.org Git - mutt/commitdiff
Introduce a new option named $print_split. While we are on it,
authorThomas Roessler <roessler@does-not-exist.org>
Sun, 19 Nov 2000 20:33:24 +0000 (20:33 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Sun, 19 Nov 2000 20:33:24 +0000 (20:33 +0000)
unify the pipe-message and print-message code, and fix the PGP
key-extraction code so it doesn't interact with OPTPIPEDECODE in
strange manners any more.

commands.c
init.h
mutt.h
pgp.c
protos.h

index 3d1af3d805089f516ba69ee3672a0b75534384e0..2d32bf74fc2c29fcf371668f803dcde8faa5100d 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 1996-2000 Michael R. Elkins <me@cs.hmc.edu>
+ * Copyright (C) 2000 Thomas Roessler <roessler@does-not-exist.org>
  * 
  *     This program is free software; you can redistribute it and/or modify
  *     it under the terms of the GNU General Public License as published by
@@ -255,7 +256,7 @@ void ci_bounce_message (HEADER *h, int *redraw)
   mutt_message (h ? _("Message bounced.") : _("Messages bounced."));
 }
 
-static void pipe_print_set_flags (int decode, int *cmflags, int *chflags)
+static void pipe_set_flags (int decode, int *cmflags, int *chflags)
 {
   if (decode)
   {
@@ -270,35 +271,43 @@ static void pipe_print_set_flags (int decode, int *cmflags, int *chflags)
   }
 }
 
-void mutt_pipe_message_to_state (HEADER *h, STATE *s)
+void pipe_msg (HEADER *h, FILE *fp, int decode)
 {
   int cmflags = 0;
   int chflags = CH_FROM;
   
-  pipe_print_set_flags (option (OPTPIPEDECODE), &cmflags, &chflags);
+  pipe_set_flags (decode, &cmflags, &chflags);
+
+#ifdef HAVE_PGP
+  
+  if (decode && (h->pgp & PGPENCRYPT))
+  {
+    if (!pgp_valid_passphrase())
+      return;
+    endwin();
+  }
   
-  if (option (OPTPIPEDECODE))
+#endif
+
+  if (decode)
     mutt_parse_mime_message (Context, h);
 
-  mutt_copy_message (s->fpout, Context, h,
-                    cmflags, chflags);
+  mutt_copy_message (fp, Context, h, cmflags, chflags);
 }
 
-int mutt_pipe_message (HEADER *h)
-{
-  STATE s;
-  char buffer[LONG_STRING];
-  int i, rc = 0; 
-  pid_t thepid;
-
-  buffer[0] = 0;
-  if (mutt_get_field (_("Pipe to command: "), buffer, sizeof (buffer), M_CMD)
-      != 0 || !buffer[0])
-    return 0;
-  mutt_expand_path (buffer, sizeof (buffer));
 
-  memset (&s, 0, sizeof (s));
+/* the following code is shared between printing and piping */
 
+static int _mutt_pipe_message (HEADER *h, char *cmd,
+                       int decode,
+                       int split,
+                       char *sep)
+{
+  
+  int i, rc = 0;
+  pid_t thepid;
+  FILE *fpout;
+  
   endwin ();
   if (h)
   {
@@ -306,7 +315,7 @@ int mutt_pipe_message (HEADER *h)
     mutt_message_hook (Context, h, M_MESSAGEHOOK);
 
 #ifdef HAVE_PGP
-    if (option (OPTPIPEDECODE))
+    if (decode)
     {
       mutt_parse_mime_message (Context, h);
       if(h->pgp & PGPENCRYPT && !pgp_valid_passphrase())
@@ -315,11 +324,9 @@ int mutt_pipe_message (HEADER *h)
     endwin ();
 #endif
 
-
-
-    thepid = mutt_create_filter (buffer, &s.fpout, NULL, NULL);
-    mutt_pipe_message_to_state (h, &s);
-    fclose (s.fpout);
+    thepid = mutt_create_filter (cmd, &fpout, NULL, NULL);
+    pipe_msg (h, fpout, decode);
+    fclose (fpout);
     rc = mutt_wait_filter (thepid);
   }
   else
@@ -329,7 +336,7 @@ int mutt_pipe_message (HEADER *h)
 
 #ifdef HAVE_PGP
 
-    if(option(OPTPIPEDECODE))
+    if (decode)
     {
       for (i = 0; i < Context->vcount; i++)
        if(Context->hdrs[Context->v2r[i]]->tagged)
@@ -343,9 +350,7 @@ int mutt_pipe_message (HEADER *h)
     }
 #endif
     
-
-
-    if (option (OPTPIPESPLIT))
+    if (split)
     {
       for (i = 0; i < Context->vcount; i++)
       {
@@ -353,12 +358,11 @@ int mutt_pipe_message (HEADER *h)
         {
          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);
+         thepid = mutt_create_filter (cmd, &fpout, NULL, NULL);
+          pipe_msg (Context->hdrs[Context->v2r[i]], fpout, decode);
           /* add the message separator */
-          if (PipeSep)
-           state_puts (PipeSep, &s);
-         fclose (s.fpout);
+          if (sep)  fputs (sep, fpout);
+         fclose (fpout);
          if (mutt_wait_filter (thepid) != 0)
            rc = 1;
         }
@@ -367,19 +371,18 @@ int mutt_pipe_message (HEADER *h)
     else
     {
       endwin ();
-      thepid = mutt_create_filter (buffer, &(s.fpout), NULL, NULL);
+      thepid = mutt_create_filter (cmd, &fpout, NULL, NULL);
       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_pipe_message_to_state (Context->hdrs[Context->v2r[i]], &s);
+          pipe_msg (Context->hdrs[Context->v2r[i]], fpout, decode);
           /* add the message separator */
-          if (PipeSep)
-           state_puts (PipeSep, &s);
+          if (sep) fputs (sep, fpout);
         }
       }
-      fclose (s.fpout);
+      fclose (fpout);
       if (mutt_wait_filter (thepid) != 0)
        rc = 1;
     }
@@ -387,9 +390,50 @@ int mutt_pipe_message (HEADER *h)
 
   if (rc || option (OPTWAITKEY))
     mutt_any_key_to_continue (NULL);
-  return 1;
+  return rc;
+}
+
+void mutt_pipe_message (HEADER *h)
+{
+  char buffer[LONG_STRING];
+
+  buffer[0] = 0;
+  if (mutt_get_field (_("Pipe to command: "), buffer, sizeof (buffer), M_CMD)
+      != 0 || !buffer[0])
+    return;
+
+  mutt_expand_path (buffer, sizeof (buffer));
+  _mutt_pipe_message (h, buffer,
+                     option (OPTPIPEDECODE),
+                     option (OPTPIPESPLIT),
+                     PipeSep);
 }
 
+void mutt_print_message (HEADER *h)
+{
+
+  if (quadoption (OPT_PRINT) && (!PrintCmd || !*PrintCmd))
+  {
+    mutt_message (_("No printing command has been defined."));
+    return;
+  }
+  
+  if (query_quadoption (OPT_PRINT,
+                       h ? _("Print message?") : _("Print tagged messages?"))
+                       != M_YES)
+    return;
+
+  if (_mutt_pipe_message (h, PrintCmd,
+                         option (OPTPRINTDECODE),
+                         option (OPTPRINTSPLIT),
+                         "\f") == 0)
+    mutt_message (h ? _("Message printed") : _("Messages printed"));
+  else
+    mutt_message (h ? _("Message could not be printed") :
+                 _("Messages could not be printed"));
+}
+
+
 int mutt_select_sort (int reverse)
 {
   int method = Sort; /* save the current method in case of abort */
@@ -720,69 +764,6 @@ int mutt_save_message (HEADER *h, int delete,
   return -1;
 }
 
-/* XXX - merge this with mutt_pipe_message_to_state? */
-
-static void print_msg (FILE *fp, CONTEXT *ctx, HEADER *h)
-{
-  int cmflags = 0;
-  int chflags = CH_FROM;
-
-  pipe_print_set_flags (option (OPTPRINTDECODE), &cmflags, &chflags);
-
-#ifdef HAVE_PGP
-  if (option (OPTPRINTDECODE) && (h->pgp & PGPENCRYPT))
-  {
-    if (!pgp_valid_passphrase ())
-      return;
-    endwin ();
-  }
-#endif
-
-  if (option (OPTPRINTDECODE))
-    mutt_parse_mime_message (ctx, h);
-
-  mutt_copy_message (fp, ctx, h, cmflags, chflags);
-}
-
-void mutt_print_message (HEADER *h)
-{
-  int i, count = 0;
-  pid_t thepid;
-  FILE *fp;
-
-  
-  if (query_quadoption (OPT_PRINT,
-                       h ? _("Print message?") : _("Print tagged messages?"))
-                       != M_YES)
-    return;
-  endwin ();
-  if ((thepid = mutt_create_filter (NONULL(PrintCmd), &fp, NULL, NULL)) == -1)
-    return;
-  if (h)
-  {
-    mutt_message_hook (Context, h, M_MESSAGEHOOK);
-    print_msg (fp, Context, h);
-    count++;
-  }
-  else
-  {
-    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);
-       print_msg (fp, Context, Context->hdrs[Context->v2r[i]]);
-       /* add a formfeed */
-       fputc ('\f', fp);
-       count++;
-      }
-    }
-  }
-  fclose (fp);
-  if (mutt_wait_filter (thepid) || option (OPTWAITKEY))
-    mutt_any_key_to_continue (NULL);
-  mutt_message ((count > 1) ? _("Message printed") : _("Messages printed"));
-}
 
 void mutt_version (void)
 {
diff --git a/init.h b/init.h
index 3a06d89fa50757d8bed919bd5ea755b548dd362f..e17e35fbc6a2c1ed6248df1f5fee54a88a5ece54 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1525,6 +1525,19 @@ struct option_t MuttVars[] = {
   ** some advanced printer filter which is able to properly format
   ** e-mail messages for printing.
   */
+  { "print_split",     DT_BOOL, R_NONE, OPTPRINTSPLIT,  0 },
+  /*
+  ** .pp
+  ** Used in connection with the print-message command.  If this option
+  ** is set, the command sepcified by $$print_command is executed once for
+  ** each message which is to be printed.  If this option is unset, 
+  ** the command specified by $$print_command is executed only once, and
+  ** all the messages are concatenated, with a form feed as the message
+  ** separator.
+  ** .pp
+  ** Those who use the \fBenscript\fP(1) program's mail-printing mode will
+  ** most likely want to set this option.
+  */
   { "prompt_after",    DT_BOOL, R_NONE, OPTPROMPTAFTER, 1 },
   /*
   ** .pp
diff --git a/mutt.h b/mutt.h
index e34963945e23378d674b6d8175805ee218262cc9..f43e0cc40da0451433d6d14aed6d497ace9b66a0 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -339,6 +339,7 @@ enum
   OPTPIPESPLIT,
   OPTPOPLAST,
   OPTPRINTDECODE,
+  OPTPRINTSPLIT,
   OPTPROMPTAFTER,
   OPTREADONLY,
   OPTREPLYSELF,
diff --git a/pgp.c b/pgp.c
index ff67cbe95465b68b25776890e33860cdd6506dc5..53b8e9fed9a234adf8117ac473adfbdaf8c0d1cd 100644 (file)
--- a/pgp.c
+++ b/pgp.c
@@ -29,6 +29,7 @@
 #include "mutt_curses.h"
 #include "pgp.h"
 #include "mime.h"
+#include "copy.h"
 
 #include <sys/wait.h>
 #include <string.h>
@@ -723,8 +724,8 @@ void pgp_signed_handler (BODY *a, STATE *s)
 void pgp_extract_keys_from_messages (HEADER *h)
 {
   int i;
-  STATE s;
   char tempfname[_POSIX_PATH_MAX];
+  FILE *fpout;
 
   if (h)
   {
@@ -733,10 +734,8 @@ void pgp_extract_keys_from_messages (HEADER *h)
       return;
   }
 
-  memset (&s, 0, sizeof (STATE));
-  
   mutt_mktemp (tempfname);
-  if (!(s.fpout = safe_fopen (tempfname, "w")))
+  if (!(fpout = safe_fopen (tempfname, "w")))
   {
     mutt_perror (tempfname);
     return;
@@ -754,10 +753,11 @@ void pgp_extract_keys_from_messages (HEADER *h)
        if (Context->hdrs[Context->v2r[i]]->pgp & PGPENCRYPT
           && !pgp_valid_passphrase())
        {
-         fclose (s.fpout);
+         fclose (fpout);
          goto bailout;
        }
-       mutt_pipe_message_to_state (Context->hdrs[Context->v2r[i]], &s);
+       mutt_copy_message (fpout, Context, Context->hdrs[Context->v2r[i]], 
+                          M_CM_DECODE|M_CM_CHARCONV, 0);
       }
     }
   } 
@@ -766,13 +766,13 @@ void pgp_extract_keys_from_messages (HEADER *h)
     mutt_parse_mime_message (Context, h);
     if (h->pgp & PGPENCRYPT && !pgp_valid_passphrase())
     {
-      fclose (s.fpout);
+      fclose (fpout);
       goto bailout;
     }
-    mutt_pipe_message_to_state (h, &s);
+    mutt_copy_message (fpout, Context, h, M_CM_DECODE|M_CM_CHARCONV, 0);
   }
       
-  fclose (s.fpout);
+  fclose (fpout);
   endwin ();
   pgp_invoke_import (tempfname);
   mutt_any_key_to_continue (NULL);
index 11a9f16e40434c3ce83cd341f7e36dda3f5cb9ec..5a5a4ec261fb9afc42d29ffeb7cac3d90d3328da 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -188,12 +188,12 @@ void mutt_normalize_time (struct tm *);
 void mutt_paddstr (int, const char *);
 void mutt_parse_mime_message (CONTEXT *ctx, HEADER *);
 void mutt_parse_part (FILE *, BODY *);
-void mutt_pipe_message_to_state (HEADER *, STATE *);
 void mutt_perror (const char *);
 void mutt_prepare_envelope (ENVELOPE *, int);
 void mutt_unprepare_envelope (ENVELOPE *);
 void mutt_pretty_mailbox (char *);
 void mutt_pretty_size (char *, size_t, long);
+void mutt_pipe_message (HEADER *);
 void mutt_print_message (HEADER *);
 void mutt_query_exit (void);
 void mutt_query_menu (char *, size_t);
@@ -296,7 +296,6 @@ int mutt_parse_unscore (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 int mutt_parse_unhook (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 int mutt_pattern_func (int, char *);
 int mutt_pipe_attachment (FILE *, BODY *, const char *, char *); 
-int mutt_pipe_message (HEADER *);
 int mutt_print_attachment (FILE *, BODY *);
 int mutt_query_complete (char *, size_t);
 int mutt_save_attachment (FILE *, BODY *, char *, int, HEADER *);