1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Message sending lifecycle, header composing, etc.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 - 2018 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
6 * SPDX-License-Identifier: BSD-3-Clause
9 * Copyright (c) 1980, 1993
10 * The Regents of the University of California. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #define n_FILE sendout
39 #ifndef HAVE_AMALGAMATION
44 #define SEND_LINESIZE \
45 ((1024 / B64_ENCODE_INPUT_PER_LINE) * B64_ENCODE_INPUT_PER_LINE)
47 enum a_sendout_addrline_flags
{
48 a_SENDOUT_AL_INC_INVADDR
= 1<<0, /* _Do_ include invalid addresses */
49 a_SENDOUT_AL_DOMIME
= 1<<1, /* Perform MIME conversion */
50 a_SENDOUT_AL_COMMA
= GCOMMA
,
51 a_SENDOUT_AL_FILES
= GFILES
,
52 _a_SENDOUT_AL_GMASK
= a_SENDOUT_AL_COMMA
| a_SENDOUT_AL_FILES
54 n_CTA(!(_a_SENDOUT_AL_GMASK
& (a_SENDOUT_AL_INC_INVADDR
|a_SENDOUT_AL_DOMIME
)),
55 "Code-required condition not satisfied but actual bit carrier value");
57 static char const *__sendout_ident
; /* TODO temporary; rewrite n_puthead() */
58 static char * _sendout_boundary
;
59 static si8_t _sendout_error
;
61 /* *fullnames* appears after command line arguments have been parsed */
62 static struct name
*a_sendout_fullnames_cleanup(struct name
*np
);
65 static bool_t
a_sendout_put_name(char const *line
, enum gfield w
,
66 enum sendaction action
, char const *prefix
,
67 FILE *fo
, struct name
**xp
, enum gfield addflags
);
69 /* Place Content-Type:, Content-Transfer-Encoding:, Content-Disposition:
70 * headers, respectively */
71 static int a_sendout_put_ct(FILE *fo
, char const *contenttype
,
73 n_INLINE
int a_sendout_put_cte(FILE *fo
, enum conversion conv
);
74 static int a_sendout_put_cd(FILE *fo
, char const *cd
, char const *filename
);
76 /* Put all entries of the given header list */
77 static bool_t
_sendout_header_list(FILE *fo
, struct n_header_field
*hfp
,
81 static si32_t
a_sendout_body(FILE *fo
, FILE *fi
, enum conversion convert
);
83 /* Write an attachment to the file buffer, converting to MIME */
84 static si32_t
a_sendout_attach_file(struct header
*hp
, struct attachment
*ap
,
86 static si32_t
a_sendout__attach_file(struct header
*hp
, struct attachment
*ap
,
89 /* There are non-local receivers, collect credentials etc. */
90 static bool_t
_sendbundle_setup_creds(struct sendbundle
*sbpm
,
93 /* Attach a message to the file buffer */
94 static si32_t
a_sendout_attach_msg(struct header
*hp
, struct attachment
*ap
,
97 /* Generate the body of a MIME multipart message */
98 static si32_t
make_multipart(struct header
*hp
, int convert
, FILE *fi
,
99 FILE *fo
, char const *contenttype
, char const *charset
);
101 /* Prepend a header in front of the collected stuff and return the new file */
102 static FILE * infix(struct header
*hp
, FILE *fi
);
104 /* Check whether Disposition-Notification-To: is desired */
105 static bool_t
_check_dispo_notif(struct name
*mdn
, struct header
*hp
,
108 /* Send mail to a bunch of user names. The interface is through mail() */
109 static int a_sendout_sendmail(void *v
, enum n_mailsend_flags msf
);
111 /* Deal with file and pipe addressees */
112 static struct name
*a_sendout_file_a_pipe(struct name
*names
, FILE *fo
,
115 /* Record outgoing mail if instructed to do so; in *record* unless to is set */
116 static bool_t
mightrecord(FILE *fp
, struct name
*to
, bool_t resend
);
118 static bool_t
a_sendout__savemail(char const *name
, FILE *fp
, bool_t resend
);
121 static bool_t
_transfer(struct sendbundle
*sbp
);
123 static bool_t
__mta_start(struct sendbundle
*sbp
);
124 static char const ** __mta_prepare_args(struct name
*to
, struct header
*hp
);
125 static void __mta_debug(struct sendbundle
*sbp
, char const *mta
,
128 /* Create a Message-ID: header field. Use either host name or from address */
129 static char const *a_sendout_random_id(struct header
*hp
, bool_t msgid
);
131 /* Format the given header line to not exceed 72 characters */
132 static bool_t
a_sendout_put_addrline(char const *hname
, struct name
*np
,
133 FILE *fo
, enum a_sendout_addrline_flags saf
);
135 /* Rewrite a message for resending, adding the Resent-Headers */
136 static int infix_resend(FILE *fi
, FILE *fo
, struct message
*mp
,
137 struct name
*to
, int add_resent
);
140 a_sendout_fullnames_cleanup(struct name
*np
){
144 for(xp
= np
; xp
!= NULL
; xp
= xp
->n_flink
){
145 xp
->n_type
&= ~(GFULL
| GFULLEXTRA
);
146 xp
->n_fullname
= xp
->n_name
;
147 xp
->n_fullextra
= NULL
;
154 a_sendout_put_name(char const *line
, enum gfield w
, enum sendaction action
,
155 char const *prefix
, FILE *fo
, struct name
**xp
, enum gfield addflags
){
160 np
= lextract(line
, GEXTRA
| GFULL
| addflags
);
167 rv
= a_sendout_put_addrline(prefix
, np
, fo
, ((w
& GCOMMA
) |
168 ((action
!= SEND_TODISP
) ? a_SENDOUT_AL_DOMIME
: 0)));
174 a_sendout_put_ct(FILE *fo
, char const *contenttype
, char const *charset
){
178 if((rv
= fprintf(fo
, "Content-Type: %s", contenttype
)) < 0)
184 if(putc(';', fo
) == EOF
)
188 if(strlen(contenttype
) + sizeof("Content-Type: ;")-1 > 50){
189 if(putc('\n', fo
) == EOF
)
197 i
= fprintf(fo
, " charset=%s", charset
);
204 if(putc('\n', fo
) == EOF
)
216 a_sendout_put_cte(FILE *fo
, enum conversion conv
){
221 * This is the default value -- that is,
222 * "Content-Transfer-Encoding: 7BIT" is assumed if the
223 * Content-Transfer-Encoding header field is not present.
225 rv
= (conv
== CONV_7BIT
) ? 0
226 : fprintf(fo
, "Content-Transfer-Encoding: %s\n",
227 mime_enc_from_conversion(conv
));
233 a_sendout_put_cd(FILE *fo
, char const *cd
, char const *filename
){
241 /* xxx Ugly with the trailing space in case of wrap! */
242 if((rv
= fprintf(fo
, "Content-Disposition: %s; ", cd
)) < 0)
245 if(!(mpc
= mime_param_create(&f
, "filename", filename
)))
247 /* Always fold if result contains newlines */
248 if(mpc
< 0 || f
.l
+ rv
> MIME_LINELEN
) { /* FIXME MIME_LINELEN_MAX */
249 if(putc('\n', fo
) == EOF
|| putc(' ', fo
) == EOF
)
253 if(fputs(f
.s
, fo
) == EOF
|| putc('\n', fo
) == EOF
)
267 _sendout_header_list(FILE *fo
, struct n_header_field
*hfp
, bool_t nodisp
){
271 for(rv
= TRU1
; hfp
!= NULL
; hfp
= hfp
->hf_next
)
272 if(fwrite(hfp
->hf_dat
, sizeof(char), hfp
->hf_nl
, fo
) != hfp
->hf_nl
||
273 putc(':', fo
) == EOF
|| putc(' ', fo
) == EOF
||
274 xmime_write(hfp
->hf_dat
+ hfp
->hf_nl
+1, hfp
->hf_bl
, fo
,
275 (!nodisp
? CONV_NONE
: CONV_TOHDR
),
276 (!nodisp
? TD_ISPR
| TD_ICONV
: TD_ICONV
), NULL
, NULL
) < 0 ||
277 putc('\n', fo
) == EOF
){
286 a_sendout_body(FILE *fo
, FILE *fi
, enum conversion convert
){
287 struct str outrest
, inrest
;
289 size_t sz
, bufsize
, cnt
;
296 buf
= n_alloc(bufsize
= SEND_LINESIZE
);
297 outrest
.s
= inrest
.s
= NULL
;
298 outrest
.l
= inrest
.l
= 0;
300 if(convert
== CONV_TOQP
302 || iconvd
!= (iconv_t
)-1
310 if(convert
== CONV_TOQP
312 || iconvd
!= (iconv_t
)-1
315 if(fgetline(&buf
, &bufsize
, &cnt
, &sz
, fi
, 0) == NULL
)
317 }else if((sz
= fread(buf
, sizeof *buf
, bufsize
, fi
)) == 0)
320 if(xmime_write(buf
, sz
, fo
, convert
, TD_ICONV
, &outrest
,
321 (iseof
> FAL0
? NULL
: &inrest
)) < 0)
324 if(iseof
<= FAL0
&& (outrest
.l
!= 0 || inrest
.l
!= 0)){
326 iseof
= (iseof
|| inrest
.l
== 0) ? TRU1
: TRUM1
;
330 rv
= ferror(fi
) ? n_ERR_IO
: n_ERR_NONE
;
332 if(outrest
.s
!= NULL
)
343 a_sendout_attach_file(struct header
*hp
, struct attachment
*ap
, FILE *fo
)
345 /* TODO of course, the MIME classification needs to performed once
346 * TODO only, not for each and every charset anew ... ;-// */
347 char *charset_iter_orig
[2];
354 /* Is this already in target charset? Simply copy over */
355 if (ap
->a_conv
== AC_TMPFILE
) {
356 err
= a_sendout__attach_file(hp
, ap
, fo
);
358 DBG( ap
->a_tmpf
= NULL
; )
362 /* If we don't apply charset conversion at all (fixed input=ouput charset)
363 * we also simply copy over, since it's the users desire */
364 if (ap
->a_conv
== AC_FIX_INCS
) {
365 ap
->a_charset
= ap
->a_input_charset
;
366 err
= a_sendout__attach_file(hp
, ap
, fo
);
369 assert(ap
->a_input_charset
!= NULL
);
371 /* Otherwise we need to iterate over all possible output charsets */
372 if ((offs
= ftell(fo
)) == -1) {
376 charset_iter_recurse(charset_iter_orig
);
377 for (charset_iter_reset(NULL
);; charset_iter_next()) {
378 if (!charset_iter_is_valid()) {
382 err
= a_sendout__attach_file(hp
, ap
, fo
);
383 if (err
== n_ERR_NONE
|| (err
!= n_ERR_ILSEQ
&& err
!= n_ERR_INVAL
))
386 if (fseek(fo
, offs
, SEEK_SET
) == -1) {
390 if (ap
->a_conv
!= AC_DEFAULT
) {
394 ap
->a_charset
= NULL
;
396 charset_iter_restore(charset_iter_orig
);
403 a_sendout__attach_file(struct header
*hp
, struct attachment
*ap
, FILE *fo
)
407 enum conversion convert
;
414 /* Either charset-converted temporary file, or plain path */
415 if (ap
->a_conv
== AC_TMPFILE
) {
417 assert(ftell(fi
) == 0);
418 } else if ((fi
= Fopen(ap
->a_path
, "r")) == NULL
) {
420 n_err(_("%s: %s\n"), n_shexp_quote_cp(ap
->a_path
, FAL0
),
425 /* MIME part header for attachment */
426 { char const *ct
, *cp
;
428 ct
= ap
->a_content_type
;
429 charset
= ap
->a_charset
;
430 convert
= n_mimetype_classify_file(fi
, (char const**)&ct
,
431 &charset
, &do_iconv
);
432 if (charset
== NULL
|| ap
->a_conv
== AC_FIX_INCS
||
433 ap
->a_conv
== AC_TMPFILE
)
436 if (fprintf(fo
, "\n--%s\n", _sendout_boundary
) < 0 ||
437 a_sendout_put_ct(fo
, ct
, charset
) < 0 ||
438 a_sendout_put_cte(fo
, convert
) < 0 ||
439 a_sendout_put_cd(fo
, ap
->a_content_disposition
, ap
->a_name
) < 0)
442 if((cp
= ok_vlook(stealthmua
)) == NULL
|| !strcmp(cp
, "noagent")){
445 /* TODO RFC 2046 specifies that the same Content-ID should be used
446 * TODO for identical data; this is too hard for use right now,
447 * TODO because if done right it should be checksum based!?! */
448 if((np
= ap
->a_content_id
) != NULL
)
451 cp
= a_sendout_random_id(hp
, FAL0
);
453 if(cp
!= NULL
&& fprintf(fo
, "Content-ID: <%s>\n", cp
) < 0)
457 if ((cp
= ap
->a_content_description
) != NULL
&&
458 (fputs("Content-Description: ", fo
) == EOF
||
459 xmime_write(cp
, strlen(cp
), fo
, CONV_TOHDR
, (TD_ISPR
| TD_ICONV
),
460 NULL
, NULL
) < 0 || putc('\n', fo
) == EOF
))
463 if (putc('\n', fo
) == EOF
) {
471 if (iconvd
!= (iconv_t
)-1)
472 n_iconv_close(iconvd
);
474 if (asccasecmp(charset
, ap
->a_input_charset
) &&
475 (iconvd
= n_iconv_open(charset
, ap
->a_input_charset
)
476 ) == (iconv_t
)-1 && (err
= n_err_no
) != 0) {
477 if (err
== n_ERR_INVAL
)
478 n_err(_("Cannot convert from %s to %s\n"), ap
->a_input_charset
,
481 n_err(_("iconv_open: %s\n"), n_err_to_doc(err
));
487 err
= a_sendout_body(fo
, fi
, convert
);
489 if(ap
->a_conv
!= AC_TMPFILE
)
498 _sendbundle_setup_creds(struct sendbundle
*sbp
, bool_t signing_caps
)
500 bool_t v15
, rv
= FAL0
;
507 v15
= ok_blook(v15_compat
);
508 shost
= (v15
? ok_vlook(smtp_hostname
) : NULL
);
509 from
= ((signing_caps
|| !v15
|| shost
== NULL
)
510 ? skin(myorigin(sbp
->sb_hp
)) : NULL
);
515 n_err(_("No *from* address for signing specified\n"));
519 sbp
->sb_signer
.l
= strlen(sbp
->sb_signer
.s
= from
);
525 if ((smtp
= ok_vlook(smtp
)) == NULL
) { /* TODO v15 url_creat(,ok_vlook(mta)*/
528 /* *smtp* OBSOLETE message in mta_start() */
529 if((proto
= n_servbyname(smtp
= ok_vlook(mta
), NULL
)) == NULL
||
536 if (!url_parse(&sbp
->sb_url
, CPROTO_SMTP
, smtp
))
543 sbp
->sb_url
.url_u_h
.l
= strlen(sbp
->sb_url
.url_u_h
.s
= from
);
545 __sendout_ident
= sbp
->sb_url
.url_u_h
.s
;
546 if (!ccred_lookup(&sbp
->sb_ccred
, &sbp
->sb_url
))
549 if ((sbp
->sb_url
.url_flags
& n_URL_HAD_USER
) ||
550 sbp
->sb_url
.url_pass
.s
!= NULL
) {
551 n_err(_("New-style URL used without *v15-compat* being set\n"));
554 /* TODO part of the entire myorigin() disaster, get rid of this! */
557 n_err(_("Your configuration requires a *from* address, "
558 "but none was given\n"));
561 if (!ccred_lookup_old(&sbp
->sb_ccred
, CPROTO_SMTP
, from
))
563 sbp
->sb_url
.url_u_h
.l
= strlen(sbp
->sb_url
.url_u_h
.s
= from
);
567 #endif /* HAVE_SMTP */
568 #if defined HAVE_SMIME || defined HAVE_SMTP
576 a_sendout_attach_msg(struct header
*hp
, struct attachment
*ap
, FILE *fo
)
586 if(fprintf(fo
, "\n--%s\nContent-Type: message/rfc822\n"
587 "Content-Disposition: inline\n", _sendout_boundary
) < 0)
590 if((ccp
= ok_vlook(stealthmua
)) == NULL
|| !strcmp(ccp
, "noagent")){
593 /* TODO RFC 2046 specifies that the same Content-ID should be used
594 * TODO for identical data; this is too hard for use right now,
595 * TODO because if done right it should be checksum based!?! */
596 if((np
= ap
->a_content_id
) != NULL
)
599 ccp
= a_sendout_random_id(hp
, FAL0
);
601 if(ccp
!= NULL
&& fprintf(fo
, "Content-ID: <%s>\n", ccp
) < 0)
605 if((ccp
= ap
->a_content_description
) != NULL
&&
606 (fputs("Content-Description: ", fo
) == EOF
||
607 xmime_write(ccp
, strlen(ccp
), fo
, CONV_TOHDR
, (TD_ISPR
| TD_ICONV
),
608 NULL
, NULL
) < 0 || putc('\n', fo
) == EOF
))
610 if(putc('\n', fo
) == EOF
)
613 mp
= message
+ ap
->a_msgno
- 1;
615 if(sendmp(mp
, fo
, 0, NULL
, SEND_RFC822
, NULL
) < 0)
617 if((err
= n_err_no
) == n_ERR_NONE
)
624 make_multipart(struct header
*hp
, int convert
, FILE *fi
, FILE *fo
,
625 char const *contenttype
, char const *charset
)
627 struct attachment
*att
;
633 if(fputs("This is a multi-part message in MIME format.\n", fo
) == EOF
)
639 if(fprintf(fo
, "\n--%s\n", _sendout_boundary
) < 0 ||
640 a_sendout_put_ct(fo
, contenttype
, charset
) < 0 ||
641 a_sendout_put_cte(fo
, convert
) < 0 ||
642 fprintf(fo
, "Content-Disposition: inline\n") < 0)
644 if (((cp
= ok_vlook(stealthmua
)) == NULL
|| !strcmp(cp
, "noagent")) &&
645 (cp
= a_sendout_random_id(hp
, FAL0
)) != NULL
&&
646 fprintf(fo
, "Content-ID: <%s>\n", cp
) < 0)
648 if(putc('\n', fo
) == EOF
)
651 if((err
= a_sendout_body(fo
, fi
, convert
)) != n_ERR_NONE
)
658 for (att
= hp
->h_attach
; att
!= NULL
; att
= att
->a_flink
) {
660 if ((err
= a_sendout_attach_msg(hp
, att
, fo
)) != n_ERR_NONE
)
662 } else if ((err
= a_sendout_attach_file(hp
, att
, fo
)) != n_ERR_NONE
)
666 /* the final boundary with two attached dashes */
667 if(fprintf(fo
, "\n--%s--\n", _sendout_boundary
) < 0)
669 if((err
= n_err_no
) == n_ERR_NONE
)
677 infix(struct header
*hp
, FILE *fi
) /* TODO check */
680 enum conversion convert
;
682 char const *contenttype
, *charset
;
685 char const *tcs
, *convhdr
= NULL
;
694 if ((nfo
= Ftmp(&tempMail
, "infix", OF_WRONLY
| OF_HOLDSIGS
| OF_REGISTER
))
696 n_perr(_("infix: temporary mail file"), err
= n_err_no
);
699 if ((nfi
= Fopen(tempMail
, "r")) == NULL
) {
700 n_perr(tempMail
, err
= n_err_no
);
703 Ftmp_release(&tempMail
);
707 n_pstate
&= ~n_PS_HEADER_NEEDED_MIME
; /* TODO hack -> be carrier tracked */
709 contenttype
= "text/plain";
710 if((n_poption
& n_PO_Mm_FLAG
) && n_poption_arg_Mm
!= NULL
)
711 contenttype
= n_poption_arg_Mm
;
712 convert
= n_mimetype_classify_file(fi
, &contenttype
, &charset
, &do_iconv
);
715 tcs
= ok_vlook(ttycharset
);
716 if ((convhdr
= need_hdrconv(hp
))) {
717 if (iconvd
!= (iconv_t
)-1) /* XXX */
718 n_iconv_close(iconvd
);
719 if (asccasecmp(convhdr
, tcs
) != 0 &&
720 (iconvd
= n_iconv_open(convhdr
, tcs
)) == (iconv_t
)-1 &&
721 (err
= n_err_no
) != n_ERR_NONE
)
725 if(!n_puthead(FAL0
, hp
, nfo
,
726 (GTO
| GSUBJECT
| GCC
| GBCC
| GNL
| GCOMMA
| GUA
| GMIME
| GMSGID
|
727 GIDENT
| GREF
| GDATE
), SEND_MBOX
, convert
, contenttype
, charset
)){
728 if((err
= n_err_no
) == n_ERR_NONE
)
733 if (iconvd
!= (iconv_t
)-1)
734 n_iconv_close(iconvd
);
738 if (do_iconv
&& charset
!= NULL
) { /*TODO charset->n_mimetype_classify_file*/
739 if (asccasecmp(charset
, tcs
) != 0 &&
740 (iconvd
= n_iconv_open(charset
, tcs
)) == (iconv_t
)-1 &&
741 (err
= n_err_no
) != n_ERR_NONE
) {
743 if (err
== n_ERR_INVAL
)
744 n_err(_("Cannot convert from %s to %s\n"), tcs
, charset
);
746 n_perr("iconv_open", err
);
752 if(hp
->h_attach
!= NULL
){
753 if((err
= make_multipart(hp
, convert
, fi
, nfo
, contenttype
, charset
)
756 }else if((err
= a_sendout_body(nfo
, fi
, convert
)) != n_ERR_NONE
)
759 if(fflush(nfo
) == EOF
)
764 if(err
== n_ERR_NONE
){
773 if(iconvd
!= (iconv_t
)-1)
774 n_iconv_close(iconvd
);
783 _check_dispo_notif(struct name
*mdn
, struct header
*hp
, FILE *fo
)
789 /* TODO smtp_disposition_notification (RFC 3798): relation to return-path
790 * TODO not yet checked */
791 if (!ok_blook(disposition_notification_send
))
794 if (mdn
!= NULL
&& mdn
!= (struct name
*)0x1)
796 else if ((from
= myorigin(hp
)) == NULL
) {
797 if (n_poption
& n_PO_D_V
)
798 n_err(_("*disposition-notification-send*: *from* not set\n"));
802 if (!a_sendout_put_addrline("Disposition-Notification-To:",
803 nalloc(n_UNCONST(from
), 0), fo
, 0))
811 a_sendout_sendmail(void *v
, enum n_mailsend_flags msf
)
818 memset(&head
, 0, sizeof head
);
819 head
.h_mailx_command
= "mail";
820 if((head
.h_to
= lextract(str
, GTO
|
821 (ok_blook(fullnames
) ? GFULL
| GSKIN
: GSKIN
))) != NULL
)
822 head
.h_mailx_raw_to
= n_namelist_dup(head
.h_to
, head
.h_to
->n_type
);
823 rv
= n_mail1(msf
, &head
, NULL
, NULL
);
825 return (rv
!= OKAY
); /* reverse! */
829 a_sendout_file_a_pipe(struct name
*names
, FILE *fo
, bool_t
*senderror
){
830 ui32_t pipecnt
, xcnt
, i
;
839 /* Look through all recipients and do a quick return if no file or pipe
840 * addressee is found */
841 for(pipecnt
= xcnt
= 0, np
= names
; np
!= NULL
; np
= np
->n_flink
){
842 if(np
->n_type
& GDEL
)
844 switch(np
->n_flags
& NAME_ADDRSPEC_ISFILEORPIPE
){
845 case NAME_ADDRSPEC_ISFILE
: ++xcnt
; break;
846 case NAME_ADDRSPEC_ISPIPE
: ++pipecnt
; break;
849 if((pipecnt
| xcnt
) == 0)
852 /* Otherwise create an array of file descriptors for each found pipe
853 * addressee to get around the dup(2)-shared-file-offset problem, i.e.,
854 * each pipe subprocess needs its very own file descriptor, and we need
856 * To make our life a bit easier let's just use the auto-reclaimed
858 if(pipecnt
== 0 || (n_poption
& n_PO_DEBUG
)){
862 i
= sizeof(FILE*) * pipecnt
;
863 fppa
= n_lofi_alloc(i
);
865 sh
= ok_vlook(SHELL
);
868 for(np
= names
; np
!= NULL
; np
= np
->n_flink
){
869 if(!(np
->n_flags
& NAME_ADDRSPEC_ISFILEORPIPE
) || (np
->n_type
& GDEL
))
872 /* In days of old we removed the entry from the the list; now for sake of
873 * header expansion we leave it in and mark it as deleted */
876 if(n_poption
& n_PO_D_VV
)
877 n_err(_(">>> Writing message via %s\n"),
878 n_shexp_quote_cp(np
->n_name
, FAL0
));
879 /* We _do_ write to STDOUT, anyway! */
880 if((n_poption
& n_PO_DEBUG
) && ((np
->n_flags
& NAME_ADDRSPEC_ISPIPE
) ||
881 np
->n_name
[0] != '-' || np
->n_name
[1] != '\0'))
884 /* See if we have copied the complete message out yet. If not, do so */
889 if((fp
= Ftmp(&tempEdit
, "outof", OF_RDWR
| OF_HOLDSIGS
| OF_REGISTER
)
891 n_perr(_("Creation of temporary image"), 0);
896 for(i
= 0; i
< pipecnt
; ++i
)
897 if((fppa
[i
] = Fopen(tempEdit
, "r")) == NULL
){
898 n_perr(_("Creation of pipe image descriptor"), 0);
902 Ftmp_release(&tempEdit
);
908 fprintf(fp
, "From %s %s", ok_vlook(LOGNAME
), time_current
.tc_ctime
);
910 while(i
= c
, (c
= getc(fo
)) != EOF
)
918 n_perr(_("Finalizing write of temporary image"), 0);
922 /* From now on use xcnt as a counter for pipecnt */
926 /* Now either copy "image" to the desired file or give it as the standard
927 * input to the desired program as appropriate */
928 if(np
->n_flags
& NAME_ADDRSPEC_ISPIPE
){
933 sigaddset(&nset
, SIGHUP
);
934 sigaddset(&nset
, SIGINT
);
935 sigaddset(&nset
, SIGQUIT
);
936 pid
= n_child_start(sh
, &nset
, fileno(fppa
[xcnt
++]), n_CHILD_FD_NULL
,
937 "-c", &np
->n_name
[1], NULL
, NULL
);
939 n_err(_("Piping message to %s failed\n"),
940 n_shexp_quote_cp(np
->n_name
, FAL0
));
947 char const *fname
, *fnameq
;
949 if((fname
= fexpand(np
->n_name
, FEXP_NSHELL
)) == NULL
)
951 fnameq
= n_shexp_quote_cp(fname
, FAL0
);
953 if(fname
[0] == '-' && fname
[1] == '\0')
957 enum n_fopen_state fs
;
959 if((fout
= n_fopen_any(fname
, "a+", &fs
)) == NULL
){
962 n_err(_("Writing message to %s failed: %s\n"),
963 fnameq
, n_err_to_doc(xerr
));
967 if((fs
& (n_PROTO_MASK
| n_FOPEN_STATE_EXISTS
)) ==
968 (n_PROTO_FILE
| n_FOPEN_STATE_EXISTS
)){
969 n_file_lock(fileno(fout
), FLT_WRITE
, 0,0, UIZ_MAX
);
971 if((xerr
= n_folder_mbox_prepare_append(fout
, NULL
)
978 while((c
= getc(fp
)) != EOF
)
981 n_err(_("Writing message to %s failed: %s\n"),
982 fnameq
, _("write error"));
995 for(i
= 0; i
< pipecnt
; ++i
)
996 if((fp
= fppa
[i
]) != NULL
)
1006 if(np
->n_flags
& NAME_ADDRSPEC_ISFILEORPIPE
)
1014 mightrecord(FILE *fp
, struct name
*to
, bool_t resend
){
1022 if(n_poption
& n_PO_DEBUG
)
1024 else if(to
!= NULL
){
1025 ccp
= cp
= savestr(skinned_name(to
));
1026 while(*cp
!= '\0' && *cp
!= '@')
1030 ccp
= ok_vlook(record
);
1033 if((cp
= fexpand(ccp
, FEXP_NSHELL
)) == NULL
)
1036 switch(*(ccp
= cp
)){
1038 if(cp
[1] != '/'){ /* DIRSEP */
1040 if(ok_blook(outfolder
)){
1042 char const *nccp
, *folder
;
1044 switch(which_protocol(ccp
, TRU1
, FAL0
, &nccp
)){
1053 n_err(_("*record*: *outfolder*: no Maildir directory "
1054 "support compiled in\n"));
1058 folder
= n_folder_query();
1060 if(which_protocol(folder
, FAL0
, FAL0
, NULL
) == PROTO_IMAP
){
1061 n_err(_("*record*: *outfolder* set, *folder* is IMAP "
1062 "based: only one protocol per file is possible\n"));
1066 ccp
= str_concat_csvl(&s
, ccp
, folder
, nccp
, NULL
)->s
;
1078 if(!a_sendout__savemail(ccp
, fp
, resend
)){
1080 n_err(_("Failed to save message in %s - message not sent\n"),
1081 n_shexp_quote_cp(ccp
, FAL0
));
1082 n_exit_status
|= n_EXIT_ERR
;
1083 savedeadletter(fp
, 1);
1092 a_sendout__savemail(char const *name
, FILE *fp
, bool_t resend
){
1094 size_t bufsize
, buflen
, cnt
;
1095 enum n_fopen_state fs
;
1096 bool_t rv
, emptyline
;
1100 buf
= n_alloc(bufsize
= LINESIZE
);
1103 if((fo
= n_fopen_any(name
, "a+", &fs
)) == NULL
){
1108 if((fs
& (n_PROTO_MASK
| n_FOPEN_STATE_EXISTS
)) ==
1109 (n_PROTO_FILE
| n_FOPEN_STATE_EXISTS
)){
1112 /* TODO RETURN check, but be aware of protocols: v15: Mailbox->lock()!
1113 * TODO BETTER yet: should be returned in lock state already! */
1114 n_file_lock(fileno(fo
), FLT_WRITE
, 0,0, UIZ_MAX
);
1116 if((xerr
= n_folder_mbox_prepare_append(fo
, NULL
)) != n_ERR_NONE
){
1125 fprintf(fo
, "From %s %s", ok_vlook(LOGNAME
), time_current
.tc_ctime
);
1126 for(emptyline
= FAL0
, buflen
= 0, cnt
= fsize(fp
);
1127 fgetline(&buf
, &bufsize
, &cnt
, &buflen
, fp
, 0) != NULL
;){
1128 /* Only if we are resending it can happen that we have to quote From_
1129 * lines here; we don't generate messages which are ambiguous ourselves */
1131 if(emptyline
&& is_head(buf
, buflen
, FAL0
))
1133 }DBG(else assert(!is_head(buf
, buflen
, FAL0
)); )
1135 emptyline
= (buflen
> 0 && *buf
== '\n');
1136 fwrite(buf
, sizeof *buf
, buflen
, fo
);
1138 if(buflen
> 0 && buf
[buflen
- 1] != '\n')
1158 _transfer(struct sendbundle
*sbp
)
1165 for (cnt
= 0, np
= sbp
->sb_to
; np
!= NULL
;) {
1166 char const k
[] = "smime-encrypt-", *cp
;
1167 size_t nl
= strlen(np
->n_name
);
1168 char *vs
= n_lofi_alloc(sizeof(k
)-1 + nl
+1);
1169 memcpy(vs
, k
, sizeof(k
) -1);
1170 memcpy(vs
+ sizeof(k
) -1, np
->n_name
, nl
+1);
1172 if ((cp
= n_var_vlook(vs
, FAL0
)) != NULL
) {
1176 if ((ef
= smime_encrypt(sbp
->sb_input
, cp
, np
->n_name
)) != NULL
) {
1177 FILE *fisave
= sbp
->sb_input
;
1178 struct name
*nsave
= sbp
->sb_to
;
1180 sbp
->sb_to
= ndup(np
, np
->n_type
& ~(GFULL
| GSKIN
));
1182 if (!__mta_start(sbp
))
1185 sbp
->sb_input
= fisave
;
1190 n_err(_("No S/MIME support compiled in\n"));
1193 n_err(_("Message not sent to: %s\n"), np
->n_name
);
1194 _sendout_error
= TRU1
;
1198 rewind(sbp
->sb_input
);
1200 if (np
->n_flink
!= NULL
)
1201 np
->n_flink
->n_blink
= np
->n_blink
;
1202 if (np
->n_blink
!= NULL
)
1203 np
->n_blink
->n_flink
= np
->n_flink
;
1204 if (np
== sbp
->sb_to
)
1205 sbp
->sb_to
= np
->n_flink
;
1214 if (cnt
> 0 && (ok_blook(smime_force_encryption
) || !__mta_start(sbp
)))
1221 __mta_start(struct sendbundle
*sbp
)
1225 char const **args
, *mta
;
1229 /* Let rv mean "is smtp-based MTA" */
1230 if((mta
= ok_vlook(smtp
)) != NULL
){
1231 n_OBSOLETE(_("please don't use *smtp*: assign a smtp:// URL to *mta*!"));
1232 /* For *smtp* the smtp:// protocol was optional; be simple: don't check
1233 * that *smtp* is misused with file:// or so */
1234 if(n_servbyname(mta
, NULL
) == NULL
)
1235 mta
= savecat("smtp://", mta
);
1240 mta
= ok_vlook(mta
); /* TODO v15: what solely remains in here */
1241 if((proto
= ok_vlook(sendmail
)) != NULL
)
1242 n_OBSOLETE(_("please use *mta* instead of *sendmail*"));
1243 if(proto
!= NULL
&& !strcmp(mta
, VAL_MTA
))
1246 /* TODO for now this is pretty hacky: in v15 we should simply create
1247 * TODO an URL object; i.e., be able to do so, and it does it right
1248 * TODO I.e.,: url_creat(&url, ok_vlook(mta)); */
1249 if((proto
= n_servbyname(mta
, NULL
)) != NULL
){
1251 mta
+= sizeof("file://") -1;
1260 char const *mta_base
;
1262 if((mta
= fexpand(mta_base
= mta
, FEXP_LOCAL
| FEXP_NOPROTO
)) == NULL
){
1263 n_err(_("*mta* variable expansion failure: %s\n"),
1264 n_shexp_quote_cp(mta_base
, FAL0
));
1268 args
= __mta_prepare_args(sbp
->sb_to
, sbp
->sb_hp
);
1269 if (n_poption
& n_PO_DEBUG
) {
1270 __mta_debug(sbp
, mta
, args
);
1275 n_UNINIT(args
, NULL
);
1277 n_err(_("No SMTP support compiled in\n"));
1283 for(np
= sbp
->sb_to
; np
!= NULL
; np
= np
->n_flink
)
1284 if(!(np
->n_type
& GDEL
) && (np
->n_flags
& NAME_ADDRSPEC_ISNAME
)){
1285 n_err(_("SMTP *mta* cannot send to alias name: %s\n"),
1286 n_shexp_quote_cp(np
->n_name
, FAL0
));
1293 if (n_poption
& n_PO_DEBUG
) {
1294 (void)smtp_mta(sbp
);
1301 /* Fork, set up the temporary mail file as standard input for "mail", and
1302 * exec with the user list we generated far above */
1303 if ((pid
= n_child_fork()) == -1) {
1306 savedeadletter(sbp
->sb_input
, 0);
1307 _sendout_error
= TRU1
;
1312 sigaddset(&nset
, SIGHUP
);
1313 sigaddset(&nset
, SIGINT
);
1314 sigaddset(&nset
, SIGQUIT
);
1315 sigaddset(&nset
, SIGTSTP
);
1316 sigaddset(&nset
, SIGTTIN
);
1317 sigaddset(&nset
, SIGTTOU
);
1318 /* n_stdin = */freopen(n_path_devnull
, "r", stdin
);
1321 n_child_prepare(&nset
, 0, 1);
1330 n_child_prepare(&nset
, fileno(sbp
->sb_input
), -1);
1331 execv(mta
, n_UNCONST(args
));
1333 ecp
= (e
!= n_ERR_NOENT
) ? n_err_to_doc(e
)
1334 : _("executable not found (adjust *mta* variable)");
1335 n_err(_("Cannot start %s: %s\n"), n_shexp_quote_cp(mta
, FAL0
), ecp
);
1337 savedeadletter(sbp
->sb_input
, 1);
1338 n_err(_("... message not sent\n"));
1342 if ((n_poption
& n_PO_D_V
) || ok_blook(sendwait
)) {
1343 if (!(rv
= n_child_wait(pid
, NULL
)))
1344 _sendout_error
= TRU1
;
1354 static char const **
1355 __mta_prepare_args(struct name
*to
, struct header
*hp
)
1357 size_t vas_cnt
, i
, j
;
1359 char const **args
, *cp
, *cp_v15compat
;
1363 if((cp_v15compat
= ok_vlook(sendmail_arguments
)) != NULL
)
1364 n_OBSOLETE(_("please use *mta-arguments*, not *sendmail-arguments*"));
1365 if((cp
= ok_vlook(mta_arguments
)) == NULL
)
1367 if ((cp
/* TODO v15: = ok_vlook(mta_arguments)*/) == NULL
) {
1371 /* Don't assume anything on the content but do allocate exactly j slots;
1372 * like this getrawlist will never overflow (and return -1) */
1374 vas
= n_lofi_alloc(sizeof(*vas
) * j
);
1375 vas_cnt
= (size_t)getrawlist(TRU1
, vas
, j
, cp
, j
);
1378 i
= 4 + n_smopts_cnt
+ vas_cnt
+ 4 + 1 + count(to
) + 1;
1379 args
= n_autorec_alloc(i
* sizeof(char*));
1381 if((cp_v15compat
= ok_vlook(sendmail_progname
)) != NULL
)
1382 n_OBSOLETE(_("please use *mta-argv0*, not *sendmail-progname*"));
1383 cp
= ok_vlook(mta_argv0
);
1384 if(cp_v15compat
!= NULL
&& !strcmp(cp
, VAL_MTA_ARGV0
))
1386 args
[0] = cp
/* TODO v15 only : = ok_vlook(mta_argv0) */;
1388 if ((snda
= ok_blook(sendmail_no_default_arguments
)))
1389 n_OBSOLETE(_("please use *mta-no-default-arguments*, "
1390 "not *sendmail-no-default-arguments*"));
1391 snda
|= ok_blook(mta_no_default_arguments
);
1392 if ((snda
/* TODO v15: = ok_blook(mta_no_default_arguments)*/))
1397 if (ok_blook(metoo
))
1399 if (n_poption
& n_PO_VERB
)
1403 for (j
= 0; j
< n_smopts_cnt
; ++j
, ++i
)
1404 args
[i
] = n_smopts
[j
];
1406 for (j
= 0; j
< vas_cnt
; ++j
, ++i
)
1409 /* -r option? In conjunction with -t we act compatible to postfix(1) and
1410 * ignore it (it is -f / -F there) if the message specified From:/Sender:.
1411 * The interdependency with -t has been resolved in n_puthead() */
1412 if (!snda
&& ((n_poption
& n_PO_r_FLAG
) || ok_blook(r_option_implicit
))) {
1413 struct name
const *np
;
1415 if (hp
!= NULL
&& (np
= hp
->h_from
) != NULL
) {
1416 /* However, what wasn't resolved there was the case that the message
1417 * specified multiple From: addresses and a Sender: */
1418 if((n_poption
& n_PO_t_FLAG
) && hp
->h_sender
!= NULL
)
1421 if (np
->n_fullextra
!= NULL
) {
1423 args
[i
++] = np
->n_fullextra
;
1427 assert(n_poption_arg_r
== NULL
);
1428 cp
= skin(myorigin(NULL
));
1437 /* Terminate option list to avoid false interpretation of system-wide
1438 * aliases that start with hyphen */
1442 /* Receivers follow */
1443 if(!ok_blook(mta_no_receiver_arguments
))
1444 for (; to
!= NULL
; to
= to
->n_flink
)
1445 if (!(to
->n_type
& GDEL
))
1446 args
[i
++] = to
->n_name
;
1456 __mta_debug(struct sendbundle
*sbp
, char const *mta
, char const **args
)
1458 size_t cnt
, bufsize
, llen
;
1462 n_err(_(">>> MTA: %s, arguments:"), n_shexp_quote_cp(mta
, FAL0
));
1463 for (; *args
!= NULL
; ++args
)
1464 n_err(" %s", n_shexp_quote_cp(*args
, FAL0
));
1467 fflush_rewind(sbp
->sb_input
);
1469 cnt
= fsize(sbp
->sb_input
);
1472 while (fgetline(&buf
, &bufsize
, &cnt
, &llen
, sbp
->sb_input
, TRU1
) != NULL
) {
1474 n_err(">>> %s\n", buf
);
1482 a_sendout_random_id(struct header
*hp
, bool_t msgid
)
1484 static ui32_t reprocnt
;
1493 if(msgid
&& hp
!= NULL
&& hp
->h_message_id
!= NULL
){
1494 rv
= hp
->h_message_id
->n_name
;
1498 if(ok_blook(message_id_disable
))
1503 if((h
= __sendout_ident
) != NULL
)
1505 if(ok_vlook(hostname
) != NULL
){
1506 h
= n_nodename(TRU1
);
1511 if(hp
!= NULL
&& (h
= skin(myorigin(hp
))) != NULL
&& strchr(h
, '@') != NULL
)
1516 tmp
= &time_current
.tc_gm
;
1517 i
= sizeof("%04d%02d%02d%02d%02d%02d.%s%c%s") -1 + rl
+ strlen(h
);
1518 rv
= n_autorec_alloc(i
+1);
1519 snprintf(rv
, i
, "%04d%02d%02d%02d%02d%02d.%s%c%s",
1520 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
1521 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
,
1522 n_random_create_cp(rl
, &reprocnt
), sep
, h
);
1523 rv
[i
] = '\0'; /* Because we don't test snprintf(3) return */
1530 a_sendout_put_addrline(char const *hname
, struct name
*np
, FILE *fo
,
1531 enum a_sendout_addrline_flags saf
)
1533 ssize_t hnlen
, col
, len
;
1544 m
= (saf
& GCOMMA
) ? m_ERROR
| m_COMMA
: m_ERROR
;
1546 if((col
= hnlen
= strlen(hname
)) > 0){
1548 #define _X(S) (col == sizeof(S) -1 && !asccasecmp(hname, S))
1551 } else if (_X("reply-to:") || _X("mail-followup-to:") ||
1552 _X("references:") || _X("in-reply-to:") ||
1553 _X("disposition-notification-to:"))
1554 m
|= m_NOPF
| m_NONAME
;
1555 else if (ok_blook(add_file_recipients
)) {
1557 } else if (_X("to:") || _X("cc:") || _X("bcc:") || _X("resent-to:"))
1562 for (; np
!= NULL
; np
= np
->n_flink
) {
1563 if(np
->n_type
& GDEL
)
1565 if(is_addr_invalid(np
,
1566 ((saf
& a_SENDOUT_AL_INC_INVADDR
? 0 : EACM_NOLOG
) |
1567 (m
& m_NONAME
? EACM_NONAME
: EACM_NONE
))) &&
1568 !(saf
& a_SENDOUT_AL_INC_INVADDR
))
1571 /* File and pipe addresses only printed with set *add-file-recipients* */
1572 if ((m
& m_NOPF
) && is_fileorpipe_addr(np
))
1575 if ((m
& (m_INIT
| m_COMMA
)) == (m_INIT
| m_COMMA
)) {
1576 if (putc(',', fo
) == EOF
)
1582 len
= strlen(np
->n_fullname
);
1583 if (np
->n_type
& GREF
)
1585 ++col
; /* The separating space */
1586 if ((m
& m_INIT
) && /*col > 1 &&*/
1587 UICMP(z
, col
+ len
, >,
1588 (np
->n_type
& GREF
? MIME_LINELEN
: 72))) {
1589 if (fputs("\n ", fo
) == EOF
)
1594 if(!(m
& m_INIT
) && fwrite(hname
, sizeof *hname
, hnlen
, fo
1595 ) != sizeof *hname
* hnlen
)
1597 if(putc(' ', fo
) == EOF
)
1600 m
= (m
& ~m_CSEEN
) | m_INIT
;
1605 /* GREF needs to be placed in angle brackets, but which are missing */
1606 hb
= np
->n_fullname
;
1607 if(np
->n_type
& GREF
){
1608 assert(UICMP(z
, len
, ==, strlen(np
->n_fullname
) + 2));
1609 hb
= n_lofi_alloc(len
+1);
1614 memcpy(&hb
[1], np
->n_fullname
, len
);
1617 len
= xmime_write(hb
, len
, fo
,
1618 ((saf
& a_SENDOUT_AL_DOMIME
) ? CONV_TOHDR_A
: CONV_NONE
),
1619 TD_ICONV
, NULL
, NULL
);
1620 if(np
->n_type
& GREF
)
1628 if(!(m
& m_INIT
) || putc('\n', fo
) != EOF
)
1632 return ((m
& m_ERROR
) == 0);
1636 infix_resend(FILE *fi
, FILE *fo
, struct message
*mp
, struct name
*to
,
1639 size_t cnt
, c
, bufsize
= 0;
1642 struct name
*fromfield
= NULL
, *senderfield
= NULL
, *mdn
;
1648 /* Write the Resent-Fields */
1650 fputs("Resent-", fo
);
1652 if ((cp
= myaddrs(NULL
)) != NULL
) {
1653 if (!a_sendout_put_name(cp
, GCOMMA
, SEND_MBOX
, "Resent-From:", fo
,
1657 /* TODO RFC 5322: Resent-Sender SHOULD NOT be used if it's EQ -From: */
1658 if ((cp
= ok_vlook(sender
)) != NULL
) {
1659 if (!a_sendout_put_name(cp
, GCOMMA
, SEND_MBOX
, "Resent-Sender:", fo
,
1663 if (!a_sendout_put_addrline("Resent-To:", to
, fo
, a_SENDOUT_AL_COMMA
))
1665 if (((cp
= ok_vlook(stealthmua
)) == NULL
|| !strcmp(cp
, "noagent")) &&
1666 (cp
= a_sendout_random_id(NULL
, TRU1
)) != NULL
&&
1667 fprintf(fo
, "Resent-Message-ID: <%s>\n", cp
) < 0)
1671 if ((mdn
= n_UNCONST(check_from_and_sender(fromfield
, senderfield
))) == NULL
)
1673 if (!_check_dispo_notif(mdn
, NULL
, fo
))
1676 /* Write the original headers */
1678 if (fgetline(&buf
, &bufsize
, &cnt
, &c
, fi
, 0) == NULL
)
1680 if (ascncasecmp("status:", buf
, 7) &&
1681 ascncasecmp("disposition-notification-to:", buf
, 28) &&
1682 !is_head(buf
, c
, FAL0
))
1683 fwrite(buf
, sizeof *buf
, c
, fo
);
1684 if (cnt
> 0 && *buf
== '\n')
1688 /* Write the message body */
1690 if (fgetline(&buf
, &bufsize
, &cnt
, &c
, fi
, 0) == NULL
)
1692 if (cnt
== 0 && *buf
== '\n')
1694 fwrite(buf
, sizeof *buf
, c
, fo
);
1699 n_perr(_("infix_resend: temporary mail file"), 0);
1709 n_mail(enum n_mailsend_flags msf
, struct name
*to
, struct name
*cc
,
1710 struct name
*bcc
, char const *subject
, struct attachment
*attach
,
1711 char const *quotefile
)
1718 memset(&head
, 0, sizeof head
);
1720 /* The given subject may be in RFC1522 format. */
1721 if (subject
!= NULL
) {
1722 in
.s
= n_UNCONST(subject
);
1723 in
.l
= strlen(subject
);
1724 mime_fromhdr(&in
, &out
, /* TODO ??? TD_ISPR |*/ TD_ICONV
);
1725 head
.h_subject
= out
.s
;
1728 fullnames
= ok_blook(fullnames
);
1730 head
.h_mailx_command
= "mail";
1731 if((head
.h_to
= to
) != NULL
){
1733 head
.h_to
= to
= a_sendout_fullnames_cleanup(to
);
1734 head
.h_mailx_raw_to
= n_namelist_dup(to
, to
->n_type
);
1736 if((head
.h_cc
= cc
) != NULL
){
1738 head
.h_cc
= cc
= a_sendout_fullnames_cleanup(cc
);
1739 head
.h_mailx_raw_cc
= n_namelist_dup(cc
, cc
->n_type
);
1741 if((head
.h_bcc
= bcc
) != NULL
){
1743 head
.h_bcc
= bcc
= a_sendout_fullnames_cleanup(bcc
);
1744 head
.h_mailx_raw_bcc
= n_namelist_dup(bcc
, bcc
->n_type
);
1747 head
.h_attach
= attach
;
1749 /* TODO n_exit_status only!!?? */n_mail1(msf
, &head
, NULL
, quotefile
);
1751 if (subject
!= NULL
)
1763 rv
= a_sendout_sendmail(v
, n_MAILSEND_NONE
);
1774 rv
= a_sendout_sendmail(v
, n_MAILSEND_RECORD_RECIPIENT
);
1780 n_mail1(enum n_mailsend_flags msf
, struct header
*hp
, struct message
*quote
,
1781 char const *quotefile
)
1784 struct sendbundle sb
;
1787 FILE * volatile mtf
, *nmtf
;
1788 enum okay
volatile rv
;
1791 _sendout_error
= FAL0
;
1792 __sendout_ident
= NULL
;
1793 n_pstate_err_no
= n_ERR_INVAL
;
1797 n_SIGMAN_ENTER_SWITCH(&sm
, n_SIGMAN_ALL
) {
1804 /* Update some globals we likely need first */
1805 time_current_update(&time_current
, TRU1
);
1807 /* Collect user's mail from standard input. Get the result as mtf */
1808 mtf
= n_collect(msf
, hp
, quote
, quotefile
, &_sendout_error
);
1811 /* TODO All custom headers should be joined here at latest
1812 * TODO In fact that should happen before we enter compose mode, so that the
1813 * TODO -C headers can be managed (removed etc.) via ~^, too, but the
1814 * TODO *customhdr* ones are fixated at this very place here, no sooner! */
1819 if(n_psonce
& n_PSO_INTERACTIVE
){
1820 if (ok_blook(asksign
))
1821 dosign
= getapproval(_("Sign this message"), TRU1
);
1824 if(fsize(mtf
) == 0){
1825 if(n_poption
& n_PO_E_FLAG
){
1826 n_pstate_err_no
= n_ERR_NONE
;
1831 if(hp
->h_subject
== NULL
)
1832 n_err(_("No message, no subject; hope that's ok\n"));
1833 else if(ok_blook(bsdcompat
) || ok_blook(bsdmsgs
))
1834 n_err(_("Null message body; hope that's ok\n"));
1837 if (dosign
== TRUM1
)
1838 dosign
= ok_blook(smime_sign
); /* TODO USER@HOST <-> *from* +++!!! */
1841 n_err(_("No S/MIME support compiled in\n"));
1846 /* XXX Update time_current again; once n_collect() offers editing of more
1847 * XXX headers, including Date:, this must only happen if Date: is the
1848 * XXX same that it was before n_collect() (e.g., postponing etc.).
1849 * XXX But *do* update otherwise because the mail seems to be backdated
1850 * XXX if the user edited some time, which looks odd and it happened
1851 * XXX to me that i got mis-dated response mails due to that... */
1852 time_current_update(&time_current
, TRU1
);
1854 /* TODO hrmpf; the MIME/send layer rewrite MUST address the init crap:
1855 * TODO setup the header ONCE; note this affects edit.c, collect.c ...,
1856 * TODO but: offer a hook that rebuilds/expands/checks/fixates all
1857 * TODO header fields ONCE, call that ONCE after user editing etc. has
1858 * TODO completed (one edit cycle) */
1860 /* Take the user names from the combined to and cc lists and do all the
1861 * alias processing. The POSIX standard says:
1862 * The names shall be substituted when alias is used as a recipient
1863 * address specified by the user in an outgoing message (that is,
1864 * other recipients addressed indirectly through the reply command
1865 * shall not be substituted in this manner).
1866 * S-nail thus violates POSIX, as has been pointed out correctly by
1867 * Martin Neitzel, but logic and usability of POSIX standards is not seldom
1868 * disputable anyway. Go for user friendliness */
1870 to
= n_namelist_vaporise_head(((quote
!= NULL
&&
1871 (msf
& n_MAILSEND_IS_FWD
) == 0) || !ok_blook(posix
)),
1873 (!(expandaddr_to_eaf() & EAF_NAME
) ? EACM_NONAME
: EACM_NONE
)),
1877 n_err(_("No recipients specified\n"));
1878 n_pstate_err_no
= n_ERR_DESTADDRREQ
;
1881 if(_sendout_error
< 0){
1882 n_err(_("Some addressees were classified as \"hard error\"\n"));
1883 n_pstate_err_no
= n_ERR_PERM
;
1888 memset(&sb
, 0, sizeof sb
);
1892 if((dosign
|| count_nonlocal(to
) > 0) &&
1893 !_sendbundle_setup_creds(&sb
, (dosign
> 0))){
1894 /* TODO saving $DEAD and recovering etc is not yet well defined */
1895 n_pstate_err_no
= n_ERR_INVAL
;
1899 /* 'Bit ugly kind of control flow until we find a charset that does it */
1900 for (charset_iter_reset(hp
->h_charset
);; charset_iter_next()) {
1903 if (!charset_iter_is_valid())
1905 else if ((nmtf
= infix(hp
, mtf
)) != NULL
)
1907 else if ((err
= n_iconv_err_no
) == n_ERR_ILSEQ
|| err
== n_ERR_INVAL
||
1908 err
== n_ERR_NOENT
) {
1913 n_perr(_("Cannot find a usable character set to encode message"), err
);
1914 n_pstate_err_no
= n_ERR_NOTSUP
;
1922 if ((nmtf
= smime_sign(mtf
, sb
.sb_signer
.s
)) == NULL
)
1929 /* TODO truly - i still don't get what follows: (1) we deliver file
1930 * TODO and pipe addressees, (2) we mightrecord() and (3) we transfer
1931 * TODO even if (1) savedeadletter() etc. To me this doesn't make sense? */
1937 /* Deliver pipe and file addressees */
1938 b
= (ok_blook(record_files
) && count(to
) > 0);
1939 to
= a_sendout_file_a_pipe(to
, mtf
, &_sendout_error
);
1942 savedeadletter(mtf
, FAL0
);
1944 to
= elide(to
); /* XXX only to drop GDELs due a_sendout_file_a_pipe()! */
1947 if (((msf
& n_MAILSEND_RECORD_RECIPIENT
) || b
|| cnt
> 0) &&
1948 !mightrecord(mtf
, (msf
& n_MAILSEND_RECORD_RECIPIENT
? to
: NULL
),
1957 } else if (!_sendout_error
)
1961 n_sigman_cleanup_ping(&sm
);
1968 if((cp
= ok_vlook(on_compose_cleanup
)) != NULL
)
1969 temporary_compose_mode_hook_call(cp
, NULL
, NULL
);
1972 temporary_compose_mode_hook_unroll();
1975 n_exit_status
|= n_EXIT_SEND_ERROR
;
1977 n_pstate_err_no
= n_ERR_NONE
;
1979 n_sigman_leave(&sm
, n_SIGMAN_VIPSIGS_NTTYOUT
);
1983 _sendout_error
= TRU1
;
1984 savedeadletter(mtf
, TRU1
);
1985 n_err(_("... message not sent\n"));
1990 mkdate(FILE *fo
, char const *field
)
1992 struct tm tmpgm
, *tmptr
;
1993 int tzdiff
, tzdiff_hour
, tzdiff_min
, rv
;
1996 memcpy(&tmpgm
, &time_current
.tc_gm
, sizeof tmpgm
);
1997 tzdiff
= time_current
.tc_time
- mktime(&tmpgm
);
1998 tzdiff_hour
= (int)(tzdiff
/ 60);
1999 tzdiff_min
= tzdiff_hour
% 60;
2001 tmptr
= &time_current
.tc_local
;
2002 if (tmptr
->tm_isdst
> 0)
2004 rv
= fprintf(fo
, "%s: %s, %02d %s %04d %02d:%02d:%02d %+05d\n",
2006 n_weekday_names
[tmptr
->tm_wday
],
2007 tmptr
->tm_mday
, n_month_names
[tmptr
->tm_mon
],
2008 tmptr
->tm_year
+ 1900, tmptr
->tm_hour
,
2009 tmptr
->tm_min
, tmptr
->tm_sec
,
2010 tzdiff_hour
* 100 + tzdiff_min
);
2016 n_puthead(bool_t nosend_msg
, struct header
*hp
, FILE *fo
, enum gfield w
,
2017 enum sendaction action
, enum conversion convert
, char const *contenttype
,
2018 char const *charset
)
2020 #define a_PUT_CC_BCC_FCC() \
2022 if ((w & GCC) && (hp->h_cc != NULL || nosend_msg == TRUM1)) {\
2023 if (!a_sendout_put_addrline("Cc:", hp->h_cc, fo, saf))\
2027 if ((w & GBCC) && (hp->h_bcc != NULL || nosend_msg == TRUM1)) {\
2028 if (!a_sendout_put_addrline("Bcc:", hp->h_bcc, fo, saf))\
2032 if((w & GBCC_IS_FCC) && nosend_msg){\
2033 for(np = hp->h_fcc; np != NULL; np = np->n_flink){\
2034 if(fprintf(fo, "Fcc: %s\n", np->n_name) < 0)\
2043 struct name
*np
, *fromasender
= NULL
;
2046 enum a_sendout_addrline_flags saf
;
2052 if ((addr
= ok_vlook(stealthmua
)) != NULL
)
2053 stealthmua
= !strcmp(addr
, "noagent") ? -1 : 1;
2057 nodisp
= (action
!= SEND_TODISP
);
2058 saf
= (w
& (GCOMMA
| GFILES
)) | (nodisp
? a_SENDOUT_AL_DOMIME
: 0);
2060 saf
|= a_SENDOUT_AL_INC_INVADDR
;
2063 mkdate(fo
, "Date"), ++gotcha
;
2065 if (hp
->h_from
== NULL
|| hp
->h_sender
== NULL
)
2066 setup_from_and_sender(hp
);
2068 if (hp
->h_from
!= NULL
) {
2069 if (!a_sendout_put_addrline("From:", hp
->h_from
, fo
, saf
))
2074 if (hp
->h_sender
!= NULL
) {
2075 if (!a_sendout_put_addrline("Sender:", hp
->h_sender
, fo
, saf
))
2080 fromasender
= n_UNCONST(check_from_and_sender(hp
->h_from
, hp
->h_sender
));
2081 if (fromasender
== NULL
)
2083 /* Note that fromasender is (NULL,) 0x1 or real sender here */
2087 if ((w
& GTO
) && (hp
->h_to
!= NULL
|| nosend_msg
== TRUM1
)) {
2088 if (!a_sendout_put_addrline("To:", hp
->h_to
, fo
, saf
))
2093 /* TODO Thought about undisclosed recipients:;, but would be such a fake
2094 * TODO given that we cannot handle group addresses. Ridiculous */
2098 if ((xto
= hp
->h_to
) != NULL
) {
2099 char const ud
[] = "To: Undisclosed recipients:;\n" /* TODO groups */;
2101 if (count_nonlocal(xto
) != 0 || ok_blook(add_file_recipients
) ||
2102 (hp
->h_cc
!= NULL
&& count_nonlocal(hp
->h_cc
) > 0))
2104 if (fwrite(ud
, 1, sizeof(ud
) -1, fo
) != sizeof(ud
) -1)
2107 } else if (nosend_msg
== TRUM1
) {
2109 if (!a_sendout_put_addrline("To:", hp
->h_to
, fo
, saf
))
2116 if (!ok_blook(bsdcompat
) && !ok_blook(bsdorder
))
2119 if ((w
& GSUBJECT
) && (hp
->h_subject
!= NULL
|| nosend_msg
== TRUM1
)) {
2120 if (fwrite("Subject: ", sizeof(char), 9, fo
) != 9)
2122 if (hp
->h_subject
!= NULL
) {
2126 sublen
= strlen(sub
= subject_re_trim(hp
->h_subject
));
2128 /* Trimmed something, (re-)add Re: */
2129 if (sub
!= hp
->h_subject
) {
2130 if (fwrite("Re: ", 1, 4, fo
) != 4) /* RFC mandates eng. "Re: " */
2133 xmime_write(sub
, sublen
, fo
,
2134 (!nodisp
? CONV_NONE
: CONV_TOHDR
),
2135 (!nodisp
? TD_ISPR
| TD_ICONV
: TD_ICONV
), NULL
, NULL
) < 0)
2138 /* This may be, e.g., a Fwd: XXX yes, unfortunately we do like that */
2139 else if (*sub
!= '\0') {
2140 if (xmime_write(sub
, sublen
, fo
, (!nodisp
? CONV_NONE
: CONV_TOHDR
),
2141 (!nodisp
? TD_ISPR
| TD_ICONV
: TD_ICONV
), NULL
, NULL
) < 0)
2149 if (ok_blook(bsdcompat
) || ok_blook(bsdorder
))
2152 if ((w
& GMSGID
) && stealthmua
<= 0 &&
2153 (addr
= a_sendout_random_id(hp
, TRU1
)) != NULL
) {
2154 if (fprintf(fo
, "Message-ID: <%s>\n", addr
) < 0)
2159 if(w
& (GREF
| GREF_IRT
)){
2160 if((np
= hp
->h_in_reply_to
) == NULL
)
2161 hp
->h_in_reply_to
= np
= n_header_setup_in_reply_to(hp
);
2163 if(nosend_msg
== TRUM1
&&
2164 fputs(_("# Removing or modifying In-Reply-To: "
2165 "breaks the old, and starts a new thread\n"), fo
) == EOF
)
2167 if(!a_sendout_put_addrline("In-Reply-To:", np
, fo
, 0))
2172 if((w
& GREF
) && (np
= hp
->h_ref
) != NULL
){
2173 if(!a_sendout_put_addrline("References:", np
, fo
, 0))
2180 /* Reply-To:. Be careful not to destroy a possible user input, duplicate
2181 * the list first.. TODO it is a terrible codebase.. */
2182 if((np
= hp
->h_reply_to
) != NULL
)
2183 np
= n_namelist_dup(np
, np
->n_type
);
2185 char const *v15compat
;
2187 if((v15compat
= ok_vlook(replyto
)) != NULL
)
2188 n_OBSOLETE(_("please use *reply-to*, not *replyto*"));
2189 if((addr
= ok_vlook(reply_to
)) == NULL
)
2191 np
= lextract(addr
, GEXTRA
|
2192 (ok_blook(fullnames
) ? GFULL
| GSKIN
: GSKIN
));
2196 checkaddrs(usermap(np
, TRU1
), EACM_STRICT
| EACM_NOLOG
,
2198 if (!a_sendout_put_addrline("Reply-To:", np
, fo
, saf
))
2204 if ((w
& GIDENT
) && !nosend_msg
) {
2205 /* Mail-Followup-To: TODO factor out this huge block of code */
2206 /* Place ourselfs in there if any non-subscribed list is an addressee */
2207 if((hp
->h_flags
& HF_LIST_REPLY
) || hp
->h_mft
!= NULL
||
2208 ok_blook(followup_to
)){
2210 _ANYLIST
= 1u<<(HF__NEXT_SHIFT
+ 0),
2211 _HADMFT
= 1u<<(HF__NEXT_SHIFT
+ 1)
2213 struct name
*mft
, **mftp
, *x
;
2216 f
= hp
->h_flags
| (hp
->h_mft
!= NULL
? _HADMFT
: 0);
2220 /* But for that, we have to remove all incarnations of ourselfs first.
2221 * TODO It is total crap that we have alternates_remove(), is_myname()
2222 * TODO or whatever; these work only with variables, not with data
2223 * TODO that is _currently_ in some header fields!!! v15.0: complete
2224 * TODO rewrite, object based, lazy evaluated, on-the-fly marked.
2225 * TODO then this should be a really cheap thing in here... */
2226 np
= elide(n_alternates_remove(cat(
2227 n_namelist_dup(hp
->h_to
, GEXTRA
| GFULL
),
2228 n_namelist_dup(hp
->h_cc
, GEXTRA
| GFULL
)), FAL0
));
2229 addr
= hp
->h_list_post
;
2231 while((x
= np
) != NULL
){
2236 /* XXX is_mlist_mp()?? */
2237 if((ml
= is_mlist(x
->n_name
, FAL0
)) == MLIST_OTHER
&&
2238 addr
!= NULL
&& !asccasecmp(addr
, x
->n_name
))
2241 /* Any non-subscribed list? Add ourselves */
2246 case MLIST_SUBSCRIBED
:
2250 if(!(f
& HF_LIST_REPLY
)){
2252 if(!is_addr_invalid(x
,
2253 EACM_STRICT
| EACM_NOLOG
| EACM_NONAME
)){
2258 } /* XXX write some warning? if verbose?? */
2261 /* And if this is a reply that honoured a M-F-T: header then
2262 * we'll also add all members of the original M-F-T: that are
2263 * still addressed by us, regardless of other circumstances */
2264 else if(f
& _HADMFT
){
2267 for(ox
= hp
->h_mft
; ox
!= NULL
; ox
= ox
->n_flink
)
2268 if(!asccasecmp(ox
->n_name
, x
->n_name
))
2275 if((f
& (_ANYLIST
| _HADMFT
)) && mft
!= NULL
){
2276 if(((f
& HF_MFT_SENDER
) ||
2277 ((f
& (_ANYLIST
| _HADMFT
)) == _HADMFT
)) &&
2278 (np
= fromasender
) != NULL
&& np
!= (struct name
*)0x1)
2279 *mftp
= ndup(np
, (np
->n_type
& ~GMASK
) | GEXTRA
| GFULL
);
2281 if(!a_sendout_put_addrline("Mail-Followup-To:", mft
, fo
, saf
))
2287 if (!_check_dispo_notif(fromasender
, hp
, fo
))
2291 if ((w
& GUA
) && stealthmua
== 0) {
2292 if (fprintf(fo
, "User-Agent: %s %s\n", n_uagent
,
2293 (n_psonce
& n_PSO_REPRODUCIBLE
2294 ? n_reproducible_name
: ok_vlook(version
))) < 0)
2299 /* Custom headers, as via -C and *customhdr* TODO JOINED AFTER COMPOSE! */
2301 struct n_header_field
*chlp
[2], *hfp
;
2304 chlp
[0] = n_poption_arg_C
;
2305 chlp
[1] = n_customhdr_list
;
2307 for(i
= 0; i
< n_NELEM(chlp
); ++i
)
2308 if((hfp
= chlp
[i
]) != NULL
){
2309 if(!_sendout_header_list(fo
, hfp
, nodisp
))
2315 /* The user may have placed headers when editing */
2317 struct n_header_field
*hfp
;
2319 if((hfp
= hp
->h_user_headers
) != NULL
){
2320 if(!_sendout_header_list(fo
, hfp
, nodisp
))
2326 /* We don't need MIME unless.. we need MIME?! */
2327 if ((w
& GMIME
) && ((n_pstate
& n_PS_HEADER_NEEDED_MIME
) ||
2328 hp
->h_attach
!= NULL
||
2329 ((n_poption
& n_PO_Mm_FLAG
) && n_poption_arg_Mm
!= NULL
) ||
2330 convert
!= CONV_7BIT
|| !n_iconv_name_is_ascii(charset
))) {
2332 if (fputs("MIME-Version: 1.0\n", fo
) == EOF
)
2334 if (hp
->h_attach
!= NULL
) {
2335 _sendout_boundary
= mime_param_boundary_create();/*TODO carrier*/
2337 "Content-Type: multipart/mixed;\n boundary=\"%s\"\n",
2338 _sendout_boundary
) < 0)
2341 if(a_sendout_put_ct(fo
, contenttype
, charset
) < 0 ||
2342 a_sendout_put_cte(fo
, convert
) < 0)
2347 if (gotcha
&& (w
& GNL
))
2348 if (putc('\n', fo
) == EOF
)
2354 #undef a_PUT_CC_BCC_FCC
2358 resend_msg(struct message
*mp
, struct header
*hp
, bool_t add_resent
)
2361 struct sendbundle sb
;
2362 FILE * volatile ibuf
, *nfo
, * volatile nfi
;
2365 enum okay
volatile rv
;
2368 _sendout_error
= FAL0
;
2369 __sendout_ident
= NULL
;
2370 n_pstate_err_no
= n_ERR_INVAL
;
2375 n_SIGMAN_ENTER_SWITCH(&sm
, n_SIGMAN_ALL
) {
2382 /* Update some globals we likely need first */
2383 time_current_update(&time_current
, TRU1
);
2385 /* If we fail we delay that a bit until we can write $DEAD! */
2387 to
= checkaddrs(to
, (EACM_NORMAL
|
2388 (!(expandaddr_to_eaf() & EAF_NAME
) ? EACM_NONAME
: EACM_NONE
)),
2390 if(_sendout_error
< 0){
2391 n_err(_("Some addressees were classified as \"hard error\"\n"));
2392 n_pstate_err_no
= n_ERR_PERM
;
2393 }else if(to
== NULL
){
2394 n_err(_("No recipients specified\n"));
2395 n_pstate_err_no
= n_ERR_DESTADDRREQ
;
2398 if((nfo
= Ftmp(&tempMail
, "resend", OF_WRONLY
| OF_HOLDSIGS
| OF_REGISTER
)
2400 _sendout_error
= TRU1
;
2401 n_perr(_("resend_msg: temporary mail file"), 0);
2402 n_pstate_err_no
= n_ERR_IO
;
2405 if((nfi
= Fopen(tempMail
, "r")) == NULL
){
2406 n_perr(tempMail
, 0);
2407 n_pstate_err_no
= n_ERR_IO
;
2409 Ftmp_release(&tempMail
);
2413 if((ibuf
= setinput(&mb
, mp
, NEED_BODY
)) == NULL
){
2414 n_pstate_err_no
= n_ERR_IO
;
2418 /* Honour delayed error */
2419 if(_sendout_error
!= 0)
2425 if((cp
= ok_vlook(on_resend_enter
)) != NULL
){
2426 /*setup_from_and_sender(hp);*/
2427 temporary_compose_mode_hook_call(cp
, &n_temporary_compose_hook_varset
,
2432 memset(&sb
, 0, sizeof sb
);
2435 if(!_sendout_error
&&
2436 count_nonlocal(to
) > 0 && !_sendbundle_setup_creds(&sb
, FAL0
)){
2437 /* ..wait until we can write DEAD */
2438 n_pstate_err_no
= n_ERR_INVAL
;
2439 _sendout_error
= -1;
2442 if(infix_resend(ibuf
, nfo
, mp
, to
, add_resent
) != 0){
2444 savedeadletter(nfi
, TRU1
);
2445 n_err(_("... message not sent\n"));
2451 _sendout_error
= TRU1
;
2455 if(_sendout_error
< 0)
2464 /* Deliver pipe and file addressees */
2465 b
= (ok_blook(record_files
) && count(to
) > 0);
2466 to
= a_sendout_file_a_pipe(to
, nfi
, &_sendout_error
);
2469 savedeadletter(nfi
, FAL0
);
2471 to
= elide(to
); /* XXX only to drop GDELs due a_sendout_file_a_pipe()! */
2472 c
= (count(to
) > 0);
2475 if(!ok_blook(record_resent
) || mightrecord(nfi
, NULL
, TRU1
)){
2477 /*sb.sb_input = nfi;*/
2478 if(!c
|| _transfer(&sb
))
2481 }else if(!_sendout_error
)
2485 n_sigman_cleanup_ping(&sm
);
2493 if((cp
= ok_vlook(on_resend_cleanup
)) != NULL
)
2494 temporary_compose_mode_hook_call(cp
, NULL
, NULL
);
2496 temporary_compose_mode_hook_unroll();
2501 n_exit_status
|= n_EXIT_SEND_ERROR
;
2503 n_pstate_err_no
= n_ERR_NONE
;
2505 n_sigman_leave(&sm
, n_SIGMAN_VIPSIGS_NTTYOUT
);
2510 savedeadletter(FILE *fp
, bool_t fflush_rewind_first
){
2511 struct n_string line
;
2513 enum {a_NONE
, a_INIT
= 1<<0, a_BODY
= 1<<1, a_NL
= 1<<2} flags
;
2516 char const *cp
, *cpq
;
2522 if(fflush_rewind_first
){
2529 cp
= n_getdeadletter();
2530 cpq
= n_shexp_quote_cp(cp
, FAL0
);
2532 if(n_poption
& n_PO_DEBUG
){
2533 n_err(_(">>> Would (try to) write $DEAD %s\n"), cpq
);
2537 if((dbuf
= Fopen(cp
, "w")) == NULL
){
2538 n_perr(_("Cannot save to $DEAD"), 0);
2541 n_file_lock(fileno(dbuf
), FLT_WRITE
, 0,0, UIZ_MAX
); /* XXX Natomic */
2543 fprintf(n_stdout
, "%s ", cpq
);
2546 /* TODO savedeadletter() non-conforming: should check whether we have any
2547 * TODO headers, if not we need to place "something", anything will do.
2548 * TODO MIME is completely missing, we use MBOXO quoting!! Yuck.
2549 * TODO I/O error handling missing. Yuck! */
2550 n_string_reserve(n_string_creat_auto(&line
), 2 * SEND_LINESIZE
);
2551 bytes
= (ul_i
)fprintf(dbuf
, "From %s %s",
2552 ok_vlook(LOGNAME
), time_current
.tc_ctime
);
2554 for(flags
= a_NONE
, c
= '\0'; c
!= EOF
; bytes
+= line
.s_len
, ++lines
){
2555 n_string_trunc(&line
, 0);
2556 while((c
= getc(fp
)) != EOF
&& c
!= '\n')
2557 n_string_push_c(&line
, c
);
2559 /* TODO It may be that we have only some plain text. It may be that we
2560 * TODO have a complete MIME encoded message. We don't know, and we
2561 * TODO have no usable mechanism to dig it!! We need v15! */
2562 if(!(flags
& a_INIT
)){
2565 /* Throw away leading empty lines! */
2568 for(i
= 0; i
< line
.s_len
; ++i
){
2569 if(fieldnamechar(line
.s_dat
[i
]))
2571 if(line
.s_dat
[i
] == ':'){
2575 /* We have no headers, this is already a body line! */
2576 flags
|= a_INIT
| a_BODY
;
2580 /* Well, i had to check whether the RFC allows this. Assume we've
2581 * passed the headers, too, then! */
2583 flags
|= a_INIT
| a_BODY
;
2586 if(line
.s_len
>= 5 && !memcmp(line
.s_dat
, "From ", 5))
2587 n_string_unshift_c(&line
, '>');
2590 flags
|= a_BODY
| a_NL
;
2594 n_string_push_c(&line
, '\n');
2595 fwrite(line
.s_dat
, sizeof *line
.s_dat
, line
.s_len
, dbuf
);
2597 if(!(flags
& a_NL
)){
2602 n_string_gut(&line
);
2605 fprintf(n_stdout
, "%lu/%lu\n", lines
, bytes
);
2613 #undef SEND_LINESIZE