X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=attach.c;h=1dbc76ed709768b06b571ab0eaf77694d900de29;hp=7bc9c436b9f3e122e37c411b75d79a04250ff32d;hb=9ab647c0e8dd74fef4f067f7f7356ffbb13da0b7;hpb=0ff1c0b36260c231b7d63ffc88646505e0ea11de diff --git a/attach.c b/attach.c index 7bc9c43..1dbc76e 100644 --- a/attach.c +++ b/attach.c @@ -507,6 +507,8 @@ int mutt_view_attachment (FILE * fp, BODY * a, int flag, HEADER * hdr, /* Don't use mailcap; the attachment is viewed in the pager */ if (flag == M_AS_TEXT) { + unlink(pagerfile); + close(pagerfd); /* just let me see the raw data */ if (mutt_save_attachment (fp, a, pagerfile, 0, NULL)) goto return_error; @@ -568,19 +570,11 @@ return_error: } /* returns 1 on success, 0 on error */ -int mutt_pipe_attachment (FILE * fp, BODY * b, const char *path, - char *outfile) +int mutt_pipe_attachment(FILE * fp, BODY * b, const char *path, int out) { pid_t thepid; - int out = -1; int rv = 0; - if (outfile && *outfile) - if ((out = safe_open (outfile, O_CREAT | O_EXCL | O_WRONLY)) < 0) { - mutt_perror ("open"); - return 0; - } - mutt_endwin (NULL); if (fp) { @@ -588,7 +582,7 @@ int mutt_pipe_attachment (FILE * fp, BODY * b, const char *path, STATE s; p_clear(&s, 1); - if (outfile && *outfile) + if (out >= 0) thepid = mutt_create_filter_fd(path, &s.fpout, NULL, NULL, -1, out, -1); else thepid = mutt_create_filter(path, &s.fpout, NULL, NULL); @@ -602,25 +596,20 @@ int mutt_pipe_attachment (FILE * fp, BODY * b, const char *path, s.fpin = fp; mutt_decode_attachment (b, &s); m_fclose(&s.fpout); - } - else { + } else { /* send case */ FILE *ifp, *ofp; if ((ifp = fopen (b->filename, "r")) == NULL) { mutt_perror ("fopen"); - if (outfile && *outfile) { - close (out); - unlink (outfile); - } return 0; } - if (outfile && *outfile) - thepid = mutt_create_filter_fd (path, &ofp, NULL, NULL, -1, out, -1); + if (out >= 0) + thepid = mutt_create_filter_fd(path, &ofp, NULL, NULL, -1, out, -1); else - thepid = mutt_create_filter (path, &ofp, NULL, NULL); + thepid = mutt_create_filter(path, &ofp, NULL, NULL); if (thepid < 0) { mutt_perror (_("Can't create filter")); @@ -638,16 +627,16 @@ int mutt_pipe_attachment (FILE * fp, BODY * b, const char *path, bail: - if (outfile && *outfile) - close (out); + if (out >= 0) + close(out); /* * check for error exit from child process */ - if (mutt_wait_filter (thepid) != 0) + if (mutt_wait_filter(thepid) != 0) rv = 0; - if (rv == 0 || option (OPTWAITKEY)) + if (rv == 0 || option(OPTWAITKEY)) mutt_any_key_to_continue (NULL); return rv; } @@ -775,10 +764,10 @@ int mutt_decode_save_attachment (FILE * fp, BODY * m, int pathfd, p_clear(&s, 1); s.flags = displaying; - s.fpout = fdopen (pathfd, "w"); if (s.fpout == NULL) { + close(pathfd); mutt_perror ("fopen"); return (-1); } @@ -922,9 +911,10 @@ int mutt_print_attachment (FILE * fp, BODY * a) tok = mime_which_token(type, -1); if (tok == MIME_TEXT_PLAIN || tok == MIME_APPLICATION_POSTSCRIPT) { - return (mutt_pipe_attachment (fp, a, NONULL (PrintCmd), NULL)); + return mutt_pipe_attachment(fp, a, NONULL (PrintCmd), -1); } - else if (mutt_can_decode (a)) { + + if (mutt_can_decode (a)) { /* decode and print */ int rc = 0; @@ -936,7 +926,7 @@ int mutt_print_attachment (FILE * fp, BODY * a) newfile_fd = m_tempfd(newfile, sizeof(newfile), NONULL(Tempdir), NULL); if (mutt_decode_save_attachment (fp, a, newfile_fd, M_PRINTING) == 0) { - if ((ifp = fdopen (newfile_fd, "r")) == NULL) { + if ((ifp = fopen(newfile, "r")) == NULL) { mutt_perror ("fopen"); goto bail0; } @@ -949,8 +939,7 @@ int mutt_print_attachment (FILE * fp, BODY * a) goto bail0; } - mutt_copy_stream (ifp, fpout); - + mutt_copy_stream(ifp, fpout); m_fclose(&fpout); m_fclose(&ifp); @@ -963,8 +952,7 @@ int mutt_print_attachment (FILE * fp, BODY * a) m_fclose(&fpout); mutt_unlink (newfile); return rc; - } - else { + } else { mutt_error _("I don't know how to print that!"); return 0;