Changeset 2189:ae8d416c65df for commands.c
- Timestamp:
- 2000-11-19 12:33:24 (8 years ago)
- Branch:
- HEAD
- Files:
-
- 1 modified
-
commands.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
commands.c
r2161 r2189 1 1 /* 2 2 * Copyright (C) 1996-2000 Michael R. Elkins <me@cs.hmc.edu> 3 * Copyright (C) 2000 Thomas Roessler <roessler@does-not-exist.org> 3 4 * 4 5 * This program is free software; you can redistribute it and/or modify … … 256 257 } 257 258 258 static void pipe_ print_set_flags (int decode, int *cmflags, int *chflags)259 static void pipe_set_flags (int decode, int *cmflags, int *chflags) 259 260 { 260 261 if (decode) … … 271 272 } 272 273 273 void mutt_pipe_message_to_state (HEADER *h, STATE *s)274 void pipe_msg (HEADER *h, FILE *fp, int decode) 274 275 { 275 276 int cmflags = 0; 276 277 int chflags = CH_FROM; 277 278 278 pipe_print_set_flags (option (OPTPIPEDECODE), &cmflags, &chflags); 279 280 if (option (OPTPIPEDECODE)) 279 pipe_set_flags (decode, &cmflags, &chflags); 280 281 #ifdef HAVE_PGP 282 283 if (decode && (h->pgp & PGPENCRYPT)) 284 { 285 if (!pgp_valid_passphrase()) 286 return; 287 endwin(); 288 } 289 290 #endif 291 292 if (decode) 281 293 mutt_parse_mime_message (Context, h); 282 294 283 mutt_copy_message (s->fpout, Context, h, 284 cmflags, chflags); 285 } 286 287 int mutt_pipe_message (HEADER *h) 288 { 289 STATE s; 290 char buffer[LONG_STRING]; 291 int i, rc = 0; 295 mutt_copy_message (fp, Context, h, cmflags, chflags); 296 } 297 298 299 /* the following code is shared between printing and piping */ 300 301 static int _mutt_pipe_message (HEADER *h, char *cmd, 302 int decode, 303 int split, 304 char *sep) 305 { 306 307 int i, rc = 0; 292 308 pid_t thepid; 293 294 buffer[0] = 0; 295 if (mutt_get_field (_("Pipe to command: "), buffer, sizeof (buffer), M_CMD) 296 != 0 || !buffer[0]) 297 return 0; 298 mutt_expand_path (buffer, sizeof (buffer)); 299 300 memset (&s, 0, sizeof (s)); 301 309 FILE *fpout; 310 302 311 endwin (); 303 312 if (h) … … 307 316 308 317 #ifdef HAVE_PGP 309 if ( option (OPTPIPEDECODE))318 if (decode) 310 319 { 311 320 mutt_parse_mime_message (Context, h); … … 316 325 #endif 317 326 318 319 320 thepid = mutt_create_filter (buffer, &s.fpout, NULL, NULL); 321 mutt_pipe_message_to_state (h, &s); 322 fclose (s.fpout); 327 thepid = mutt_create_filter (cmd, &fpout, NULL, NULL); 328 pipe_msg (h, fpout, decode); 329 fclose (fpout); 323 330 rc = mutt_wait_filter (thepid); 324 331 } … … 330 337 #ifdef HAVE_PGP 331 338 332 if (option(OPTPIPEDECODE))339 if (decode) 333 340 { 334 341 for (i = 0; i < Context->vcount; i++) … … 344 351 #endif 345 352 346 347 348 if (option (OPTPIPESPLIT)) 353 if (split) 349 354 { 350 355 for (i = 0; i < Context->vcount; i++) … … 354 359 mutt_message_hook (Context, Context->hdrs[Context->v2r[i]], M_MESSAGEHOOK); 355 360 endwin (); 356 thepid = mutt_create_filter ( buffer, &(s.fpout), NULL, NULL);357 mutt_pipe_message_to_state (Context->hdrs[Context->v2r[i]], &s);361 thepid = mutt_create_filter (cmd, &fpout, NULL, NULL); 362 pipe_msg (Context->hdrs[Context->v2r[i]], fpout, decode); 358 363 /* add the message separator */ 359 if (PipeSep) 360 state_puts (PipeSep, &s); 361 fclose (s.fpout); 364 if (sep) fputs (sep, fpout); 365 fclose (fpout); 362 366 if (mutt_wait_filter (thepid) != 0) 363 367 rc = 1; … … 368 372 { 369 373 endwin (); 370 thepid = mutt_create_filter ( buffer, &(s.fpout), NULL, NULL);374 thepid = mutt_create_filter (cmd, &fpout, NULL, NULL); 371 375 for (i = 0; i < Context->vcount; i++) 372 376 { … … 374 378 { 375 379 mutt_message_hook (Context, Context->hdrs[Context->v2r[i]], M_MESSAGEHOOK); 376 mutt_pipe_message_to_state (Context->hdrs[Context->v2r[i]], &s);380 pipe_msg (Context->hdrs[Context->v2r[i]], fpout, decode); 377 381 /* add the message separator */ 378 if (PipeSep) 379 state_puts (PipeSep, &s); 382 if (sep) fputs (sep, fpout); 380 383 } 381 384 } 382 fclose ( s.fpout);385 fclose (fpout); 383 386 if (mutt_wait_filter (thepid) != 0) 384 387 rc = 1; … … 388 391 if (rc || option (OPTWAITKEY)) 389 392 mutt_any_key_to_continue (NULL); 390 return 1; 391 } 393 return rc; 394 } 395 396 void mutt_pipe_message (HEADER *h) 397 { 398 char buffer[LONG_STRING]; 399 400 buffer[0] = 0; 401 if (mutt_get_field (_("Pipe to command: "), buffer, sizeof (buffer), M_CMD) 402 != 0 || !buffer[0]) 403 return; 404 405 mutt_expand_path (buffer, sizeof (buffer)); 406 _mutt_pipe_message (h, buffer, 407 option (OPTPIPEDECODE), 408 option (OPTPIPESPLIT), 409 PipeSep); 410 } 411 412 void mutt_print_message (HEADER *h) 413 { 414 415 if (quadoption (OPT_PRINT) && (!PrintCmd || !*PrintCmd)) 416 { 417 mutt_message (_("No printing command has been defined.")); 418 return; 419 } 420 421 if (query_quadoption (OPT_PRINT, 422 h ? _("Print message?") : _("Print tagged messages?")) 423 != M_YES) 424 return; 425 426 if (_mutt_pipe_message (h, PrintCmd, 427 option (OPTPRINTDECODE), 428 option (OPTPRINTSPLIT), 429 "\f") == 0) 430 mutt_message (h ? _("Message printed") : _("Messages printed")); 431 else 432 mutt_message (h ? _("Message could not be printed") : 433 _("Messages could not be printed")); 434 } 435 392 436 393 437 int mutt_select_sort (int reverse) … … 721 765 } 722 766 723 /* XXX - merge this with mutt_pipe_message_to_state? */724 725 static void print_msg (FILE *fp, CONTEXT *ctx, HEADER *h)726 {727 int cmflags = 0;728 int chflags = CH_FROM;729 730 pipe_print_set_flags (option (OPTPRINTDECODE), &cmflags, &chflags);731 732 #ifdef HAVE_PGP733 if (option (OPTPRINTDECODE) && (h->pgp & PGPENCRYPT))734 {735 if (!pgp_valid_passphrase ())736 return;737 endwin ();738 }739 #endif740 741 if (option (OPTPRINTDECODE))742 mutt_parse_mime_message (ctx, h);743 744 mutt_copy_message (fp, ctx, h, cmflags, chflags);745 }746 747 void mutt_print_message (HEADER *h)748 {749 int i, count = 0;750 pid_t thepid;751 FILE *fp;752 753 754 if (query_quadoption (OPT_PRINT,755 h ? _("Print message?") : _("Print tagged messages?"))756 != M_YES)757 return;758 endwin ();759 if ((thepid = mutt_create_filter (NONULL(PrintCmd), &fp, NULL, NULL)) == -1)760 return;761 if (h)762 {763 mutt_message_hook (Context, h, M_MESSAGEHOOK);764 print_msg (fp, Context, h);765 count++;766 }767 else768 {769 for (i = 0 ; i < Context->vcount ; i++)770 {771 if (Context->hdrs[Context->v2r[i]]->tagged)772 {773 mutt_message_hook (Context, Context->hdrs[Context->v2r[i]], M_MESSAGEHOOK);774 print_msg (fp, Context, Context->hdrs[Context->v2r[i]]);775 /* add a formfeed */776 fputc ('\f', fp);777 count++;778 }779 }780 }781 fclose (fp);782 if (mutt_wait_filter (thepid) || option (OPTWAITKEY))783 mutt_any_key_to_continue (NULL);784 mutt_message ((count > 1) ? _("Message printed") : _("Messages printed"));785 }786 767 787 768 void mutt_version (void)
