1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Message content preparation (sendmp()).
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 - 2017 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
8 * Copyright (c) 1980, 1993
9 * The Regents of the University of California. All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #ifndef HAVE_AMALGAMATION
42 static sigjmp_buf _send_pipejmp
;
44 /* Going for user display, print Part: info string */
45 static void _print_part_info(FILE *obuf
, struct mimepart
const *mpp
,
46 struct n_ignore
const *doitp
, int level
,
47 struct quoteflt
*qf
, ui64_t
*stats
);
49 /* Create a pipe; if mpp is not NULL, place some n_PIPEENV_* environment
50 * variables accordingly */
51 static FILE * _pipefile(struct mime_handler
*mhp
,
52 struct mimepart
const *mpp
, FILE **qbuf
,
53 char const *tmpname
, int term_infd
);
55 /* Call mime_write() as approbiate and adjust statistics */
56 SINLINE ssize_t
_out(char const *buf
, size_t len
, FILE *fp
,
57 enum conversion convert
, enum sendaction action
,
58 struct quoteflt
*qf
, ui64_t
*stats
, struct str
*outrest
,
62 static void _send_onpipe(int signo
);
65 static int sendpart(struct message
*zmp
, struct mimepart
*ip
,
66 FILE *obuf
, struct n_ignore
const *doitp
,
67 struct quoteflt
*qf
, enum sendaction action
,
68 char **linedat
, size_t *linesize
,
69 ui64_t
*stats
, int level
);
71 /* Get a file for an attachment */
72 static FILE * newfile(struct mimepart
*ip
, bool_t
volatile *ispipe
);
74 static void pipecpy(FILE *pipebuf
, FILE *outbuf
, FILE *origobuf
,
75 struct quoteflt
*qf
, ui64_t
*stats
);
77 /* Output a reasonable looking status field */
78 static void statusput(const struct message
*mp
, FILE *obuf
,
79 struct quoteflt
*qf
, ui64_t
*stats
);
80 static void xstatusput(const struct message
*mp
, FILE *obuf
,
81 struct quoteflt
*qf
, ui64_t
*stats
);
83 static void put_from_(FILE *fp
, struct mimepart
*ip
, ui64_t
*stats
);
86 _print_part_info(FILE *obuf
, struct mimepart
const *mpp
, /* TODO strtofmt.. */
87 struct n_ignore
const *doitp
, int level
, struct quoteflt
*qf
, ui64_t
*stats
)
91 bool_t want_ct
, needsep
;
92 struct str
const *cpre
, *csuf
;
98 if(n_COLOUR_IS_ACTIVE()){
99 struct n_colour_pen
*cpen
;
101 cpen
= n_colour_pen_create(n_COLOUR_ID_VIEW_PARTINFO
, NULL
);
102 if((cpre
= n_colour_pen_to_str(cpen
)) != NULL
)
103 csuf
= n_colour_reset_to_str();
107 /* Take care of "99.99", i.e., 5 */
108 if ((cp
= mpp
->m_partstring
) == NULL
|| cp
[0] == '\0')
110 if (level
|| (cp
[0] != '1' && cp
[1] == '\0') || (cp
[0] == '1' && /* TODO */
111 cp
[1] == '.' && cp
[2] != '1')) /* TODO code should not look like so */
112 _out("\n", 1, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
114 /* Part id, content-type, encoding, charset */
116 _out(cpre
->s
, cpre
->l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
117 _out("[-- #", 5, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
118 _out(cp
, strlen(cp
), obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
120 to
.l
= snprintf(buf
, sizeof buf
, " %" PRIuZ
"/%" PRIuZ
" ",
121 (uiz_t
)mpp
->m_lines
, (uiz_t
)mpp
->m_size
);
122 _out(buf
, to
.l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
126 if((cp
= mpp
->m_ct_type_usr_ovwr
) != NULL
){
127 _out("+", 1, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
129 }else if((want_ct
= n_ignore_is_ign(doitp
,
130 "content-type", sizeof("content-type") -1)))
131 cp
= mpp
->m_ct_type_plain
;
133 (to
.l
= strlen(cp
)) > 30 && is_asccaseprefix("application/", cp
)) {
134 size_t const al
= sizeof("appl../") -1, fl
= sizeof("application/") -1;
135 size_t i
= to
.l
- fl
;
136 char *x
= salloc(al
+ i
+1);
138 memcpy(x
, "appl../", al
);
139 memcpy(x
+ al
, cp
+ fl
, i
+1);
144 _out(cp
, to
.l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
148 if(mpp
->m_multipart
== NULL
/* TODO */ && (cp
= mpp
->m_ct_enc
) != NULL
&&
149 (!asccasecmp(cp
, "7bit") ||
150 n_ignore_is_ign(doitp
, "content-transfer-encoding",
151 sizeof("content-transfer-encoding") -1))){
153 _out(", ", 2, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
154 if (to
.l
> 25 && !asccasecmp(cp
, "quoted-printable"))
156 _out(cp
, strlen(cp
), obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
160 if (want_ct
&& mpp
->m_multipart
== NULL
/* TODO */ &&
161 (cp
= mpp
->m_charset
) != NULL
) {
163 _out(", ", 2, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
164 _out(cp
, strlen(cp
), obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
168 _out(&" --]"[needsep
], 4 - needsep
,
169 obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
171 _out(csuf
->s
, csuf
->l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
172 _out("\n", 1, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
175 if (mpp
->m_content_info
& CI_MIME_ERRORS
) {
177 _out(cpre
->s
, cpre
->l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
,
179 _out("[-- ", 4, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
181 ti
.l
= strlen(ti
.s
= n_UNCONST(_("Defective MIME structure")));
183 to
.l
= delctrl(to
.s
, to
.l
);
184 _out(to
.s
, to
.l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
187 _out(" --]", 4, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
189 _out(csuf
->s
, csuf
->l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
,
191 _out("\n", 1, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
194 /* Content-Description */
195 if (n_ignore_is_ign(doitp
, "content-description", 19) &&
196 (cp
= mpp
->m_content_description
) != NULL
&& *cp
!= '\0') {
198 _out(cpre
->s
, cpre
->l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
,
200 _out("[-- ", 4, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
202 ti
.l
= strlen(ti
.s
= n_UNCONST(mpp
->m_content_description
));
203 mime_fromhdr(&ti
, &to
, TD_ISPR
| TD_ICONV
);
204 _out(to
.s
, to
.l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
207 _out(" --]", 4, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
209 _out(csuf
->s
, csuf
->l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
,
211 _out("\n", 1, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
215 if (n_ignore_is_ign(doitp
, "content-disposition", 19) &&
216 mpp
->m_filename
!= NULL
&& *mpp
->m_filename
!= '\0') {
218 _out(cpre
->s
, cpre
->l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
,
220 _out("[-- ", 4, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
222 ti
.l
= strlen(ti
.s
= mpp
->m_filename
);
224 to
.l
= delctrl(to
.s
, to
.l
);
225 _out(to
.s
, to
.l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
228 _out(" --]", 4, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
230 _out(csuf
->s
, csuf
->l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
,
232 _out("\n", 1, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
238 _pipefile(struct mime_handler
*mhp
, struct mimepart
const *mpp
, FILE **qbuf
,
239 char const *tmpname
, int term_infd
)
242 char const *env_addon
[8 +8/*v15*/], *cp
, *sh
;
248 if (mhp
->mh_flags
& MIME_HDL_ISQUOTE
) {
249 if ((*qbuf
= Ftmp(NULL
, "sendp", OF_RDWR
| OF_UNLINK
| OF_REGISTER
)) ==
251 n_perr(_("tmpfile"), 0);
256 if ((mhp
->mh_flags
& MIME_HDL_TYPE_MASK
) == MIME_HDL_PTF
) {
257 union {int (*ptf
)(void); char const *sh
;} u
;
260 if (*qbuf
!= n_stdout
) /* xxx never? v15: it'll be a filter anyway */
264 if((rbuf
= Popen((char*)-1, "W", u
.sh
, NULL
, fileno(*qbuf
))) == NULL
)
270 if (mpp
== NULL
|| (cp
= mpp
->m_filename
) == NULL
)
272 env_addon
[0] = str_concat_csvl(&s
, n_PIPEENV_FILENAME
, "=", cp
, NULL
)->s
;
273 env_addon
[1] = str_concat_csvl(&s
, "NAIL_FILENAME", "=", cp
, NULL
)->s
;/* v15 */
275 /* MAILX_FILENAME_GENERATED *//* TODO pathconf NAME_MAX; but user can create
276 * TODO a file wherever he wants! *Do* create a zero-size temporary file
277 * TODO and give *that* path as MAILX_FILENAME_TEMPORARY, clean it up once
278 * TODO the pipe returns? Like this we *can* verify path/name issues! */
279 cp
= n_random_create_cp(n_MIN(NAME_MAX
/ 4, 16), NULL
);
280 env_addon
[2] = str_concat_csvl(&s
, n_PIPEENV_FILENAME_GENERATED
, "=", cp
,
282 env_addon
[3] = str_concat_csvl(&s
, "NAIL_FILENAME_GENERATED", "=", cp
,/* v15 */
285 /* MAILX_CONTENT{,_EVIDENCE} */
286 if (mpp
== NULL
|| (cp
= mpp
->m_ct_type_plain
) == NULL
)
288 env_addon
[4] = str_concat_csvl(&s
, n_PIPEENV_CONTENT
, "=", cp
, NULL
)->s
;
289 env_addon
[5] = str_concat_csvl(&s
, "NAIL_CONTENT", "=", cp
, NULL
)->s
;/* v15 */
291 if (mpp
!= NULL
&& mpp
->m_ct_type_usr_ovwr
!= NULL
)
292 cp
= mpp
->m_ct_type_usr_ovwr
;
293 env_addon
[6] = str_concat_csvl(&s
, n_PIPEENV_CONTENT_EVIDENCE
, "=", cp
,
295 env_addon
[7] = str_concat_csvl(&s
, "NAIL_CONTENT_EVIDENCE", "=", cp
,/* v15 */
300 /* MAILX_FILENAME_TEMPORARY? */
301 if (tmpname
!= NULL
) {
302 env_addon
[8] = str_concat_csvl(&s
,
303 n_PIPEENV_FILENAME_TEMPORARY
, "=", tmpname
, NULL
)->s
;
304 env_addon
[9] = str_concat_csvl(&s
,
305 "NAIL_FILENAME_TEMPORARY", "=", tmpname
, NULL
)->s
;/* v15 */
306 env_addon
[10] = NULL
;
309 sh
= ok_vlook(SHELL
);
311 if (mhp
->mh_flags
& MIME_HDL_NEEDSTERM
) {
316 pid
= n_child_run(sh
, &nset
, term_infd
, n_CHILD_FD_PASS
, "-c",
317 mhp
->mh_shell_cmd
, NULL
, env_addon
, NULL
);
318 rbuf
= (pid
< 0) ? NULL
: (FILE*)-1;
320 rbuf
= Popen(mhp
->mh_shell_cmd
, "W", sh
, env_addon
,
321 (mhp
->mh_flags
& MIME_HDL_ASYNC
? -1 : fileno(*qbuf
)));
324 n_err(_("Cannot run MIME type handler: %s: %s\n"),
325 mhp
->mh_msg
, n_err_to_doc(n_err_no
));
328 if (*qbuf
!= n_stdout
)
338 _out(char const *buf
, size_t len
, FILE *fp
, enum conversion convert
, enum
339 sendaction action
, struct quoteflt
*qf
, ui64_t
*stats
, struct str
*outrest
,
346 /* TODO We should not need is_head() here, i think in v15 the actual Mailbox
347 * TODO subclass should detect such From_ cases and either reencode the part
348 * TODO in question, or perform From_ quoting as necessary!?!?!? How?!? */
352 if((action
== SEND_MBOX
|| action
== SEND_DECRYPT
) &&
353 (from_
= is_head(buf
, len
, TRU1
))){
354 if(from_
!= TRUM1
|| ok_blook(mbox_rfc4155
)){
361 flags
= ((int)action
& _TD_EOF
);
363 n
= mime_write(buf
, len
, fp
,
364 action
== SEND_MBOX
? CONV_NONE
: convert
,
365 flags
| ((action
== SEND_TODISP
|| action
== SEND_TODISP_ALL
||
366 action
== SEND_TODISP_PARTS
||
367 action
== SEND_QUOTE
|| action
== SEND_QUOTE_ALL
)
369 : (action
== SEND_TOSRCH
|| action
== SEND_TOPIPE
||
370 action
== SEND_TOFILE
)
371 ? TD_ICONV
: (action
== SEND_SHOW
? TD_ISPR
: TD_NONE
)),
372 qf
, outrest
, inrest
);
385 _send_onpipe(int signo
)
387 NYD_X
; /* Signal handler */
389 siglongjmp(_send_pipejmp
, 1);
392 static sigjmp_buf __sendp_actjmp
; /* TODO someday.. */
393 static int __sendp_sig
; /* TODO someday.. */
394 static sighandler_type __sendp_opipe
;
396 __sendp_onsig(int sig
) /* TODO someday, we won't need it no more */
398 NYD_X
; /* Signal handler */
400 siglongjmp(__sendp_actjmp
, 1);
404 sendpart(struct message
*zmp
, struct mimepart
*ip
, FILE * volatile obuf
,
405 struct n_ignore
const *doitp
, struct quoteflt
*qf
,
406 enum sendaction
volatile action
,
407 char **linedat
, size_t *linesize
, ui64_t
* volatile stats
, int level
)
410 struct mime_handler mh
;
411 struct str outrest
, inrest
;
413 char const * volatile tmpname
= NULL
;
415 int volatile dostat
, term_infd
;
417 struct mimepart
* volatile np
;
418 FILE * volatile ibuf
= NULL
, * volatile pbuf
= obuf
,
419 * volatile qbuf
= obuf
, *origobuf
= obuf
;
420 enum conversion
volatile convert
;
421 sighandler_type
volatile oldpipe
= SIG_DFL
;
424 n_UNINIT(term_infd
, 0);
427 quoteflt_reset(qf
, obuf
);
429 #if 0 /* TODO PART_INFO should be displayed here!! search PART_INFO */
430 if(ip
->m_mimecontent
!= MIME_DISCARD
&& level
> 0)
431 _print_part_info(obuf
, ip
, doitp
, level
, qf
, stats
);
434 if (ip
->m_mimecontent
== MIME_PKCS7
) {
435 if (ip
->m_multipart
&&
436 action
!= SEND_MBOX
&& action
!= SEND_RFC822
&& action
!= SEND_SHOW
)
441 if (level
== 0 && action
!= SEND_TODISP_PARTS
) {
443 if (!n_ignore_is_ign(doitp
, "status", 6))
445 if (!n_ignore_is_ign(doitp
, "x-status", 8))
451 if ((ibuf
= setinput(&mb
, (struct message
*)ip
, NEED_BODY
)) == NULL
) {
456 if(action
== SEND_TODISP
|| action
== SEND_TODISP_ALL
||
457 action
== SEND_TODISP_PARTS
||
458 action
== SEND_QUOTE
|| action
== SEND_QUOTE_ALL
||
459 action
== SEND_TOSRCH
)
464 if (ip
->m_mimecontent
== MIME_DISCARD
)
467 if (!(ip
->m_flag
& MNOFROM
))
468 while (cnt
&& (c
= getc(ibuf
)) != EOF
) {
473 convert
= (dostat
& 4) ? CONV_FROMHDR
: CONV_NONE
;
475 /* Work the headers */
477 struct n_string hl
, *hlp
;
479 bool_t hstop
/*see below, hany*/;
481 hlp
= n_string_creat_auto(&hl
); /* TODO pool [or, v15: filter!] */
482 /* Reserve three lines, still not enough for references and DKIM etc. */
483 hlp
= n_string_reserve(hlp
, n_MAX(MIME_LINELEN
, MIME_LINELEN_RFC2047
) * 3);
485 for(hstop
= /*see below hany =*/ FAL0
; !hstop
;){
489 if(fgetline(linedat
, linesize
, &cnt
, &linelen
, ibuf
, 0) == NULL
)
492 if (linelen
== 0 || (cp
= *linedat
)[0] == '\n')
493 /* If line is blank, we've reached end of headers */
495 if(cp
[linelen
- 1] == '\n'){
496 cp
[--linelen
] = '\0';
501 /* Are we in a header? */
504 fseek(ibuf
, -(off_t
)(lcnt
- cnt
), SEEK_CUR
);
510 /* Pick up the header field if we have one */
511 while((c
= *cp
) != ':' && !spacechar(c
) && c
!= '\0')
514 if(!spacechar(c
) || c
== '\0')
519 /* That won't work with MIME when saving etc., before v15 */
521 /* XXX This disturbs, and may happen multiple times, and we
522 * XXX cannot heal it for multipart except for display <v15 */
523 n_err(_("Malformed message: headers and body not separated "
524 "(with empty line)\n"));
527 fseek(ibuf
, -(off_t
)(lcnt
- cnt
), SEEK_CUR
);
535 hlp
= n_string_push_buf(hlp
, cp
, (ui32_t
)linelen
);
536 hlp
= n_string_push_c(hlp
, '\n');
538 bool_t lblank
, isblank
;
540 for(lblank
= FAL0
, lcnt
= 0; lcnt
< linelen
; ++cp
, ++lcnt
){
544 if(!(isblank
= blankchar(c8
)) || !lblank
){
545 if((lblank
= isblank
))
547 hlp
= n_string_push_c(hlp
, c8
);
555 /* If it is an ignored header, skip it */
556 *(cp
= memchr(hlp
->s_dat
, ':', hlp
->s_len
)) = '\0';
560 i
= PTR2SIZE(cp
- hlp
->s_dat
);
561 if((doitp
!= NULL
&& n_ignore_is_ign(doitp
, hlp
->s_dat
, i
)) ||
562 !asccasecmp(hlp
->s_dat
, "status") ||
563 !asccasecmp(hlp
->s_dat
, "x-status") ||
564 (action
== SEND_MBOX
&&
565 (!asccasecmp(hlp
->s_dat
, "content-length") ||
566 !asccasecmp(hlp
->s_dat
, "lines")) &&
567 !ok_blook(keep_content_length
)))
573 if(n_COLOUR_IS_ACTIVE())
574 n_colour_put(n_COLOUR_ID_VIEW_HEADER
, hlp
->s_dat
);
577 _out(hlp
->s_dat
, hlp
->s_len
, obuf
, convert
, action
, qf
, stats
, NULL
,NULL
);
579 if(n_COLOUR_IS_ACTIVE())
584 /*see below hany = TRU1;*/
587 hlp
= n_string_trunc(hlp
, 0);
593 /* We've reached end of headers, so eventually force out status: field and
594 * note that we are no longer in header fields */
596 statusput(zmp
, obuf
, qf
, stats
);
597 /*see below hany = TRU1;*/
600 xstatusput(zmp
, obuf
, qf
, stats
);
601 /*see below hany = TRU1;*/
603 if(/* TODO PART_INFO hany && */ doitp
!= n_IGNORE_ALL
)
604 _out("\n", 1, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
615 memset(&mh
, 0, sizeof mh
);
617 switch (ip
->m_mimecontent
) {
620 case SEND_TODISP_PARTS
:
623 case SEND_TODISP_ALL
:
626 if (ok_blook(rfc822_body_from_
)) {
627 if (qf
->qf_pfix_len
> 0) {
628 size_t i
= fwrite(qf
->qf_pfix
, sizeof *qf
->qf_pfix
,
629 qf
->qf_pfix_len
, obuf
);
630 if (i
== qf
->qf_pfix_len
&& stats
!= NULL
)
633 put_from_(obuf
, ip
->m_multipart
, stats
);
641 if (ok_blook(rfc822_body_from_
))
642 put_from_(obuf
, ip
->m_multipart
, stats
);
652 case MIME_TEXT_PLAIN
:
655 case SEND_TODISP_ALL
:
656 case SEND_TODISP_PARTS
:
659 switch (n_mimetype_handler(&mh
, ip
, action
)) {
661 if(action
!= SEND_TODISP_PARTS
)
664 case MIME_HDL_MSG
:/* TODO these should be part of partinfo! */
665 _out(mh
.mh_msg
.s
, mh
.mh_msg
.l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
,
667 /* We would print this as plain text, so better force going home */
670 if(action
== SEND_TODISP_PARTS
&&
671 (mh
.mh_flags
& MIME_HDL_COPIOUSOUTPUT
))
676 if(action
== SEND_TODISP_PARTS
)
688 if (action
!= SEND_DECRYPT
)
692 if (action
!= SEND_MBOX
&& action
!= SEND_RFC822
&&
693 action
!= SEND_SHOW
&& ip
->m_multipart
!= NULL
)
699 case SEND_TODISP_ALL
:
700 case SEND_TODISP_PARTS
:
703 switch (n_mimetype_handler(&mh
, ip
, action
)) {
706 if (action
!= SEND_TODISP
&& action
!= SEND_TODISP_ALL
&&
710 case MIME_HDL_MSG
:/* TODO these should be part of partinfo! */
711 _out(mh
.mh_msg
.s
, mh
.mh_msg
.l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
,
713 /* We would print this as plain text, so better force going home */
716 if(action
== SEND_TODISP_PARTS
){
717 if(mh
.mh_flags
& MIME_HDL_COPIOUSOUTPUT
)
720 _print_part_info(obuf
, ip
, doitp
, level
, qf
, stats
);
721 if(!getapproval(_("Run MIME handler for this part?"), FAL0
))
728 if(action
== SEND_TODISP_PARTS
)
743 case MIME_ALTERNATIVE
:
744 if ((action
== SEND_TODISP
|| action
== SEND_QUOTE
) &&
745 !ok_blook(print_alternatives
)) {
746 /* XXX This (a) should not remain (b) should be own fun
747 * TODO (despite the fact that v15 will do this completely differently
748 * TODO by having an action-specific "manager" that will traverse the
749 * TODO parsed MIME tree and decide for each part whether it'll be
750 * TODO displayed or not *before* we walk the tree for doing action */
752 struct mpstack
*outer
;
754 } outermost
, * volatile curr
, * volatile mpsp
;
755 bool_t
volatile neednl
, hadpart
;
756 struct n_sigman smalter
;
758 (curr
= &outermost
)->outer
= NULL
;
760 neednl
= hadpart
= FAL0
;
762 n_SIGMAN_ENTER_SWITCH(&smalter
, n_SIGMAN_ALL
) {
770 for (np
= ip
->m_multipart
;;) {
772 for (; np
!= NULL
; np
= np
->m_nextpart
) {
773 if (action
!= SEND_QUOTE
&& np
->m_ct_type_plain
!= NULL
) {
775 _out("\n", 1, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
,
777 _print_part_info(obuf
, np
, doitp
, level
, qf
, stats
);
781 switch (np
->m_mimecontent
) {
782 case MIME_ALTERNATIVE
:
788 mpsp
= salloc(sizeof *mpsp
);
790 mpsp
->mp
= np
->m_multipart
;
799 switch (n_mimetype_handler(&mh
, np
, action
)) {
801 mh
.mh_flags
= MIME_HDL_NULL
;
802 continue; /* break; break; */
804 if (!ok_blook(mime_alternative_favour_rich
)) {/* TODO */
805 struct mimepart
*x
= np
;
807 while ((x
= x
->m_nextpart
) != NULL
) {
808 struct mime_handler mhx
;
810 if (x
->m_mimecontent
== MIME_TEXT_PLAIN
||
811 n_mimetype_handler(&mhx
, x
, action
) ==
816 continue; /* break; break; */
824 case MIME_TEXT_PLAIN
:
827 if (ok_blook(mime_alternative_favour_rich
)) { /* TODO */
828 struct mimepart
*x
= np
;
830 /* TODO twice TODO, we should dive into /related and
831 * TODO check whether that has rich parts! */
832 while ((x
= x
->m_nextpart
) != NULL
) {
833 struct mime_handler mhx
;
835 switch (n_mimetype_handler(&mhx
, x
, action
)) {
844 continue; /* break; break; */
848 if (action
== SEND_QUOTE
&& hadpart
) {
849 struct quoteflt
*dummy
= quoteflt_dummy();
850 _out("\n", 1, obuf
, CONV_NONE
, SEND_MBOX
, dummy
, stats
,
852 quoteflt_flush(dummy
);
856 rv
= sendpart(zmp
, np
, obuf
, doitp
, qf
, action
,
857 linedat
, linesize
, stats
, level
+ 1);
858 quoteflt_reset(qf
, origobuf
);
861 curr
= &outermost
; /* Cause overall loop termination */
870 np
= curr
->mp
->m_nextpart
;
873 n_sigman_leave(&smalter
, n_SIGMAN_VIPSIGS_NTTYOUT
);
884 case SEND_TODISP_ALL
:
885 case SEND_TODISP_PARTS
:
893 if ((action
== SEND_TODISP
|| action
== SEND_TODISP_ALL
) &&
894 ip
->m_multipart
!= NULL
&&
895 ip
->m_multipart
->m_mimecontent
== MIME_DISCARD
&&
896 ip
->m_multipart
->m_nextpart
== NULL
) {
897 char const *x
= _("[Missing multipart boundary - use `show' "
898 "to display the raw message]\n");
899 _out(x
, strlen(x
), obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
,
903 for (np
= ip
->m_multipart
; np
!= NULL
; np
= np
->m_nextpart
) {
904 bool_t
volatile ispipe
;
906 if (np
->m_mimecontent
== MIME_DISCARD
&& action
!= SEND_DECRYPT
)
912 if (np
->m_partstring
&&
913 np
->m_partstring
[0] == '1' && np
->m_partstring
[1] == '\0')
916 /* TODO Always open multipart on /dev/null, it's a hack to be
917 * TODO able to dive into that structure, and still better
918 * TODO than asking the user for something stupid.
919 * TODO oh, wait, we did ask for a filename for this MIME mail,
920 * TODO and that outer container is useless anyway ;-P */
921 if (np
->m_multipart
!= NULL
) {
922 if ((obuf
= Fopen(n_path_devnull
, "w")) == NULL
)
924 } else if ((obuf
= newfile(np
, &ispipe
)) == NULL
)
928 if (sigsetjmp(_send_pipejmp
, 1)) {
932 oldpipe
= safe_signal(SIGPIPE
, &_send_onpipe
);
935 case SEND_TODISP_ALL
:
936 if (ip
->m_mimecontent
!= MIME_ALTERNATIVE
&&
937 ip
->m_mimecontent
!= MIME_RELATED
&&
938 ip
->m_mimecontent
!= MIME_DIGEST
&&
939 ip
->m_mimecontent
!= MIME_SIGNED
&&
940 ip
->m_mimecontent
!= MIME_ENCRYPTED
&&
941 ip
->m_mimecontent
!= MIME_MULTI
)
943 _print_part_info(obuf
, np
, doitp
, level
, qf
, stats
);
945 case SEND_TODISP_PARTS
:
958 if ((action
== SEND_QUOTE
|| action
== SEND_QUOTE_ALL
) &&
959 np
->m_multipart
== NULL
&& ip
->m_parent
!= NULL
) {
960 struct quoteflt
*dummy
= quoteflt_dummy();
961 _out("\n", 1, obuf
, CONV_NONE
, SEND_MBOX
, dummy
, stats
,
963 quoteflt_flush(dummy
);
965 if (sendpart(zmp
, np
, obuf
, doitp
, qf
, action
, linedat
, linesize
,
968 quoteflt_reset(qf
, origobuf
);
970 if (action
== SEND_QUOTE
) {
971 if (ip
->m_mimecontent
!= MIME_RELATED
)
974 if (action
== SEND_TOFILE
&& obuf
!= origobuf
) {
979 safe_signal(SIGPIPE
, SIG_IGN
);
981 safe_signal(SIGPIPE
, oldpipe
);
994 /* Copy out message body */
995 if (doitp
== n_IGNORE_ALL
&& level
== 0) /* skip final blank line */
997 switch (ip
->m_mime_enc
) {
1001 convert
= CONV_NONE
;
1004 convert
= CONV_FROMQP
;
1007 switch (ip
->m_mimecontent
) {
1009 case MIME_TEXT_PLAIN
:
1010 case MIME_TEXT_HTML
:
1011 convert
= CONV_FROMB64_T
;
1014 switch (mh
.mh_flags
& MIME_HDL_TYPE_MASK
) {
1017 convert
= CONV_FROMB64_T
;
1020 convert
= CONV_FROMB64
;
1027 convert
= CONV_NONE
;
1030 /* TODO Unless we have filters, ensure iconvd==-1 so that mime.c:fwrite_td()
1031 * TODO cannot mess things up misusing outrest as line buffer */
1033 if (iconvd
!= (iconv_t
)-1) {
1034 n_iconv_close(iconvd
);
1035 iconvd
= (iconv_t
)-1;
1039 if (action
== SEND_DECRYPT
|| action
== SEND_MBOX
||
1040 action
== SEND_RFC822
|| action
== SEND_SHOW
)
1041 convert
= CONV_NONE
;
1043 else if ((action
== SEND_TODISP
|| action
== SEND_TODISP_ALL
||
1044 action
== SEND_TODISP_PARTS
||
1045 action
== SEND_QUOTE
|| action
== SEND_QUOTE_ALL
||
1046 action
== SEND_TOSRCH
|| action
== SEND_TOFILE
) &&
1047 (ip
->m_mimecontent
== MIME_TEXT_PLAIN
||
1048 ip
->m_mimecontent
== MIME_TEXT_HTML
||
1049 ip
->m_mimecontent
== MIME_TEXT
||
1050 (mh
.mh_flags
& MIME_HDL_TYPE_MASK
) == MIME_HDL_TEXT
||
1051 (mh
.mh_flags
& MIME_HDL_TYPE_MASK
) == MIME_HDL_PTF
)) {
1054 tcs
= ok_vlook(ttycharset
);
1055 if (asccasecmp(tcs
, ip
->m_charset
) &&
1056 asccasecmp(ok_vlook(charset_7bit
), ip
->m_charset
)) {
1057 iconvd
= n_iconv_open(tcs
, ip
->m_charset
);
1058 if (iconvd
== (iconv_t
)-1 && n_err_no
== n_ERR_INVAL
) {
1059 n_err(_("Cannot convert from %s to %s\n"), ip
->m_charset
, tcs
);
1060 /*rv = 1; goto jleave;*/
1066 switch (mh
.mh_flags
& MIME_HDL_TYPE_MASK
) {
1068 if(!(mh
.mh_flags
& MIME_HDL_COPIOUSOUTPUT
) &&
1069 action
!= SEND_TODISP_PARTS
)
1076 term_infd
= n_CHILD_FD_PASS
;
1077 if (mh
.mh_flags
& (MIME_HDL_TMPF
| MIME_HDL_NEEDSTERM
)) {
1080 of
= OF_RDWR
| OF_REGISTER
;
1081 if (!(mh
.mh_flags
& MIME_HDL_TMPF
)) {
1083 mh
.mh_flags
|= MIME_HDL_TMPF_FILL
;
1085 } else if (mh
.mh_flags
& MIME_HDL_TMPF_UNLINK
)
1086 of
|= OF_REGISTER_UNLINK
;
1088 if ((pbuf
= Ftmp((mh
.mh_flags
& MIME_HDL_TMPF
? &cp
: NULL
),
1089 (mh
.mh_flags
& MIME_HDL_TMPF_FILL
? "mimehdlfill" : "mimehdl"),
1093 if (mh
.mh_flags
& MIME_HDL_TMPF
) {
1094 tmpname
= savestr(cp
);
1098 if (mh
.mh_flags
& MIME_HDL_TMPF_FILL
) {
1100 term_infd
= fileno(pbuf
);
1106 pbuf
= _pipefile(&mh
, ip
, n_UNVOLATILE(&qbuf
), tmpname
, term_infd
);
1112 } else if ((mh
.mh_flags
& MIME_HDL_NEEDSTERM
) && pbuf
== (FILE*)-1) {
1117 action
= SEND_TOPIPE
;
1119 oldpipe
= safe_signal(SIGPIPE
, &_send_onpipe
);
1120 if (sigsetjmp(_send_pipejmp
, 1))
1127 mh
.mh_flags
= MIME_HDL_NULL
;
1134 bool_t
volatile eof
;
1135 ui32_t save_qf_pfix_len
= qf
->qf_pfix_len
;
1136 ui64_t
*save_stats
= stats
;
1138 if (pbuf
!= origobuf
) {
1139 qf
->qf_pfix_len
= 0; /* XXX legacy (remove filter instead) */
1143 outrest
.s
= inrest
.s
= NULL
;
1144 outrest
.l
= inrest
.l
= 0;
1148 __sendp_opipe
= safe_signal(SIGPIPE
, &__sendp_onsig
);
1149 if (sigsetjmp(__sendp_actjmp
, 1)) {
1150 n_pstate
&= ~n_PS_BASE64_STRIP_CR
;/* (but protected by outer sigman) */
1151 if (outrest
.s
!= NULL
)
1153 if (inrest
.s
!= NULL
)
1156 if (iconvd
!= (iconv_t
)-1)
1157 n_iconv_close(iconvd
);
1159 safe_signal(SIGPIPE
, __sendp_opipe
);
1160 n_raise(__sendp_sig
);
1164 quoteflt_reset(qf
, pbuf
);
1166 n_pstate
|= n_PS_BASE64_STRIP_CR
;
1167 while (!eof
&& fgetline(linedat
, linesize
, &cnt
, &linelen
, ibuf
, 0)) {
1169 if (_out(*linedat
, linelen
, pbuf
, convert
, action
, qf
, stats
, &outrest
,
1170 (action
& _TD_EOF
? NULL
: &inrest
)) < 0 || ferror(pbuf
)) {
1171 rv
= -1; /* XXX Should bail away?! */
1175 if(eof
<= FAL0
&& rv
>= 0 && (outrest
.l
!= 0 || inrest
.l
!= 0)){
1177 if(eof
|| inrest
.l
== 0)
1179 eof
= eof
? TRU1
: TRUM1
;
1182 n_pstate
&= ~n_PS_BASE64_STRIP_CR
;
1185 /* TODO HACK: when sending to the display we yet get fooled if a message
1186 * TODO doesn't end in a newline, because of our input/output 1:1.
1187 * TODO This should be handled automatically by a display filter, then */
1188 if(rv
>= 0 && !qf
->qf_nl_last
&&
1189 (action
== SEND_TODISP
|| action
== SEND_TODISP_ALL
))
1190 rv
= quoteflt_push(qf
, "\n", 1);
1194 if (rv
>= 0 && (mh
.mh_flags
& MIME_HDL_TMPF_FILL
)) {
1195 mh
.mh_flags
&= ~MIME_HDL_TMPF_FILL
;
1197 really_rewind(pbuf
);
1198 /* Don't Fclose() the Ftmp() thing due to OF_REGISTER_UNLINK++ */
1199 goto jpipe_for_real
;
1203 safe_signal(SIGPIPE
, __sendp_opipe
);
1205 if (outrest
.s
!= NULL
)
1207 if (inrest
.s
!= NULL
)
1210 if (pbuf
!= origobuf
) {
1211 qf
->qf_pfix_len
= save_qf_pfix_len
;
1218 safe_signal(SIGPIPE
, SIG_IGN
);
1219 Pclose(pbuf
, !(mh
.mh_flags
& MIME_HDL_ASYNC
));
1220 safe_signal(SIGPIPE
, oldpipe
);
1221 if (rv
>= 0 && qbuf
!= NULL
&& qbuf
!= obuf
)
1222 pipecpy(qbuf
, obuf
, origobuf
, qf
, stats
);
1225 if (iconvd
!= (iconv_t
)-1)
1226 n_iconv_close(iconvd
);
1234 newfile(struct mimepart
*ip
, bool_t
volatile *ispipe
)
1244 if (f
!= NULL
&& f
!= (char*)-1) {
1247 makeprint(&in
, &out
);
1248 out
.l
= delctrl(out
.s
, out
.l
);
1249 f
= savestrbuf(out
.s
, out
.l
);
1253 /* In interactive mode, let user perform all kind of expansions as desired,
1254 * and offer |SHELL-SPEC pipe targets, too */
1255 if (n_psonce
& n_PSO_INTERACTIVE
) {
1257 struct n_string shou
, *shoup
;
1260 shoup
= n_string_creat_auto(&shou
);
1262 /* TODO Generic function which asks for filename.
1263 * TODO If the current part is the first textpart the target
1264 * TODO is implicit from outer `write' etc! */
1265 /* I18N: Filename input prompt with file type indication */
1266 str_concat_csvl(&prompt
, _("Enter filename for part "),
1267 (ip
->m_partstring
!= NULL
? ip
->m_partstring
: n_qm
),
1268 " (", ip
->m_ct_type_plain
, "): ", NULL
);
1270 f2
= n_go_input_cp(n_GO_INPUT_CTX_DEFAULT
| n_GO_INPUT_HIST_ADD
,
1271 prompt
.s
, ((f
!= (char*)-1 && f
!= NULL
)
1272 ? n_shexp_quote_cp(f
, FAL0
) : NULL
));
1274 in
.s
= n_UNCONST(f2
);
1276 if((n_shexp_parse_token((n_SHEXP_PARSE_TRUNC
|
1277 n_SHEXP_PARSE_TRIM_SPACE
| n_SHEXP_PARSE_TRIM_IFSSPACE
|
1278 n_SHEXP_PARSE_LOG
| n_SHEXP_PARSE_IGNORE_EMPTY
),
1280 ) & (n_SHEXP_STATE_STOP
|
1281 n_SHEXP_STATE_OUTPUT
| n_SHEXP_STATE_ERR_MASK
)
1282 ) != (n_SHEXP_STATE_STOP
| n_SHEXP_STATE_OUTPUT
))
1284 f2
= n_string_cp(shoup
);
1286 if (f2
== NULL
|| *f2
== '\0') {
1287 if (n_poption
& n_PO_D_V
)
1288 n_err(_("... skipping this\n"));
1289 n_string_gut(shoup
);
1295 /* Pipes are expanded by the shell */
1297 else if ((f3
= fexpand(f2
, FEXP_LOCAL
| FEXP_NVAR
)) == NULL
)
1298 /* (Error message written by fexpand()) */
1303 n_string_gut(shoup
);
1306 if (f
== NULL
|| f
== (char*)-1 || *f
== '\0')
1308 else if (n_psonce
& n_PSO_INTERACTIVE
) {
1310 fp
= Popen(&f
[1], "w", ok_vlook(SHELL
), NULL
, 1);
1311 if (!(*ispipe
= (fp
!= NULL
)))
1313 } else if ((fp
= Fopen(f
, "w")) == NULL
)
1314 n_err(_("Cannot open %s\n"), n_shexp_quote_cp(f
, FAL0
));
1316 /* Be very picky in non-interactive mode: actively disallow pipes,
1317 * prevent directory separators, and any filename member that would
1318 * become expanded by the shell if the name would be echo(1)ed */
1319 if(anyof(f
, "/" n_SHEXP_MAGIC_PATH_CHARS
)){
1322 for(out
.s
= salloc((strlen(f
) * 3) +1), out
.l
= 0; (c
= *f
++) != '\0';)
1323 if(strchr("/" n_SHEXP_MAGIC_PATH_CHARS
, c
)){
1324 out
.s
[out
.l
++] = '%';
1325 n_c_to_hex_base16(&out
.s
[out
.l
], c
);
1329 out
.s
[out
.l
] = '\0';
1333 /* Avoid overwriting of existing files */
1334 while((fp
= Fopen(f
, "wx")) == NULL
){
1337 if((e
= n_err_no
) != n_ERR_EXIST
){
1338 n_err(_("Cannot open %s: %s\n"),
1339 n_shexp_quote_cp(f
, FAL0
), n_err_to_doc(e
));
1343 if(ip
->m_partstring
!= NULL
)
1344 f
= savecatsep(f
, '#', ip
->m_partstring
);
1346 f
= savecat(f
, "#.");
1355 pipecpy(FILE *pipebuf
, FILE *outbuf
, FILE *origobuf
, struct quoteflt
*qf
,
1358 char *line
= NULL
; /* TODO line pool */
1359 size_t linesize
= 0, linelen
, cnt
;
1365 cnt
= (size_t)fsize(pipebuf
);
1368 quoteflt_reset(qf
, outbuf
);
1369 while (fgetline(&line
, &linesize
, &cnt
, &linelen
, pipebuf
, 0) != NULL
) {
1370 if ((sz
= quoteflt_push(qf
, line
, linelen
)) < 0)
1374 if ((sz
= quoteflt_flush(qf
)) > 0)
1379 if (all_sz
> 0 && outbuf
== origobuf
&& stats
!= NULL
)
1386 statusput(const struct message
*mp
, FILE *obuf
, struct quoteflt
*qf
,
1389 char statout
[3], *cp
= statout
;
1392 if (mp
->m_flag
& MREAD
)
1394 if (!(mp
->m_flag
& MNEW
))
1398 int i
= fprintf(obuf
, "%.*sStatus: %s\n", (int)qf
->qf_pfix_len
,
1399 (qf
->qf_pfix_len
> 0 ? qf
->qf_pfix
: 0), statout
);
1400 if (i
> 0 && stats
!= NULL
)
1407 xstatusput(const struct message
*mp
, FILE *obuf
, struct quoteflt
*qf
,
1411 char *xp
= xstatout
;
1414 if (mp
->m_flag
& MFLAGGED
)
1416 if (mp
->m_flag
& MANSWERED
)
1418 if (mp
->m_flag
& MDRAFTED
)
1422 int i
= fprintf(obuf
, "%.*sX-Status: %s\n", (int)qf
->qf_pfix_len
,
1423 (qf
->qf_pfix_len
> 0 ? qf
->qf_pfix
: 0), xstatout
);
1424 if (i
> 0 && stats
!= NULL
)
1431 put_from_(FILE *fp
, struct mimepart
*ip
, ui64_t
*stats
)
1433 char const *froma
, *date
, *nl
;
1437 if (ip
!= NULL
&& ip
->m_from
!= NULL
) {
1439 date
= fakedate(ip
->m_time
);
1442 froma
= ok_vlook(LOGNAME
);
1443 date
= time_current
.tc_ctime
;
1448 if(n_COLOUR_IS_ACTIVE())
1449 n_colour_put(n_COLOUR_ID_VIEW_FROM_
, NULL
);
1451 i
= fprintf(fp
, "From %s %s%s", froma
, date
, nl
);
1453 if(n_COLOUR_IS_ACTIVE())
1456 if (i
> 0 && stats
!= NULL
)
1462 sendmp(struct message
*mp
, FILE *obuf
, struct n_ignore
const *doitp
,
1463 char const *prefix
, enum sendaction action
, ui64_t
*stats
)
1465 struct n_sigman linedat_protect
;
1468 enum mime_parse_flags mpf
;
1469 struct mimepart
*ip
;
1470 size_t linesize
, cnt
, sz
, i
;
1475 time_current_update(&time_current
, TRU1
);
1479 quoteflt_init(&qf
, prefix
);
1481 n_SIGMAN_ENTER_SWITCH(&linedat_protect
, n_SIGMAN_ALL
){
1488 if (mp
== dot
&& action
!= SEND_TOSRCH
)
1489 n_pstate
|= n_PS_DID_PRINT_DOT
;
1493 /* First line is the From_ line, so no headers there to worry about */
1494 if ((ibuf
= setinput(&mb
, mp
, NEED_BODY
)) == NULL
)
1501 char const *cpre
= n_empty
, *csuf
= n_empty
;
1504 if(n_COLOUR_IS_ACTIVE()){
1505 struct n_colour_pen
*cpen
;
1506 struct str
const *sp
;
1508 cpen
= n_colour_pen_create(n_COLOUR_ID_VIEW_FROM_
,NULL
);
1509 if((sp
= n_colour_pen_to_str(cpen
)) != NULL
){
1511 sp
= n_colour_reset_to_str();
1518 nozap
= (doitp
!= n_IGNORE_ALL
&& doitp
!= n_IGNORE_FWD
&&
1519 action
!= SEND_RFC822
&&
1520 !n_ignore_is_ign(doitp
, "from_", sizeof("from_") -1));
1521 if (mp
->m_flag
& MNOFROM
) {
1523 sz
= fprintf(obuf
, "%s%.*sFrom %s %s%s\n",
1524 cpre
, (int)qf
.qf_pfix_len
,
1525 (qf
.qf_pfix_len
!= 0 ? qf
.qf_pfix
: n_empty
), fakefrom(mp
),
1526 fakedate(mp
->m_time
), csuf
);
1528 if (qf
.qf_pfix_len
> 0) {
1529 i
= fwrite(qf
.qf_pfix
, sizeof *qf
.qf_pfix
, qf
.qf_pfix_len
, obuf
);
1530 if (i
!= qf
.qf_pfix_len
)
1537 cpre
= (char const*)0x1;
1541 while (cnt
> 0 && (c
= getc(ibuf
)) != EOF
) {
1543 if(c
== '\n' && *csuf
!= '\0'){
1544 cpre
= (char const*)0x1;
1556 if(*csuf
!= '\0' && cpre
!= (char const*)0x1 && *cpre
!= '\0')
1560 while (cnt
> 0 && (c
= getc(ibuf
)) != EOF
) {
1567 if (sz
> 0 && stats
!= NULL
)
1570 mpf
= MIME_PARSE_NONE
;
1571 if (action
!= SEND_MBOX
&& action
!= SEND_RFC822
&& action
!= SEND_SHOW
)
1572 mpf
|= MIME_PARSE_PARTS
| MIME_PARSE_DECRYPT
;
1573 if ((ip
= mime_parse_msg(mp
, mpf
)) == NULL
)
1576 rv
= sendpart(mp
, ip
, obuf
, doitp
, &qf
, action
, &linedat
, &linesize
,
1579 n_sigman_cleanup_ping(&linedat_protect
);
1581 n_pstate
&= ~n_PS_BASE64_STRIP_CR
;
1582 quoteflt_destroy(&qf
);
1586 n_sigman_leave(&linedat_protect
, n_SIGMAN_VIPSIGS_NTTYOUT
);