diff options
author | Kevin McCarthy <kevin@8t8.us> | 2020-07-09 19:31:48 -0700 |
---|---|---|
committer | Kevin McCarthy <kevin@8t8.us> | 2020-07-10 14:39:36 -0700 |
commit | b8217c6b21b38f01ebf13bdd6789496debd14ce0 (patch) | |
tree | 4d1137be373e912a1c8c33fd2e3f2b82ecdda20e /attach.c | |
parent | 104768bf285b23cada0a2141d18b1a17ed89edec (diff) |
Fix mutt_pipe_attachment_list() to unstuff format=flowed.
The pipe routines are not used in other places (except printing
attachments - to be handled next), so just directly modify them.
Take care to space-stuff the filter output, since it replaces the
space-stuffed compose part.
Diffstat (limited to 'attach.c')
-rw-r--r-- | attach.c | 119 |
1 files changed, 80 insertions, 39 deletions
@@ -608,9 +608,10 @@ return_error: /* returns 1 on success, 0 on error */ int mutt_pipe_attachment (FILE *fp, BODY *b, const char *path, const char *outfile) { - pid_t thepid; - int out = -1; - int rv = 0; + pid_t thepid = 0; + int out = -1, rv = 0, is_flowed = 0, unlink_unstuff = 0; + FILE *filter_fp = NULL, *unstuff_fp = NULL, *ifp = NULL; + BUFFER *unstuff_tempfile = NULL; if (outfile && *outfile) if ((out = safe_open (outfile, O_CREAT | O_EXCL | O_WRONLY)) < 0) @@ -619,78 +620,118 @@ int mutt_pipe_attachment (FILE *fp, BODY *b, const char *path, const char *outfi return 0; } + if (mutt_rfc3676_is_format_flowed (b)) + { + is_flowed = 1; + unstuff_tempfile = mutt_buffer_pool_get (); + mutt_buffer_mktemp (unstuff_tempfile); + } + mutt_endwin (NULL); - if (fp) + if (outfile && *outfile) + thepid = mutt_create_filter_fd (path, &filter_fp, NULL, NULL, -1, out, -1); + else + thepid = mutt_create_filter (path, &filter_fp, NULL, NULL); + if (thepid < 0) { - /* recv case */ + mutt_perror _("Can't create filter"); + goto bail; + } + /* recv case */ + if (fp) + { STATE s; memset (&s, 0, sizeof (STATE)); /* perform charset conversion on text attachments when piping */ s.flags = MUTT_CHARCONV; - if (outfile && *outfile) - thepid = mutt_create_filter_fd (path, &s.fpout, NULL, NULL, -1, out, -1); - else - thepid = mutt_create_filter (path, &s.fpout, NULL, NULL); + if (is_flowed) + { + unstuff_fp = safe_fopen (mutt_b2s (unstuff_tempfile), "w"); + if (unstuff_fp == NULL) + { + mutt_perror ("safe_fopen"); + goto bail; + } + unlink_unstuff = 1; + + s.fpin = fp; + s.fpout = unstuff_fp; + mutt_decode_attachment (b, &s); + safe_fclose (&unstuff_fp); - if (thepid < 0) + mutt_rfc3676_space_unstuff_attachment (b, mutt_b2s (unstuff_tempfile)); + + unstuff_fp = safe_fopen (mutt_b2s (unstuff_tempfile), "r"); + if (unstuff_fp == NULL) + { + mutt_perror ("safe_fopen"); + goto bail; + } + mutt_copy_stream (unstuff_fp, filter_fp); + safe_fclose (&unstuff_fp); + } + else { - mutt_perror _("Can't create filter"); - goto bail; + s.fpin = fp; + s.fpout = filter_fp; + mutt_decode_attachment (b, &s); } - - s.fpin = fp; - mutt_decode_attachment (b, &s); - safe_fclose (&s.fpout); } + + /* send case */ else { - /* send case */ - - FILE *ifp, *ofp; + const char *infile; - if ((ifp = fopen (b->filename, "r")) == NULL) + if (is_flowed) { - mutt_perror ("fopen"); - if (outfile && *outfile) - { - close (out); - unlink (outfile); - } - return 0; + if (mutt_save_attachment (fp, b, mutt_b2s (unstuff_tempfile), 0, NULL) == -1) + goto bail; + unlink_unstuff = 1; + mutt_rfc3676_space_unstuff_attachment (b, mutt_b2s (unstuff_tempfile)); + infile = mutt_b2s (unstuff_tempfile); } - - if (outfile && *outfile) - thepid = mutt_create_filter_fd (path, &ofp, NULL, NULL, -1, out, -1); else - thepid = mutt_create_filter (path, &ofp, NULL, NULL); + infile = b->filename; - if (thepid < 0) + if ((ifp = fopen (infile, "r")) == NULL) { - mutt_perror _("Can't create filter"); - safe_fclose (&ifp); + mutt_perror ("fopen"); goto bail; } - - mutt_copy_stream (ifp, ofp); - safe_fclose (&ofp); + mutt_copy_stream (ifp, filter_fp); safe_fclose (&ifp); } + safe_fclose (&filter_fp); rv = 1; bail: - if (outfile && *outfile) + { close (out); + if (rv == 0) + unlink (outfile); + else if (is_flowed) + mutt_rfc3676_space_stuff_attachment (NULL, outfile); + } + + safe_fclose (&unstuff_fp); + safe_fclose (&filter_fp); + safe_fclose (&ifp); + + if (unlink_unstuff) + mutt_unlink (mutt_b2s (unstuff_tempfile)); + mutt_buffer_pool_release (&unstuff_tempfile); /* * check for error exit from child process */ - if (mutt_wait_filter (thepid) != 0) + if ((thepid > 0) && (mutt_wait_filter (thepid) != 0)) rv = 0; if (rv == 0 || option (OPTWAITKEY)) |