1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Collect input from standard input, handling ~ escapes.
3 *@ TODO This needs a complete rewrite, with carriers, etc.
5 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
6 * Copyright (c) 2012 - 2018 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
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 collect
39 #ifndef HAVE_AMALGAMATION
43 struct a_coll_ocs_arg
{
44 sighandler_type coa_opipe
;
45 sighandler_type coa_oint
;
46 FILE *coa_stdin
; /* The descriptor (pipe(2)+Fdopen()) we read from */
47 FILE *coa_stdout
; /* The Popen()ed pipe through which we write to the hook */
48 int coa_pipe
[2]; /* ..backing .coa_stdin */
49 si8_t
*coa_senderr
; /* Set to 1 on failure */
50 char coa_cmd
[n_VFIELD_SIZE(0)];
53 /* The following hookiness with global variables is so that on receipt of an
54 * interrupt signal, the partial message can be salted away on *DEAD* */
56 static sighandler_type _coll_saveint
; /* Previous SIGINT value */
57 static sighandler_type _coll_savehup
; /* Previous SIGHUP value */
58 static FILE *_coll_fp
; /* File for saving away */
59 static int volatile _coll_hadintr
; /* Have seen one SIGINT so far */
60 static sigjmp_buf _coll_jmp
; /* To get back to work */
61 static sigjmp_buf _coll_abort
; /* To end collection with error */
62 static char const *a_coll_ocs__macname
; /* *on-compose-splice* */
64 /* Handle `~:', `~_' and some hooks; hp may be NULL */
65 static void _execute_command(struct header
*hp
, char const *linebuf
,
69 static si32_t
a_coll_include_file(char const *name
, bool_t indent
,
72 /* Execute cmd and insert its standard output into fp, return errno */
73 static si32_t
a_coll_insert_cmd(FILE *fp
, char const *cmd
);
76 static void print_collf(FILE *collf
, struct header
*hp
);
78 /* Write a file, ex-like if f set */
79 static si32_t
a_coll_write(char const *name
, FILE *fp
, int f
);
81 /* *message-inject-head* */
82 static bool_t
a_coll_message_inject_head(FILE *fp
);
84 /* Parse off the message header from fp and store relevant fields in hp,
85 * replace _coll_fp with a shiny new version without any header */
86 static bool_t
a_coll_makeheader(FILE *fp
, struct header
*hp
,
87 si8_t
*checkaddr_err
, bool_t do_delayed_due_t
);
89 /* Edit the message being collected on fp. On return, make the edit file the
90 * new temp file. Return errno */
91 static si32_t
a_coll_edit(int c
, struct header
*hp
);
93 /* Pipe the message through the command. Old message is on stdin of command,
94 * new message collected from stdout. Shell must return 0 to accept new msg */
95 static si32_t
a_coll_pipe(char const *cmd
);
97 /* Interpolate the named messages into the current message, possibly doing
98 * indent stuff. The flag argument is one of the command escapes: [mMfFuU].
100 static si32_t
a_coll_forward(char const *ms
, FILE *fp
, int f
);
103 static bool_t
a_collect_plumbing(char const *ms
, struct header
*p
);
105 static bool_t
a_collect__plumb_header(char const *cp
, struct header
*p
,
107 static bool_t
a_collect__plumb_attach(char const *cp
, struct header
*p
,
110 /* On interrupt, come here to save the partial message in ~/dead.letter.
111 * Then jump out of the collection loop */
112 static void _collint(int s
);
114 static void collhup(int s
);
116 /* ~[AaIi], *message-inject-**: put value, expand \[nt] if *posix* */
117 static bool_t
a_coll_putesc(char const *s
, bool_t addnl
, FILE *stream
);
119 /* *on-compose-splice* driver and *on-compose-splice(-shell)?* finalizer */
120 static int a_coll_ocs__mac(void);
121 static void a_coll_ocs__finalize(void *vp
);
124 _execute_command(struct header
*hp
, char const *linebuf
, size_t linesize
){
125 /* The problem arises if there are rfc822 message attachments and the
126 * user uses `~:' to change the current file. TODO Unfortunately we
127 * TODO cannot simply keep a pointer to, or increment a reference count
128 * TODO of the current `file' (mailbox that is) object, because the
129 * TODO codebase doesn't deal with that at all; so, until some far
130 * TODO later time, copy the name of the path, and warn the user if it
131 * TODO changed; we COULD use the AC_TMPFILE attachment type, i.e.,
132 * TODO copy the message attachments over to temporary files, but that
133 * TODO would require more changes so that the user still can recognize
134 * TODO in `~@' etc. that its a rfc822 message attachment; see below */
136 struct attachment
*ap
;
137 char * volatile mnbuf
;
143 n_SIGMAN_ENTER_SWITCH(&sm
, n_SIGMAN_HUP
| n_SIGMAN_INT
| n_SIGMAN_QUIT
){
147 n_pstate_err_no
= n_ERR_INTR
;
152 /* If the above todo is worked, remove or outsource to attachment.c! */
153 if(hp
!= NULL
&& (ap
= hp
->h_attach
) != NULL
) do
155 mnbuf
= sstrdup(mailname
);
158 while((ap
= ap
->a_flink
) != NULL
);
160 n_go_command(n_GO_INPUT_CTX_COMPOSE
, linebuf
);
162 n_sigman_cleanup_ping(&sm
);
165 if(strcmp(mnbuf
, mailname
))
166 n_err(_("Mailbox changed: it is likely that existing "
167 "rfc822 attachments became invalid!\n"));
171 n_sigman_leave(&sm
, n_SIGMAN_VIPSIGS_NTTYOUT
);
175 a_coll_include_file(char const *name
, bool_t indent
, bool_t writestat
){
177 char const *heredb
, *indb
;
178 size_t linesize
, heredl
, indl
, cnt
, linelen
;
186 linebuf
= NULL
; /* TODO line pool */
191 /* The -M case is special */
192 if(name
== (char*)-1){
195 }else if(name
[0] == '-' &&
196 (name
[1] == '\0' || blankspacechar(name
[1]))){
199 if(!(n_psonce
& n_PSO_INTERACTIVE
)){
200 n_err(_("~< -: HERE-delimiter required in non-interactive mode\n"));
205 for(heredb
= &name
[2]; *heredb
!= '\0' && blankspacechar(*heredb
);
208 if((heredl
= strlen(heredb
)) == 0){
210 n_err(_("~< - HERE-delimiter: delimiter must not be empty\n"));
216 for(indb
= ++heredb
; *indb
!= '\0' && *indb
!= '\''; ++indb
)
219 n_err(_("~< - HERE-delimiter: missing trailing quote\n"));
222 }else if(indb
[1] != '\0'){
223 n_err(_("~< - HERE-delimiter: trailing characters after "
228 if((heredl
= PTR2SIZE(indb
- heredb
)) == 0)
230 heredb
= savestrbuf(heredb
, heredl
);
234 }else if((fbuf
= Fopen(name
, "r")) == NULL
){
235 n_perr(name
, rv
= n_err_no
);
239 indl
= indent
? strlen(indb
= ok_vlook(indentprefix
)) : 0;
243 while(fgetline(&linebuf
, &linesize
, (fbuf
== n_stdin
? NULL
: &cnt
),
244 &linelen
, fbuf
, 0) != NULL
){
245 if(heredl
> 0 && heredl
== linelen
- 1 &&
246 !memcmp(heredb
, linebuf
, heredl
)){
252 if(fwrite(indb
, sizeof *indb
, indl
, _coll_fp
) != indl
){
259 if(fwrite(linebuf
, sizeof *linebuf
, linelen
, _coll_fp
) != linelen
){
266 if(fflush(_coll_fp
)){
272 rv
= n_ERR_NOTOBACCO
;
284 fprintf(n_stdout
, "%s%s %" PRId64
"/%" PRId64
"\n",
285 n_shexp_quote_cp(name
, FAL0
), (rv
? " " n_ERROR
: n_empty
), lc
, cc
);
291 a_coll_insert_cmd(FILE *fp
, char const *cmd
){
300 if((ibuf
= Popen(cmd
, "r", ok_vlook(SHELL
), NULL
, 0)) != NULL
){
303 while((c
= getc(ibuf
)) != EOF
){ /* XXX bytewise, yuck! */
304 if(putc(c
, fp
) == EOF
){
312 if(!feof(ibuf
) || ferror(ibuf
)){
316 if(!Pclose(ibuf
, TRU1
)){
321 n_perr(cmd
, rv
= n_err_no
);
323 fprintf(n_stdout
, "CMD%s %" PRId64
"/%" PRId64
"\n",
324 (rv
== n_ERR_NONE
? n_empty
: " " n_ERROR
), lc
, cc
);
330 print_collf(FILE *cf
, struct header
*hp
)
334 size_t cnt
, linesize
, linelen
;
338 cnt
= (size_t)fsize(cf
);
340 if((obuf
= Ftmp(NULL
, "collfp", OF_RDWR
| OF_UNLINK
| OF_REGISTER
)) == NULL
){
341 n_perr(_("Can't create temporary file for `~p' command"), 0);
347 fprintf(obuf
, _("-------\nMessage contains:\n")); /* xxx SEARCH112 */
348 puthead(TRU1
, hp
, obuf
,
349 (GIDENT
| GTO
| GSUBJECT
| GCC
| GBCC
| GNL
| GFILES
| GCOMMA
),
350 SEND_TODISP
, CONV_NONE
, NULL
, NULL
);
354 while(fgetline(&lbuf
, &linesize
, &cnt
, &linelen
, cf
, 1))
355 prout(lbuf
, linelen
, obuf
);
359 if(hp
->h_attach
!= NULL
){
360 fputs(_("-------\nAttachments:\n"), obuf
);
361 n_attachment_list_print(hp
->h_attach
, obuf
);
366 page_or_print(obuf
, 0);
374 a_coll_write(char const *name
, FILE *fp
, int f
)
385 fprintf(n_stdout
, "%s ", n_shexp_quote_cp(name
, FAL0
));
389 if ((of
= Fopen(name
, "a")) == NULL
) {
390 n_perr(name
, rv
= n_err_no
);
395 while ((c
= getc(fp
)) != EOF
) {
399 if (putc(c
, of
) == EOF
) {
400 n_perr(name
, rv
= n_err_no
);
404 fprintf(n_stdout
, _("%" PRId64
"/%" PRId64
"\n"), lc
, cc
);
414 putc('\n', n_stdout
);
419 a_coll_message_inject_head(FILE *fp
){
421 char const *cp
, *cp_obsolete
;
424 cp_obsolete
= ok_vlook(NAIL_HEAD
);
425 if(cp_obsolete
!= NULL
)
426 n_OBSOLETE(_("please use *message-inject-head*, not *NAIL_HEAD*"));
428 if(((cp
= ok_vlook(message_inject_head
)) != NULL
||
429 (cp
= cp_obsolete
) != NULL
) && !a_coll_putesc(cp
, TRU1
, fp
))
438 a_coll_makeheader(FILE *fp
, struct header
*hp
, si8_t
*checkaddr_err
,
439 bool_t do_delayed_due_t
)
448 if ((nf
= Ftmp(NULL
, "colhead", OF_RDWR
| OF_UNLINK
| OF_REGISTER
)) ==NULL
) {
449 n_perr(_("temporary mail edit file"), 0);
453 extract_header(fp
, hp
, checkaddr_err
);
454 if (checkaddr_err
!= NULL
&& *checkaddr_err
!= 0)
457 /* In template mode some things have been delayed until the template has
459 if(do_delayed_due_t
){
462 if((cp
= ok_vlook(on_compose_enter
)) != NULL
){
463 setup_from_and_sender(hp
);
464 temporary_compose_mode_hook_call(cp
, &n_temporary_compose_hook_varset
,
468 if(!a_coll_message_inject_head(nf
))
472 while ((c
= getc(fp
)) != EOF
) /* XXX bytewise, yuck! */
481 if (check_from_and_sender(hp
->h_from
, hp
->h_sender
) == NULL
)
492 a_coll_edit(int c
, struct header
*hp
) /* TODO error(return) weird */
496 sighandler_type
volatile sigint
;
501 n_UNINIT(sigint
, SIG_ERR
);
504 if(!(saved
= ok_blook(add_file_recipients
)))
505 ok_bset(add_file_recipients
);
507 n_SIGMAN_ENTER_SWITCH(&sm
, n_SIGMAN_ALL
){
509 sigint
= safe_signal(SIGINT
, SIG_IGN
);
516 nf
= run_editor(_coll_fp
, (off_t
)-1, c
, FAL0
, hp
, NULL
, SEND_MBOX
, sigint
);
519 if(!a_coll_makeheader(nf
, hp
, NULL
, FAL0
))
522 fseek(nf
, 0L, SEEK_END
);
529 n_sigman_cleanup_ping(&sm
);
532 ok_bclear(add_file_recipients
);
533 safe_signal(SIGINT
, sigint
);
535 n_sigman_leave(&sm
, n_SIGMAN_VIPSIGS_NTTYOUT
);
540 a_coll_pipe(char const *cmd
)
544 sighandler_type sigint
;
549 sigint
= safe_signal(SIGINT
, SIG_IGN
);
551 if ((nf
= Ftmp(NULL
, "colpipe", OF_RDWR
| OF_UNLINK
| OF_REGISTER
)) ==NULL
) {
552 n_perr(_("temporary mail edit file"), rv
= n_err_no
);
556 /* stdin = current message. stdout = new message */
558 if (n_child_run(ok_vlook(SHELL
), 0, fileno(_coll_fp
), fileno(nf
), "-c",
559 cmd
, NULL
, NULL
, &ws
) < 0 || WEXITSTATUS(ws
) != 0) {
565 if (fsize(nf
) == 0) {
566 n_err(_("No bytes from %s !?\n"), n_shexp_quote_cp(cmd
, FAL0
));
573 fseek(nf
, 0L, SEEK_END
);
577 safe_signal(SIGINT
, sigint
);
583 a_coll_forward(char const *ms
, FILE *fp
, int f
)
586 struct n_ignore
const *itp
;
588 enum sendaction action
;
591 msgvec
= salloc((size_t)(msgCount
+ 1) * sizeof *msgvec
);
592 if (getmsglist(ms
, msgvec
, 0) < 0) {
593 rv
= n_ERR_NOENT
; /* XXX not really, should be handled there! */
597 *msgvec
= first(0, MMNORM
);
599 n_err(_("No appropriate messages\n"));
606 if (f
== 'f' || f
== 'F' || f
== 'u')
609 tabst
= ok_vlook(indentprefix
);
610 if (f
== 'u' || f
== 'U')
613 itp
= upperchar(f
) ? NULL
: n_IGNORE_TYPE
;
614 action
= (upperchar(f
) && f
!= 'U') ? SEND_QUOTE_ALL
: SEND_QUOTE
;
616 fprintf(n_stdout
, _("Interpolating:"));
618 for (; *msgvec
!= 0; ++msgvec
) {
619 struct message
*mp
= message
+ *msgvec
- 1;
622 fprintf(n_stdout
, " %d", *msgvec
);
624 if (sendmp(mp
, fp
, itp
, tabst
, action
, NULL
) < 0) {
625 n_perr(_("forward: temporary mail file"), 0);
632 fprintf(n_stdout
, "\n");
639 a_collect_plumbing(char const *ms
, struct header
*hp
){
640 /* TODO _collect_plumbing: instead of fields the basic headers should
641 * TODO be in an array and have IDs, like in termcap etc., so then this
642 * TODO could be simplified as table-walks. Also true for arg-checks! */
644 char const *cp
, *cmd
[4];
647 /* Protcol version for *on-compose-splice** -- update manual on change! */
648 #define a_COLL_PLUMBING_VERSION "0 0 1"
654 for(i
= 0; i
< n_NELEM(cmd
); ++i
){ /* TODO trim+strlist_split(_ifs?)() */
655 while(blankchar(*cp
))
660 if(i
< n_NELEM(cmd
) - 1)
661 for(cmd
[i
] = cp
++; *cp
!= '\0' && !blankchar(*cp
); ++cp
)
664 /* Last slot takes all the rest of the line, less trailing WS */
665 for(cmd
[i
] = cp
++; *cp
!= '\0'; ++cp
)
667 while(blankchar(cp
[-1]))
670 cmd
[i
] = savestrbuf(cmd
[i
], PTR2SIZE(cp
- cmd
[i
]));
675 if(n_UNLIKELY(cmd
[0] == NULL
))
677 if(is_asccaseprefix(cmd
[0], "header"))
678 rv
= a_collect__plumb_header(cp
, hp
, cmd
);
679 else if(is_asccaseprefix(cmd
[0], "attachment"))
680 rv
= a_collect__plumb_attach(cp
, hp
, cmd
);
683 fputs("500\n", n_stdout
);
693 a_collect__plumb_header(char const *cp
, struct header
*hp
,
696 struct n_header_field
*hfp
;
697 struct name
*np
, **npp
;
703 if(is_asccaseprefix(cmd
[1], "insert")){ /* TODO LOGIC BELONGS head.c
704 * TODO That is: Header::factory(string) -> object (blahblah).
705 * TODO I.e., as long as we don't have regular RFC compliant parsers
706 * TODO which differentiate in between structured and unstructured
707 * TODO header fields etc., a little workaround */
710 enum expand_addr_check_mode eacm
;
714 if(cmd
[2] == NULL
|| cmd
[3] == NULL
)
717 /* Strip [\r\n] which would render a body invalid XXX all controls? */
721 cmd
[3] = xp
= savestr(cmd
[3]);
722 for(; (c
= *xp
) != '\0'; ++xp
)
723 if(c
== '\n' || c
== '\r')
727 if(!asccasecmp(cmd
[2], cp
= "Subject")){
728 if(cmd
[3][0] != '\0'){
729 if(hp
->h_subject
!= NULL
)
730 hp
->h_subject
= savecatsep(hp
->h_subject
, ' ', cmd
[3]);
732 hp
->h_subject
= n_UNCONST(cmd
[3]);
733 fprintf(n_stdout
, "210 %s 1\n", cp
);
740 ntype
= GEXTRA
| GFULL
| GFULLEXTRA
;
743 if(!asccasecmp(cmd
[2], cp
= "From")){
747 if((np
= lextract(cmd
[3], ntype
)) == NULL
)
750 if((np
= checkaddrs(np
, eacm
, &aerr
), aerr
!= 0)){
751 fprintf(n_stdout
, "505 %s\n", cp
);
755 /* Go to the end of the list, track whether it contains any
756 * non-deleted entries */
758 if((xnp
= *npp
) != NULL
)
759 for(;; xnp
= xnp
->n_flink
){
760 if(!(xnp
->n_type
& GDEL
))
762 if(xnp
->n_flink
== NULL
)
766 if(!mult_ok
&& (i
!= 0 || np
->n_flink
!= NULL
))
767 fprintf(n_stdout
, "506 %s\n", cp
);
774 fprintf(n_stdout
, "210 %s %" PRIuZ
"\n", cp
, ++i
);
778 if(!asccasecmp(cmd
[2], cp
= "Sender")){
783 if(!asccasecmp(cmd
[2], cp
= "To")){
786 eacm
= EACM_NORMAL
| EAF_NAME
;
789 if(!asccasecmp(cmd
[2], cp
= "Cc")){
792 eacm
= EACM_NORMAL
| EAF_NAME
;
795 if(!asccasecmp(cmd
[2], cp
= "Bcc")){
797 ntype
= GBCC
| GFULL
;
798 eacm
= EACM_NORMAL
| EAF_NAME
;
801 if(!asccasecmp(cmd
[2], cp
= "Reply-To")){
802 npp
= &hp
->h_reply_to
;
806 if(!asccasecmp(cmd
[2], cp
= "Mail-Followup-To")){
811 if(!asccasecmp(cmd
[2], cp
= "Message-ID")){
813 npp
= &hp
->h_message_id
;
818 if(!asccasecmp(cmd
[2], cp
= "References")){
824 if(!asccasecmp(cmd
[2], cp
= "In-Reply-To")){
825 npp
= &hp
->h_in_reply_to
;
831 if((cp
= n_header_is_standard(cmd
[2], UIZ_MAX
)) != NULL
){
832 fprintf(n_stdout
, "505 %s\n", cp
);
836 /* Free-form header fields */
839 struct n_header_field
**hfpp
;
841 for(cp
= cmd
[2]; *cp
!= '\0'; ++cp
)
842 if(!fieldnamechar(*cp
)){
847 for(i
= 0, hfpp
= &hp
->h_user_headers
; *hfpp
!= NULL
; ++i
)
848 hfpp
= &(*hfpp
)->hf_next
;
850 nl
= strlen(cp
= cmd
[2]) +1;
851 bl
= strlen(cmd
[3]) +1;
852 *hfpp
= hfp
= salloc(n_VSTRUCT_SIZEOF(struct n_header_field
, hf_dat
857 memcpy(&hfp
->hf_dat
[0], cp
, nl
);
858 memcpy(&hfp
->hf_dat
[nl
], cmd
[3], bl
);
859 fprintf(n_stdout
, "210 %s %" PRIuZ
"\n", &hfp
->hf_dat
[0], ++i
);
864 if(is_asccaseprefix(cmd
[1], "list")){
867 fputs("210", n_stdout
);
868 if(hp
->h_subject
!= NULL
) fputs(" Subject", n_stdout
);
869 if(hp
->h_from
!= NULL
) fputs(" From", n_stdout
);
870 if(hp
->h_sender
!= NULL
) fputs(" Sender", n_stdout
);
871 if(hp
->h_to
!= NULL
) fputs(" To", n_stdout
);
872 if(hp
->h_cc
!= NULL
) fputs(" Cc", n_stdout
);
873 if(hp
->h_bcc
!= NULL
) fputs(" Bcc", n_stdout
);
874 if(hp
->h_reply_to
!= NULL
) fputs(" Reply-To", n_stdout
);
875 if(hp
->h_mft
!= NULL
) fputs(" Mail-Followup-To", n_stdout
);
876 if(hp
->h_message_id
!= NULL
) fputs(" Message-ID", n_stdout
);
877 if(hp
->h_ref
!= NULL
) fputs(" References", n_stdout
);
878 if(hp
->h_in_reply_to
!= NULL
) fputs(" In-Reply-To", n_stdout
);
879 if(hp
->h_mailx_command
!= NULL
) fputs(" Mailx-Command", n_stdout
);
880 if(hp
->h_mailx_raw_to
!= NULL
) fputs(" Mailx-Raw-To", n_stdout
);
881 if(hp
->h_mailx_raw_cc
!= NULL
) fputs(" Mailx-Raw-Cc", n_stdout
);
882 if(hp
->h_mailx_raw_bcc
!= NULL
) fputs(" Mailx-Raw-Bcc", n_stdout
);
883 if(hp
->h_mailx_orig_from
!= NULL
) fputs(" Mailx-Orig-From", n_stdout
);
884 if(hp
->h_mailx_orig_to
!= NULL
) fputs(" Mailx-Orig-To", n_stdout
);
885 if(hp
->h_mailx_orig_cc
!= NULL
) fputs(" Mailx-Orig-Cc", n_stdout
);
886 if(hp
->h_mailx_orig_bcc
!= NULL
) fputs(" Mailx-Orig-Bcc", n_stdout
);
888 /* Print only one instance of each free-form header */
889 for(hfp
= hp
->h_user_headers
; hfp
!= NULL
; hfp
= hfp
->hf_next
){
890 struct n_header_field
*hfpx
;
892 for(hfpx
= hp
->h_user_headers
;; hfpx
= hfpx
->hf_next
)
895 fputs(&hfp
->hf_dat
[0], n_stdout
);
897 }else if(!asccasecmp(&hfpx
->hf_dat
[0], &hfp
->hf_dat
[0]))
900 putc('\n', n_stdout
);
907 if(!asccasecmp(cmd
[2], cp
= "Subject")){
908 np
= (hp
->h_subject
!= NULL
) ? (struct name
*)-1 : NULL
;
911 if(!asccasecmp(cmd
[2], cp
= "From")){
914 fprintf(n_stdout
, "%s %s\n", (np
== NULL
? "501" : "210"), cp
);
917 if(!asccasecmp(cmd
[2], cp
= "Sender")){
921 if(!asccasecmp(cmd
[2], cp
= "To")){
925 if(!asccasecmp(cmd
[2], cp
= "Cc")){
929 if(!asccasecmp(cmd
[2], cp
= "Bcc")){
933 if(!asccasecmp(cmd
[2], cp
= "Reply-To")){
937 if(!asccasecmp(cmd
[2], cp
= "Mail-Followup-To")){
941 if(!asccasecmp(cmd
[2], cp
= "Message-ID")){
942 np
= hp
->h_message_id
;
945 if(!asccasecmp(cmd
[2], cp
= "References")){
949 if(!asccasecmp(cmd
[2], cp
= "In-Reply-To")){
950 np
= hp
->h_in_reply_to
;
954 if(!asccasecmp(cmd
[2], cp
= "Mailx-Command")){
955 np
= (hp
->h_mailx_command
!= NULL
) ? (struct name
*)-1 : NULL
;
958 if(!asccasecmp(cmd
[2], cp
= "Mailx-Raw-To")){
959 np
= hp
->h_mailx_raw_to
;
962 if(!asccasecmp(cmd
[2], cp
= "Mailx-Raw-Cc")){
963 np
= hp
->h_mailx_raw_cc
;
966 if(!asccasecmp(cmd
[2], cp
= "Mailx-Raw-Bcc")){
967 np
= hp
->h_mailx_raw_bcc
;
970 if(!asccasecmp(cmd
[2], cp
= "Mailx-Orig-From")){
971 np
= hp
->h_mailx_orig_from
;
974 if(!asccasecmp(cmd
[2], cp
= "Mailx-Orig-To")){
975 np
= hp
->h_mailx_orig_to
;
978 if(!asccasecmp(cmd
[2], cp
= "Mailx-Orig-Cc")){
979 np
= hp
->h_mailx_orig_cc
;
982 if(!asccasecmp(cmd
[2], cp
= "Mailx-Orig-Bcc")){
983 np
= hp
->h_mailx_orig_bcc
;
987 /* Free-form header fields */
988 for(cp
= cmd
[2]; *cp
!= '\0'; ++cp
)
989 if(!fieldnamechar(*cp
)){
994 for(hfp
= hp
->h_user_headers
;; hfp
= hfp
->hf_next
){
997 else if(!asccasecmp(cp
, &hfp
->hf_dat
[0])){
998 fprintf(n_stdout
, "210 %s\n", &hfp
->hf_dat
[0]);
1005 if(is_asccaseprefix(cmd
[1], "remove")){
1006 if(cmd
[2] == NULL
|| cmd
[3] != NULL
)
1009 if(!asccasecmp(cmd
[2], cp
= "Subject")){
1010 if(hp
->h_subject
!= NULL
){
1011 hp
->h_subject
= NULL
;
1012 fprintf(n_stdout
, "210 %s\n", cp
);
1018 if(!asccasecmp(cmd
[2], cp
= "From")){
1023 fprintf(n_stdout
, "210 %s\n", cp
);
1028 if(!asccasecmp(cmd
[2], cp
= "Sender")){
1029 npp
= &hp
->h_sender
;
1032 if(!asccasecmp(cmd
[2], cp
= "To")){
1036 if(!asccasecmp(cmd
[2], cp
= "Cc")){
1040 if(!asccasecmp(cmd
[2], cp
= "Bcc")){
1044 if(!asccasecmp(cmd
[2], cp
= "Reply-To")){
1045 npp
= &hp
->h_reply_to
;
1048 if(!asccasecmp(cmd
[2], cp
= "Mail-Followup-To")){
1052 if(!asccasecmp(cmd
[2], cp
= "Message-ID")){
1053 npp
= &hp
->h_message_id
;
1056 if(!asccasecmp(cmd
[2], cp
= "References")){
1060 if(!asccasecmp(cmd
[2], cp
= "In-Reply-To")){
1061 npp
= &hp
->h_in_reply_to
;
1065 if((cp
= n_header_is_standard(cmd
[2], UIZ_MAX
)) != NULL
){
1066 fprintf(n_stdout
, "505 %s\n", cp
);
1070 /* Free-form header fields (note j501cp may print non-normalized name) */
1072 struct n_header_field
**hfpp
;
1075 for(cp
= cmd
[2]; *cp
!= '\0'; ++cp
)
1076 if(!fieldnamechar(*cp
)){
1082 for(any
= FAL0
, hfpp
= &hp
->h_user_headers
; (hfp
= *hfpp
) != NULL
;){
1083 if(!asccasecmp(cp
, &hfp
->hf_dat
[0])){
1084 *hfpp
= hfp
->hf_next
;
1086 fprintf(n_stdout
, "210 %s\n", &hfp
->hf_dat
[0]);
1089 hfpp
= &hfp
->hf_next
;
1097 if(is_asccaseprefix(cmd
[1], "remove-at")){
1098 if(cmd
[2] == NULL
|| cmd
[3] == NULL
)
1101 if((n_idec_uiz_cp(&i
, cmd
[3], 0, NULL
1102 ) & (n_IDEC_STATE_EMASK
| n_IDEC_STATE_CONSUMED
)
1103 ) != n_IDEC_STATE_CONSUMED
|| i
== 0){
1104 fputs("505\n", n_stdout
);
1108 if(!asccasecmp(cmd
[2], cp
= "Subject")){
1109 if(hp
->h_subject
!= NULL
&& i
== 1){
1110 hp
->h_subject
= NULL
;
1111 fprintf(n_stdout
, "210 %s 1\n", cp
);
1117 if(!asccasecmp(cmd
[2], cp
= "From")){
1120 if((np
= *npp
) == NULL
)
1122 while(--i
!= 0 && np
!= NULL
)
1127 if(np
->n_blink
!= NULL
)
1128 np
->n_blink
->n_flink
= np
->n_flink
;
1131 if(np
->n_flink
!= NULL
)
1132 np
->n_flink
->n_blink
= np
->n_blink
;
1134 fprintf(n_stdout
, "210 %s\n", cp
);
1137 if(!asccasecmp(cmd
[2], cp
= "Sender")){
1138 npp
= &hp
->h_sender
;
1141 if(!asccasecmp(cmd
[2], cp
= "To")){
1145 if(!asccasecmp(cmd
[2], cp
= "Cc")){
1149 if(!asccasecmp(cmd
[2], cp
= "Bcc")){
1153 if(!asccasecmp(cmd
[2], cp
= "Reply-To")){
1154 npp
= &hp
->h_reply_to
;
1157 if(!asccasecmp(cmd
[2], cp
= "Mail-Followup-To")){
1161 if(!asccasecmp(cmd
[2], cp
= "Message-ID")){
1162 npp
= &hp
->h_message_id
;
1165 if(!asccasecmp(cmd
[2], cp
= "References")){
1169 if(!asccasecmp(cmd
[2], cp
= "In-Reply-To")){
1170 npp
= &hp
->h_in_reply_to
;
1174 if((cp
= n_header_is_standard(cmd
[2], UIZ_MAX
)) != NULL
){
1175 fprintf(n_stdout
, "505 %s\n", cp
);
1179 /* Free-form header fields */
1181 struct n_header_field
**hfpp
;
1183 for(cp
= cmd
[2]; *cp
!= '\0'; ++cp
)
1184 if(!fieldnamechar(*cp
)){
1190 for(hfpp
= &hp
->h_user_headers
; (hfp
= *hfpp
) != NULL
;){
1192 *hfpp
= hfp
->hf_next
;
1193 fprintf(n_stdout
, "210 %s %" PRIuZ
"\n", &hfp
->hf_dat
[0], i
);
1196 hfpp
= &hfp
->hf_next
;
1204 if(is_asccaseprefix(cmd
[1], "show")){
1205 if(cmd
[2] == NULL
|| cmd
[3] != NULL
)
1208 if(!asccasecmp(cmd
[2], cp
= "Subject")){
1209 if(hp
->h_subject
== NULL
)
1211 fprintf(n_stdout
, "212 %s\n%s\n\n", cp
, hp
->h_subject
);
1215 if(!asccasecmp(cmd
[2], cp
= "From")){
1219 fprintf(n_stdout
, "211 %s\n", cp
);
1220 do if(!(np
->n_type
& GDEL
))
1221 fprintf(n_stdout
, "%s %s\n", np
->n_name
, np
->n_fullname
);
1222 while((np
= np
->n_flink
) != NULL
);
1223 putc('\n', n_stdout
);
1228 if(!asccasecmp(cmd
[2], cp
= "Sender")){
1232 if(!asccasecmp(cmd
[2], cp
= "To")){
1236 if(!asccasecmp(cmd
[2], cp
= "Cc")){
1240 if(!asccasecmp(cmd
[2], cp
= "Bcc")){
1244 if(!asccasecmp(cmd
[2], cp
= "Reply-To")){
1245 np
= hp
->h_reply_to
;
1248 if(!asccasecmp(cmd
[2], cp
= "Mail-Followup-To")){
1252 if(!asccasecmp(cmd
[2], cp
= "Message-ID")){
1253 np
= hp
->h_message_id
;
1256 if(!asccasecmp(cmd
[2], cp
= "References")){
1260 if(!asccasecmp(cmd
[2], cp
= "In-Reply-To")){
1261 np
= hp
->h_in_reply_to
;
1265 if(!asccasecmp(cmd
[2], cp
= "Mailx-Command")){
1266 if(hp
->h_mailx_command
== NULL
)
1268 fprintf(n_stdout
, "212 %s\n%s\n\n", cp
, hp
->h_mailx_command
);
1271 if(!asccasecmp(cmd
[2], cp
= "Mailx-Raw-To")){
1272 np
= hp
->h_mailx_raw_to
;
1275 if(!asccasecmp(cmd
[2], cp
= "Mailx-Raw-Cc")){
1276 np
= hp
->h_mailx_raw_cc
;
1279 if(!asccasecmp(cmd
[2], cp
= "Mailx-Raw-Bcc")){
1280 np
= hp
->h_mailx_raw_bcc
;
1283 if(!asccasecmp(cmd
[2], cp
= "Mailx-Orig-From")){
1284 np
= hp
->h_mailx_orig_from
;
1287 if(!asccasecmp(cmd
[2], cp
= "Mailx-Orig-To")){
1288 np
= hp
->h_mailx_orig_to
;
1291 if(!asccasecmp(cmd
[2], cp
= "Mailx-Orig-Cc")){
1292 np
= hp
->h_mailx_orig_cc
;
1295 if(!asccasecmp(cmd
[2], cp
= "Mailx-Orig-Bcc")){
1296 np
= hp
->h_mailx_orig_bcc
;
1300 /* Free-form header fields */
1304 for(cp
= cmd
[2]; *cp
!= '\0'; ++cp
)
1305 if(!fieldnamechar(*cp
)){
1311 for(any
= FAL0
, hfp
= hp
->h_user_headers
; hfp
!= NULL
;
1312 hfp
= hfp
->hf_next
){
1313 if(!asccasecmp(cp
, &hfp
->hf_dat
[0])){
1315 fprintf(n_stdout
, "212 %s\n", &hfp
->hf_dat
[0]);
1317 fprintf(n_stdout
, "%s\n", &hfp
->hf_dat
[hfp
->hf_nl
+1]);
1321 putc('\n', n_stdout
);
1329 fputs("500\n", n_stdout
);
1333 return (cp
!= NULL
);
1336 fputs("501 ", n_stdout
);
1337 fputs(cp
, n_stdout
);
1338 putc('\n', n_stdout
);
1343 a_collect__plumb_attach(char const *cp
, struct header
*hp
,
1344 char const *cmd
[4]){
1346 struct attachment
*ap
;
1352 if(is_asccaseprefix(cmd
[1], "attribute")){
1353 if(cmd
[2] == NULL
|| cmd
[3] != NULL
)
1356 if((ap
= n_attachment_find(hp
->h_attach
, cmd
[2], NULL
)) != NULL
){
1358 fprintf(n_stdout
, "212 %s\n", cmd
[2]);
1360 fprintf(n_stdout
, "message-number %d\n\n", ap
->a_msgno
);
1363 "creation-name %s\nopen-path %s\nfilename %s\n",
1364 ap
->a_path_user
, ap
->a_path
, ap
->a_name
);
1365 if(ap
->a_content_description
!= NULL
)
1366 fprintf(n_stdout
, "content-description %s\n",
1367 ap
->a_content_description
);
1368 if(ap
->a_content_id
!= NULL
)
1369 fprintf(n_stdout
, "content-id %s\n",
1370 ap
->a_content_id
->n_name
);
1371 if(ap
->a_content_type
!= NULL
)
1372 fprintf(n_stdout
, "content-type %s\n", ap
->a_content_type
);
1373 if(ap
->a_content_disposition
!= NULL
)
1374 fprintf(n_stdout
, "content-disposition %s\n",
1375 ap
->a_content_disposition
);
1376 putc('\n', n_stdout
);
1379 fputs("501\n", n_stdout
);
1383 if(is_asccaseprefix(cmd
[1], "attribute-at")){
1386 if(cmd
[2] == NULL
|| cmd
[3] != NULL
)
1389 if((n_idec_uiz_cp(&i
, cmd
[2], 0, NULL
1390 ) & (n_IDEC_STATE_EMASK
| n_IDEC_STATE_CONSUMED
)
1391 ) != n_IDEC_STATE_CONSUMED
|| i
== 0)
1392 fputs("505\n", n_stdout
);
1394 for(ap
= hp
->h_attach
; ap
!= NULL
&& --i
!= 0; ap
= ap
->a_flink
)
1399 fputs("501\n", n_stdout
);
1404 if(is_asccaseprefix(cmd
[1], "attribute-set")){
1405 if(cmd
[2] == NULL
|| cmd
[3] == NULL
)
1408 if((ap
= n_attachment_find(hp
->h_attach
, cmd
[2], NULL
)) != NULL
){
1411 fputs("505\n", n_stdout
);
1416 while((c
= *cp
) != '\0' && !blankchar(c
))
1418 keyw
= savestrbuf(cmd
[3], PTR2SIZE(cp
- cmd
[3]));
1420 for(; (c
= *++cp
) != '\0' && blankchar(c
);)
1425 /* Strip [\r\n] which would render a parameter invalid XXX
1426 * XXX all controls? */
1427 cp
= xp
= savestr(cp
);
1428 for(; (c
= *xp
) != '\0'; ++xp
)
1429 if(c
== '\n' || c
== '\r')
1435 if(!asccasecmp(keyw
, "filename"))
1436 ap
->a_name
= (c
== '\0') ? ap
->a_path_bname
: cp
;
1437 else if(!asccasecmp(keyw
, "content-description"))
1438 ap
->a_content_description
= (c
== '\0') ? NULL
: cp
;
1439 else if(!asccasecmp(keyw
, "content-id")){
1440 ap
->a_content_id
= NULL
;
1445 np
= checkaddrs(lextract(cp
, GREF
),
1446 /*EACM_STRICT | TODO '/' valid!! */ EACM_NOLOG
|
1448 if(np
!= NULL
&& np
->n_flink
== NULL
)
1449 ap
->a_content_id
= np
;
1453 }else if(!asccasecmp(keyw
, "content-type"))
1454 ap
->a_content_type
= (c
== '\0') ? NULL
: cp
;
1455 else if(!asccasecmp(keyw
, "content-disposition"))
1456 ap
->a_content_disposition
= (c
== '\0') ? NULL
: cp
;
1463 for(i
= 0; ap
!= NULL
; ++i
, ap
= ap
->a_blink
)
1465 fprintf(n_stdout
, "210 %" PRIuZ
"\n", i
);
1467 fputs("505\n", n_stdout
);
1470 fputs("501\n", n_stdout
);
1474 if(is_asccaseprefix(cmd
[1], "attribute-set-at")){
1477 if(cmd
[2] == NULL
|| cmd
[3] == NULL
)
1480 if((n_idec_uiz_cp(&i
, cmd
[2], 0, NULL
1481 ) & (n_IDEC_STATE_EMASK
| n_IDEC_STATE_CONSUMED
)
1482 ) != n_IDEC_STATE_CONSUMED
|| i
== 0)
1483 fputs("505\n", n_stdout
);
1485 for(ap
= hp
->h_attach
; ap
!= NULL
&& --i
!= 0; ap
= ap
->a_flink
)
1490 fputs("501\n", n_stdout
);
1495 if(is_asccaseprefix(cmd
[1], "insert")){
1496 enum n_attach_error aerr
;
1498 if(cmd
[2] == NULL
|| cmd
[3] != NULL
)
1501 hp
->h_attach
= n_attachment_append(hp
->h_attach
, cmd
[2], &aerr
, &ap
);
1503 case n_ATTACH_ERR_FILE_OPEN
: cp
= "505\n"; goto jatt_ins
;
1504 case n_ATTACH_ERR_ICONV_FAILED
: cp
= "506\n"; goto jatt_ins
;
1505 case n_ATTACH_ERR_ICONV_NAVAIL
:
1506 case n_ATTACH_ERR_OTHER
:
1510 fputs(cp
, n_stdout
);
1512 case n_ATTACH_ERR_NONE
:{
1515 for(i
= 0; ap
!= NULL
; ++i
, ap
= ap
->a_blink
)
1517 fprintf(n_stdout
, "210 %" PRIuZ
"\n", i
);
1523 if(is_asccaseprefix(cmd
[1], "list")){
1528 if((ap
= hp
->h_attach
) != NULL
){
1529 fputs("212\n", n_stdout
);
1531 fprintf(n_stdout
, "%s\n", ap
->a_path_user
);
1532 while((ap
= ap
->a_flink
) != NULL
);
1533 putc('\n', n_stdout
);
1535 fputs("501\n", n_stdout
);
1539 if(is_asccaseprefix(cmd
[1], "remove")){
1540 if(cmd
[2] == NULL
|| cmd
[3] != NULL
)
1543 if((ap
= n_attachment_find(hp
->h_attach
, cmd
[2], &status
)) != NULL
){
1545 fputs("506\n", n_stdout
);
1547 hp
->h_attach
= n_attachment_remove(hp
->h_attach
, ap
);
1548 fprintf(n_stdout
, "210 %s\n", cmd
[2]);
1551 fputs("501\n", n_stdout
);
1555 if(is_asccaseprefix(cmd
[1], "remove-at")){
1558 if(cmd
[2] == NULL
|| cmd
[3] != NULL
)
1561 if((n_idec_uiz_cp(&i
, cmd
[2], 0, NULL
1562 ) & (n_IDEC_STATE_EMASK
| n_IDEC_STATE_CONSUMED
)
1563 ) != n_IDEC_STATE_CONSUMED
|| i
== 0)
1564 fputs("505\n", n_stdout
);
1566 for(ap
= hp
->h_attach
; ap
!= NULL
&& --i
!= 0; ap
= ap
->a_flink
)
1569 hp
->h_attach
= n_attachment_remove(hp
->h_attach
, ap
);
1570 fprintf(n_stdout
, "210 %s\n", cmd
[2]);
1572 fputs("501\n", n_stdout
);
1578 fputs("500\n", n_stdout
);
1582 return (cp
!= NULL
);
1588 NYD_X
; /* Signal handler */
1590 /* the control flow is subtle, because we can be called from ~q */
1591 if (_coll_hadintr
== 0) {
1592 if (ok_blook(ignore
)) {
1593 fputs("@\n", n_stdout
);
1598 siglongjmp(_coll_jmp
, 1);
1600 n_exit_status
|= n_EXIT_SEND_ERROR
;
1602 savedeadletter(_coll_fp
, TRU1
);
1603 /* Aborting message, no need to fflush() .. */
1604 siglongjmp(_coll_abort
, 1);
1610 NYD_X
; /* Signal handler */
1613 savedeadletter(_coll_fp
, TRU1
);
1614 /* Let's pretend nobody else wants to clean up, a true statement at
1620 a_coll_putesc(char const *s
, bool_t addnl
, FILE *stream
){
1625 isposix
= ok_blook(posix
);
1627 while((c1
= *s
++) != '\0'){
1628 if(c1
== '\\' && ((c2
= *s
) == 't' || c2
== 'n')){
1630 isposix
= TRU1
; /* TODO v15 OBSOLETE! */
1631 n_err(_("Compose mode warning: expanding \\t or \\n in variable "
1633 "\n Support remains only for ~A,~a,~I,~i in *posix* mode!\n"));
1636 c1
= (c2
== 't') ? '\t' : '\n';
1639 if(putc(c1
, stream
) == EOF
)
1643 if(addnl
&& putc('\n', stream
) == EOF
)
1648 return (c1
== '\0');
1652 a_coll_ocs__mac(void){
1653 /* Executes in a fork(2)ed child TODO if remains, global MASKs for those! */
1654 setvbuf(n_stdin
, NULL
, _IOLBF
, 0);
1655 setvbuf(n_stdout
, NULL
, _IOLBF
, 0);
1656 n_psonce
&= ~(n_PSO_INTERACTIVE
| n_PSO_TTYIN
| n_PSO_TTYOUT
);
1657 n_pstate
|= n_PS_COMPOSE_FORKHOOK
;
1658 n_readctl_overlay
= NULL
; /* TODO we need OnForkEvent! See c_readctl() */
1659 if(n_poption
& n_PO_D_VV
){
1662 snprintf(buf
, sizeof buf
, "[%d]%s", getpid(), ok_vlook(log_prefix
));
1663 ok_vset(log_prefix
, buf
);
1665 /* TODO If that uses `!' it will effectively SIG_IGN SIGINT, ...and such */
1666 temporary_compose_mode_hook_call(a_coll_ocs__macname
, NULL
, NULL
);
1671 a_coll_ocs__finalize(void *vp
){
1672 /* Note we use this for destruction upon setup errors, thus */
1673 sighandler_type opipe
;
1674 sighandler_type oint
;
1675 struct a_coll_ocs_arg
**coapp
, *coap
;
1678 temporary_compose_mode_hook_call((char*)-1, NULL
, NULL
);
1680 coap
= *(coapp
= vp
);
1681 *coapp
= (struct a_coll_ocs_arg
*)-1;
1683 if(coap
->coa_stdin
!= NULL
)
1684 Fclose(coap
->coa_stdin
);
1685 else if(coap
->coa_pipe
[0] != -1)
1686 close(coap
->coa_pipe
[0]);
1688 if(coap
->coa_stdout
!= NULL
&& !Pclose(coap
->coa_stdout
, TRU1
))
1689 *coap
->coa_senderr
= 111;
1690 if(coap
->coa_pipe
[1] != -1)
1691 close(coap
->coa_pipe
[1]);
1693 opipe
= coap
->coa_opipe
;
1694 oint
= coap
->coa_oint
;
1699 safe_signal(SIGPIPE
, opipe
);
1700 safe_signal(SIGINT
, oint
);
1706 n_temporary_compose_hook_varset(void *arg
){ /* TODO v15: drop */
1713 if((val
= hp
->h_subject
) == NULL
)
1715 ok_vset(mailx_subject
, val
);
1716 if((val
= detract(hp
->h_from
, GNAMEONLY
)) == NULL
)
1718 ok_vset(mailx_from
, val
);
1719 if((val
= detract(hp
->h_sender
, GNAMEONLY
)) == NULL
)
1721 ok_vset(mailx_sender
, val
);
1722 if((val
= detract(hp
->h_to
, GNAMEONLY
)) == NULL
)
1724 ok_vset(mailx_to
, val
);
1725 if((val
= detract(hp
->h_cc
, GNAMEONLY
)) == NULL
)
1727 ok_vset(mailx_cc
, val
);
1728 if((val
= detract(hp
->h_bcc
, GNAMEONLY
)) == NULL
)
1730 ok_vset(mailx_bcc
, val
);
1732 if((val
= hp
->h_mailx_command
) == NULL
)
1734 ok_vset(mailx_command
, val
);
1736 if((val
= detract(hp
->h_mailx_raw_to
, GNAMEONLY
)) == NULL
)
1738 ok_vset(mailx_raw_to
, val
);
1739 if((val
= detract(hp
->h_mailx_raw_cc
, GNAMEONLY
)) == NULL
)
1741 ok_vset(mailx_raw_cc
, val
);
1742 if((val
= detract(hp
->h_mailx_raw_bcc
, GNAMEONLY
)) == NULL
)
1744 ok_vset(mailx_raw_bcc
, val
);
1746 if((val
= detract(hp
->h_mailx_orig_from
, GNAMEONLY
)) == NULL
)
1748 ok_vset(mailx_orig_from
, val
);
1749 if((val
= detract(hp
->h_mailx_orig_to
, GNAMEONLY
)) == NULL
)
1751 ok_vset(mailx_orig_to
, val
);
1752 if((val
= detract(hp
->h_mailx_orig_cc
, GNAMEONLY
)) == NULL
)
1754 ok_vset(mailx_orig_cc
, val
);
1755 if((val
= detract(hp
->h_mailx_orig_bcc
, GNAMEONLY
)) == NULL
)
1757 ok_vset(mailx_orig_bcc
, val
);
1762 collect(struct header
*hp
, int printheaders
, struct message
*mp
,
1763 char const *quotefile
, int doprefix
, si8_t
*checkaddr_err
)
1765 struct n_string s
, * volatile sp
;
1766 struct n_ignore
const *quoteitp
;
1767 struct a_coll_ocs_arg
*coap
;
1769 int volatile t
, eofcnt
, getfields
;
1770 char volatile escape
;
1775 a_COAP_NOSIGTERM
= 1u<<8
1776 #define a_HARDERR() ((flags & (a_ERREXIT | a_IGNERR)) == a_ERREXIT)
1779 char const *cp
, *cp_base
, * volatile coapm
, * volatile ifs_saved
;
1780 size_t i
, linesize
; /* TODO line pool */
1782 enum sendaction action
;
1783 sigset_t oset
, nset
;
1784 FILE * volatile sigfp
;
1792 ifs_saved
= coapm
= NULL
;
1796 /* Start catching signals from here, but we're still die on interrupts
1797 * until we're in the main loop */
1799 sigprocmask(SIG_BLOCK
, &nset
, &oset
);
1800 if ((_coll_saveint
= safe_signal(SIGINT
, SIG_IGN
)) != SIG_IGN
)
1801 safe_signal(SIGINT
, &_collint
);
1802 if ((_coll_savehup
= safe_signal(SIGHUP
, SIG_IGN
)) != SIG_IGN
)
1803 safe_signal(SIGHUP
, collhup
);
1804 if (sigsetjmp(_coll_abort
, 1))
1806 if (sigsetjmp(_coll_jmp
, 1))
1808 n_pstate
|= n_PS_COMPOSE_MODE
;
1809 sigprocmask(SIG_SETMASK
, &oset
, (sigset_t
*)NULL
);
1811 if ((_coll_fp
= Ftmp(NULL
, "collect", OF_RDWR
| OF_UNLINK
| OF_REGISTER
)) ==
1813 n_perr(_("collect: temporary mail file"), 0);
1817 /* If we are going to prompt for a subject, refrain from printing a newline
1818 * after the headers (since some people mind) */
1820 if(!(n_poption
& n_PO_t_FLAG
)){
1821 t
= GTO
| GSUBJECT
| GCC
| GNL
;
1822 if(ok_blook(fullnames
))
1825 if((n_psonce
& n_PSO_INTERACTIVE
) && !(n_pstate
& n_PS_ROBOT
)){
1826 if(hp
->h_subject
== NULL
&& ok_blook(asksub
)/* *ask* auto warped! */)
1827 t
&= ~GNL
, getfields
|= GSUBJECT
;
1829 if(hp
->h_to
== NULL
)
1830 t
&= ~GNL
, getfields
|= GTO
;
1832 if(!ok_blook(bsdcompat
) && !ok_blook(askatend
)){
1833 if(ok_blook(askbcc
))
1834 t
&= ~GNL
, getfields
|= GBCC
;
1836 t
&= ~GNL
, getfields
|= GCC
;
1845 if (!sigsetjmp(_coll_jmp
, 1)) {
1846 /* Ask for some headers first, as necessary */
1848 grab_headers(n_GO_INPUT_CTX_COMPOSE
, hp
, getfields
, 1);
1850 /* Execute compose-enter; delayed for -t mode */
1851 if(!(n_poption
& n_PO_t_FLAG
) &&
1852 (cp
= ok_vlook(on_compose_enter
)) != NULL
){
1853 setup_from_and_sender(hp
);
1854 temporary_compose_mode_hook_call(cp
, &n_temporary_compose_hook_varset
,
1858 /* TODO Mm: nope since it may require turning this into a multipart one */
1859 if(!(n_poption
& (n_PO_Mm_FLAG
| n_PO_t_FLAG
))){
1860 if(!a_coll_message_inject_head(_coll_fp
))
1863 /* Quote an original message */
1864 if (mp
!= NULL
&& (doprefix
|| (cp
= ok_vlook(quote
)) != NULL
)) {
1865 quoteitp
= n_IGNORE_ALL
;
1866 action
= SEND_QUOTE
;
1868 char const *cp_v15compat
;
1870 quoteitp
= n_IGNORE_FWD
;
1872 if((cp_v15compat
= ok_vlook(fwdheading
)) != NULL
)
1873 n_OBSOLETE(_("please use *forward-inject-head*, "
1874 "not *fwdheading*"));
1875 cp
= ok_vlook(forward_inject_head
);
1876 if(cp
== NULL
&& (cp
= cp_v15compat
) == NULL
)
1877 cp
= "-------- Original Message --------";
1878 if (*cp
!= '\0' && fprintf(_coll_fp
, "%s\n", cp
) < 0)
1880 } else if (!strcmp(cp
, "noheading")) {
1882 } else if (!strcmp(cp
, "headers")) {
1883 quoteitp
= n_IGNORE_TYPE
;
1884 } else if (!strcmp(cp
, "allheaders")) {
1886 action
= SEND_QUOTE_ALL
;
1888 cp
= hfield1("from", mp
);
1889 if (cp
!= NULL
&& (cnt
= (long)strlen(cp
)) > 0) {
1890 if (xmime_write(cp
, cnt
, _coll_fp
, CONV_FROMHDR
, TD_NONE
,
1893 if (fprintf(_coll_fp
, _(" wrote:\n\n")) < 0)
1897 if (fflush(_coll_fp
))
1899 if (sendmp(mp
, _coll_fp
, quoteitp
,
1900 (doprefix
? NULL
: ok_vlook(indentprefix
)),
1906 if (quotefile
!= NULL
) {
1907 if((n_pstate_err_no
= a_coll_include_file(quotefile
, FAL0
, FAL0
)
1912 if(n_psonce
& n_PSO_INTERACTIVE
){
1913 if(!(n_pstate
& n_PS_SOURCING
)){
1914 sp
= n_string_creat_auto(&s
);
1915 sp
= n_string_reserve(sp
, 80);
1918 if(!(n_poption
& n_PO_Mm_FLAG
) && !(n_pstate
& n_PS_ROBOT
)){
1919 /* Print what we have sofar also on the terminal (if useful) */
1920 if (!ok_blook(editalong
)) {
1922 puthead(TRU1
, hp
, n_stdout
, t
,
1923 SEND_TODISP
, CONV_NONE
, NULL
, NULL
);
1926 while ((c
= getc(_coll_fp
)) != EOF
) /* XXX bytewise, yuck! */
1928 if (fseek(_coll_fp
, 0, SEEK_END
))
1932 if(a_coll_edit('e', hp
) != n_ERR_NONE
)
1934 /* Print msg mandated by the Mail Reference Manual */
1936 if((n_psonce
& n_PSO_INTERACTIVE
) && !(n_pstate
& n_PS_ROBOT
))
1937 fputs(_("(continue)\n"), n_stdout
);
1943 /* Come here for printing the after-signal message. Duplicate messages
1944 * won't be printed because the write is aborted if we get a SIGTTOU */
1945 if(_coll_hadintr
&& (n_psonce
& n_PSO_INTERACTIVE
) &&
1946 !(n_pstate
& n_PS_ROBOT
))
1947 n_err(_("\n(Interrupt -- one more to kill letter)\n"));
1950 /* If not under shell hook control */
1952 /* We're done with -M or -m TODO because: we are too stupid yet, above */
1953 if(n_poption
& n_PO_Mm_FLAG
)
1955 /* No command escapes, interrupts not expected. Simply copy STDIN */
1956 if(!(n_psonce
& n_PSO_INTERACTIVE
) &&
1957 !(n_poption
& (n_PO_t_FLAG
| n_PO_TILDE_FLAG
))){
1958 linebuf
= srealloc(linebuf
, linesize
= LINESIZE
);
1959 while ((i
= fread(linebuf
, sizeof *linebuf
, linesize
, n_stdin
)) > 0) {
1960 if (i
!= fwrite(linebuf
, sizeof *linebuf
, i
, _coll_fp
))
1967 /* The interactive collect loop */
1969 escape
= *ok_vlook(escape
);
1970 flags
= ok_blook(errexit
) ? a_ERREXIT
: a_NONE
;
1973 enum {a_HIST_NONE
, a_HIST_ADD
= 1u<<0, a_HIST_GABBY
= 1u<<1} hist
;
1976 enum n_go_input_flags gif
;
1979 gif
= n_GO_INPUT_CTX_COMPOSE
;
1980 histadd
= (sp
!= NULL
);
1981 if((n_psonce
& n_PSO_INTERACTIVE
) || (n_poption
& n_PO_TILDE_FLAG
)){
1982 if(!(n_poption
& n_PO_t_FLAG
))
1983 gif
|= n_GO_INPUT_NL_ESC
;
1985 cnt
= n_go_input(gif
, n_empty
, &linebuf
, &linesize
, NULL
, &histadd
);
1986 hist
= histadd
? a_HIST_ADD
| a_HIST_GABBY
: a_HIST_NONE
;
1992 if(n_poption
& n_PO_t_FLAG
){
1993 fflush_rewind(_coll_fp
);
1994 /* It is important to set n_PSO_t_FLAG before extract_header()
1995 * *and* keep n_PO_t_FLAG for the first parse of the message!
1996 * TODO This is a hack, we need a clean approach for this */
1997 n_psonce
|= n_PSO_t_FLAG
;
1998 if(!a_coll_makeheader(_coll_fp
, hp
, checkaddr_err
, TRU1
))
2000 n_poption
&= ~n_PO_t_FLAG
;
2002 }else if((n_psonce
& n_PSO_INTERACTIVE
) && !(n_pstate
& n_PS_ROBOT
) &&
2003 ok_blook(ignoreeof
) && ++eofcnt
< 4){
2005 _("*ignoreeof* set, use `~.' to terminate letter\n"));
2006 n_go_input_clearerr();
2017 else if(coap
== NULL
){
2018 if(!(n_psonce
& n_PSO_INTERACTIVE
) && !(n_poption
& n_PO_TILDE_FLAG
))
2020 else if(cp
[0] == '.'){
2021 if(cnt
== 1 && (ok_blook(dot
) ||
2022 (ok_blook(posix
) && ok_blook(ignoreeof
))))
2026 if(cp
[0] != escape
){
2028 if(fwrite(cp
, sizeof *cp
, cnt
, _coll_fp
) != (size_t)cnt
)
2030 /* TODO n_PS_READLINE_NL is a terrible hack to ensure that _in_all_-
2031 * TODO _code_paths_ a file without trailing newline isn't modified
2032 * TODO to contain one; the "saw-newline" needs to be part of an
2033 * TODO I/O input machinery object */
2035 if(n_pstate
& n_PS_READLINE_NL
){
2036 if(putc('\n', _coll_fp
) == EOF
)
2042 c
= *(cp_base
= ++cp
);
2046 /* Avoid history entry? */
2047 while(spacechar(c
)){
2049 c
= *(cp_base
= ++cp
);
2054 /* It may just be an escaped escaped character, do that quick */
2058 /* Avoid hard *errexit*? */
2067 /* Trim input, also to gain a somewhat normalized history entry */
2072 x
.s
= n_UNCONST(cp
);
2074 n_str_trim_ifs(&x
, TRU1
);
2077 cnt
= (int)/*XXX*/x
.l
;
2080 if(hist
!= a_HIST_NONE
){
2081 sp
= n_string_assign_c(sp
, escape
);
2082 if(flags
& a_IGNERR
)
2083 sp
= n_string_push_c(sp
, '-');
2084 sp
= n_string_push_c(sp
, c
);
2086 sp
= n_string_push_c(sp
, ' ');
2087 sp
= n_string_push_buf(sp
, cp
, cnt
);
2091 /* Switch over all command escapes */
2095 char buf
[sizeof(n_UNIREPL
)];
2098 buf
[0] = c
, buf
[1] = '\0';
2099 else if(n_psonce
& n_PSO_UNICODE
)
2100 memcpy(buf
, n_unirepl
, sizeof n_unirepl
);
2102 buf
[0] = '?', buf
[1] = '\0';
2103 n_err(_("Unknown command escape: `%c%s'\n"), escape
, buf
);
2106 n_err(_("Invalid command escape usage: %s\n"),
2107 n_shexp_quote_cp(linebuf
, FAL0
));
2110 n_pstate_err_no
= n_ERR_INVAL
;
2114 /* Shell escape, send the balance of line to sh -c */
2115 if(cnt
== 0 || coap
!= NULL
)
2118 char const *argv
[2];
2122 n_pstate_ex_no
= c_shell(argv
); /* TODO history norm.; errexit? */
2126 /* Simulate end of file on input */
2127 if(cnt
!= 0 || coap
!= NULL
)
2129 goto jout
; /* TODO does not enter history, thus */
2132 /* Escape to command mode, but be nice! *//* TODO command expansion
2133 * TODO should be handled here so that we have unique history! */
2136 _execute_command(hp
, cp
, cnt
);
2137 if(ok_blook(errexit
))
2140 flags
&= ~a_ERREXIT
;
2141 if(n_pstate_ex_no
!= 0 && a_HARDERR())
2144 escape
= *ok_vlook(escape
);
2146 /* case '<': <> 'd' */
2149 "COMMAND ESCAPES (to be placed after a newline) excerpt:\n"
2150 "~. Commit and send message\n"
2151 "~: <command> Execute an internal command\n"
2152 "~< <file> Insert <file> (\"~<! <command>\" inserts shell command)\n"
2153 "~@ [<files>] Edit[/Add] attachments (file[=input-charset[#output-charset]])\n"
2154 "~c <users> Add users to Cc: list (`~b': to Bcc:)\n"
2155 "~d Read in $DEAD (dead.letter)\n"
2156 "~e Edit message via $EDITOR\n"
2157 "~F <msglist> Read in with headers, do not *indentprefix* lines\n"
2160 "~f <msglist> Like ~F, but honour `ignore' / `retain' configuration\n"
2161 "~H Edit From:, Reply-To: and Sender:\n"
2162 "~h Prompt for Subject:, To:, Cc: and \"blind\" Bcc:\n"
2163 "~i <variable> Insert a value and a newline\n"
2164 "~M <msglist> Read in with headers, *indentprefix* (`~m': `retain' etc.)\n"
2165 "~p Show current message compose buffer\n"
2166 "~r <file> Insert <file> (`~R': likewise, but *indentprefix* lines)\n"
2167 " <file> may also be <- [HERE-DELIMITER]>\n"
2170 "~s <subject> Set Subject:\n"
2171 "~t <users> Add users to To: list\n"
2172 "~u <msglist> Read in message(s) without headers (`~U': indent lines)\n"
2173 "~v Edit message via $VISUAL\n"
2174 "~w <file> Write message onto file\n"
2175 "~x Abort composition, discard message (`~q': save in $DEAD)\n"
2176 "~| <command> Pipe message through shell filter\n"
2180 n_pstate_err_no
= n_ERR_NONE
;
2184 struct attachment
*aplist
;
2186 /* Edit the attachment list */
2187 aplist
= hp
->h_attach
;
2188 hp
->h_attach
= NULL
;
2190 hp
->h_attach
= n_attachment_append_list(aplist
, cp
);
2192 hp
->h_attach
= n_attachment_list_edit(aplist
,
2193 n_GO_INPUT_CTX_COMPOSE
);
2194 n_pstate_err_no
= n_ERR_NONE
; /* XXX ~@ does NOT handle $!/$?! */
2195 n_pstate_ex_no
= 0; /* XXX */
2198 if(!a_collect_plumbing(cp
, hp
)){
2199 if(ferror(_coll_fp
))
2203 n_pstate_err_no
= n_ERR_NONE
; /* XXX */
2204 n_pstate_ex_no
= 0; /* XXX */
2205 hist
&= ~a_HIST_GABBY
;
2207 /* case '_': <> ':' */
2209 /* Pipe message through command. Collect output as new message */
2213 if((n_pstate_err_no
= a_coll_pipe(cp
)) == n_ERR_NONE
)
2215 else if(a_HARDERR())
2219 hist
&= ~a_HIST_GABBY
;
2223 /* Insert the contents of a sign variable */
2226 cp
= (c
== 'a') ? ok_vlook(sign
) : ok_vlook(Sign
);
2229 /* Add stuff to blind carbon copies list TODO join 'c' */
2237 if((np
= checkaddrs(lextract(cp
, GBCC
| GFULL
), EACM_NORMAL
, &soe
)
2239 hp
->h_bcc
= cat(hp
->h_bcc
, np
);
2241 n_pstate_err_no
= n_ERR_NONE
;
2245 n_pstate_err_no
= (soe
< 0) ? n_ERR_PERM
: n_ERR_INVAL
;
2248 hist
&= ~a_HIST_GABBY
;
2251 /* Add to the CC list TODO join 'b' */
2259 if((np
= checkaddrs(lextract(cp
, GCC
| GFULL
), EACM_NORMAL
, &soe
)
2261 hp
->h_cc
= cat(hp
->h_cc
, np
);
2263 n_pstate_err_no
= n_ERR_NONE
;
2267 n_pstate_err_no
= (soe
< 0) ? n_ERR_PERM
: n_ERR_INVAL
;
2270 hist
&= ~a_HIST_GABBY
;
2275 cp
= n_getdeadletter();
2280 /* Invoke a file: Search for the file name, then open it and copy
2281 * the contents to _coll_fp */
2283 n_err(_("Interpolate what file?\n"));
2286 n_pstate_err_no
= n_ERR_NOENT
;
2290 if(*cp
== '!' && c
== '<'){
2291 /* TODO hist. normalization */
2292 if((n_pstate_err_no
= a_coll_insert_cmd(_coll_fp
, ++cp
)
2294 if(ferror(_coll_fp
))
2303 /* Note this also expands things like
2304 * !:vput vexpr delim random 0
2306 if((cp
= fexpand(cp
, FEXP_LOCAL
| FEXP_NOPROTO
| FEXP_NSHELL
)
2310 n_pstate_err_no
= n_ERR_INVAL
;
2315 if(n_is_dir(cp
, FAL0
)){
2316 n_err(_("%s: is a directory\n"), n_shexp_quote_cp(cp
, FAL0
));
2319 n_pstate_err_no
= n_ERR_ISDIR
;
2323 if((n_pstate_err_no
= a_coll_include_file(cp
, (c
== 'R'), TRU1
)
2325 if(ferror(_coll_fp
))
2332 n_pstate_err_no
= n_ERR_NONE
; /* XXX */
2333 n_pstate_ex_no
= 0; /* XXX */
2337 /* Edit the current message. 'e' -> use EDITOR, 'v' -> use VISUAL */
2338 if(cnt
!= 0 || coap
!= NULL
)
2341 if((n_pstate_err_no
= a_coll_edit(c
, ok_blook(editheaders
) ? hp
: NULL
)
2344 else if(ferror(_coll_fp
))
2346 else if(a_HARDERR())
2357 /* Interpolate the named messages, if we are in receiving mail mode.
2358 * Does the standard list processing garbage. If ~f is given, we
2359 * don't shift over */
2362 if((n_pstate_err_no
= a_coll_forward(cp
, _coll_fp
, c
)) == n_ERR_NONE
)
2364 else if(ferror(_coll_fp
))
2366 else if(a_HARDERR())
2372 /* Grab extra headers */
2376 grab_headers(n_GO_INPUT_CTX_COMPOSE
, hp
, GEXTRA
, 0);
2377 while(check_from_and_sender(hp
->h_from
, hp
->h_sender
) == NULL
);
2378 n_pstate_err_no
= n_ERR_NONE
; /* XXX */
2379 n_pstate_ex_no
= 0; /* XXX */
2382 /* Grab a bunch of headers */
2386 grab_headers(n_GO_INPUT_CTX_COMPOSE
, hp
,
2387 (GTO
| GSUBJECT
| GCC
| GBCC
),
2388 (ok_blook(bsdcompat
) && ok_blook(bsdorder
)));
2389 while(hp
->h_to
== NULL
);
2390 n_pstate_err_no
= n_ERR_NONE
; /* XXX */
2391 n_pstate_ex_no
= 0; /* XXX */
2395 /* Insert a variable into the file */
2398 cp
= n_var_vlook(cp
, TRU1
);
2400 if(cp
== NULL
|| *cp
== '\0')
2402 if(!a_coll_putesc(cp
, (c
!= 'I'), _coll_fp
))
2404 if((n_psonce
& n_PSO_INTERACTIVE
) && !(n_pstate
& n_PS_ROBOT
) &&
2405 !a_coll_putesc(cp
, (c
!= 'I'), n_stdout
))
2407 n_pstate_err_no
= n_ERR_NONE
; /* XXX */
2408 n_pstate_ex_no
= 0; /* XXX */
2410 /* case 'M': <> 'F' */
2411 /* case 'm': <> 'f' */
2413 /* Print current state of the message without altering anything */
2416 print_collf(_coll_fp
, hp
); /* XXX pstate_err_no ++ */
2417 if(ferror(_coll_fp
))
2419 n_pstate_err_no
= n_ERR_NONE
; /* XXX */
2420 n_pstate_ex_no
= 0; /* XXX */
2424 /* Force a quit, act like an interrupt had happened */
2427 /* If we are running a splice hook, assume it quits on its own now,
2428 * otherwise we (no true out-of-band IPC to signal this state, XXX sic)
2429 * have to SIGTERM it in order to stop this wild beast */
2430 flags
|= a_COAP_NOSIGTERM
;
2432 _collint((c
== 'x') ? 0 : SIGINT
);
2435 /* case 'R': <> 'd' */
2436 /* case 'r': <> 'd' */
2438 /* Set the Subject list */
2441 /* Subject:; take care for Debian #419840 and strip any \r and \n */
2442 if(n_anyof_cp("\n\r", hp
->h_subject
= savestr(cp
))){
2445 n_err(_("-s: normalizing away invalid ASCII NL / CR bytes\n"));
2446 for(xp
= hp
->h_subject
; *xp
!= '\0'; ++xp
)
2447 if(*xp
== '\n' || *xp
== '\r')
2449 n_pstate_err_no
= n_ERR_INVAL
;
2452 n_pstate_err_no
= n_ERR_NONE
;
2457 /* Add to the To: list TODO join 'b', 'c' */
2465 if((np
= checkaddrs(lextract(cp
, GTO
| GFULL
), EACM_NORMAL
, &soe
)
2467 hp
->h_to
= cat(hp
->h_to
, np
);
2469 n_pstate_err_no
= n_ERR_NONE
;
2473 n_pstate_err_no
= (soe
< 0) ? n_ERR_PERM
: n_ERR_INVAL
;
2476 hist
&= ~a_HIST_GABBY
;
2478 /* case 'U': <> 'F' */
2479 /* case 'u': <> 'f' */
2480 /* case 'v': <> 'e' */
2482 /* Write the message on a file */
2485 if((cp
= fexpand(cp
, FEXP_LOCAL
| FEXP_NOPROTO
)) == NULL
){
2486 n_err(_("Write what file!?\n"));
2489 n_pstate_err_no
= n_ERR_INVAL
;
2494 if((n_pstate_err_no
= a_coll_write(cp
, _coll_fp
, 1)) == n_ERR_NONE
)
2496 else if(ferror(_coll_fp
))
2498 else if(a_HARDERR())
2503 /* case 'x': <> 'q' */
2506 /* Finally place an entry in history as applicable */
2512 if(hist
& a_HIST_ADD
){
2513 /* Do not add *escape* to the history in order to allow history search
2514 * to be handled generically in the MLE regardless of actual *escape*
2516 n_tty_addhist(&n_string_cp(sp
)[1], (n_GO_INPUT_CTX_COMPOSE
|
2517 (hist
& a_HIST_GABBY
? n_GO_INPUT_HIST_GABBY
: n_GO_INPUT_NONE
)));
2524 /* Do we have *on-compose-splice-shell*, or *on-compose-splice*?
2525 * TODO Usual f...ed up state of signals and terminal etc. */
2526 if(coap
== NULL
&& (cp
= ok_vlook(on_compose_splice_shell
)) != NULL
) Jocs
:{
2527 union {int (*ptf
)(void); char const *sh
;} u
;
2530 /* Reset *escape* and more to their defaults. On change update manual! */
2531 if(ifs_saved
== NULL
)
2532 ifs_saved
= savestr(ok_vlook(ifs
));
2533 escape
= n_ESCAPE
[0];
2537 /* XXX Due Popen() fflush(NULL) in PTF mode, ensure nothing to flush */
2538 /*if(!n_real_seek(_coll_fp, 0, SEEK_END))
2540 u
.ptf
= &a_coll_ocs__mac
;
2542 a_coll_ocs__macname
= cp
= coapm
;
2544 u
.sh
= ok_vlook(SHELL
);
2549 coap
= n_lofi_alloc(n_VSTRUCT_SIZEOF(struct a_coll_ocs_arg
, coa_cmd
2551 coap
->coa_pipe
[0] = coap
->coa_pipe
[1] = -1;
2552 coap
->coa_stdin
= coap
->coa_stdout
= NULL
;
2553 coap
->coa_senderr
= checkaddr_err
;
2554 memcpy(coap
->coa_cmd
, cp
, i
);
2557 coap
->coa_opipe
= safe_signal(SIGPIPE
, SIG_IGN
);
2558 coap
->coa_oint
= safe_signal(SIGINT
, SIG_IGN
);
2561 if(pipe_cloexec(coap
->coa_pipe
) != -1 &&
2562 (coap
->coa_stdin
= Fdopen(coap
->coa_pipe
[0], "r", FAL0
)) != NULL
&&
2563 (coap
->coa_stdout
= Popen(cmd
, "W", u
.sh
, NULL
, coap
->coa_pipe
[1])
2565 close(coap
->coa_pipe
[1]);
2566 coap
->coa_pipe
[1] = -1;
2568 temporary_compose_mode_hook_call(NULL
, NULL
, NULL
);
2569 n_go_splice_hack(coap
->coa_cmd
, coap
->coa_stdin
, coap
->coa_stdout
,
2570 (n_psonce
& ~(n_PSO_INTERACTIVE
| n_PSO_TTYIN
| n_PSO_TTYOUT
)),
2571 &a_coll_ocs__finalize
, &coap
);
2572 /* Hook version protocol for ~^: update manual upon change! */
2573 fputs(a_COLL_PLUMBING_VERSION
"\n", coap
->coa_stdout
);
2574 #undef a_COLL_PLUMBING_VERSION
2579 a_coll_ocs__finalize(coap
);
2580 n_perr(_("Cannot invoke *on-compose-splice(-shell)?*"), c
);
2583 if(*checkaddr_err
!= 0){
2587 if(coapm
== NULL
&& (coapm
= ok_vlook(on_compose_splice
)) != NULL
)
2590 ok_vset(ifs
, ifs_saved
);
2594 /* Final chance to edit headers, if not already above */
2595 if((n_psonce
& n_PSO_INTERACTIVE
) && !(n_pstate
& n_PS_ROBOT
)){
2596 if(ok_blook(bsdcompat
) || ok_blook(askatend
)){
2602 if(ok_blook(askbcc
))
2605 grab_headers(n_GO_INPUT_CTX_COMPOSE
, hp
, gf
, 1);
2607 if(ok_blook(askattach
))
2608 hp
->h_attach
= n_attachment_list_edit(hp
->h_attach
,
2609 n_GO_INPUT_CTX_COMPOSE
);
2612 /* Execute compose-leave */
2613 if((cp
= ok_vlook(on_compose_leave
)) != NULL
){
2614 setup_from_and_sender(hp
);
2615 temporary_compose_mode_hook_call(cp
, &n_temporary_compose_hook_varset
,
2619 /* Add automatic receivers */
2620 if ((cp
= ok_vlook(autocc
)) != NULL
&& *cp
!= '\0')
2621 hp
->h_cc
= cat(hp
->h_cc
, checkaddrs(lextract(cp
, GCC
|
2622 (ok_blook(fullnames
) ? GFULL
| GSKIN
: GSKIN
)),
2623 EACM_NORMAL
, checkaddr_err
));
2624 if ((cp
= ok_vlook(autobcc
)) != NULL
&& *cp
!= '\0')
2625 hp
->h_bcc
= cat(hp
->h_bcc
, checkaddrs(lextract(cp
, GBCC
|
2626 (ok_blook(fullnames
) ? GFULL
| GSKIN
: GSKIN
)),
2627 EACM_NORMAL
, checkaddr_err
));
2628 if (*checkaddr_err
!= 0)
2631 if((n_psonce
& n_PSO_INTERACTIVE
) && !(n_pstate
& n_PS_ROBOT
) &&
2635 ifs_saved
= coapm
= NULL
;
2638 fprintf(n_stdout
, _("-------\nEnvelope contains:\n")); /* xxx SEARCH112 */
2639 puthead(TRU1
, hp
, n_stdout
, GIDENT
| GSUBJECT
| GTO
| GCC
| GBCC
| GCOMMA
,
2640 SEND_TODISP
, CONV_NONE
, NULL
, NULL
);
2643 if(n_go_input(n_GO_INPUT_CTX_COMPOSE
| n_GO_INPUT_NL_ESC
,
2644 _("Send this message [yes/no, empty: recompose]? "),
2645 &linebuf
, &linesize
, NULL
, NULL
) < 0){
2646 if(!n_go_input_is_eof())
2651 if((b
= n_boolify(linebuf
, UIZ_MAX
, TRUM1
)) < FAL0
)
2659 /* TODO Cannot do since it may require turning this into a multipart one */
2660 if(n_poption
& n_PO_Mm_FLAG
)
2663 /* Place signature? */
2664 if((cp
= ok_vlook(signature
)) != NULL
&& *cp
!= '\0'){ /* TODO OBSOLETE */
2667 n_OBSOLETE(_("please use *on-compose-{leave,splice}* and/or "
2668 "*message-inject-tail*, not *signature*"));
2670 if((cpq
= fexpand(cp
, FEXP_LOCAL
| FEXP_NOPROTO
)) == NULL
){
2671 n_err(_("*signature* expands to invalid file: %s\n"),
2672 n_shexp_quote_cp(cp
, FAL0
));
2675 cpq
= n_shexp_quote_cp(cp
= cpq
, FAL0
);
2677 if((sigfp
= Fopen(cp
, "r")) == NULL
){
2678 n_err(_("Can't open *signature* %s: %s\n"),
2679 cpq
, n_err_to_doc(n_err_no
));
2684 linebuf
= smalloc(linesize
= LINESIZE
);
2686 while((i
= fread(linebuf
, sizeof *linebuf
, linesize
, n_UNVOLATILE(sigfp
)))
2689 if(i
!= fwrite(linebuf
, sizeof *linebuf
, i
, _coll_fp
))
2694 FILE *x
= n_UNVOLATILE(sigfp
);
2695 int e
= n_err_no
, ise
= ferror(x
);
2701 n_err(_("Errors while reading *signature* %s: %s\n"),
2702 cpq
, n_err_to_doc(e
));
2707 if(c
!= '\0' && c
!= '\n')
2708 putc('\n', _coll_fp
);
2711 { char const *cp_obsolete
= ok_vlook(NAIL_TAIL
);
2713 if(cp_obsolete
!= NULL
)
2714 n_OBSOLETE(_("please use *message-inject-tail*, not *NAIL_TAIL*"));
2716 if((cp
= ok_vlook(message_inject_tail
)) != NULL
||
2717 (cp
= cp_obsolete
) != NULL
){
2718 if(!a_coll_putesc(cp
, TRU1
, _coll_fp
))
2720 if((n_psonce
& n_PSO_INTERACTIVE
) && !(n_pstate
& n_PS_ROBOT
) &&
2721 !a_coll_putesc(cp
, TRU1
, n_stdout
))
2727 if(fflush(_coll_fp
))
2732 if (linebuf
!= NULL
)
2734 sigprocmask(SIG_BLOCK
, &nset
, NULL
);
2735 n_pstate
&= ~n_PS_COMPOSE_MODE
;
2736 safe_signal(SIGINT
, _coll_saveint
);
2737 safe_signal(SIGHUP
, _coll_savehup
);
2738 sigprocmask(SIG_SETMASK
, &oset
, NULL
);
2745 if(coap
!= NULL
&& coap
!= (struct a_coll_ocs_arg
*)-1){
2746 if(!(flags
& a_COAP_NOSIGTERM
))
2747 n_psignal(coap
->coa_stdout
, SIGTERM
);
2748 n_go_splice_hack_remove_after_jump();
2751 if(ifs_saved
!= NULL
){
2752 ok_vset(ifs
, ifs_saved
);
2756 Fclose(n_UNVOLATILE(sigfp
));
2759 if(_coll_fp
!= NULL
){
2766 assert(checkaddr_err
!= NULL
);
2767 /* TODO We don't save in $DEAD upon error because msg not readily composed?
2768 * TODO But this no good, it should go ZOMBIE / DRAFT / POSTPONED or what! */
2769 if(*checkaddr_err
!= 0){
2770 if(*checkaddr_err
== 111)
2771 n_err(_("Compose mode splice hook failure\n"));
2773 n_err(_("Some addressees were classified as \"hard error\"\n"));
2774 }else if(_coll_hadintr
== 0){
2775 *checkaddr_err
= TRU1
; /* TODO ugly: "sendout_error" now.. */
2776 n_err(_("Failed to prepare composed message\n"));