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 - 2018 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 n_INLINE 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
,
61 /* Simply (!) print out a LF */
62 static bool_t
a_send_out_nl(FILE *fp
, ui64_t
*stats
);
65 static void _send_onpipe(int signo
);
68 static int sendpart(struct message
*zmp
, struct mimepart
*ip
,
69 FILE *obuf
, struct n_ignore
const *doitp
,
70 struct quoteflt
*qf
, enum sendaction action
,
71 char **linedat
, size_t *linesize
,
72 ui64_t
*stats
, int level
);
74 /* Get a file for an attachment */
75 static FILE * newfile(struct mimepart
*ip
, bool_t
volatile *ispipe
);
77 static void pipecpy(FILE *pipebuf
, FILE *outbuf
, FILE *origobuf
,
78 struct quoteflt
*qf
, ui64_t
*stats
);
80 /* Output a reasonable looking status field */
81 static void statusput(const struct message
*mp
, FILE *obuf
,
82 struct quoteflt
*qf
, ui64_t
*stats
);
83 static void xstatusput(const struct message
*mp
, FILE *obuf
,
84 struct quoteflt
*qf
, ui64_t
*stats
);
86 static void put_from_(FILE *fp
, struct mimepart
*ip
, ui64_t
*stats
);
89 _print_part_info(FILE *obuf
, struct mimepart
const *mpp
, /* TODO strtofmt.. */
90 struct n_ignore
const *doitp
, int level
, struct quoteflt
*qf
, ui64_t
*stats
)
94 bool_t want_ct
, needsep
;
95 struct str
const *cpre
, *csuf
;
101 if(n_COLOUR_IS_ACTIVE()){
102 struct n_colour_pen
*cpen
;
104 cpen
= n_colour_pen_create(n_COLOUR_ID_VIEW_PARTINFO
, NULL
);
105 if((cpre
= n_colour_pen_to_str(cpen
)) != NULL
)
106 csuf
= n_colour_reset_to_str();
110 /* Take care of "99.99", i.e., 5 */
111 if ((cp
= mpp
->m_partstring
) == NULL
|| cp
[0] == '\0')
113 if (level
|| (cp
[0] != '1' && cp
[1] == '\0') || (cp
[0] == '1' && /* TODO */
114 cp
[1] == '.' && cp
[2] != '1')) /* TODO code should not look like so */
115 _out("\n", 1, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
117 /* Part id, content-type, encoding, charset */
119 _out(cpre
->s
, cpre
->l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
120 _out("[-- #", 5, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
121 _out(cp
, strlen(cp
), obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
123 to
.l
= snprintf(buf
, sizeof buf
, " %" PRIuZ
"/%" PRIuZ
" ",
124 (uiz_t
)mpp
->m_lines
, (uiz_t
)mpp
->m_size
);
125 _out(buf
, to
.l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
129 if((cp
= mpp
->m_ct_type_usr_ovwr
) != NULL
){
130 _out("+", 1, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
132 }else if((want_ct
= n_ignore_is_ign(doitp
,
133 "content-type", sizeof("content-type") -1)))
134 cp
= mpp
->m_ct_type_plain
;
136 (to
.l
= strlen(cp
)) > 30 && is_asccaseprefix("application/", cp
)) {
137 size_t const al
= sizeof("appl../") -1, fl
= sizeof("application/") -1;
138 size_t i
= to
.l
- fl
;
139 char *x
= salloc(al
+ i
+1);
141 memcpy(x
, "appl../", al
);
142 memcpy(x
+ al
, cp
+ fl
, i
+1);
147 _out(cp
, to
.l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
151 if(mpp
->m_multipart
== NULL
/* TODO */ && (cp
= mpp
->m_ct_enc
) != NULL
&&
152 (!asccasecmp(cp
, "7bit") ||
153 n_ignore_is_ign(doitp
, "content-transfer-encoding",
154 sizeof("content-transfer-encoding") -1))){
156 _out(", ", 2, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
157 if (to
.l
> 25 && !asccasecmp(cp
, "quoted-printable"))
159 _out(cp
, strlen(cp
), obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
163 if (want_ct
&& mpp
->m_multipart
== NULL
/* TODO */ &&
164 (cp
= mpp
->m_charset
) != NULL
) {
166 _out(", ", 2, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
167 _out(cp
, strlen(cp
), obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
171 _out(&" --]"[needsep
], 4 - needsep
,
172 obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
174 _out(csuf
->s
, csuf
->l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
175 _out("\n", 1, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
178 if (mpp
->m_content_info
& CI_MIME_ERRORS
) {
180 _out(cpre
->s
, cpre
->l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
,
182 _out("[-- ", 4, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
184 ti
.l
= strlen(ti
.s
= n_UNCONST(_("Defective MIME structure")));
186 to
.l
= delctrl(to
.s
, to
.l
);
187 _out(to
.s
, to
.l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
190 _out(" --]", 4, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
192 _out(csuf
->s
, csuf
->l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
,
194 _out("\n", 1, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
197 /* Content-Description */
198 if (n_ignore_is_ign(doitp
, "content-description", 19) &&
199 (cp
= mpp
->m_content_description
) != NULL
&& *cp
!= '\0') {
201 _out(cpre
->s
, cpre
->l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
,
203 _out("[-- ", 4, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
205 ti
.l
= strlen(ti
.s
= n_UNCONST(mpp
->m_content_description
));
206 mime_fromhdr(&ti
, &to
, TD_ISPR
| TD_ICONV
);
207 _out(to
.s
, to
.l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
210 _out(" --]", 4, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
212 _out(csuf
->s
, csuf
->l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
,
214 _out("\n", 1, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
218 if (n_ignore_is_ign(doitp
, "content-disposition", 19) &&
219 mpp
->m_filename
!= NULL
&& *mpp
->m_filename
!= '\0') {
221 _out(cpre
->s
, cpre
->l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
,
223 _out("[-- ", 4, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
225 ti
.l
= strlen(ti
.s
= mpp
->m_filename
);
227 to
.l
= delctrl(to
.s
, to
.l
);
228 _out(to
.s
, to
.l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
231 _out(" --]", 4, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
233 _out(csuf
->s
, csuf
->l
, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
,
235 _out("\n", 1, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
, NULL
);
241 _pipefile(struct mime_handler
*mhp
, struct mimepart
const *mpp
, FILE **qbuf
,
242 char const *tmpname
, int term_infd
)
245 char const *env_addon
[9 +8/*v15*/], *cp
, *sh
;
252 if (mhp
->mh_flags
& MIME_HDL_ISQUOTE
) {
253 if ((*qbuf
= Ftmp(NULL
, "sendp", OF_RDWR
| OF_UNLINK
| OF_REGISTER
)) ==
255 n_perr(_("tmpfile"), 0);
260 if ((mhp
->mh_flags
& MIME_HDL_TYPE_MASK
) == MIME_HDL_PTF
) {
261 union {int (*ptf
)(void); char const *sh
;} u
;
264 if (*qbuf
!= n_stdout
) /* xxx never? v15: it'll be a filter anyway */
268 if((rbuf
= Popen((char*)-1, "W", u
.sh
, NULL
, fileno(*qbuf
))) == NULL
)
276 if (mpp
== NULL
|| (cp
= mpp
->m_filename
) == NULL
)
278 env_addon
[i
++] = str_concat_csvl(&s
, n_PIPEENV_FILENAME
, "=", cp
, NULL
)->s
;
279 env_addon
[i
++] = str_concat_csvl(&s
, "NAIL_FILENAME", "=", cp
, NULL
)->s
;/*v15*/
281 /* MAILX_FILENAME_GENERATED *//* TODO pathconf NAME_MAX; but user can create
282 * TODO a file wherever he wants! *Do* create a zero-size temporary file
283 * TODO and give *that* path as MAILX_FILENAME_TEMPORARY, clean it up once
284 * TODO the pipe returns? Like this we *can* verify path/name issues! */
285 cp
= n_random_create_cp(n_MIN(NAME_MAX
/ 4, 16), NULL
);
286 env_addon
[i
++] = str_concat_csvl(&s
, n_PIPEENV_FILENAME_GENERATED
, "=", cp
,
288 env_addon
[i
++] = str_concat_csvl(&s
, "NAIL_FILENAME_GENERATED", "=", cp
,/*v15*/
291 /* MAILX_CONTENT{,_EVIDENCE} */
292 if (mpp
== NULL
|| (cp
= mpp
->m_ct_type_plain
) == NULL
)
294 env_addon
[i
++] = str_concat_csvl(&s
, n_PIPEENV_CONTENT
, "=", cp
, NULL
)->s
;
295 env_addon
[i
++] = str_concat_csvl(&s
, "NAIL_CONTENT", "=", cp
, NULL
)->s
;/*v15*/
297 if (mpp
!= NULL
&& mpp
->m_ct_type_usr_ovwr
!= NULL
)
298 cp
= mpp
->m_ct_type_usr_ovwr
;
299 env_addon
[i
++] = str_concat_csvl(&s
, n_PIPEENV_CONTENT_EVIDENCE
, "=", cp
,
301 env_addon
[i
++] = str_concat_csvl(&s
, "NAIL_CONTENT_EVIDENCE", "=", cp
,/* v15 */
304 /* message/external-body, access-type=url */
305 env_addon
[i
++] = str_concat_csvl(&s
, n_PIPEENV_EXTERNAL_BODY_URL
, "=",
306 ((mpp
!= NULL
&& (cp
= mpp
->m_external_body_url
) != NULL
307 ) ? cp
: n_empty
), NULL
)->s
;
309 /* MAILX_FILENAME_TEMPORARY? */
310 if (tmpname
!= NULL
) {
311 env_addon
[i
++] = str_concat_csvl(&s
,
312 n_PIPEENV_FILENAME_TEMPORARY
, "=", tmpname
, NULL
)->s
;
313 env_addon
[i
++] = str_concat_csvl(&s
,
314 "NAIL_FILENAME_TEMPORARY", "=", tmpname
, NULL
)->s
;/* v15 */
317 /* TODO we should include header information, especially From:, so
318 * TODO that same-origin can be tested for e.g. external-body!!! */
321 sh
= ok_vlook(SHELL
);
323 if (mhp
->mh_flags
& MIME_HDL_NEEDSTERM
) {
328 pid
= n_child_run(sh
, &nset
, term_infd
, n_CHILD_FD_PASS
, "-c",
329 mhp
->mh_shell_cmd
, NULL
, env_addon
, NULL
);
330 rbuf
= (pid
< 0) ? NULL
: (FILE*)-1;
332 rbuf
= Popen(mhp
->mh_shell_cmd
, "W", sh
, env_addon
,
333 (mhp
->mh_flags
& MIME_HDL_ASYNC
? -1 : fileno(*qbuf
)));
336 n_err(_("Cannot run MIME type handler: %s: %s\n"),
337 mhp
->mh_msg
, n_err_to_doc(n_err_no
));
340 if (*qbuf
!= n_stdout
)
350 _out(char const *buf
, size_t len
, FILE *fp
, enum conversion convert
, enum
351 sendaction action
, struct quoteflt
*qf
, ui64_t
*stats
, struct str
*outrest
,
358 /* TODO We should not need is_head() here, i think in v15 the actual Mailbox
359 * TODO subclass should detect such From_ cases and either reencode the part
360 * TODO in question, or perform From_ quoting as necessary!?!?!? How?!? */
364 if((action
== SEND_MBOX
|| action
== SEND_DECRYPT
) &&
365 (from_
= is_head(buf
, len
, TRU1
))){
366 if(from_
!= TRUM1
|| ok_blook(mbox_rfc4155
)){
373 flags
= ((int)action
& _TD_EOF
);
375 n
= mime_write(buf
, len
, fp
,
376 action
== SEND_MBOX
? CONV_NONE
: convert
,
377 flags
| ((action
== SEND_TODISP
|| action
== SEND_TODISP_ALL
||
378 action
== SEND_TODISP_PARTS
||
379 action
== SEND_QUOTE
|| action
== SEND_QUOTE_ALL
)
381 : (action
== SEND_TOSRCH
|| action
== SEND_TOPIPE
||
382 action
== SEND_TOFILE
)
383 ? TD_ICONV
: (action
== SEND_SHOW
? TD_ISPR
: TD_NONE
)),
384 qf
, outrest
, inrest
);
397 a_send_out_nl(FILE *fp
, ui64_t
*stats
){
402 quoteflt_reset(qf
= quoteflt_dummy(), fp
);
403 rv
= (_out("\n", 1, fp
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
) > 0);
410 _send_onpipe(int signo
)
412 NYD_X
; /* Signal handler */
414 siglongjmp(_send_pipejmp
, 1);
417 static sigjmp_buf __sendp_actjmp
; /* TODO someday.. */
418 static int __sendp_sig
; /* TODO someday.. */
419 static sighandler_type __sendp_opipe
;
421 __sendp_onsig(int sig
) /* TODO someday, we won't need it no more */
423 NYD_X
; /* Signal handler */
425 siglongjmp(__sendp_actjmp
, 1);
429 sendpart(struct message
*zmp
, struct mimepart
*ip
, FILE * volatile obuf
,
430 struct n_ignore
const *doitp
, struct quoteflt
*qf
,
431 enum sendaction
volatile action
,
432 char **linedat
, size_t *linesize
, ui64_t
* volatile stats
, int level
)
435 struct mime_handler mh
;
436 struct str outrest
, inrest
;
438 char const * volatile tmpname
= NULL
;
440 int volatile dostat
, term_infd
;
442 struct mimepart
* volatile np
;
443 FILE * volatile ibuf
= NULL
, * volatile pbuf
= obuf
,
444 * volatile qbuf
= obuf
, *origobuf
= obuf
;
445 enum conversion
volatile convert
;
446 sighandler_type
volatile oldpipe
= SIG_DFL
;
449 n_UNINIT(term_infd
, 0);
452 quoteflt_reset(qf
, obuf
);
454 #if 0 /* TODO PART_INFO should be displayed here!! search PART_INFO */
455 if(ip
->m_mimecontent
!= MIME_DISCARD
&& level
> 0)
456 _print_part_info(obuf
, ip
, doitp
, level
, qf
, stats
);
459 if (ip
->m_mimecontent
== MIME_PKCS7
) {
460 if (ip
->m_multipart
&&
461 action
!= SEND_MBOX
&& action
!= SEND_RFC822
&& action
!= SEND_SHOW
)
466 if (level
== 0 && action
!= SEND_TODISP_PARTS
) {
468 if (!n_ignore_is_ign(doitp
, "status", 6))
470 if (!n_ignore_is_ign(doitp
, "x-status", 8))
476 if ((ibuf
= setinput(&mb
, (struct message
*)ip
, NEED_BODY
)) == NULL
) {
481 if(action
== SEND_TODISP
|| action
== SEND_TODISP_ALL
||
482 action
== SEND_TODISP_PARTS
||
483 action
== SEND_QUOTE
|| action
== SEND_QUOTE_ALL
||
484 action
== SEND_TOSRCH
)
489 if (ip
->m_mimecontent
== MIME_DISCARD
)
492 if (!(ip
->m_flag
& MNOFROM
))
493 while (cnt
&& (c
= getc(ibuf
)) != EOF
) {
498 convert
= (dostat
& 4) ? CONV_FROMHDR
: CONV_NONE
;
500 /* Work the headers */
502 struct n_string hl
, *hlp
;
504 bool_t hstop
/*see below, hany*/;
506 hlp
= n_string_creat_auto(&hl
); /* TODO pool [or, v15: filter!] */
507 /* Reserve three lines, still not enough for references and DKIM etc. */
508 hlp
= n_string_reserve(hlp
, n_MAX(MIME_LINELEN
, MIME_LINELEN_RFC2047
) * 3);
510 for(hstop
= /*see below hany =*/ FAL0
; !hstop
;){
514 if(fgetline(linedat
, linesize
, &cnt
, &linelen
, ibuf
, 0) == NULL
)
517 if (linelen
== 0 || (cp
= *linedat
)[0] == '\n')
518 /* If line is blank, we've reached end of headers */
520 if(cp
[linelen
- 1] == '\n'){
521 cp
[--linelen
] = '\0';
526 /* Are we in a header? */
529 fseek(ibuf
, -(off_t
)(lcnt
- cnt
), SEEK_CUR
);
535 /* Pick up the header field if we have one */
536 while((c
= *cp
) != ':' && !spacechar(c
) && c
!= '\0')
539 if(!spacechar(c
) || c
== '\0')
544 /* That won't work with MIME when saving etc., before v15 */
546 /* XXX This disturbs, and may happen multiple times, and we
547 * XXX cannot heal it for multipart except for display <v15 */
548 n_err(_("Malformed message: headers and body not separated "
549 "(with empty line)\n"));
552 fseek(ibuf
, -(off_t
)(lcnt
- cnt
), SEEK_CUR
);
560 hlp
= n_string_push_buf(hlp
, cp
, (ui32_t
)linelen
);
561 hlp
= n_string_push_c(hlp
, '\n');
563 bool_t lblank
, isblank
;
565 for(lblank
= FAL0
, lcnt
= 0; lcnt
< linelen
; ++cp
, ++lcnt
){
569 if(!(isblank
= blankchar(c8
)) || !lblank
){
570 if((lblank
= isblank
))
572 hlp
= n_string_push_c(hlp
, c8
);
580 /* If it is an ignored header, skip it */
581 *(cp
= memchr(hlp
->s_dat
, ':', hlp
->s_len
)) = '\0';
585 i
= PTR2SIZE(cp
- hlp
->s_dat
);
586 if((doitp
!= NULL
&& n_ignore_is_ign(doitp
, hlp
->s_dat
, i
)) ||
587 !asccasecmp(hlp
->s_dat
, "status") ||
588 !asccasecmp(hlp
->s_dat
, "x-status") ||
589 (action
== SEND_MBOX
&&
590 (!asccasecmp(hlp
->s_dat
, "content-length") ||
591 !asccasecmp(hlp
->s_dat
, "lines")) &&
592 !ok_blook(keep_content_length
)))
598 if(n_COLOUR_IS_ACTIVE())
599 n_colour_put(n_COLOUR_ID_VIEW_HEADER
, hlp
->s_dat
);
602 _out(hlp
->s_dat
, hlp
->s_len
, obuf
, convert
, action
, qf
, stats
, NULL
,NULL
);
604 if(n_COLOUR_IS_ACTIVE())
608 _out("\n", sizeof("\n") -1, obuf
, convert
, action
, qf
, stats
,
610 /*see below hany = TRU1;*/
613 hlp
= n_string_trunc(hlp
, 0);
619 /* We've reached end of headers, so eventually force out status: field and
620 * note that we are no longer in header fields */
622 statusput(zmp
, obuf
, qf
, stats
);
623 /*see below hany = TRU1;*/
626 xstatusput(zmp
, obuf
, qf
, stats
);
627 /*see below hany = TRU1;*/
629 if(/* TODO PART_INFO hany && */ doitp
!= n_IGNORE_ALL
)
630 _out("\n", 1, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
, NULL
,NULL
);
641 memset(&mh
, 0, sizeof mh
);
643 switch (ip
->m_mimecontent
) {
646 case SEND_TODISP_PARTS
:
649 case SEND_TODISP_ALL
:
652 if (ok_blook(rfc822_body_from_
)) {
653 if (qf
->qf_pfix_len
> 0) {
654 size_t i
= fwrite(qf
->qf_pfix
, sizeof *qf
->qf_pfix
,
655 qf
->qf_pfix_len
, obuf
);
656 if (i
== qf
->qf_pfix_len
&& stats
!= NULL
)
659 put_from_(obuf
, ip
->m_multipart
, stats
);
667 put_from_(obuf
, ip
->m_multipart
, stats
);
677 case MIME_TEXT_PLAIN
:
680 case SEND_TODISP_ALL
:
681 case SEND_TODISP_PARTS
:
684 switch (n_mimetype_handler(&mh
, ip
, action
)) {
686 if(action
!= SEND_TODISP_PARTS
)
689 case MIME_HDL_MSG
:/* TODO these should be part of partinfo! */
691 _out(mh
.mh_msg
.s
, mh
.mh_msg
.l
, obuf
, CONV_NONE
, SEND_MBOX
,
692 qf
, stats
, NULL
, NULL
);
693 /* We would print this as plain text, so better force going home */
696 if(action
== SEND_TODISP_PARTS
&&
697 (mh
.mh_flags
& MIME_HDL_COPIOUSOUTPUT
))
702 if(action
== SEND_TODISP_PARTS
)
714 if (action
!= SEND_DECRYPT
)
718 if (action
!= SEND_MBOX
&& action
!= SEND_RFC822
&&
719 action
!= SEND_SHOW
&& ip
->m_multipart
!= NULL
)
725 case SEND_TODISP_ALL
:
726 case SEND_TODISP_PARTS
:
729 switch (n_mimetype_handler(&mh
, ip
, action
)) {
732 if (action
!= SEND_TODISP
&& action
!= SEND_TODISP_ALL
&&
736 case MIME_HDL_MSG
:/* TODO these should be part of partinfo! */
738 _out(mh
.mh_msg
.s
, mh
.mh_msg
.l
, obuf
, CONV_NONE
, SEND_MBOX
,
739 qf
, stats
, NULL
, NULL
);
740 /* We would print this as plain text, so better force going home */
743 if(action
== SEND_TODISP_PARTS
){
744 if(mh
.mh_flags
& MIME_HDL_COPIOUSOUTPUT
)
747 _print_part_info(obuf
, ip
, doitp
, level
, qf
, stats
);
748 if(!getapproval(_("Run MIME handler for this part?"), FAL0
))
755 if(action
== SEND_TODISP_PARTS
)
770 case MIME_ALTERNATIVE
:
771 if ((action
== SEND_TODISP
|| action
== SEND_QUOTE
) &&
772 !ok_blook(print_alternatives
)) {
773 /* XXX This (a) should not remain (b) should be own fun
774 * TODO (despite the fact that v15 will do this completely differently
775 * TODO by having an action-specific "manager" that will traverse the
776 * TODO parsed MIME tree and decide for each part whether it'll be
777 * TODO displayed or not *before* we walk the tree for doing action */
779 struct mpstack
*outer
;
781 } outermost
, * volatile curr
, * volatile mpsp
;
782 bool_t
volatile neednl
, hadpart
;
783 struct n_sigman smalter
;
785 (curr
= &outermost
)->outer
= NULL
;
787 neednl
= hadpart
= FAL0
;
789 n_SIGMAN_ENTER_SWITCH(&smalter
, n_SIGMAN_ALL
) {
797 for (np
= ip
->m_multipart
;;) {
799 for (; np
!= NULL
; np
= np
->m_nextpart
) {
800 if (action
!= SEND_QUOTE
&& np
->m_ct_type_plain
!= NULL
) {
802 _out("\n", 1, obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
,
804 _print_part_info(obuf
, np
, doitp
, level
, qf
, stats
);
808 switch (np
->m_mimecontent
) {
809 case MIME_ALTERNATIVE
:
815 mpsp
= salloc(sizeof *mpsp
);
817 mpsp
->mp
= np
->m_multipart
;
826 switch (n_mimetype_handler(&mh
, np
, action
)) {
828 mh
.mh_flags
= MIME_HDL_NULL
;
829 continue; /* break; break; */
831 if(!(mh
.mh_flags
& MIME_HDL_COPIOUSOUTPUT
)){
832 mh
.mh_flags
= MIME_HDL_NULL
;
833 continue; /* break; break; */
837 if (!ok_blook(mime_alternative_favour_rich
)) {/* TODO */
838 struct mimepart
*x
= np
;
840 while ((x
= x
->m_nextpart
) != NULL
) {
841 struct mime_handler mhx
;
843 if (x
->m_mimecontent
== MIME_TEXT_PLAIN
||
844 n_mimetype_handler(&mhx
, x
, action
) ==
849 continue; /* break; break; */
857 case MIME_TEXT_PLAIN
:
860 if (ok_blook(mime_alternative_favour_rich
)) { /* TODO */
861 struct mimepart
*x
= np
;
863 /* TODO twice TODO, we should dive into /related and
864 * TODO check whether that has rich parts! */
865 while ((x
= x
->m_nextpart
) != NULL
) {
866 struct mime_handler mhx
;
868 switch (n_mimetype_handler(&mhx
, x
, action
)) {
870 if(!(mhx
.mh_flags
& MIME_HDL_COPIOUSOUTPUT
))
881 continue; /* break; break; */
885 if (action
== SEND_QUOTE
&& hadpart
)
886 /* XXX (void)*/a_send_out_nl(obuf
, stats
);
889 rv
= sendpart(zmp
, np
, obuf
, doitp
, qf
, action
,
890 linedat
, linesize
, stats
, level
+ 1);
891 quoteflt_reset(qf
, origobuf
);
894 curr
= &outermost
; /* Cause overall loop termination */
903 np
= curr
->mp
->m_nextpart
;
906 n_sigman_leave(&smalter
, n_SIGMAN_VIPSIGS_NTTYOUT
);
917 case SEND_TODISP_ALL
:
918 case SEND_TODISP_PARTS
:
926 if ((action
== SEND_TODISP
|| action
== SEND_TODISP_ALL
) &&
927 ip
->m_multipart
!= NULL
&&
928 ip
->m_multipart
->m_mimecontent
== MIME_DISCARD
&&
929 ip
->m_multipart
->m_nextpart
== NULL
) {
930 char const *x
= _("[Missing multipart boundary - use `show' "
931 "to display the raw message]\n");
932 _out(x
, strlen(x
), obuf
, CONV_NONE
, SEND_MBOX
, qf
, stats
,
936 for (np
= ip
->m_multipart
; np
!= NULL
; np
= np
->m_nextpart
) {
937 bool_t
volatile ispipe
;
939 if (np
->m_mimecontent
== MIME_DISCARD
&& action
!= SEND_DECRYPT
)
945 if (np
->m_partstring
&&
946 np
->m_partstring
[0] == '1' && np
->m_partstring
[1] == '\0')
949 /* TODO Always open multipart on /dev/null, it's a hack to be
950 * TODO able to dive into that structure, and still better
951 * TODO than asking the user for something stupid.
952 * TODO oh, wait, we did ask for a filename for this MIME mail,
953 * TODO and that outer container is useless anyway ;-P */
954 if (np
->m_multipart
!= NULL
&& np
->m_mimecontent
!= MIME_822
) {
955 if ((obuf
= Fopen(n_path_devnull
, "w")) == NULL
)
957 } else if ((obuf
= newfile(np
, &ispipe
)) == NULL
)
961 if (sigsetjmp(_send_pipejmp
, 1)) {
965 oldpipe
= safe_signal(SIGPIPE
, &_send_onpipe
);
968 case SEND_TODISP_ALL
:
969 if (ip
->m_mimecontent
!= MIME_ALTERNATIVE
&&
970 ip
->m_mimecontent
!= MIME_RELATED
&&
971 ip
->m_mimecontent
!= MIME_DIGEST
&&
972 ip
->m_mimecontent
!= MIME_SIGNED
&&
973 ip
->m_mimecontent
!= MIME_ENCRYPTED
&&
974 ip
->m_mimecontent
!= MIME_MULTI
)
976 _print_part_info(obuf
, np
, doitp
, level
, qf
, stats
);
978 case SEND_TODISP_PARTS
:
991 if ((action
== SEND_QUOTE
|| action
== SEND_QUOTE_ALL
) &&
992 np
->m_multipart
== NULL
&& ip
->m_parent
!= NULL
)
993 /*XXX (void)*/a_send_out_nl(obuf
, stats
);
994 if (sendpart(zmp
, np
, obuf
, doitp
, qf
, action
, linedat
, linesize
,
997 quoteflt_reset(qf
, origobuf
);
999 if (action
== SEND_QUOTE
) {
1000 if (ip
->m_mimecontent
!= MIME_RELATED
)
1003 if (action
== SEND_TOFILE
&& obuf
!= origobuf
) {
1008 safe_signal(SIGPIPE
, SIG_IGN
);
1010 safe_signal(SIGPIPE
, oldpipe
);
1023 /* Copy out message body */
1024 if (doitp
== n_IGNORE_ALL
&& level
== 0) /* skip final blank line */
1026 switch (ip
->m_mime_enc
) {
1030 convert
= CONV_NONE
;
1033 convert
= CONV_FROMQP
;
1036 switch (ip
->m_mimecontent
) {
1038 case MIME_TEXT_PLAIN
:
1039 case MIME_TEXT_HTML
:
1040 convert
= CONV_FROMB64_T
;
1043 switch (mh
.mh_flags
& MIME_HDL_TYPE_MASK
) {
1046 convert
= CONV_FROMB64_T
;
1049 convert
= CONV_FROMB64
;
1056 convert
= CONV_NONE
;
1059 /* TODO Unless we have filters, ensure iconvd==-1 so that mime.c:fwrite_td()
1060 * TODO cannot mess things up misusing outrest as line buffer */
1062 if (iconvd
!= (iconv_t
)-1) {
1063 n_iconv_close(iconvd
);
1064 iconvd
= (iconv_t
)-1;
1068 if (action
== SEND_DECRYPT
|| action
== SEND_MBOX
||
1069 action
== SEND_RFC822
|| action
== SEND_SHOW
)
1070 convert
= CONV_NONE
;
1072 else if ((action
== SEND_TODISP
|| action
== SEND_TODISP_ALL
||
1073 action
== SEND_TODISP_PARTS
||
1074 action
== SEND_QUOTE
|| action
== SEND_QUOTE_ALL
||
1075 action
== SEND_TOSRCH
|| action
== SEND_TOFILE
) &&
1076 (ip
->m_mimecontent
== MIME_TEXT_PLAIN
||
1077 ip
->m_mimecontent
== MIME_TEXT_HTML
||
1078 ip
->m_mimecontent
== MIME_TEXT
||
1079 (mh
.mh_flags
& MIME_HDL_TYPE_MASK
) == MIME_HDL_TEXT
||
1080 (mh
.mh_flags
& MIME_HDL_TYPE_MASK
) == MIME_HDL_PTF
)) {
1083 tcs
= ok_vlook(ttycharset
);
1084 if (asccasecmp(tcs
, ip
->m_charset
) &&
1085 asccasecmp(ok_vlook(charset_7bit
), ip
->m_charset
)) {
1086 iconvd
= n_iconv_open(tcs
, ip
->m_charset
);
1087 if (iconvd
== (iconv_t
)-1 && n_err_no
== n_ERR_INVAL
) {
1088 n_err(_("Cannot convert from %s to %s\n"), ip
->m_charset
, tcs
);
1089 /*rv = 1; goto jleave;*/
1095 switch (mh
.mh_flags
& MIME_HDL_TYPE_MASK
) {
1097 if(!(mh
.mh_flags
& MIME_HDL_COPIOUSOUTPUT
) &&
1098 action
!= SEND_TODISP_PARTS
)
1105 term_infd
= n_CHILD_FD_PASS
;
1106 if (mh
.mh_flags
& (MIME_HDL_TMPF
| MIME_HDL_NEEDSTERM
)) {
1109 of
= OF_RDWR
| OF_REGISTER
;
1110 if (!(mh
.mh_flags
& MIME_HDL_TMPF
)) {
1112 mh
.mh_flags
|= MIME_HDL_TMPF_FILL
;
1114 } else if (mh
.mh_flags
& MIME_HDL_TMPF_UNLINK
)
1115 of
|= OF_REGISTER_UNLINK
;
1117 if ((pbuf
= Ftmp((mh
.mh_flags
& MIME_HDL_TMPF
? &cp
: NULL
),
1118 (mh
.mh_flags
& MIME_HDL_TMPF_FILL
? "mimehdlfill" : "mimehdl"),
1122 if (mh
.mh_flags
& MIME_HDL_TMPF
) {
1123 tmpname
= savestr(cp
);
1127 if (mh
.mh_flags
& MIME_HDL_TMPF_FILL
) {
1129 term_infd
= fileno(pbuf
);
1135 pbuf
= _pipefile(&mh
, ip
, n_UNVOLATILE(&qbuf
), tmpname
, term_infd
);
1141 } else if ((mh
.mh_flags
& MIME_HDL_NEEDSTERM
) && pbuf
== (FILE*)-1) {
1146 action
= SEND_TOPIPE
;
1148 oldpipe
= safe_signal(SIGPIPE
, &_send_onpipe
);
1149 if (sigsetjmp(_send_pipejmp
, 1))
1156 mh
.mh_flags
= MIME_HDL_NULL
;
1163 bool_t
volatile eof
;
1164 ui32_t save_qf_pfix_len
= qf
->qf_pfix_len
;
1165 ui64_t
*save_stats
= stats
;
1167 if (pbuf
!= origobuf
) {
1168 qf
->qf_pfix_len
= 0; /* XXX legacy (remove filter instead) */
1172 outrest
.s
= inrest
.s
= NULL
;
1173 outrest
.l
= inrest
.l
= 0;
1177 __sendp_opipe
= safe_signal(SIGPIPE
, &__sendp_onsig
);
1178 if (sigsetjmp(__sendp_actjmp
, 1)) {
1179 n_pstate
&= ~n_PS_BASE64_STRIP_CR
;/* (but protected by outer sigman) */
1180 if (outrest
.s
!= NULL
)
1182 if (inrest
.s
!= NULL
)
1185 if (iconvd
!= (iconv_t
)-1)
1186 n_iconv_close(iconvd
);
1188 safe_signal(SIGPIPE
, __sendp_opipe
);
1189 n_raise(__sendp_sig
);
1193 quoteflt_reset(qf
, pbuf
);
1194 if((dostat
& 4) && pbuf
== origobuf
) /* TODO */
1195 n_pstate
|= n_PS_BASE64_STRIP_CR
;
1196 while (!eof
&& fgetline(linedat
, linesize
, &cnt
, &linelen
, ibuf
, 0)) {
1198 if (_out(*linedat
, linelen
, pbuf
, convert
, action
, qf
, stats
, &outrest
,
1199 (action
& _TD_EOF
? NULL
: &inrest
)) < 0 || ferror(pbuf
)) {
1200 rv
= -1; /* XXX Should bail away?! */
1204 if(eof
<= FAL0
&& rv
>= 0 && (outrest
.l
!= 0 || inrest
.l
!= 0)){
1206 if(eof
|| inrest
.l
== 0)
1208 eof
= eof
? TRU1
: TRUM1
;
1211 n_pstate
&= ~n_PS_BASE64_STRIP_CR
;
1214 /* TODO HACK: when sending to the display we yet get fooled if a message
1215 * TODO doesn't end in a newline, because of our input/output 1:1.
1216 * TODO This should be handled automatically by a display filter, then */
1217 if(rv
>= 0 && !qf
->qf_nl_last
&&
1218 (action
== SEND_TODISP
|| action
== SEND_TODISP_ALL
))
1219 rv
= quoteflt_push(qf
, "\n", 1);
1223 if (rv
>= 0 && (mh
.mh_flags
& MIME_HDL_TMPF_FILL
)) {
1224 mh
.mh_flags
&= ~MIME_HDL_TMPF_FILL
;
1226 really_rewind(pbuf
);
1227 /* Don't Fclose() the Ftmp() thing due to OF_REGISTER_UNLINK++ */
1228 goto jpipe_for_real
;
1232 safe_signal(SIGPIPE
, __sendp_opipe
);
1234 if (outrest
.s
!= NULL
)
1236 if (inrest
.s
!= NULL
)
1239 if (pbuf
!= origobuf
) {
1240 qf
->qf_pfix_len
= save_qf_pfix_len
;
1247 safe_signal(SIGPIPE
, SIG_IGN
);
1248 Pclose(pbuf
, !(mh
.mh_flags
& MIME_HDL_ASYNC
));
1249 safe_signal(SIGPIPE
, oldpipe
);
1250 if (rv
>= 0 && qbuf
!= NULL
&& qbuf
!= obuf
)
1251 pipecpy(qbuf
, obuf
, origobuf
, qf
, stats
);
1254 if (iconvd
!= (iconv_t
)-1)
1255 n_iconv_close(iconvd
);
1263 newfile(struct mimepart
*ip
, bool_t
volatile *ispipe
)
1273 if (f
!= NULL
&& f
!= (char*)-1) {
1276 makeprint(&in
, &out
);
1277 out
.l
= delctrl(out
.s
, out
.l
);
1278 f
= savestrbuf(out
.s
, out
.l
);
1282 /* In interactive mode, let user perform all kind of expansions as desired,
1283 * and offer |SHELL-SPEC pipe targets, too */
1284 if (n_psonce
& n_PSO_INTERACTIVE
) {
1286 struct n_string shou
, *shoup
;
1289 shoup
= n_string_creat_auto(&shou
);
1291 /* TODO Generic function which asks for filename.
1292 * TODO If the current part is the first textpart the target
1293 * TODO is implicit from outer `write' etc! */
1294 /* I18N: Filename input prompt with file type indication */
1295 str_concat_csvl(&prompt
, _("Enter filename for part "),
1296 (ip
->m_partstring
!= NULL
? ip
->m_partstring
: n_qm
),
1297 " (", ip
->m_ct_type_plain
, "): ", NULL
);
1299 f2
= n_go_input_cp(n_GO_INPUT_CTX_DEFAULT
| n_GO_INPUT_HIST_ADD
,
1300 prompt
.s
, ((f
!= (char*)-1 && f
!= NULL
)
1301 ? n_shexp_quote_cp(f
, FAL0
) : NULL
));
1303 in
.s
= n_UNCONST(f2
);
1305 if((n_shexp_parse_token((n_SHEXP_PARSE_TRUNC
|
1306 n_SHEXP_PARSE_TRIM_SPACE
| n_SHEXP_PARSE_TRIM_IFSSPACE
|
1307 n_SHEXP_PARSE_LOG
| n_SHEXP_PARSE_IGNORE_EMPTY
),
1309 ) & (n_SHEXP_STATE_STOP
|
1310 n_SHEXP_STATE_OUTPUT
| n_SHEXP_STATE_ERR_MASK
)
1311 ) != (n_SHEXP_STATE_STOP
| n_SHEXP_STATE_OUTPUT
))
1313 f2
= n_string_cp(shoup
);
1315 if (f2
== NULL
|| *f2
== '\0') {
1316 if (n_poption
& n_PO_D_V
)
1317 n_err(_("... skipping this\n"));
1318 n_string_gut(shoup
);
1324 /* Pipes are expanded by the shell */
1326 else if ((f3
= fexpand(f2
, FEXP_LOCAL
| FEXP_NVAR
)) == NULL
)
1327 /* (Error message written by fexpand()) */
1332 n_string_gut(shoup
);
1335 if (f
== NULL
|| f
== (char*)-1 || *f
== '\0')
1337 else if (n_psonce
& n_PSO_INTERACTIVE
) {
1339 fp
= Popen(&f
[1], "w", ok_vlook(SHELL
), NULL
, 1);
1340 if (!(*ispipe
= (fp
!= NULL
)))
1342 } else if ((fp
= Fopen(f
, "w")) == NULL
)
1343 n_err(_("Cannot open %s\n"), n_shexp_quote_cp(f
, FAL0
));
1345 /* Be very picky in non-interactive mode: actively disallow pipes,
1346 * prevent directory separators, and any filename member that would
1347 * become expanded by the shell if the name would be echo(1)ed */
1348 if(n_anyof_cp("/" n_SHEXP_MAGIC_PATH_CHARS
, f
)){
1351 for(out
.s
= salloc((strlen(f
) * 3) +1), out
.l
= 0; (c
= *f
++) != '\0';)
1352 if(strchr("/" n_SHEXP_MAGIC_PATH_CHARS
, c
)){
1353 out
.s
[out
.l
++] = '%';
1354 n_c_to_hex_base16(&out
.s
[out
.l
], c
);
1358 out
.s
[out
.l
] = '\0';
1362 /* Avoid overwriting of existing files */
1363 while((fp
= Fopen(f
, "wx")) == NULL
){
1366 if((e
= n_err_no
) != n_ERR_EXIST
){
1367 n_err(_("Cannot open %s: %s\n"),
1368 n_shexp_quote_cp(f
, FAL0
), n_err_to_doc(e
));
1372 if(ip
->m_partstring
!= NULL
)
1373 f
= savecatsep(f
, '#', ip
->m_partstring
);
1375 f
= savecat(f
, "#.");
1384 pipecpy(FILE *pipebuf
, FILE *outbuf
, FILE *origobuf
, struct quoteflt
*qf
,
1387 char *line
= NULL
; /* TODO line pool */
1388 size_t linesize
= 0, linelen
, cnt
;
1394 cnt
= (size_t)fsize(pipebuf
);
1397 quoteflt_reset(qf
, outbuf
);
1398 while (fgetline(&line
, &linesize
, &cnt
, &linelen
, pipebuf
, 0) != NULL
) {
1399 if ((sz
= quoteflt_push(qf
, line
, linelen
)) < 0)
1403 if ((sz
= quoteflt_flush(qf
)) > 0)
1408 if (all_sz
> 0 && outbuf
== origobuf
&& stats
!= NULL
)
1415 statusput(const struct message
*mp
, FILE *obuf
, struct quoteflt
*qf
,
1418 char statout
[3], *cp
= statout
;
1421 if (mp
->m_flag
& MREAD
)
1423 if (!(mp
->m_flag
& MNEW
))
1427 int i
= fprintf(obuf
, "%.*sStatus: %s\n", (int)qf
->qf_pfix_len
,
1428 (qf
->qf_pfix_len
> 0 ? qf
->qf_pfix
: 0), statout
);
1429 if (i
> 0 && stats
!= NULL
)
1436 xstatusput(const struct message
*mp
, FILE *obuf
, struct quoteflt
*qf
,
1440 char *xp
= xstatout
;
1443 if (mp
->m_flag
& MFLAGGED
)
1445 if (mp
->m_flag
& MANSWERED
)
1447 if (mp
->m_flag
& MDRAFTED
)
1451 int i
= fprintf(obuf
, "%.*sX-Status: %s\n", (int)qf
->qf_pfix_len
,
1452 (qf
->qf_pfix_len
> 0 ? qf
->qf_pfix
: 0), xstatout
);
1453 if (i
> 0 && stats
!= NULL
)
1460 put_from_(FILE *fp
, struct mimepart
*ip
, ui64_t
*stats
)
1462 char const *froma
, *date
, *nl
;
1466 if (ip
!= NULL
&& ip
->m_from
!= NULL
) {
1468 date
= n_time_ctime(ip
->m_time
, NULL
);
1471 froma
= ok_vlook(LOGNAME
);
1472 date
= time_current
.tc_ctime
;
1477 if(n_COLOUR_IS_ACTIVE())
1478 n_colour_put(n_COLOUR_ID_VIEW_FROM_
, NULL
);
1480 i
= fprintf(fp
, "From %s %s%s", froma
, date
, nl
);
1482 if(n_COLOUR_IS_ACTIVE())
1485 if (i
> 0 && stats
!= NULL
)
1491 sendmp(struct message
*mp
, FILE *obuf
, struct n_ignore
const *doitp
,
1492 char const *prefix
, enum sendaction action
, ui64_t
*stats
)
1494 struct n_sigman linedat_protect
;
1497 enum mime_parse_flags mpf
;
1498 struct mimepart
*ip
;
1499 size_t linesize
, cnt
, sz
, i
;
1504 time_current_update(&time_current
, TRU1
);
1508 quoteflt_init(&qf
, prefix
);
1510 n_SIGMAN_ENTER_SWITCH(&linedat_protect
, n_SIGMAN_ALL
){
1517 if (mp
== dot
&& action
!= SEND_TOSRCH
)
1518 n_pstate
|= n_PS_DID_PRINT_DOT
;
1522 /* First line is the From_ line, so no headers there to worry about */
1523 if ((ibuf
= setinput(&mb
, mp
, NEED_BODY
)) == NULL
)
1530 char const *cpre
= n_empty
, *csuf
= n_empty
;
1533 if(n_COLOUR_IS_ACTIVE()){
1534 struct n_colour_pen
*cpen
;
1535 struct str
const *sp
;
1537 cpen
= n_colour_pen_create(n_COLOUR_ID_VIEW_FROM_
,NULL
);
1538 if((sp
= n_colour_pen_to_str(cpen
)) != NULL
){
1540 sp
= n_colour_reset_to_str();
1547 nozap
= (doitp
!= n_IGNORE_ALL
&& doitp
!= n_IGNORE_FWD
&&
1548 action
!= SEND_RFC822
&&
1549 !n_ignore_is_ign(doitp
, "from_", sizeof("from_") -1));
1550 if (mp
->m_flag
& MNOFROM
) {
1552 sz
= fprintf(obuf
, "%s%.*sFrom %s %s%s\n",
1553 cpre
, (int)qf
.qf_pfix_len
,
1554 (qf
.qf_pfix_len
!= 0 ? qf
.qf_pfix
: n_empty
), fakefrom(mp
),
1555 n_time_ctime(mp
->m_time
, NULL
), csuf
);
1557 if (qf
.qf_pfix_len
> 0) {
1558 i
= fwrite(qf
.qf_pfix
, sizeof *qf
.qf_pfix
, qf
.qf_pfix_len
, obuf
);
1559 if (i
!= qf
.qf_pfix_len
)
1566 cpre
= (char const*)0x1;
1570 while (cnt
> 0 && (c
= getc(ibuf
)) != EOF
) {
1572 if(c
== '\n' && *csuf
!= '\0'){
1573 cpre
= (char const*)0x1;
1585 if(*csuf
!= '\0' && cpre
!= (char const*)0x1 && *cpre
!= '\0')
1589 while (cnt
> 0 && (c
= getc(ibuf
)) != EOF
) {
1596 if (sz
> 0 && stats
!= NULL
)
1599 mpf
= MIME_PARSE_NONE
;
1600 if (action
!= SEND_MBOX
&& action
!= SEND_RFC822
&& action
!= SEND_SHOW
)
1601 mpf
|= MIME_PARSE_PARTS
| MIME_PARSE_DECRYPT
;
1602 if(action
== SEND_TODISP
|| action
== SEND_TODISP_ALL
||
1603 action
== SEND_QUOTE
|| action
== SEND_QUOTE_ALL
)
1604 mpf
|= MIME_PARSE_FOR_USER_CONTEXT
;
1605 if ((ip
= mime_parse_msg(mp
, mpf
)) == NULL
)
1608 rv
= sendpart(mp
, ip
, obuf
, doitp
, &qf
, action
, &linedat
, &linesize
,
1611 n_sigman_cleanup_ping(&linedat_protect
);
1613 n_pstate
&= ~n_PS_BASE64_STRIP_CR
;
1614 quoteflt_destroy(&qf
);
1618 n_sigman_leave(&linedat_protect
, n_SIGMAN_VIPSIGS_NTTYOUT
);