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 - 2017 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 static bool_t
a_coll_putesc(char const *s
, bool_t addnl
, FILE *stream
);
118 /* *on-compose-splice* driver and *on-compose-splice(-shell)?* finalizer */
119 static int a_coll_ocs__mac(void);
120 static void a_coll_ocs__finalize(void *vp
);
123 _execute_command(struct header
*hp
, char const *linebuf
, size_t linesize
){
124 /* The problem arises if there are rfc822 message attachments and the
125 * user uses `~:' to change the current file. TODO Unfortunately we
126 * TODO cannot simply keep a pointer to, or increment a reference count
127 * TODO of the current `file' (mailbox that is) object, because the
128 * TODO codebase doesn't deal with that at all; so, until some far
129 * TODO later time, copy the name of the path, and warn the user if it
130 * TODO changed; we COULD use the AC_TMPFILE attachment type, i.e.,
131 * TODO copy the message attachments over to temporary files, but that
132 * TODO would require more changes so that the user still can recognize
133 * TODO in `~@' etc. that its a rfc822 message attachment; see below */
135 struct attachment
*ap
;
136 char * volatile mnbuf
;
142 n_SIGMAN_ENTER_SWITCH(&sm
, n_SIGMAN_HUP
| n_SIGMAN_INT
| n_SIGMAN_QUIT
){
146 n_pstate_err_no
= n_ERR_INTR
;
151 /* If the above todo is worked, remove or outsource to attachment.c! */
152 if(hp
!= NULL
&& (ap
= hp
->h_attach
) != NULL
) do
154 mnbuf
= sstrdup(mailname
);
157 while((ap
= ap
->a_flink
) != NULL
);
159 n_go_command(n_GO_INPUT_CTX_COMPOSE
, linebuf
);
161 n_sigman_cleanup_ping(&sm
);
164 if(strcmp(mnbuf
, mailname
))
165 n_err(_("Mailbox changed: it is likely that existing "
166 "rfc822 attachments became invalid!\n"));
170 n_sigman_leave(&sm
, n_SIGMAN_VIPSIGS_NTTYOUT
);
174 a_coll_include_file(char const *name
, bool_t indent
, bool_t writestat
){
176 char const *heredb
, *indb
;
177 size_t linesize
, heredl
, indl
, cnt
, linelen
;
185 linebuf
= NULL
; /* TODO line pool */
190 /* The -M case is special */
191 if(name
== (char*)-1){
194 }else if(name
[0] == '-' &&
195 (name
[1] == '\0' || blankspacechar(name
[1]))){
198 if(!(n_psonce
& n_PSO_INTERACTIVE
)){
199 n_err(_("~< -: HERE-delimiter required in non-interactive mode\n"));
204 for(heredb
= &name
[2]; *heredb
!= '\0' && blankspacechar(*heredb
);
207 if((heredl
= strlen(heredb
)) == 0){
209 n_err(_("~< - HERE-delimiter: delimiter must not be empty\n"));
215 for(indb
= ++heredb
; *indb
!= '\0' && *indb
!= '\''; ++indb
)
218 n_err(_("~< - HERE-delimiter: missing trailing quote\n"));
221 }else if(indb
[1] != '\0'){
222 n_err(_("~< - HERE-delimiter: trailing characters after "
227 if((heredl
= PTR2SIZE(indb
- heredb
)) == 0)
229 heredb
= savestrbuf(heredb
, heredl
);
233 }else if((fbuf
= Fopen(name
, "r")) == NULL
){
234 n_perr(name
, rv
= n_err_no
);
241 if((indb
= ok_vlook(indentprefix
)) == NULL
)
242 indb
= INDENT_DEFAULT
;
248 while(fgetline(&linebuf
, &linesize
, (fbuf
== n_stdin
? NULL
: &cnt
),
249 &linelen
, fbuf
, 0) != NULL
){
250 if(heredl
> 0 && heredl
== linelen
- 1 &&
251 !memcmp(heredb
, linebuf
, heredl
)){
257 if(fwrite(indb
, sizeof *indb
, indl
, _coll_fp
) != indl
){
264 if(fwrite(linebuf
, sizeof *linebuf
, linelen
, _coll_fp
) != linelen
){
271 if(fflush(_coll_fp
)){
277 rv
= n_ERR_NOTOBACCO
;
289 fprintf(n_stdout
, "%s%s %" PRId64
"/%" PRId64
"\n",
290 n_shexp_quote_cp(name
, FAL0
), (rv
? " " n_ERROR
: n_empty
), lc
, cc
);
296 a_coll_insert_cmd(FILE *fp
, char const *cmd
){
305 if((ibuf
= Popen(cmd
, "r", ok_vlook(SHELL
), NULL
, 0)) != NULL
){
308 while((c
= getc(ibuf
)) != EOF
){ /* XXX bytewise, yuck! */
309 if(putc(c
, fp
) == EOF
){
317 if(!feof(ibuf
) || ferror(ibuf
)){
321 if(!Pclose(ibuf
, TRU1
)){
326 n_perr(cmd
, rv
= n_err_no
);
328 fprintf(n_stdout
, "CMD%s %" PRId64
"/%" PRId64
"\n",
329 (rv
== n_ERR_NONE
? n_empty
: " " n_ERROR
), lc
, cc
);
335 print_collf(FILE *cf
, struct header
*hp
)
339 size_t cnt
, linesize
, linelen
;
343 cnt
= (size_t)fsize(cf
);
345 if((obuf
= Ftmp(NULL
, "collfp", OF_RDWR
| OF_UNLINK
| OF_REGISTER
)) == NULL
){
346 n_perr(_("Can't create temporary file for `~p' command"), 0);
352 fprintf(obuf
, _("-------\nMessage contains:\n"));
353 puthead(TRU1
, hp
, obuf
,
354 (GIDENT
| GTO
| GSUBJECT
| GCC
| GBCC
| GNL
| GFILES
| GCOMMA
),
355 SEND_TODISP
, CONV_NONE
, NULL
, NULL
);
359 while(fgetline(&lbuf
, &linesize
, &cnt
, &linelen
, cf
, 1))
360 prout(lbuf
, linelen
, obuf
);
364 if(hp
->h_attach
!= NULL
){
365 fputs(_("-------\nAttachments:\n"), obuf
);
366 n_attachment_list_print(hp
->h_attach
, obuf
);
371 page_or_print(obuf
, 0);
379 a_coll_write(char const *name
, FILE *fp
, int f
)
390 fprintf(n_stdout
, "%s ", n_shexp_quote_cp(name
, FAL0
));
394 if ((of
= Fopen(name
, "a")) == NULL
) {
395 n_perr(name
, rv
= n_err_no
);
400 while ((c
= getc(fp
)) != EOF
) {
404 if (putc(c
, of
) == EOF
) {
405 n_perr(name
, rv
= n_err_no
);
409 fprintf(n_stdout
, _("%" PRId64
"/%" PRId64
"\n"), lc
, cc
);
419 putc('\n', n_stdout
);
424 a_coll_message_inject_head(FILE *fp
){
426 char const *cp
, *cp_obsolete
;
429 cp_obsolete
= ok_vlook(NAIL_HEAD
);
430 if(cp_obsolete
!= NULL
)
431 n_OBSOLETE(_("please use *message-inject-head*, not *NAIL_HEAD*"));
433 if(((cp
= ok_vlook(message_inject_head
)) != NULL
||
434 (cp
= cp_obsolete
) != NULL
) && !a_coll_putesc(cp
, TRU1
, fp
))
443 a_coll_makeheader(FILE *fp
, struct header
*hp
, si8_t
*checkaddr_err
,
444 bool_t do_delayed_due_t
)
453 if ((nf
= Ftmp(NULL
, "colhead", OF_RDWR
| OF_UNLINK
| OF_REGISTER
)) ==NULL
) {
454 n_perr(_("temporary mail edit file"), 0);
458 extract_header(fp
, hp
, checkaddr_err
);
459 if (checkaddr_err
!= NULL
&& *checkaddr_err
!= 0)
462 /* In template mode some things have been delayed until the template has
464 if(do_delayed_due_t
){
467 if((cp
= ok_vlook(on_compose_enter
)) != NULL
){
468 setup_from_and_sender(hp
);
469 temporary_compose_mode_hook_call(cp
, &n_temporary_compose_hook_varset
,
473 if(!a_coll_message_inject_head(nf
))
477 while ((c
= getc(fp
)) != EOF
) /* XXX bytewise, yuck! */
486 if (check_from_and_sender(hp
->h_from
, hp
->h_sender
) == NULL
)
497 a_coll_edit(int c
, struct header
*hp
) /* TODO error(return) weird */
501 sighandler_type
volatile sigint
;
506 n_UNINIT(sigint
, SIG_ERR
);
509 if(!(saved
= ok_blook(add_file_recipients
)))
510 ok_bset(add_file_recipients
);
512 n_SIGMAN_ENTER_SWITCH(&sm
, n_SIGMAN_ALL
){
514 sigint
= safe_signal(SIGINT
, SIG_IGN
);
521 nf
= run_editor(_coll_fp
, (off_t
)-1, c
, FAL0
, hp
, NULL
, SEND_MBOX
, sigint
);
524 if(!a_coll_makeheader(nf
, hp
, NULL
, FAL0
))
527 fseek(nf
, 0L, SEEK_END
);
534 n_sigman_cleanup_ping(&sm
);
537 ok_bclear(add_file_recipients
);
538 safe_signal(SIGINT
, sigint
);
540 n_sigman_leave(&sm
, n_SIGMAN_VIPSIGS_NTTYOUT
);
545 a_coll_pipe(char const *cmd
)
549 sighandler_type sigint
;
554 sigint
= safe_signal(SIGINT
, SIG_IGN
);
556 if ((nf
= Ftmp(NULL
, "colpipe", OF_RDWR
| OF_UNLINK
| OF_REGISTER
)) ==NULL
) {
557 n_perr(_("temporary mail edit file"), rv
= n_err_no
);
561 /* stdin = current message. stdout = new message */
563 if (n_child_run(ok_vlook(SHELL
), 0, fileno(_coll_fp
), fileno(nf
), "-c",
564 cmd
, NULL
, NULL
, &ws
) < 0 || WEXITSTATUS(ws
) != 0) {
570 if (fsize(nf
) == 0) {
571 n_err(_("No bytes from %s !?\n"), n_shexp_quote_cp(cmd
, FAL0
));
578 fseek(nf
, 0L, SEEK_END
);
582 safe_signal(SIGINT
, sigint
);
588 a_coll_forward(char const *ms
, FILE *fp
, int f
)
591 struct n_ignore
const *itp
;
593 enum sendaction action
;
596 msgvec
= salloc((size_t)(msgCount
+ 1) * sizeof *msgvec
);
597 if (getmsglist(ms
, msgvec
, 0) < 0) {
598 rv
= n_ERR_NOENT
; /* XXX not really, should be handled there! */
602 *msgvec
= first(0, MMNORM
);
604 n_err(_("No appropriate messages\n"));
611 if (f
== 'f' || f
== 'F' || f
== 'u')
613 else if ((tabst
= ok_vlook(indentprefix
)) == NULL
)
614 tabst
= INDENT_DEFAULT
;
615 if (f
== 'u' || f
== 'U')
618 itp
= upperchar(f
) ? NULL
: n_IGNORE_TYPE
;
619 action
= (upperchar(f
) && f
!= 'U') ? SEND_QUOTE_ALL
: SEND_QUOTE
;
621 fprintf(n_stdout
, _("Interpolating:"));
623 for (; *msgvec
!= 0; ++msgvec
) {
624 struct message
*mp
= message
+ *msgvec
- 1;
627 fprintf(n_stdout
, " %d", *msgvec
);
629 if (sendmp(mp
, fp
, itp
, tabst
, action
, NULL
) < 0) {
630 n_perr(_("temporary mail file"), 0);
637 fprintf(n_stdout
, "\n");
644 a_collect_plumbing(char const *ms
, struct header
*hp
){
645 /* TODO _collect_plumbing: instead of fields the basic headers should
646 * TODO be in an array and have IDs, like in termcap etc., so then this
647 * TODO could be simplified as table-walks. Also true for arg-checks! */
649 char const *cp
, *cmd
[4];
652 /* Protcol version for *on-compose-splice** -- update manual on change! */
653 #define a_COLL_PLUMBING_VERSION "0 0 1"
659 for(i
= 0; i
< n_NELEM(cmd
); ++i
){ /* TODO trim+strlist_split(_ifs?)() */
660 while(blankchar(*cp
))
665 if(i
< n_NELEM(cmd
) - 1)
666 for(cmd
[i
] = cp
++; *cp
!= '\0' && !blankchar(*cp
); ++cp
)
669 /* Last slot takes all the rest of the line, less trailing WS */
670 for(cmd
[i
] = cp
++; *cp
!= '\0'; ++cp
)
672 while(blankchar(cp
[-1]))
675 cmd
[i
] = savestrbuf(cmd
[i
], PTR2SIZE(cp
- cmd
[i
]));
680 if(n_UNLIKELY(cmd
[0] == NULL
))
682 if(is_asccaseprefix(cmd
[0], "header"))
683 rv
= a_collect__plumb_header(cp
, hp
, cmd
);
684 else if(is_asccaseprefix(cmd
[0], "attachment"))
685 rv
= a_collect__plumb_attach(cp
, hp
, cmd
);
688 fputs("500\n", n_stdout
);
698 a_collect__plumb_header(char const *cp
, struct header
*hp
,
701 struct n_header_field
*hfp
;
702 struct name
*np
, **npp
;
708 if(is_asccaseprefix(cmd
[1], "insert")){ /* TODO LOGIC BELONGS head.c
709 * TODO That is: Header::factory(string) -> object (blahblah).
710 * TODO I.e., as long as we don't have regular RFC compliant parsers
711 * TODO which differentiate in between structured and unstructured
712 * TODO header fields etc., a little workaround */
715 enum expand_addr_check_mode eacm
;
719 if(cmd
[2] == NULL
|| cmd
[3] == NULL
)
722 /* Strip [\r\n] which would render a body invalid XXX all controls? */
726 cmd
[3] = xp
= savestr(cmd
[3]);
727 for(; (c
= *xp
) != '\0'; ++xp
)
728 if(c
== '\n' || c
== '\r')
732 if(!asccasecmp(cmd
[2], cp
= "Subject")){
733 if(cmd
[3][0] != '\0'){
734 if(hp
->h_subject
!= NULL
)
735 hp
->h_subject
= savecatsep(hp
->h_subject
, ' ', cmd
[3]);
737 hp
->h_subject
= n_UNCONST(cmd
[3]);
738 fprintf(n_stdout
, "210 %s 1\n", cp
);
745 ntype
= GEXTRA
| GFULL
| GFULLEXTRA
;
748 if(!asccasecmp(cmd
[2], cp
= "From")){
752 if((np
= lextract(cmd
[3], ntype
)) == NULL
)
755 if((np
= checkaddrs(np
, eacm
, &aerr
), aerr
!= 0)){
756 fprintf(n_stdout
, "505 %s\n", cp
);
760 /* Go to the end of the list, track whether it contains any
761 * non-deleted entries */
763 if((xnp
= *npp
) != NULL
)
764 for(;; xnp
= xnp
->n_flink
){
765 if(!(xnp
->n_type
& GDEL
))
767 if(xnp
->n_flink
== NULL
)
771 if(!mult_ok
&& (i
!= 0 || np
->n_flink
!= NULL
))
772 fprintf(n_stdout
, "506 %s\n", cp
);
779 fprintf(n_stdout
, "210 %s %" PRIuZ
"\n", cp
, ++i
);
783 if(!asccasecmp(cmd
[2], cp
= "Sender")){
788 if(!asccasecmp(cmd
[2], cp
= "To")){
791 eacm
= EACM_NORMAL
| EAF_NAME
;
794 if(!asccasecmp(cmd
[2], cp
= "Cc")){
797 eacm
= EACM_NORMAL
| EAF_NAME
;
800 if(!asccasecmp(cmd
[2], cp
= "Bcc")){
802 ntype
= GBCC
| GFULL
;
803 eacm
= EACM_NORMAL
| EAF_NAME
;
806 if(!asccasecmp(cmd
[2], cp
= "Reply-To")){
807 npp
= &hp
->h_replyto
;
811 if(!asccasecmp(cmd
[2], cp
= "Mail-Followup-To")){
816 if(!asccasecmp(cmd
[2], cp
= "Message-ID")){
818 npp
= &hp
->h_message_id
;
823 if(!asccasecmp(cmd
[2], cp
= "References")){
829 if(!asccasecmp(cmd
[2], cp
= "In-Reply-To")){
830 npp
= &hp
->h_in_reply_to
;
836 if(!asccasecmp(cmd
[2], cp
= "Mailx-Command") ||
837 !asccasecmp(cmd
[2], cp
= "Mailx-Raw-To") ||
838 !asccasecmp(cmd
[2], cp
= "Mailx-Raw-Cc") ||
839 !asccasecmp(cmd
[2], cp
= "Mailx-Raw-Bcc") ||
840 !asccasecmp(cmd
[2], cp
= "Mailx-Orig-From") ||
841 !asccasecmp(cmd
[2], cp
= "Mailx-Orig-To") ||
842 !asccasecmp(cmd
[2], cp
= "Mailx-Orig-Cc") ||
843 !asccasecmp(cmd
[2], cp
= "Mailx-Orig-Bcc")){
844 fprintf(n_stdout
, "505 %s\n", cp
);
848 /* Free-form header fields (note j501cp may print non-normalized name) */
851 struct n_header_field
**hfpp
;
853 for(cp
= cmd
[2]; *cp
!= '\0'; ++cp
)
854 if(!fieldnamechar(*cp
)){
859 for(i
= 0, hfpp
= &hp
->h_user_headers
; *hfpp
!= NULL
; ++i
)
860 hfpp
= &(*hfpp
)->hf_next
;
862 nl
= strlen(cp
= cmd
[2]) +1;
863 bl
= strlen(cmd
[3]) +1;
864 *hfpp
= hfp
= salloc(n_VSTRUCT_SIZEOF(struct n_header_field
, hf_dat
869 hfp
->hf_dat
[nl
= 0] = upperconv(*cp
);
871 hfp
->hf_dat
[++nl
] = lowerconv(*cp
);
872 memcpy(&hfp
->hf_dat
[++nl
], cmd
[3], bl
);
873 fprintf(n_stdout
, "210 %s %" PRIuZ
"\n", &hfp
->hf_dat
[0], ++i
);
878 if(is_asccaseprefix(cmd
[1], "list")){
881 fputs("210", n_stdout
);
882 if(hp
->h_subject
!= NULL
) fputs(" Subject", n_stdout
);
883 if(hp
->h_from
!= NULL
) fputs(" From", n_stdout
);
884 if(hp
->h_sender
!= NULL
) fputs(" Sender", n_stdout
);
885 if(hp
->h_to
!= NULL
) fputs(" To", n_stdout
);
886 if(hp
->h_cc
!= NULL
) fputs(" Cc", n_stdout
);
887 if(hp
->h_bcc
!= NULL
) fputs(" Bcc", n_stdout
);
888 if(hp
->h_replyto
!= NULL
) fputs(" Reply-To", n_stdout
);
889 if(hp
->h_mft
!= NULL
) fputs(" Mail-Followup-To", n_stdout
);
890 if(hp
->h_message_id
!= NULL
) fputs(" Message-ID", n_stdout
);
891 if(hp
->h_ref
!= NULL
) fputs(" References", n_stdout
);
892 if(hp
->h_in_reply_to
!= NULL
) fputs(" In-Reply-To", n_stdout
);
893 if(hp
->h_mailx_command
!= NULL
) fputs(" Mailx-Command", n_stdout
);
894 if(hp
->h_mailx_raw_to
!= NULL
) fputs(" Mailx-Raw-To", n_stdout
);
895 if(hp
->h_mailx_raw_cc
!= NULL
) fputs(" Mailx-Raw-Cc", n_stdout
);
896 if(hp
->h_mailx_raw_bcc
!= NULL
) fputs(" Mailx-Raw-Bcc", n_stdout
);
897 if(hp
->h_mailx_orig_from
!= NULL
) fputs(" Mailx-Orig-From", n_stdout
);
898 if(hp
->h_mailx_orig_to
!= NULL
) fputs(" Mailx-Orig-To", n_stdout
);
899 if(hp
->h_mailx_orig_cc
!= NULL
) fputs(" Mailx-Orig-Cc", n_stdout
);
900 if(hp
->h_mailx_orig_bcc
!= NULL
) fputs(" Mailx-Orig-Bcc", n_stdout
);
902 /* Print only one instance of each free-form header */
903 for(hfp
= hp
->h_user_headers
; hfp
!= NULL
; hfp
= hfp
->hf_next
){
904 struct n_header_field
*hfpx
;
906 for(hfpx
= hp
->h_user_headers
;; hfpx
= hfpx
->hf_next
)
909 fputs(&hfp
->hf_dat
[0], n_stdout
);
911 }else if(!strcmp(&hfpx
->hf_dat
[0], &hfp
->hf_dat
[0]))
914 putc('\n', n_stdout
);
921 if(!asccasecmp(cmd
[2], cp
= "Subject")){
922 np
= (hp
->h_subject
!= NULL
) ? (struct name
*)-1 : NULL
;
925 if(!asccasecmp(cmd
[2], cp
= "From")){
928 fprintf(n_stdout
, "%s %s\n", (np
== NULL
? "501" : "210"), cp
);
931 if(!asccasecmp(cmd
[2], cp
= "Sender")){
935 if(!asccasecmp(cmd
[2], cp
= "To")){
939 if(!asccasecmp(cmd
[2], cp
= "Cc")){
943 if(!asccasecmp(cmd
[2], cp
= "Bcc")){
947 if(!asccasecmp(cmd
[2], cp
= "Reply-To")){
951 if(!asccasecmp(cmd
[2], cp
= "Mail-Followup-To")){
955 if(!asccasecmp(cmd
[2], cp
= "Message-ID")){
956 np
= hp
->h_message_id
;
959 if(!asccasecmp(cmd
[2], cp
= "References")){
963 if(!asccasecmp(cmd
[2], cp
= "In-Reply-To")){
964 np
= hp
->h_in_reply_to
;
968 if(!asccasecmp(cmd
[2], cp
= "Mailx-Command")){
969 np
= (hp
->h_mailx_command
!= NULL
) ? (struct name
*)-1 : NULL
;
972 if(!asccasecmp(cmd
[2], cp
= "Mailx-Raw-To")){
973 np
= hp
->h_mailx_raw_to
;
976 if(!asccasecmp(cmd
[2], cp
= "Mailx-Raw-Cc")){
977 np
= hp
->h_mailx_raw_cc
;
980 if(!asccasecmp(cmd
[2], cp
= "Mailx-Raw-Bcc")){
981 np
= hp
->h_mailx_raw_bcc
;
984 if(!asccasecmp(cmd
[2], cp
= "Mailx-Orig-From")){
985 np
= hp
->h_mailx_orig_from
;
988 if(!asccasecmp(cmd
[2], cp
= "Mailx-Orig-To")){
989 np
= hp
->h_mailx_orig_to
;
992 if(!asccasecmp(cmd
[2], cp
= "Mailx-Orig-Cc")){
993 np
= hp
->h_mailx_orig_cc
;
996 if(!asccasecmp(cmd
[2], cp
= "Mailx-Orig-Bcc")){
997 np
= hp
->h_mailx_orig_bcc
;
1001 /* Free-form header fields (note j501cp may print non-normalized name) */
1002 for(cp
= cmd
[2]; *cp
!= '\0'; ++cp
)
1003 if(!fieldnamechar(*cp
)){
1008 for(hfp
= hp
->h_user_headers
;; hfp
= hfp
->hf_next
){
1011 else if(!asccasecmp(cp
, &hfp
->hf_dat
[0])){
1012 fprintf(n_stdout
, "210 %s\n", &hfp
->hf_dat
[0]);
1019 if(is_asccaseprefix(cmd
[1], "remove")){
1020 if(cmd
[2] == NULL
|| cmd
[3] != NULL
)
1023 if(!asccasecmp(cmd
[2], cp
= "Subject")){
1024 if(hp
->h_subject
!= NULL
){
1025 hp
->h_subject
= NULL
;
1026 fprintf(n_stdout
, "210 %s\n", cp
);
1032 if(!asccasecmp(cmd
[2], cp
= "From")){
1037 fprintf(n_stdout
, "210 %s\n", cp
);
1042 if(!asccasecmp(cmd
[2], cp
= "Sender")){
1043 npp
= &hp
->h_sender
;
1046 if(!asccasecmp(cmd
[2], cp
= "To")){
1050 if(!asccasecmp(cmd
[2], cp
= "Cc")){
1054 if(!asccasecmp(cmd
[2], cp
= "Bcc")){
1058 if(!asccasecmp(cmd
[2], cp
= "Reply-To")){
1059 npp
= &hp
->h_replyto
;
1062 if(!asccasecmp(cmd
[2], cp
= "Mail-Followup-To")){
1066 if(!asccasecmp(cmd
[2], cp
= "Message-ID")){
1067 npp
= &hp
->h_message_id
;
1070 if(!asccasecmp(cmd
[2], cp
= "References")){
1074 if(!asccasecmp(cmd
[2], cp
= "In-Reply-To")){
1075 npp
= &hp
->h_in_reply_to
;
1079 if(!asccasecmp(cmd
[2], cp
= "Mailx-Command") ||
1080 !asccasecmp(cmd
[2], cp
= "Mailx-Raw-To") ||
1081 !asccasecmp(cmd
[2], cp
= "Mailx-Raw-Cc") ||
1082 !asccasecmp(cmd
[2], cp
= "Mailx-Raw-Bcc") ||
1083 !asccasecmp(cmd
[2], cp
= "Mailx-Orig-From") ||
1084 !asccasecmp(cmd
[2], cp
= "Mailx-Orig-To") ||
1085 !asccasecmp(cmd
[2], cp
= "Mailx-Orig-Cc") ||
1086 !asccasecmp(cmd
[2], cp
= "Mailx-Orig-Bcc")){
1087 fprintf(n_stdout
, "505 %s\n", cp
);
1091 /* Free-form header fields (note j501cp may print non-normalized name) */
1093 struct n_header_field
**hfpp
;
1096 for(cp
= cmd
[2]; *cp
!= '\0'; ++cp
)
1097 if(!fieldnamechar(*cp
)){
1103 for(any
= FAL0
, hfpp
= &hp
->h_user_headers
; (hfp
= *hfpp
) != NULL
;){
1104 if(!asccasecmp(cp
, &hfp
->hf_dat
[0])){
1105 *hfpp
= hfp
->hf_next
;
1107 fprintf(n_stdout
, "210 %s\n", &hfp
->hf_dat
[0]);
1110 hfpp
= &hfp
->hf_next
;
1118 if(is_asccaseprefix(cmd
[1], "remove-at")){
1119 if(cmd
[2] == NULL
|| cmd
[3] == NULL
)
1122 if((n_idec_uiz_cp(&i
, cmd
[3], 0, NULL
1123 ) & (n_IDEC_STATE_EMASK
| n_IDEC_STATE_CONSUMED
)
1124 ) != n_IDEC_STATE_CONSUMED
|| i
== 0){
1125 fputs("505\n", n_stdout
);
1129 if(!asccasecmp(cmd
[2], cp
= "Subject")){
1130 if(hp
->h_subject
!= NULL
&& i
== 1){
1131 hp
->h_subject
= NULL
;
1132 fprintf(n_stdout
, "210 %s 1\n", cp
);
1138 if(!asccasecmp(cmd
[2], cp
= "From")){
1141 if((np
= *npp
) == NULL
)
1143 while(--i
!= 0 && np
!= NULL
)
1148 if(np
->n_blink
!= NULL
)
1149 np
->n_blink
->n_flink
= np
->n_flink
;
1152 if(np
->n_flink
!= NULL
)
1153 np
->n_flink
->n_blink
= np
->n_blink
;
1155 fprintf(n_stdout
, "210 %s\n", cp
);
1158 if(!asccasecmp(cmd
[2], cp
= "Sender")){
1159 npp
= &hp
->h_sender
;
1162 if(!asccasecmp(cmd
[2], cp
= "To")){
1166 if(!asccasecmp(cmd
[2], cp
= "Cc")){
1170 if(!asccasecmp(cmd
[2], cp
= "Bcc")){
1174 if(!asccasecmp(cmd
[2], cp
= "Reply-To")){
1175 npp
= &hp
->h_replyto
;
1178 if(!asccasecmp(cmd
[2], cp
= "Mail-Followup-To")){
1182 if(!asccasecmp(cmd
[2], cp
= "Message-ID")){
1183 npp
= &hp
->h_message_id
;
1186 if(!asccasecmp(cmd
[2], cp
= "References")){
1190 if(!asccasecmp(cmd
[2], cp
= "In-Reply-To")){
1191 npp
= &hp
->h_in_reply_to
;
1195 if(!asccasecmp(cmd
[2], cp
= "Mailx-Command") ||
1196 !asccasecmp(cmd
[2], cp
= "Mailx-Raw-To") ||
1197 !asccasecmp(cmd
[2], cp
= "Mailx-Raw-Cc") ||
1198 !asccasecmp(cmd
[2], cp
= "Mailx-Raw-Bcc") ||
1199 !asccasecmp(cmd
[2], cp
= "Mailx-Orig-From") ||
1200 !asccasecmp(cmd
[2], cp
= "Mailx-Orig-To") ||
1201 !asccasecmp(cmd
[2], cp
= "Mailx-Orig-Cc") ||
1202 !asccasecmp(cmd
[2], cp
= "Mailx-Orig-Bcc")){
1203 fprintf(n_stdout
, "505 %s\n", cp
);
1207 /* Free-form header fields (note j501cp may print non-normalized name) */
1209 struct n_header_field
**hfpp
;
1211 for(cp
= cmd
[2]; *cp
!= '\0'; ++cp
)
1212 if(!fieldnamechar(*cp
)){
1218 for(hfpp
= &hp
->h_user_headers
; (hfp
= *hfpp
) != NULL
;){
1220 *hfpp
= hfp
->hf_next
;
1221 fprintf(n_stdout
, "210 %s %" PRIuZ
"\n", &hfp
->hf_dat
[0], i
);
1224 hfpp
= &hfp
->hf_next
;
1232 if(is_asccaseprefix(cmd
[1], "show")){
1233 if(cmd
[2] == NULL
|| cmd
[3] != NULL
)
1236 if(!asccasecmp(cmd
[2], cp
= "Subject")){
1237 if(hp
->h_subject
== NULL
)
1239 fprintf(n_stdout
, "212 %s\n%s\n\n", cp
, hp
->h_subject
);
1243 if(!asccasecmp(cmd
[2], cp
= "From")){
1247 fprintf(n_stdout
, "211 %s\n", cp
);
1248 do if(!(np
->n_type
& GDEL
))
1249 fprintf(n_stdout
, "%s %s\n", np
->n_name
, np
->n_fullname
);
1250 while((np
= np
->n_flink
) != NULL
);
1251 putc('\n', n_stdout
);
1256 if(!asccasecmp(cmd
[2], cp
= "Sender")){
1260 if(!asccasecmp(cmd
[2], cp
= "To")){
1264 if(!asccasecmp(cmd
[2], cp
= "Cc")){
1268 if(!asccasecmp(cmd
[2], cp
= "Bcc")){
1272 if(!asccasecmp(cmd
[2], cp
= "Reply-To")){
1276 if(!asccasecmp(cmd
[2], cp
= "Mail-Followup-To")){
1280 if(!asccasecmp(cmd
[2], cp
= "Message-ID")){
1281 np
= hp
->h_message_id
;
1284 if(!asccasecmp(cmd
[2], cp
= "References")){
1288 if(!asccasecmp(cmd
[2], cp
= "In-Reply-To")){
1289 np
= hp
->h_in_reply_to
;
1293 if(!asccasecmp(cmd
[2], cp
= "Mailx-Command")){
1294 if(hp
->h_mailx_command
== NULL
)
1296 fprintf(n_stdout
, "212 %s\n%s\n\n", cp
, hp
->h_mailx_command
);
1299 if(!asccasecmp(cmd
[2], cp
= "Mailx-Raw-To")){
1300 np
= hp
->h_mailx_raw_to
;
1303 if(!asccasecmp(cmd
[2], cp
= "Mailx-Raw-Cc")){
1304 np
= hp
->h_mailx_raw_cc
;
1307 if(!asccasecmp(cmd
[2], cp
= "Mailx-Raw-Bcc")){
1308 np
= hp
->h_mailx_raw_bcc
;
1311 if(!asccasecmp(cmd
[2], cp
= "Mailx-Orig-From")){
1312 np
= hp
->h_mailx_orig_from
;
1315 if(!asccasecmp(cmd
[2], cp
= "Mailx-Orig-To")){
1316 np
= hp
->h_mailx_orig_to
;
1319 if(!asccasecmp(cmd
[2], cp
= "Mailx-Orig-Cc")){
1320 np
= hp
->h_mailx_orig_cc
;
1323 if(!asccasecmp(cmd
[2], cp
= "Mailx-Orig-Bcc")){
1324 np
= hp
->h_mailx_orig_bcc
;
1328 /* Free-form header fields (note j501cp may print non-normalized name) */
1332 for(cp
= cmd
[2]; *cp
!= '\0'; ++cp
)
1333 if(!fieldnamechar(*cp
)){
1339 for(any
= FAL0
, hfp
= hp
->h_user_headers
; hfp
!= NULL
;
1340 hfp
= hfp
->hf_next
){
1341 if(!asccasecmp(cp
, &hfp
->hf_dat
[0])){
1343 fprintf(n_stdout
, "212 %s\n", &hfp
->hf_dat
[0]);
1345 fprintf(n_stdout
, "%s\n", &hfp
->hf_dat
[hfp
->hf_nl
+1]);
1349 putc('\n', n_stdout
);
1357 fputs("500\n", n_stdout
);
1361 return (cp
!= NULL
);
1364 fputs("501 ", n_stdout
);
1365 fputs(cp
, n_stdout
);
1366 putc('\n', n_stdout
);
1371 a_collect__plumb_attach(char const *cp
, struct header
*hp
,
1372 char const *cmd
[4]){
1374 struct attachment
*ap
;
1380 if(is_asccaseprefix(cmd
[1], "attribute")){
1381 if(cmd
[2] == NULL
|| cmd
[3] != NULL
)
1384 if((ap
= n_attachment_find(hp
->h_attach
, cmd
[2], NULL
)) != NULL
){
1386 fprintf(n_stdout
, "212 %s\n", cmd
[2]);
1388 fprintf(n_stdout
, "message-number %d\n\n", ap
->a_msgno
);
1391 "creation-name %s\nopen-path %s\nfilename %s\n",
1392 ap
->a_path_user
, ap
->a_path
, ap
->a_name
);
1393 if(ap
->a_content_description
!= NULL
)
1394 fprintf(n_stdout
, "content-description %s\n",
1395 ap
->a_content_description
);
1396 if(ap
->a_content_id
!= NULL
)
1397 fprintf(n_stdout
, "content-id %s\n",
1398 ap
->a_content_id
->n_name
);
1399 if(ap
->a_content_type
!= NULL
)
1400 fprintf(n_stdout
, "content-type %s\n", ap
->a_content_type
);
1401 if(ap
->a_content_disposition
!= NULL
)
1402 fprintf(n_stdout
, "content-disposition %s\n",
1403 ap
->a_content_disposition
);
1404 putc('\n', n_stdout
);
1407 fputs("501\n", n_stdout
);
1411 if(is_asccaseprefix(cmd
[1], "attribute-at")){
1414 if(cmd
[2] == NULL
|| cmd
[3] != NULL
)
1417 if((n_idec_uiz_cp(&i
, cmd
[2], 0, NULL
1418 ) & (n_IDEC_STATE_EMASK
| n_IDEC_STATE_CONSUMED
)
1419 ) != n_IDEC_STATE_CONSUMED
|| i
== 0)
1420 fputs("505\n", n_stdout
);
1422 for(ap
= hp
->h_attach
; ap
!= NULL
&& --i
!= 0; ap
= ap
->a_flink
)
1427 fputs("501\n", n_stdout
);
1432 if(is_asccaseprefix(cmd
[1], "attribute-set")){
1433 if(cmd
[2] == NULL
|| cmd
[3] == NULL
)
1436 if((ap
= n_attachment_find(hp
->h_attach
, cmd
[2], NULL
)) != NULL
){
1439 fputs("505\n", n_stdout
);
1444 while((c
= *cp
) != '\0' && !blankchar(c
))
1446 keyw
= savestrbuf(cmd
[3], PTR2SIZE(cp
- cmd
[3]));
1448 for(; (c
= *++cp
) != '\0' && blankchar(c
);)
1453 /* Strip [\r\n] which would render a parameter invalid XXX
1454 * XXX all controls? */
1455 cp
= xp
= savestr(cp
);
1456 for(; (c
= *xp
) != '\0'; ++xp
)
1457 if(c
== '\n' || c
== '\r')
1463 if(!asccasecmp(keyw
, "filename"))
1464 ap
->a_name
= (c
== '\0') ? ap
->a_path_bname
: cp
;
1465 else if(!asccasecmp(keyw
, "content-description"))
1466 ap
->a_content_description
= (c
== '\0') ? NULL
: cp
;
1467 else if(!asccasecmp(keyw
, "content-id")){
1468 ap
->a_content_id
= NULL
;
1473 np
= checkaddrs(lextract(cp
, GREF
),
1474 /*EACM_STRICT | TODO '/' valid!! */ EACM_NOLOG
|
1476 if(np
!= NULL
&& np
->n_flink
== NULL
)
1477 ap
->a_content_id
= np
;
1481 }else if(!asccasecmp(keyw
, "content-type"))
1482 ap
->a_content_type
= (c
== '\0') ? NULL
: cp
;
1483 else if(!asccasecmp(keyw
, "content-disposition"))
1484 ap
->a_content_disposition
= (c
== '\0') ? NULL
: cp
;
1491 for(i
= 0; ap
!= NULL
; ++i
, ap
= ap
->a_blink
)
1493 fprintf(n_stdout
, "210 %" PRIuZ
"\n", i
);
1495 fputs("505\n", n_stdout
);
1498 fputs("501\n", n_stdout
);
1502 if(is_asccaseprefix(cmd
[1], "attribute-set-at")){
1505 if(cmd
[2] == NULL
|| cmd
[3] == NULL
)
1508 if((n_idec_uiz_cp(&i
, cmd
[2], 0, NULL
1509 ) & (n_IDEC_STATE_EMASK
| n_IDEC_STATE_CONSUMED
)
1510 ) != n_IDEC_STATE_CONSUMED
|| i
== 0)
1511 fputs("505\n", n_stdout
);
1513 for(ap
= hp
->h_attach
; ap
!= NULL
&& --i
!= 0; ap
= ap
->a_flink
)
1518 fputs("501\n", n_stdout
);
1523 if(is_asccaseprefix(cmd
[1], "insert")){
1524 enum n_attach_error aerr
;
1526 if(cmd
[2] == NULL
|| cmd
[3] != NULL
)
1529 hp
->h_attach
= n_attachment_append(hp
->h_attach
, cmd
[2], &aerr
, &ap
);
1531 case n_ATTACH_ERR_FILE_OPEN
: cp
= "505\n"; goto jatt_ins
;
1532 case n_ATTACH_ERR_ICONV_FAILED
: cp
= "506\n"; goto jatt_ins
;
1533 case n_ATTACH_ERR_ICONV_NAVAIL
:
1534 case n_ATTACH_ERR_OTHER
:
1538 fputs(cp
, n_stdout
);
1540 case n_ATTACH_ERR_NONE
:{
1543 for(i
= 0; ap
!= NULL
; ++i
, ap
= ap
->a_blink
)
1545 fprintf(n_stdout
, "210 %" PRIuZ
"\n", i
);
1551 if(is_asccaseprefix(cmd
[1], "list")){
1556 if((ap
= hp
->h_attach
) != NULL
){
1557 fputs("212\n", n_stdout
);
1559 fprintf(n_stdout
, "%s\n", ap
->a_path_user
);
1560 while((ap
= ap
->a_flink
) != NULL
);
1561 putc('\n', n_stdout
);
1563 fputs("501\n", n_stdout
);
1567 if(is_asccaseprefix(cmd
[1], "remove")){
1568 if(cmd
[2] == NULL
|| cmd
[3] != NULL
)
1571 if((ap
= n_attachment_find(hp
->h_attach
, cmd
[2], &status
)) != NULL
){
1573 fputs("506\n", n_stdout
);
1575 hp
->h_attach
= n_attachment_remove(hp
->h_attach
, ap
);
1576 fprintf(n_stdout
, "210 %s\n", cmd
[2]);
1579 fputs("501\n", n_stdout
);
1583 if(is_asccaseprefix(cmd
[1], "remove-at")){
1586 if(cmd
[2] == NULL
|| cmd
[3] != NULL
)
1589 if((n_idec_uiz_cp(&i
, cmd
[2], 0, NULL
1590 ) & (n_IDEC_STATE_EMASK
| n_IDEC_STATE_CONSUMED
)
1591 ) != n_IDEC_STATE_CONSUMED
|| i
== 0)
1592 fputs("505\n", n_stdout
);
1594 for(ap
= hp
->h_attach
; ap
!= NULL
&& --i
!= 0; ap
= ap
->a_flink
)
1597 hp
->h_attach
= n_attachment_remove(hp
->h_attach
, ap
);
1598 fprintf(n_stdout
, "210 %s\n", cmd
[2]);
1600 fputs("501\n", n_stdout
);
1606 fputs("500\n", n_stdout
);
1610 return (cp
!= NULL
);
1616 NYD_X
; /* Signal handler */
1618 /* the control flow is subtle, because we can be called from ~q */
1619 if (_coll_hadintr
== 0) {
1620 if (ok_blook(ignore
)) {
1621 fputs("@\n", n_stdout
);
1626 siglongjmp(_coll_jmp
, 1);
1628 n_exit_status
|= n_EXIT_SEND_ERROR
;
1630 savedeadletter(_coll_fp
, TRU1
);
1631 /* Aborting message, no need to fflush() .. */
1632 siglongjmp(_coll_abort
, 1);
1638 NYD_X
; /* Signal handler */
1641 savedeadletter(_coll_fp
, TRU1
);
1642 /* Let's pretend nobody else wants to clean up, a true statement at
1648 a_coll_putesc(char const *s
, bool_t addnl
, FILE *stream
) /* TODO: v15: drop */
1655 while (s
[0] != '\0') { /* TODO v15: user resp upon `set' time! */
1658 if (putc('\t', stream
) == EOF
)
1664 if (putc('\n', stream
) == EOF
)
1670 if (putc(s
[0], stream
) == EOF
)
1676 if(putc('\n', stream
) == EOF
)
1687 a_coll_ocs__mac(void){
1688 /* Executes in a fork(2)ed child TODO if remains, global MASKs for those! */
1689 setvbuf(n_stdin
, NULL
, _IOLBF
, 0);
1690 setvbuf(n_stdout
, NULL
, _IOLBF
, 0);
1691 n_psonce
&= ~(n_PSO_INTERACTIVE
| n_PSO_TTYIN
| n_PSO_TTYOUT
);
1692 n_pstate
|= n_PS_COMPOSE_FORKHOOK
;
1693 n_readctl_overlay
= NULL
; /* TODO we need OnForkEvent! See c_readctl() */
1694 if(n_poption
& n_PO_D_VV
){
1697 snprintf(buf
, sizeof buf
, "[%d]%s", getpid(), ok_vlook(log_prefix
));
1698 ok_vset(log_prefix
, buf
);
1700 /* TODO If that uses `!' it will effectively SIG_IGN SIGINT, ...and such */
1701 temporary_compose_mode_hook_call(a_coll_ocs__macname
, NULL
, NULL
);
1706 a_coll_ocs__finalize(void *vp
){
1707 /* Note we use this for destruction upon setup errors, thus */
1708 sighandler_type opipe
;
1709 sighandler_type oint
;
1710 struct a_coll_ocs_arg
**coapp
, *coap
;
1713 temporary_compose_mode_hook_call((char*)-1, NULL
, NULL
);
1715 coap
= *(coapp
= vp
);
1716 *coapp
= (struct a_coll_ocs_arg
*)-1;
1718 if(coap
->coa_stdin
!= NULL
)
1719 Fclose(coap
->coa_stdin
);
1720 else if(coap
->coa_pipe
[0] != -1)
1721 close(coap
->coa_pipe
[0]);
1723 if(coap
->coa_stdout
!= NULL
&& !Pclose(coap
->coa_stdout
, TRU1
))
1724 *coap
->coa_senderr
= 111;
1725 if(coap
->coa_pipe
[1] != -1)
1726 close(coap
->coa_pipe
[1]);
1728 opipe
= coap
->coa_opipe
;
1729 oint
= coap
->coa_oint
;
1734 safe_signal(SIGPIPE
, opipe
);
1735 safe_signal(SIGINT
, oint
);
1741 n_temporary_compose_hook_varset(void *arg
){ /* TODO v15: drop */
1748 if((val
= hp
->h_subject
) == NULL
)
1750 ok_vset(mailx_subject
, val
);
1751 if((val
= detract(hp
->h_from
, GNAMEONLY
)) == NULL
)
1753 ok_vset(mailx_from
, val
);
1754 if((val
= detract(hp
->h_sender
, GNAMEONLY
)) == NULL
)
1756 ok_vset(mailx_sender
, val
);
1757 if((val
= detract(hp
->h_to
, GNAMEONLY
)) == NULL
)
1759 ok_vset(mailx_to
, val
);
1760 if((val
= detract(hp
->h_cc
, GNAMEONLY
)) == NULL
)
1762 ok_vset(mailx_cc
, val
);
1763 if((val
= detract(hp
->h_bcc
, GNAMEONLY
)) == NULL
)
1765 ok_vset(mailx_bcc
, val
);
1767 if((val
= hp
->h_mailx_command
) == NULL
)
1769 ok_vset(mailx_command
, val
);
1771 if((val
= detract(hp
->h_mailx_raw_to
, GNAMEONLY
)) == NULL
)
1773 ok_vset(mailx_raw_to
, val
);
1774 if((val
= detract(hp
->h_mailx_raw_cc
, GNAMEONLY
)) == NULL
)
1776 ok_vset(mailx_raw_cc
, val
);
1777 if((val
= detract(hp
->h_mailx_raw_bcc
, GNAMEONLY
)) == NULL
)
1779 ok_vset(mailx_raw_bcc
, val
);
1781 if((val
= detract(hp
->h_mailx_orig_from
, GNAMEONLY
)) == NULL
)
1783 ok_vset(mailx_orig_from
, val
);
1784 if((val
= detract(hp
->h_mailx_orig_to
, GNAMEONLY
)) == NULL
)
1786 ok_vset(mailx_orig_to
, val
);
1787 if((val
= detract(hp
->h_mailx_orig_cc
, GNAMEONLY
)) == NULL
)
1789 ok_vset(mailx_orig_cc
, val
);
1790 if((val
= detract(hp
->h_mailx_orig_bcc
, GNAMEONLY
)) == NULL
)
1792 ok_vset(mailx_orig_bcc
, val
);
1797 collect(struct header
*hp
, int printheaders
, struct message
*mp
,
1798 char const *quotefile
, int doprefix
, si8_t
*checkaddr_err
)
1800 struct n_string s
, * volatile sp
;
1801 struct n_ignore
const *quoteitp
;
1802 struct a_coll_ocs_arg
*coap
;
1804 int volatile t
, eofcnt
, getfields
;
1805 char volatile escape
;
1810 a_COAP_NOSIGTERM
= 1u<<8
1811 #define a_HARDERR() ((flags & (a_ERREXIT | a_IGNERR)) == a_ERREXIT)
1814 char const *cp
, *cp_base
, * volatile coapm
, * volatile ifs_saved
;
1815 size_t i
, linesize
; /* TODO line pool */
1817 enum sendaction action
;
1818 sigset_t oset
, nset
;
1819 FILE * volatile sigfp
;
1827 ifs_saved
= coapm
= NULL
;
1831 /* Start catching signals from here, but we're still die on interrupts
1832 * until we're in the main loop */
1834 sigprocmask(SIG_BLOCK
, &nset
, &oset
);
1835 if ((_coll_saveint
= safe_signal(SIGINT
, SIG_IGN
)) != SIG_IGN
)
1836 safe_signal(SIGINT
, &_collint
);
1837 if ((_coll_savehup
= safe_signal(SIGHUP
, SIG_IGN
)) != SIG_IGN
)
1838 safe_signal(SIGHUP
, collhup
);
1839 if (sigsetjmp(_coll_abort
, 1))
1841 if (sigsetjmp(_coll_jmp
, 1))
1843 n_pstate
|= n_PS_COMPOSE_MODE
;
1844 sigprocmask(SIG_SETMASK
, &oset
, (sigset_t
*)NULL
);
1846 if ((_coll_fp
= Ftmp(NULL
, "collect", OF_RDWR
| OF_UNLINK
| OF_REGISTER
)) ==
1848 n_perr(_("temporary mail file"), 0);
1852 /* If we are going to prompt for a subject, refrain from printing a newline
1853 * after the headers (since some people mind) */
1855 if (!(n_poption
& n_PO_t_FLAG
)) {
1856 t
= GTO
| GSUBJECT
| GCC
| GNL
;
1857 if (ok_blook(fullnames
))
1860 if (n_psonce
& n_PSO_INTERACTIVE
) {
1861 if (hp
->h_subject
== NULL
&& (ok_blook(ask
) || ok_blook(asksub
)))
1862 t
&= ~GNL
, getfields
|= GSUBJECT
;
1864 if (hp
->h_to
== NULL
)
1865 t
&= ~GNL
, getfields
|= GTO
;
1867 if (!ok_blook(bsdcompat
) && !ok_blook(askatend
)) {
1868 if (hp
->h_bcc
== NULL
&& ok_blook(askbcc
))
1869 t
&= ~GNL
, getfields
|= GBCC
;
1870 if (hp
->h_cc
== NULL
&& ok_blook(askcc
))
1871 t
&= ~GNL
, getfields
|= GCC
;
1880 if (!sigsetjmp(_coll_jmp
, 1)) {
1881 /* Ask for some headers first, as necessary */
1883 grab_headers(n_GO_INPUT_CTX_COMPOSE
, hp
, getfields
, 1);
1885 /* Execute compose-enter; delayed for -t mode */
1886 if(!(n_poption
& n_PO_t_FLAG
) &&
1887 (cp
= ok_vlook(on_compose_enter
)) != NULL
){
1888 setup_from_and_sender(hp
);
1889 temporary_compose_mode_hook_call(cp
, &n_temporary_compose_hook_varset
,
1893 /* TODO Mm: nope since it may require turning this into a multipart one */
1894 if(!(n_poption
& (n_PO_Mm_FLAG
| n_PO_t_FLAG
))){
1895 if(!a_coll_message_inject_head(_coll_fp
))
1898 /* Quote an original message */
1899 if (mp
!= NULL
&& (doprefix
|| (cp
= ok_vlook(quote
)) != NULL
)) {
1900 quoteitp
= n_IGNORE_ALL
;
1901 action
= SEND_QUOTE
;
1903 char const *cp_v15compat
;
1905 quoteitp
= n_IGNORE_FWD
;
1907 if((cp_v15compat
= ok_vlook(fwdheading
)) != NULL
)
1908 n_OBSOLETE(_("please use *forward-inject-head*, "
1909 "not *fwdheading*"));
1910 cp
= ok_vlook(forward_inject_head
);
1911 if(cp
== NULL
&& (cp
= cp_v15compat
) == NULL
)
1912 cp
= "-------- Original Message --------";
1913 if (*cp
!= '\0' && fprintf(_coll_fp
, "%s\n", cp
) < 0)
1915 } else if (!strcmp(cp
, "noheading")) {
1917 } else if (!strcmp(cp
, "headers")) {
1918 quoteitp
= n_IGNORE_TYPE
;
1919 } else if (!strcmp(cp
, "allheaders")) {
1921 action
= SEND_QUOTE_ALL
;
1923 cp
= hfield1("from", mp
);
1924 if (cp
!= NULL
&& (cnt
= (long)strlen(cp
)) > 0) {
1925 if (xmime_write(cp
, cnt
, _coll_fp
, CONV_FROMHDR
, TD_NONE
) < 0)
1927 if (fprintf(_coll_fp
, _(" wrote:\n\n")) < 0)
1931 if (fflush(_coll_fp
))
1935 else if ((cp
= ok_vlook(indentprefix
)) == NULL
)
1936 cp
= INDENT_DEFAULT
;
1937 if (sendmp(mp
, _coll_fp
, quoteitp
, cp
, action
, NULL
) < 0)
1942 if (quotefile
!= NULL
) {
1943 if((n_pstate_err_no
= a_coll_include_file(quotefile
, FAL0
, FAL0
)
1948 if(n_psonce
& n_PSO_INTERACTIVE
){
1949 if(!(n_pstate
& n_PS_SOURCING
)){
1950 sp
= n_string_creat_auto(&s
);
1951 sp
= n_string_reserve(sp
, 80);
1954 if(!(n_poption
& n_PO_Mm_FLAG
)){
1955 /* Print what we have sofar also on the terminal (if useful) */
1956 if (!ok_blook(editalong
)) {
1958 puthead(TRU1
, hp
, n_stdout
, t
,
1959 SEND_TODISP
, CONV_NONE
, NULL
, NULL
);
1962 while ((c
= getc(_coll_fp
)) != EOF
) /* XXX bytewise, yuck! */
1964 if (fseek(_coll_fp
, 0, SEEK_END
))
1968 if(a_coll_edit('e', hp
) != n_ERR_NONE
)
1970 /* Print msg mandated by the Mail Reference Manual */
1972 if(n_psonce
& n_PSO_INTERACTIVE
)
1973 fputs(_("(continue)\n"), n_stdout
);
1979 /* Come here for printing the after-signal message. Duplicate messages
1980 * won't be printed because the write is aborted if we get a SIGTTOU */
1982 n_err(_("\n(Interrupt -- one more to kill letter)\n"));
1985 /* If not under shell hook control */
1987 /* We're done with -M or -m TODO because: we are too stupid yet, above */
1988 if(n_poption
& n_PO_Mm_FLAG
)
1990 /* No command escapes, interrupts not expected. Simply copy STDIN */
1991 if(!(n_psonce
& n_PSO_INTERACTIVE
) &&
1992 !(n_poption
& (n_PO_t_FLAG
| n_PO_TILDE_FLAG
))){
1993 linebuf
= srealloc(linebuf
, linesize
= LINESIZE
);
1994 while ((i
= fread(linebuf
, sizeof *linebuf
, linesize
, n_stdin
)) > 0) {
1995 if (i
!= fwrite(linebuf
, sizeof *linebuf
, i
, _coll_fp
))
2002 /* The interactive collect loop */
2004 escape
= *ok_vlook(escape
);
2005 flags
= ok_blook(errexit
) ? a_ERREXIT
: a_NONE
;
2008 enum {a_HIST_NONE
, a_HIST_ADD
= 1u<<0, a_HIST_GABBY
= 1u<<1} hist
;
2011 enum n_go_input_flags gif
;
2014 gif
= n_GO_INPUT_CTX_COMPOSE
;
2015 histadd
= (sp
!= NULL
);
2016 if((n_psonce
& n_PSO_INTERACTIVE
) || (n_poption
& n_PO_TILDE_FLAG
)){
2017 if(!(n_poption
& n_PO_t_FLAG
))
2018 gif
|= n_GO_INPUT_NL_ESC
;
2020 cnt
= n_go_input(gif
, n_empty
, &linebuf
, &linesize
, NULL
, &histadd
);
2021 hist
= histadd
? a_HIST_ADD
| a_HIST_GABBY
: a_HIST_NONE
;
2027 if(n_poption
& n_PO_t_FLAG
){
2028 fflush_rewind(_coll_fp
);
2029 /* It is important to set n_PSO_t_FLAG before extract_header()
2030 * *and* keep n_PO_t_FLAG for the first parse of the message!
2031 * TODO This is a hack, we need a clean approach for this */
2032 n_psonce
|= n_PSO_t_FLAG
;
2033 if(!a_coll_makeheader(_coll_fp
, hp
, checkaddr_err
, TRU1
))
2035 n_poption
&= ~n_PO_t_FLAG
;
2037 }else if((n_psonce
& n_PSO_INTERACTIVE
) && ok_blook(ignoreeof
) &&
2040 _("*ignoreeof* set, use `~.' to terminate letter\n"));
2041 n_go_input_clearerr();
2052 else if(coap
== NULL
){
2053 if(!(n_psonce
& n_PSO_INTERACTIVE
) && !(n_poption
& n_PO_TILDE_FLAG
))
2055 else if(cp
[0] == '.'){
2056 if(cnt
== 1 && (ok_blook(dot
) ||
2057 (ok_blook(posix
) && ok_blook(ignoreeof
))))
2061 if(cp
[0] != escape
){
2063 if(fwrite(cp
, sizeof *cp
, cnt
, _coll_fp
) != (size_t)cnt
)
2065 /* TODO n_PS_READLINE_NL is a terrible hack to ensure that _in_all_-
2066 * TODO _code_paths_ a file without trailing newline isn't modified
2067 * TODO to contain one; the "saw-newline" needs to be part of an
2068 * TODO I/O input machinery object */
2070 if(n_pstate
& n_PS_READLINE_NL
){
2071 if(putc('\n', _coll_fp
) == EOF
)
2077 c
= *(cp_base
= ++cp
);
2081 /* Avoid history entry? */
2082 while(spacechar(c
)){
2084 c
= *(cp_base
= ++cp
);
2089 /* It may just be an escaped escaped character, do that quick */
2093 /* Avoid hard *errexit*? */
2102 /* Trim input, also to gain a somewhat normalized history entry */
2107 x
.s
= n_UNCONST(cp
);
2109 n_str_trim_ifs(&x
, TRU1
);
2112 cnt
= (int)/*XXX*/x
.l
;
2115 if(hist
!= a_HIST_NONE
){
2116 sp
= n_string_assign_c(sp
, escape
);
2117 if(flags
& a_IGNERR
)
2118 sp
= n_string_push_c(sp
, '-');
2119 sp
= n_string_push_c(sp
, c
);
2121 sp
= n_string_push_c(sp
, ' ');
2122 sp
= n_string_push_buf(sp
, cp
, cnt
);
2129 char buf
[sizeof(n_UNIREPL
)];
2132 buf
[0] = c
, buf
[1] = '\0';
2133 else if(n_psonce
& n_PSO_UNICODE
)
2134 memcpy(buf
, n_unirepl
, sizeof n_unirepl
);
2136 buf
[0] = '?', buf
[1] = '\0';
2137 n_err(_("Unknown command escape: `%c%s'\n"), escape
, buf
);
2140 n_err(_("Invalid command escape usage: %s\n"),
2141 n_shexp_quote_cp(linebuf
, FAL0
));
2144 n_pstate_err_no
= n_ERR_INVAL
;
2148 /* Shell escape, send the balance of line to sh -c */
2149 if(cnt
== 0 || coap
!= NULL
)
2152 char const *argv
[2];
2156 n_pstate_ex_no
= c_shell(argv
); /* TODO history norm.; errexit? */
2162 /* Escape to command mode, but be nice! *//* TODO command expansion
2163 * TODO should be handled here so that we have unique history! */
2166 _execute_command(hp
, cp
, cnt
);
2167 if(ok_blook(errexit
))
2170 flags
&= ~a_ERREXIT
;
2171 if(n_pstate_ex_no
!= 0 && a_HARDERR())
2174 escape
= *ok_vlook(escape
);
2177 /* Simulate end of file on input */
2178 if(cnt
!= 0 || coap
!= NULL
)
2180 goto jout
; /* TODO does not enter history, thus */
2182 /* Same as 'q', but no *DEAD* saving */
2185 /* Force a quit, act like an interrupt had happened */
2188 /* If we are running a splice hook, assume it quits on its own now,
2189 * otherwise we (no true out-of-band IPC to signal this state, XXX sic)
2190 * have to SIGTERM it in order to stop this wild beast */
2191 flags
|= a_COAP_NOSIGTERM
;
2193 _collint((c
== 'x') ? 0 : SIGINT
);
2197 /* Grab a bunch of headers */
2201 grab_headers(n_GO_INPUT_CTX_COMPOSE
, hp
,
2202 (GTO
| GSUBJECT
| GCC
| GBCC
),
2203 (ok_blook(bsdcompat
) && ok_blook(bsdorder
)));
2204 while(hp
->h_to
== NULL
);
2205 n_pstate_err_no
= n_ERR_NONE
; /* XXX */
2206 n_pstate_ex_no
= 0; /* XXX */
2209 /* Grab extra headers */
2213 grab_headers(n_GO_INPUT_CTX_COMPOSE
, hp
, GEXTRA
, 0);
2214 while(check_from_and_sender(hp
->h_from
, hp
->h_sender
) == NULL
);
2215 n_pstate_err_no
= n_ERR_NONE
; /* XXX */
2216 n_pstate_ex_no
= 0; /* XXX */
2219 /* Add to the To: list */
2227 if((np
= checkaddrs(lextract(cp
, GTO
| GFULL
), EACM_NORMAL
, &soe
)
2229 hp
->h_to
= cat(hp
->h_to
, np
);
2231 n_pstate_err_no
= n_ERR_NONE
;
2235 n_pstate_err_no
= (soe
< 0) ? n_ERR_PERM
: n_ERR_INVAL
;
2238 hist
&= ~a_HIST_GABBY
;
2241 /* Set the Subject list */
2244 /* Subject:; take care for Debian #419840 and strip any \r and \n */
2245 if(n_anyof_cp("\n\r", hp
->h_subject
= savestr(cp
))){
2248 n_err(_("-s: normalizing away invalid ASCII NL / CR bytes\n"));
2249 for(xp
= hp
->h_subject
; *xp
!= '\0'; ++xp
)
2250 if(*xp
== '\n' || *xp
== '\r')
2252 n_pstate_err_no
= n_ERR_INVAL
;
2255 n_pstate_err_no
= n_ERR_NONE
;
2260 struct attachment
*aplist
;
2262 /* Edit the attachment list */
2263 aplist
= hp
->h_attach
;
2264 hp
->h_attach
= NULL
;
2266 hp
->h_attach
= n_attachment_append_list(aplist
, cp
);
2268 hp
->h_attach
= n_attachment_list_edit(aplist
,
2269 n_GO_INPUT_CTX_COMPOSE
);
2270 n_pstate_err_no
= n_ERR_NONE
; /* XXX ~@ does NOT handle $!/$?! */
2271 n_pstate_ex_no
= 0; /* XXX */
2274 /* Add to the CC list */
2282 if((np
= checkaddrs(lextract(cp
, GCC
| GFULL
), EACM_NORMAL
, &soe
)
2284 hp
->h_cc
= cat(hp
->h_cc
, np
);
2286 n_pstate_err_no
= n_ERR_NONE
;
2290 n_pstate_err_no
= (soe
< 0) ? n_ERR_PERM
: n_ERR_INVAL
;
2293 hist
&= ~a_HIST_GABBY
;
2296 /* Add stuff to blind carbon copies list */
2304 if((np
= checkaddrs(lextract(cp
, GBCC
| GFULL
), EACM_NORMAL
, &soe
)
2306 hp
->h_bcc
= cat(hp
->h_bcc
, np
);
2308 n_pstate_err_no
= n_ERR_NONE
;
2312 n_pstate_err_no
= (soe
< 0) ? n_ERR_PERM
: n_ERR_INVAL
;
2315 hist
&= ~a_HIST_GABBY
;
2320 cp
= n_getdeadletter();
2326 /* Invoke a file: Search for the file name, then open it and copy
2327 * the contents to _coll_fp */
2329 n_err(_("Interpolate what file?\n"));
2332 n_pstate_err_no
= n_ERR_NOENT
;
2336 if(*cp
== '!' && c
== '<'){
2337 /* TODO hist. normalization */
2338 if((n_pstate_err_no
= a_coll_insert_cmd(_coll_fp
, ++cp
)
2340 if(ferror(_coll_fp
))
2349 /* Note this also expands things like
2350 * !:vput vexpr delim random 0
2352 if((cp
= fexpand(cp
, FEXP_LOCAL
| FEXP_NOPROTO
| FEXP_NSHELL
)
2356 n_pstate_err_no
= n_ERR_INVAL
;
2361 if(n_is_dir(cp
, FAL0
)){
2362 n_err(_("%s: is a directory\n"), n_shexp_quote_cp(cp
, FAL0
));
2365 n_pstate_err_no
= n_ERR_ISDIR
;
2369 if((n_pstate_err_no
= a_coll_include_file(cp
, (c
== 'R'), TRU1
)
2371 if(ferror(_coll_fp
))
2378 n_pstate_err_no
= n_ERR_NONE
; /* XXX */
2379 n_pstate_ex_no
= 0; /* XXX */
2383 /* Insert a variable into the file */
2386 if((cp
= n_var_vlook(cp
, TRU1
)) == NULL
|| *cp
== '\0')
2388 if(!a_coll_putesc(cp
, (c
!= 'I'), _coll_fp
))
2390 if((n_psonce
& n_PSO_INTERACTIVE
) &&
2391 !a_coll_putesc(cp
, (c
!= 'I'), n_stdout
))
2393 n_pstate_err_no
= n_ERR_NONE
; /* XXX */
2394 n_pstate_ex_no
= 0; /* XXX */
2398 /* Insert the contents of a signature variable */
2401 cp
= (c
== 'a') ? ok_vlook(sign
) : ok_vlook(Sign
);
2402 if(cp
!= NULL
&& *cp
!= '\0'){
2403 if(!a_coll_putesc(cp
, TRU1
, _coll_fp
))
2405 if((n_psonce
& n_PSO_INTERACTIVE
) &&
2406 !a_coll_putesc(cp
, TRU1
, n_stdout
))
2409 n_pstate_err_no
= n_ERR_NONE
; /* XXX */
2410 n_pstate_ex_no
= 0; /* XXX */
2413 /* Write the message on a file */
2416 if((cp
= fexpand(cp
, FEXP_LOCAL
| FEXP_NOPROTO
)) == NULL
){
2417 n_err(_("Write what file!?\n"));
2420 n_pstate_err_no
= n_ERR_INVAL
;
2425 if((n_pstate_err_no
= a_coll_write(cp
, _coll_fp
, 1)) == n_ERR_NONE
)
2427 else if(ferror(_coll_fp
))
2429 else if(a_HARDERR())
2440 /* Interpolate the named messages, if we are in receiving mail mode.
2441 * Does the standard list processing garbage. If ~f is given, we
2442 * don't shift over */
2445 if((n_pstate_err_no
= a_coll_forward(cp
, _coll_fp
, c
)) == n_ERR_NONE
)
2447 else if(ferror(_coll_fp
))
2449 else if(a_HARDERR())
2455 /* Print current state of the message without altering anything */
2458 print_collf(_coll_fp
, hp
); /* XXX pstate_err_no ++ */
2459 if(ferror(_coll_fp
))
2461 n_pstate_err_no
= n_ERR_NONE
; /* XXX */
2462 n_pstate_ex_no
= 0; /* XXX */
2465 /* Pipe message through command. Collect output as new message */
2469 if((n_pstate_err_no
= a_coll_pipe(cp
)) == n_ERR_NONE
)
2471 else if(a_HARDERR())
2475 hist
&= ~a_HIST_GABBY
;
2479 /* Edit the current message. 'e' -> use EDITOR, 'v' -> use VISUAL */
2480 if(cnt
!= 0 || coap
!= NULL
)
2483 if((n_pstate_err_no
= a_coll_edit(c
, ok_blook(editheaders
) ? hp
: NULL
)
2486 else if(ferror(_coll_fp
))
2488 else if(a_HARDERR())
2494 if(!a_collect_plumbing(cp
, hp
)){
2495 if(ferror(_coll_fp
))
2499 n_pstate_err_no
= n_ERR_NONE
; /* XXX */
2500 n_pstate_ex_no
= 0; /* XXX */
2501 hist
&= ~a_HIST_GABBY
;
2504 /* Last the lengthy help string. (Very ugly, but take care for
2505 * compiler supported string lengths :() */
2507 "COMMAND ESCAPES (to be placed after a newline) excerpt:\n"
2508 "~. Commit and send message\n"
2509 "~: <command> Execute an internal command\n"
2510 "~< <file> Insert <file> (\"~<! <command>\" inserts shell command)\n"
2511 "~@ [<files>] Edit[/Add] attachments (file[=input-charset[#output-charset]])\n"
2512 "~c <users> Add users to Cc: list (`~b': to Bcc:)\n"
2513 "~d Read in $DEAD (dead.letter)\n"
2514 "~e Edit message via $EDITOR\n"
2515 "~F <msglist> Read in with headers, do not *indentprefix* lines\n"
2518 "~f <msglist> Like ~F, but honour `ignore' / `retain' configuration\n"
2519 "~H Edit From:, Reply-To: and Sender:\n"
2520 "~h Prompt for Subject:, To:, Cc: and \"blind\" Bcc:\n"
2521 "~i <variable> Insert a value and a newline\n"
2522 "~M <msglist> Read in with headers, *indentprefix* (`~m': `retain' etc.)\n"
2523 "~p Show current message compose buffer\n"
2524 "~r <file> Insert <file> (`~R': likewise, but *indentprefix* lines)\n"
2525 " <file> may also be <- [HERE-DELIMITER]>\n"
2528 "~s <subject> Set Subject:\n"
2529 "~t <users> Add users to To: list\n"
2530 "~u <msglist> Read in message(s) without headers (`~U': indent lines)\n"
2531 "~v Edit message via $VISUAL\n"
2532 "~w <file> Write message onto file\n"
2533 "~x Abort composition, discard message (`~q': save in $DEAD)\n"
2534 "~| <command> Pipe message through shell filter\n"
2538 n_pstate_err_no
= n_ERR_NONE
;
2543 /* Finally place an entry in history as applicable */
2549 if(hist
& a_HIST_ADD
)
2550 n_tty_addhist(n_string_cp(sp
), ((hist
& a_HIST_GABBY
) != 0));
2556 /* Do we have *on-compose-splice-shell*, or *on-compose-splice*?
2557 * TODO Usual f...ed up state of signals and terminal etc. */
2558 if(coap
== NULL
&& (cp
= ok_vlook(on_compose_splice_shell
)) != NULL
) Jocs
:{
2559 union {int (*ptf
)(void); char const *sh
;} u
;
2562 /* Reset *escape* and more to their defaults. On change update manual! */
2563 if(ifs_saved
== NULL
)
2564 ifs_saved
= savestr(ok_vlook(ifs
));
2565 escape
= n_ESCAPE
[0];
2569 /* XXX Due Popen() fflush(NULL) in PTF mode, ensure nothing to flush */
2570 /*if(!n_real_seek(_coll_fp, 0, SEEK_END))
2572 u
.ptf
= &a_coll_ocs__mac
;
2574 a_coll_ocs__macname
= cp
= coapm
;
2576 u
.sh
= ok_vlook(SHELL
);
2581 coap
= n_lofi_alloc(n_VSTRUCT_SIZEOF(struct a_coll_ocs_arg
, coa_cmd
2583 coap
->coa_pipe
[0] = coap
->coa_pipe
[1] = -1;
2584 coap
->coa_stdin
= coap
->coa_stdout
= NULL
;
2585 coap
->coa_senderr
= checkaddr_err
;
2586 memcpy(coap
->coa_cmd
, cp
, i
);
2589 coap
->coa_opipe
= safe_signal(SIGPIPE
, SIG_IGN
);
2590 coap
->coa_oint
= safe_signal(SIGINT
, SIG_IGN
);
2593 if(pipe_cloexec(coap
->coa_pipe
) != -1 &&
2594 (coap
->coa_stdin
= Fdopen(coap
->coa_pipe
[0], "r", FAL0
)) != NULL
&&
2595 (coap
->coa_stdout
= Popen(cmd
, "W", u
.sh
, NULL
, coap
->coa_pipe
[1])
2597 close(coap
->coa_pipe
[1]);
2598 coap
->coa_pipe
[1] = -1;
2600 temporary_compose_mode_hook_call(NULL
, NULL
, NULL
);
2601 n_go_splice_hack(coap
->coa_cmd
, coap
->coa_stdin
, coap
->coa_stdout
,
2602 (n_psonce
& ~(n_PSO_INTERACTIVE
| n_PSO_TTYIN
| n_PSO_TTYOUT
)),
2603 &a_coll_ocs__finalize
, &coap
);
2604 /* Hook version protocol for ~^: update manual upon change! */
2605 fputs(a_COLL_PLUMBING_VERSION
"\n", coap
->coa_stdout
);
2606 #undef a_COLL_PLUMBING_VERSION
2611 a_coll_ocs__finalize(coap
);
2612 n_perr(_("Cannot invoke *on-compose-splice(-shell)?*"), c
);
2615 if(*checkaddr_err
!= 0){
2619 if(coapm
== NULL
&& (coapm
= ok_vlook(on_compose_splice
)) != NULL
)
2622 ok_vset(ifs
, ifs_saved
);
2626 /* Final chance to edit headers, if not already above */
2627 if (ok_blook(bsdcompat
) || ok_blook(askatend
)) {
2628 if (hp
->h_cc
== NULL
&& ok_blook(askcc
))
2629 grab_headers(n_GO_INPUT_CTX_COMPOSE
, hp
, GCC
, 1);
2630 if (hp
->h_bcc
== NULL
&& ok_blook(askbcc
))
2631 grab_headers(n_GO_INPUT_CTX_COMPOSE
, hp
, GBCC
, 1);
2633 if (hp
->h_attach
== NULL
&& ok_blook(askattach
))
2634 hp
->h_attach
= n_attachment_list_edit(hp
->h_attach
,
2635 n_GO_INPUT_CTX_COMPOSE
);
2637 /* Execute compose-leave */
2638 if((cp
= ok_vlook(on_compose_leave
)) != NULL
){
2639 setup_from_and_sender(hp
);
2640 temporary_compose_mode_hook_call(cp
, &n_temporary_compose_hook_varset
,
2644 /* Add automatic receivers */
2645 if ((cp
= ok_vlook(autocc
)) != NULL
&& *cp
!= '\0')
2646 hp
->h_cc
= cat(hp
->h_cc
, checkaddrs(lextract(cp
, GCC
| GFULL
),
2647 EACM_NORMAL
, checkaddr_err
));
2648 if ((cp
= ok_vlook(autobcc
)) != NULL
&& *cp
!= '\0')
2649 hp
->h_bcc
= cat(hp
->h_bcc
, checkaddrs(lextract(cp
, GBCC
| GFULL
),
2650 EACM_NORMAL
, checkaddr_err
));
2651 if (*checkaddr_err
!= 0)
2654 /* TODO Cannot do since it may require turning this into a multipart one */
2655 if(n_poption
& n_PO_Mm_FLAG
)
2658 /* Place signature? */
2659 if((cp
= ok_vlook(signature
)) != NULL
&& *cp
!= '\0'){
2662 if((cpq
= fexpand(cp
, FEXP_LOCAL
| FEXP_NOPROTO
)) == NULL
){
2663 n_err(_("*signature* expands to invalid file: %s\n"),
2664 n_shexp_quote_cp(cp
, FAL0
));
2667 cpq
= n_shexp_quote_cp(cp
= cpq
, FAL0
);
2669 if((sigfp
= Fopen(cp
, "r")) == NULL
){
2670 n_err(_("Can't open *signature* %s: %s\n"),
2671 cpq
, n_err_to_doc(n_err_no
));
2676 linebuf
= smalloc(linesize
= LINESIZE
);
2678 while((i
= fread(linebuf
, sizeof *linebuf
, linesize
, n_UNVOLATILE(sigfp
)))
2681 if(i
!= fwrite(linebuf
, sizeof *linebuf
, i
, _coll_fp
))
2686 FILE *x
= n_UNVOLATILE(sigfp
);
2687 int e
= n_err_no
, ise
= ferror(x
);
2693 n_err(_("Errors while reading *signature* %s: %s\n"),
2694 cpq
, n_err_to_doc(e
));
2699 if(c
!= '\0' && c
!= '\n')
2700 putc('\n', _coll_fp
);
2703 { char const *cp_obsolete
= ok_vlook(NAIL_TAIL
);
2705 if(cp_obsolete
!= NULL
)
2706 n_OBSOLETE(_("please use *message-inject-tail*, not *NAIL_TAIL*"));
2708 if((cp
= ok_vlook(message_inject_tail
)) != NULL
||
2709 (cp
= cp_obsolete
) != NULL
){
2710 if(!a_coll_putesc(cp
, TRU1
, _coll_fp
))
2712 if((n_psonce
& n_PSO_INTERACTIVE
) && !a_coll_putesc(cp
, TRU1
, n_stdout
))
2718 if(fflush(_coll_fp
))
2723 if (linebuf
!= NULL
)
2725 sigprocmask(SIG_BLOCK
, &nset
, NULL
);
2726 n_pstate
&= ~n_PS_COMPOSE_MODE
;
2727 safe_signal(SIGINT
, _coll_saveint
);
2728 safe_signal(SIGHUP
, _coll_savehup
);
2729 sigprocmask(SIG_SETMASK
, &oset
, NULL
);
2736 if(coap
!= NULL
&& coap
!= (struct a_coll_ocs_arg
*)-1){
2737 if(!(flags
& a_COAP_NOSIGTERM
))
2738 n_psignal(coap
->coa_stdout
, SIGTERM
);
2739 n_go_splice_hack_remove_after_jump();
2742 if(ifs_saved
!= NULL
){
2743 ok_vset(ifs
, ifs_saved
);
2747 Fclose(n_UNVOLATILE(sigfp
));
2750 if(_coll_fp
!= NULL
){
2757 assert(checkaddr_err
!= NULL
);
2758 /* TODO We don't save in $DEAD upon error because msg not readily composed?
2759 * TODO But this no good, it should go ZOMBIE / DRAFT / POSTPONED or what! */
2760 if(*checkaddr_err
!= 0){
2761 if(*checkaddr_err
== 111)
2762 n_err(_("Compose mode splice hook failure\n"));
2764 n_err(_("Some addressees were classified as \"hard error\"\n"));
2765 }else if(_coll_hadintr
== 0){
2766 *checkaddr_err
= TRU1
; /* TODO ugly: "sendout_error" now.. */
2767 n_err(_("Failed to prepare composed message (I/O error, disk full?)\n"));