/*
* 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
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)
{
}
}
-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)
{
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())
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
#ifdef HAVE_PGP
- if(option(OPTPIPEDECODE))
+ if (decode)
{
for (i = 0; i < Context->vcount; i++)
if(Context->hdrs[Context->v2r[i]]->tagged)
}
#endif
-
-
- if (option (OPTPIPESPLIT))
+ if (split)
{
for (i = 0; i < Context->vcount; i++)
{
{
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;
}
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;
}
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 */
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)
{
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);
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 *);