privsep.c: and just verify the box is also in CWD (wapiflapi)
[s-mailx.git] / collect.c
blob702ea3806bfee9f09a2bc477475c653c949f32b7
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>.
7 */
8 /*
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
14 * are met:
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
34 * SUCH DAMAGE.
36 #undef n_FILE
37 #define n_FILE collect
39 #ifndef HAVE_AMALGAMATION
40 # include "nail.h"
41 #endif
43 struct a_coll_ocds_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_ocds__macname; /* *on-compose-done* */
64 /* Handle `~:', `~_' and some hooks; hp may be NULL */
65 static void _execute_command(struct header *hp, char const *linebuf,
66 size_t linesize);
68 /* */
69 static int _include_file(char const *name, int *linecount,
70 int *charcount, bool_t indent);
72 /* Execute cmd and insert its standard output into fp */
73 static void insertcommand(FILE *fp, char const *cmd);
75 /* ~p command */
76 static void print_collf(FILE *collf, struct header *hp);
78 /* Write a file, ex-like if f set */
79 static int exwrite(char const *name, FILE *fp, int f);
81 /* Parse off the message header from fp and store relevant fields in hp,
82 * replace _coll_fp with a shiny new version without any header */
83 static enum okay makeheader(FILE *fp, struct header *hp, si8_t *checkaddr_err);
85 /* Edit the message being collected on fp. On return, make the edit file the
86 * new temp file */
87 static void mesedit(int c, struct header *hp);
89 /* Pipe the message through the command. Old message is on stdin of command,
90 * new message collected from stdout. Shell must return 0 to accept new msg */
91 static void mespipe(char *cmd);
93 /* Interpolate the named messages into the current message, possibly doing
94 * indent stuff. The flag argument is one of the command escapes: [mMfFuU].
95 * Return a count of the number of characters now in the message, or -1 if an
96 * error is encountered writing the message temporary */
97 static int forward(char *ms, FILE *fp, int f);
99 /* ~^ mode */
100 static bool_t a_collect_plumbing(char const *ms, struct header *p);
102 /* On interrupt, come here to save the partial message in ~/dead.letter.
103 * Then jump out of the collection loop */
104 static void _collint(int s);
106 static void collhup(int s);
108 static int putesc(char const *s, FILE *stream); /* TODO wysh set! */
110 /* temporary_call_compose_mode_hook() setter hook */
111 static void a_coll__hook_setter(void *arg);
113 /* *on-compose-done* driver and *on-compose-done(-shell)?* finalizer */
114 static int a_coll_ocds__mac(void);
115 static void a_coll_ocds__finalize(void *vp);
117 static void
118 _execute_command(struct header *hp, char const *linebuf, size_t linesize){
119 /* The problem arises if there are rfc822 message attachments and the
120 * user uses `~:' to change the current file. TODO Unfortunately we
121 * TODO cannot simply keep a pointer to, or increment a reference count
122 * TODO of the current `file' (mailbox that is) object, because the
123 * TODO codebase doesn't deal with that at all; so, until some far
124 * TODO later time, copy the name of the path, and warn the user if it
125 * TODO changed; we COULD use the AC_TMPFILE attachment type, i.e.,
126 * TODO copy the message attachments over to temporary files, but that
127 * TODO would require more changes so that the user still can recognize
128 * TODO in `~@' etc. that its a rfc822 message attachment; see below */
129 struct n_sigman sm;
130 struct attachment *ap;
131 char * volatile mnbuf;
132 NYD_ENTER;
134 n_UNUSED(linesize);
135 mnbuf = NULL;
137 n_SIGMAN_ENTER_SWITCH(&sm, n_SIGMAN_ALL){
138 case 0:
139 break;
140 default:
141 goto jleave;
144 /* If the above todo is worked, remove or outsource to attachment.c! */
145 if(hp != NULL && (ap = hp->h_attach) != NULL) do
146 if(ap->a_msgno){
147 mnbuf = sstrdup(mailname);
148 break;
150 while((ap = ap->a_flink) != NULL);
152 n_source_command(n_LEXINPUT_CTX_COMPOSE, linebuf);
154 n_sigman_cleanup_ping(&sm);
155 jleave:
156 if(mnbuf != NULL){
157 if(strcmp(mnbuf, mailname))
158 n_err(_("Mailbox changed: it is likely that existing "
159 "rfc822 attachments became invalid!\n"));
160 free(mnbuf);
162 NYD_LEAVE;
163 n_sigman_leave(&sm, n_SIGMAN_VIPSIGS_NTTYOUT);
166 static int
167 _include_file(char const *name, int *linecount, int *charcount, bool_t indent)
169 FILE *fbuf;
170 char const *indb;
171 int ret = -1;
172 char *linebuf = NULL; /* TODO line pool */
173 size_t linesize = 0, indl, linelen, cnt;
174 NYD_ENTER;
176 /* The -M case is special */
177 if (name == (char*)-1)
178 fbuf = stdin;
179 else if ((fbuf = Fopen(name, "r")) == NULL) {
180 n_perr(name, 0);
181 goto jleave;
184 if (!indent)
185 indb = NULL, indl = 0;
186 else {
187 if ((indb = ok_vlook(indentprefix)) == NULL)
188 indb = INDENT_DEFAULT;
189 indl = strlen(indb);
192 *linecount = *charcount = 0;
193 cnt = fsize(fbuf);
194 while (fgetline(&linebuf, &linesize, &cnt, &linelen, fbuf, 0) != NULL) {
195 if (indl > 0 && fwrite(indb, sizeof *indb, indl, _coll_fp) != indl)
196 goto jleave;
197 if (fwrite(linebuf, sizeof *linebuf, linelen, _coll_fp) != linelen)
198 goto jleave;
199 ++(*linecount);
200 (*charcount) += linelen + indl;
202 if (fflush(_coll_fp))
203 goto jleave;
205 ret = 0;
206 jleave:
207 if (linebuf != NULL)
208 free(linebuf);
209 if (fbuf != NULL && fbuf != stdin)
210 Fclose(fbuf);
211 NYD_LEAVE;
212 return ret;
215 static void
216 insertcommand(FILE *fp, char const *cmd)
218 FILE *ibuf = NULL;
219 int c;
220 NYD_ENTER;
222 if ((ibuf = Popen(cmd, "r", ok_vlook(SHELL), NULL, 0)) != NULL) {
223 while ((c = getc(ibuf)) != EOF) /* XXX bytewise, yuck! */
224 putc(c, fp);
225 Pclose(ibuf, TRU1);
226 } else
227 n_perr(cmd, 0);
228 NYD_LEAVE;
231 static void
232 print_collf(FILE *cf, struct header *hp)
234 char *lbuf;
235 FILE *obuf;
236 size_t cnt, linesize, linelen;
237 NYD_ENTER;
239 fflush_rewind(cf);
240 cnt = (size_t)fsize(cf);
242 if((obuf = Ftmp(NULL, "collfp", OF_RDWR | OF_UNLINK | OF_REGISTER)) == NULL){
243 n_perr(_("Can't create temporary file for `~p' command"), 0);
244 goto jleave;
247 hold_all_sigs();
249 fprintf(obuf, _("-------\nMessage contains:\n"));
250 puthead(TRU1, hp, obuf,
251 (GIDENT | GTO | GSUBJECT | GCC | GBCC | GNL | GFILES | GCOMMA),
252 SEND_TODISP, CONV_NONE, NULL, NULL);
254 lbuf = NULL;
255 linesize = 0;
256 while(fgetline(&lbuf, &linesize, &cnt, &linelen, cf, 1))
257 prout(lbuf, linelen, obuf);
258 if(lbuf != NULL)
259 free(lbuf);
261 if(hp->h_attach != NULL){
262 fputs(_("-------\nAttachments:\n"), obuf);
263 n_attachment_list_print(hp->h_attach, obuf);
266 rele_all_sigs();
268 page_or_print(obuf, 0);
269 jleave:
270 Fclose(obuf);
271 NYD_LEAVE;
274 static int
275 exwrite(char const *name, FILE *fp, int f)
277 FILE *of;
278 int c, rv;
279 long lc, cc;
280 NYD_ENTER;
282 if (f) {
283 printf("%s ", n_shexp_quote_cp(name, FAL0));
284 fflush(stdout);
287 if ((of = Fopen(name, "a")) == NULL) {
288 n_perr(name, 0);
289 goto jerr;
292 lc = cc = 0;
293 while ((c = getc(fp)) != EOF) {
294 ++cc;
295 if (c == '\n')
296 ++lc;
297 if (putc(c, of) == EOF) {
298 n_perr(name, 0);
299 goto jerr;
302 printf(_("%ld/%ld\n"), lc, cc);
304 rv = 0;
305 jleave:
306 if(of != NULL)
307 Fclose(of);
308 fflush(stdout);
309 NYD_LEAVE;
310 return rv;
311 jerr:
312 putchar('-');
313 putchar('\n');
314 rv = -1;
315 goto jleave;
318 static enum okay
319 makeheader(FILE *fp, struct header *hp, si8_t *checkaddr_err)
321 FILE *nf;
322 int c;
323 enum okay rv = STOP;
324 NYD_ENTER;
326 if ((nf = Ftmp(NULL, "colhead", OF_RDWR | OF_UNLINK | OF_REGISTER)) ==NULL) {
327 n_perr(_("temporary mail edit file"), 0);
328 goto jleave;
331 extract_header(fp, hp, checkaddr_err);
332 if (checkaddr_err != NULL && *checkaddr_err != 0)
333 goto jleave;
335 while ((c = getc(fp)) != EOF) /* XXX bytewise, yuck! */
336 putc(c, nf);
337 if (fp != _coll_fp)
338 Fclose(_coll_fp);
339 Fclose(fp);
340 _coll_fp = nf;
341 if (check_from_and_sender(hp->h_from, hp->h_sender) == NULL)
342 goto jleave;
343 rv = OKAY;
344 jleave:
345 NYD_LEAVE;
346 return rv;
349 static void
350 mesedit(int c, struct header *hp)
352 bool_t saved;
353 sighandler_type sigint;
354 FILE *nf;
355 NYD_ENTER;
357 if(!(saved = ok_blook(add_file_recipients)))
358 ok_bset(add_file_recipients);
360 sigint = safe_signal(SIGINT, SIG_IGN);
361 nf = run_editor(_coll_fp, (off_t)-1, c, FAL0, hp, NULL, SEND_MBOX, sigint);
362 if (nf != NULL) {
363 if (hp) {
364 rewind(nf);
365 makeheader(nf, hp, NULL);
366 } else {
367 fseek(nf, 0L, SEEK_END);
368 Fclose(_coll_fp);
369 _coll_fp = nf;
372 safe_signal(SIGINT, sigint);
374 if(!saved)
375 ok_bclear(add_file_recipients);
376 NYD_LEAVE;
379 static void
380 mespipe(char *cmd)
382 FILE *nf;
383 sighandler_type sigint;
384 NYD_ENTER;
386 sigint = safe_signal(SIGINT, SIG_IGN);
388 if ((nf = Ftmp(NULL, "colpipe", OF_RDWR | OF_UNLINK | OF_REGISTER)) ==NULL) {
389 n_perr(_("temporary mail edit file"), 0);
390 goto jout;
393 /* stdin = current message. stdout = new message */
394 fflush(_coll_fp);
395 if (run_command(ok_vlook(SHELL), 0, fileno(_coll_fp), fileno(nf), "-c",
396 cmd, NULL, NULL) < 0) {
397 Fclose(nf);
398 goto jout;
401 if (fsize(nf) == 0) {
402 n_err(_("No bytes from %s !?\n"), n_shexp_quote_cp(cmd, FAL0));
403 Fclose(nf);
404 goto jout;
407 /* Take new files */
408 fseek(nf, 0L, SEEK_END);
409 Fclose(_coll_fp);
410 _coll_fp = nf;
411 jout:
412 safe_signal(SIGINT, sigint);
413 NYD_LEAVE;
416 static int
417 forward(char *ms, FILE *fp, int f)
419 int *msgvec, rv = 0;
420 struct n_ignore const *itp;
421 char const *tabst;
422 enum sendaction action;
423 NYD_ENTER;
425 msgvec = salloc((size_t)(msgCount + 1) * sizeof *msgvec);
426 if (getmsglist(ms, msgvec, 0) < 0)
427 goto jleave;
428 if (*msgvec == 0) {
429 *msgvec = first(0, MMNORM);
430 if (*msgvec == 0) {
431 n_err(_("No appropriate messages\n"));
432 goto jleave;
434 msgvec[1] = 0;
437 if (f == 'f' || f == 'F' || f == 'u')
438 tabst = NULL;
439 else if ((tabst = ok_vlook(indentprefix)) == NULL)
440 tabst = INDENT_DEFAULT;
441 if (f == 'u' || f == 'U')
442 itp = n_IGNORE_ALL;
443 else
444 itp = upperchar(f) ? NULL : n_IGNORE_TYPE;
445 action = (upperchar(f) && f != 'U') ? SEND_QUOTE_ALL : SEND_QUOTE;
447 printf(_("Interpolating:"));
448 srelax_hold();
449 for (; *msgvec != 0; ++msgvec) {
450 struct message *mp = message + *msgvec - 1;
452 touch(mp);
453 printf(" %d", *msgvec);
454 fflush(stdout);
455 if (sendmp(mp, fp, itp, tabst, action, NULL) < 0) {
456 n_perr(_("temporary mail file"), 0);
457 rv = -1;
458 break;
460 srelax();
462 srelax_rele();
463 printf("\n");
464 jleave:
465 NYD_LEAVE;
466 return rv;
469 static bool_t
470 a_collect_plumbing(char const *ms, struct header *hp){
471 /* TODO _collect_plumbing: instead of fields the basic headers should
472 * TODO be in an array and have IDs, like in termcap etc., so then this
473 * TODO could be simplified as table-walks. Also true for arg-checks! */
474 char const *cp, *cmd[4];
475 NYD2_ENTER;
477 /* Protcol version for *on-compose-done-shell* -- update manual on change! */
478 #define a_COLL_PLUMBING_VERSION "0 0 1"
479 cp = ms;
481 /* C99 */{
482 size_t i;
484 for(i = 0; i < n_NELEM(cmd); ++i){
485 while(blankchar(*cp))
486 ++cp;
487 if(*cp == '\0')
488 cmd[i] = NULL;
489 else{
490 if(i < n_NELEM(cmd) - 1)
491 for(cmd[i] = cp++; *cp != '\0' && !blankchar(*cp); ++cp)
493 else{
494 /* Last slot takes all the rest of the line, less trailing WS */
495 for(cmd[i] = cp++; *cp != '\0'; ++cp)
497 while(blankchar(cp[-1]))
498 --cp;
500 cmd[i] = savestrbuf(cmd[i], PTR2SIZE(cp - cmd[i]));
505 if(n_UNLIKELY(cmd[0] == NULL))
506 goto jecmd;
508 if(is_asccaseprefix(cmd[0], "header")){
509 struct n_header_field *hfp;
510 struct name *np, **npp;
512 if(cmd[1] == NULL || is_asccaseprefix(cmd[1], "list")){
513 if(cmd[2] == NULL){
514 fputs("210", stdout);
515 if(hp->h_from != NULL) fputs(" From", stdout);
516 if(hp->h_sender != NULL) fputs(" Sender", stdout);
517 if(hp->h_to != NULL) fputs(" To", stdout);
518 if(hp->h_cc != NULL) fputs(" Cc", stdout);
519 if(hp->h_bcc != NULL) fputs(" Bcc", stdout);
520 if(hp->h_subject != NULL) fputs(" Subject", stdout);
521 if(hp->h_replyto != NULL) fputs(" Reply-To", stdout);
522 if(hp->h_mft != NULL) fputs(" Mail-Followup-To", stdout);
523 if(hp->h_message_id != NULL) fputs(" Message-ID", stdout);
524 if(hp->h_ref != NULL) fputs(" References", stdout);
525 if(hp->h_in_reply_to != NULL) fputs(" In-Reply-To", stdout);
526 for(hfp = hp->h_user_headers; hfp != NULL; hfp = hfp->hf_next){
527 putc(' ', stdout);
528 fputs(&hfp->hf_dat[0], stdout);
530 putc('\n', stdout);
531 goto jleave;
534 if(cmd[3] != NULL)
535 goto jecmd;
537 if(!asccasecmp(cmd[2], "from")){
538 np = hp->h_from;
539 jlist:
540 fprintf(stdout, "%s %s\n", (np == NULL ? "501" : "210"), cp);
541 goto jleave;
543 if(!asccasecmp(cmd[2], cp = "Sender")){
544 np = hp->h_sender;
545 goto jlist;
547 if(!asccasecmp(cmd[2], cp = "To")){
548 np = hp->h_to;
549 goto jlist;
551 if(!asccasecmp(cmd[2], cp = "Cc")){
552 np = hp->h_cc;
553 goto jlist;
555 if(!asccasecmp(cmd[2], cp = "Bcc")){
556 np = hp->h_bcc;
557 goto jlist;
559 if(!asccasecmp(cmd[2], cp = "Subject")){
560 np = (struct name*)-1;
561 goto jlist;
563 if(!asccasecmp(cmd[2], cp = "Reply-To")){
564 np = hp->h_replyto;
565 goto jlist;
567 if(!asccasecmp(cmd[2], cp = "Mail-Followup-To")){
568 np = hp->h_mft;
569 goto jlist;
571 if(!asccasecmp(cmd[2], cp = "Message-ID")){
572 np = hp->h_message_id;
573 goto jlist;
575 if(!asccasecmp(cmd[2], cp = "References")){
576 np = hp->h_ref;
577 goto jlist;
579 if(!asccasecmp(cmd[2], cp = "In-Reply-To")){
580 np = hp->h_in_reply_to;
581 goto jlist;
584 /* Primitive name normalization XXX header object should
585 * XXX have a more sophisticated accessible one */
586 /* C99 */{
587 char *xp;
589 cp = xp = savestr(cmd[2]);
590 xp[0] = upperchar(xp[0]);
591 while(*++xp != '\0')
592 xp[0] = lowerchar(xp[0]);
594 for(hfp = hp->h_user_headers;; hfp = hfp->hf_next){
595 if(hfp == NULL)
596 goto j501cp;
597 else if(!asccasecmp(cp, &hfp->hf_dat[0])){
598 fprintf(stdout, "210 %s\n", cp);
599 break;
603 goto jleave;
606 if(is_asccaseprefix(cmd[1], "show")){
607 if(cmd[2] == NULL || cmd[3] != NULL)
608 goto jecmd;
610 if(!asccasecmp(cmd[2], "from")){
611 np = hp->h_from;
612 jshow:
613 if(np != NULL){
614 fprintf(stdout, "211 %s\n", cp);
615 do if(!(np->n_type & GDEL))
616 fprintf(stdout, "%s %s\n", np->n_name, np->n_fullname);
617 while((np = np->n_flink) != NULL);
618 putc('\n', stdout);
619 goto jleave;
620 }else
621 goto j501cp;
623 if(!asccasecmp(cmd[2], cp = "Sender")){
624 np = hp->h_sender;
625 goto jshow;
627 if(!asccasecmp(cmd[2], cp = "To")){
628 np = hp->h_to;
629 goto jshow;
631 if(!asccasecmp(cmd[2], cp = "Cc")){
632 np = hp->h_cc;
633 goto jshow;
635 if(!asccasecmp(cmd[2], cp = "Bcc")){
636 np = hp->h_bcc;
637 goto jshow;
639 if(!asccasecmp(cmd[2], cp = "Reply-To")){
640 np = hp->h_replyto;
641 goto jshow;
643 if(!asccasecmp(cmd[2], cp = "Mail-Followup-To")){
644 np = hp->h_mft;
645 goto jshow;
647 if(!asccasecmp(cmd[2], cp = "Message-ID")){
648 np = hp->h_message_id;
649 goto jshow;
651 if(!asccasecmp(cmd[2], cp = "References")){
652 np = hp->h_ref;
653 goto jshow;
655 if(!asccasecmp(cmd[2], cp = "In-Reply-To")){
656 np = hp->h_in_reply_to;
657 goto jshow;
660 if(!asccasecmp(cmd[2], cp = "Subject")){
661 if(hp->h_subject != NULL)
662 fprintf(stdout, "212 %s\n%s\n\n", cp, hp->h_subject);
663 else
664 fprintf(stdout, "501 %s\n", cp);
665 goto jleave;
668 /* Primitive name normalization XXX header object should
669 * XXX have a more sophisticated accessible one */
670 /* C99 */{
671 bool_t any;
672 char *xp;
674 cp = xp = savestr(cmd[2]);
675 xp[0] = upperchar(xp[0]);
676 while(*++xp != '\0')
677 xp[0] = lowerchar(xp[0]);
679 for(any = FAL0, hfp = hp->h_user_headers; hfp != NULL;
680 hfp = hfp->hf_next){
681 if(!asccasecmp(cp, &hfp->hf_dat[0])){
682 if(!any)
683 fprintf(stdout, "212 %s\n", cp);
684 any = TRU1;
685 fprintf(stdout, "%s\n", &hfp->hf_dat[hfp->hf_nl +1]);
688 if(any)
689 putc('\n', stdout);
690 else
691 goto j501cp;
693 goto jleave;
696 if(is_asccaseprefix(cmd[1], "remove")){
697 if(cmd[2] == NULL || cmd[3] != NULL)
698 goto jecmd;
700 if(!asccasecmp(cmd[2], "from")){
701 npp = &hp->h_from;
702 jrem:
703 if(*npp != NULL){
704 *npp = NULL;
705 fprintf(stdout, "210 %s\n", cp);
706 goto jleave;
707 }else
708 goto j501cp;
710 if(!asccasecmp(cmd[2], cp = "Sender")){
711 npp = &hp->h_sender;
712 goto jrem;
714 if(!asccasecmp(cmd[2], cp = "To")){
715 npp = &hp->h_to;
716 goto jrem;
718 if(!asccasecmp(cmd[2], cp = "Cc")){
719 npp = &hp->h_cc;
720 goto jrem;
722 if(!asccasecmp(cmd[2], cp = "Bcc")){
723 npp = &hp->h_bcc;
724 goto jrem;
726 if(!asccasecmp(cmd[2], cp = "Reply-To")){
727 npp = &hp->h_replyto;
728 goto jrem;
730 if(!asccasecmp(cmd[2], cp = "Mail-Followup-To")){
731 npp = &hp->h_mft;
732 goto jrem;
734 if(!asccasecmp(cmd[2], cp = "Message-ID")){
735 npp = &hp->h_message_id;
736 goto jrem;
738 if(!asccasecmp(cmd[2], cp = "References")){
739 npp = &hp->h_ref;
740 goto jrem;
742 if(!asccasecmp(cmd[2], cp = "In-Reply-To")){
743 npp = &hp->h_in_reply_to;
744 goto jrem;
747 if(!asccasecmp(cmd[2], cp = "Subject")){
748 if(hp->h_subject != NULL){
749 hp->h_subject = NULL;
750 fprintf(stdout, "210 %s\n", cp);
751 goto jleave;
752 }else
753 goto j501cp;
756 /* Primitive name normalization XXX header object should
757 * XXX have a more sophisticated accessible one */
758 /* C99 */{
759 struct n_header_field **hfpp;
760 bool_t any;
761 char *xp;
763 cp = xp = savestr(cmd[2]);
764 xp[0] = upperchar(xp[0]);
765 while(*++xp != '\0')
766 xp[0] = lowerchar(xp[0]);
768 for(any = FAL0, hfpp = &hp->h_user_headers; (hfp = *hfpp) != NULL;){
769 if(!asccasecmp(cp, &hfp->hf_dat[0])){
770 *hfpp = hfp->hf_next;
771 if(!any)
772 fprintf(stdout, "210 %s\n", cp);
773 any = TRU1;
774 }else
775 hfp = *(hfpp = &hfp->hf_next);
777 if(!any)
778 goto j501cp;
780 goto jleave;
783 if(is_asccaseprefix(cmd[1], "insert")){ /* TODO LOGIC BELONGS head.c
784 * TODO That is: Header::factory(string) -> object (blahblah).
785 * TODO I.e., as long as we don't have regular RFC compliant parsers
786 * TODO which differentiate in between structured and unstructured
787 * TODO header fields etc., a little workaround */
788 si8_t aerr;
789 enum expand_addr_check_mode eacm;
790 enum gfield ntype;
791 bool_t mult_ok;
793 if(cmd[2] == NULL || cmd[3] == NULL)
794 goto jecmd;
796 /* Strip [\r\n] which would render a body invalid XXX all controls? */
797 /* C99 */{
798 char *xp, c;
800 cmd[3] = xp = savestr(cmd[3]);
801 for(; (c = *xp) != '\0'; ++xp)
802 if(c == '\n' || c == '\r')
803 *xp = ' ';
806 mult_ok = TRU1;
807 ntype = GEXTRA | GFULL | GFULLEXTRA;
808 eacm = EACM_STRICT;
810 if(!asccasecmp(cmd[2], "from")){
811 npp = &hp->h_from;
812 jins:
813 aerr = 0;
814 if((np = lextract(cmd[3], ntype)) == NULL)
815 goto j501cp;
817 if((np = checkaddrs(np, eacm, &aerr), aerr != 0)){
818 fprintf(stdout, "505 %s\n", cp);
819 goto jleave;
822 if(!mult_ok){
823 struct name *xnp;
825 for(xnp = *npp; xnp != NULL && !(xnp->n_type & GDEL);
826 xnp = xnp->n_flink)
828 if(xnp != NULL || np->n_flink != NULL){
829 fprintf(stdout, "506 %s\n", cp);
830 goto jleave;
834 *npp = cat(*npp, np);
835 fprintf(stdout, "210 %s\n", cp);
836 goto jleave;
838 if(!asccasecmp(cmd[2], cp = "Sender")){
839 mult_ok = FAL0;
840 npp = &hp->h_sender;
841 goto jins;
843 if(!asccasecmp(cmd[2], cp = "To")){
844 npp = &hp->h_to;
845 ntype = GTO | GFULL;
846 eacm = EACM_NORMAL | EAF_NAME;
847 goto jins;
849 if(!asccasecmp(cmd[2], cp = "Cc")){
850 npp = &hp->h_cc;
851 ntype = GCC | GFULL;
852 eacm = EACM_NORMAL | EAF_NAME;
853 goto jins;
855 if(!asccasecmp(cmd[2], cp = "Bcc")){
856 npp = &hp->h_bcc;
857 ntype = GCC | GFULL;
858 eacm = EACM_NORMAL | EAF_NAME;
859 goto jins;
861 if(!asccasecmp(cmd[2], cp = "Reply-To")){
862 npp = &hp->h_replyto;
863 goto jins;
865 if(!asccasecmp(cmd[2], cp = "Mail-Followup-To")){
866 npp = &hp->h_mft;
867 eacm = EACM_NONAME;
868 goto jins;
870 if(!asccasecmp(cmd[2], cp = "Message-ID")){
871 mult_ok = FAL0;
872 npp = &hp->h_message_id;
873 eacm = EACM_NONAME;
874 goto jins;
876 if(!asccasecmp(cmd[2], cp = "References")){
877 npp = &hp->h_ref;
878 ntype = GREF;
879 eacm = EACM_NONAME;
880 goto jins;
882 if(!asccasecmp(cmd[2], cp = "In-Reply-To")){
883 npp = &hp->h_in_reply_to;
884 ntype = GREF;
885 eacm = EACM_NONAME;
886 goto jins;
889 if(!asccasecmp(cmd[2], cp = "Subject")){
890 if(cmd[3][0] != '\0'){
891 if(hp->h_subject != NULL)
892 hp->h_subject = savecatsep(hp->h_subject, ' ', cmd[3]);
893 else
894 hp->h_subject = n_UNCONST(cmd[3]);
895 fprintf(stdout, "210 %s\n", cp);
896 goto jleave;
897 }else
898 goto j501cp;
901 /* Primitive name normalization XXX header object should
902 * XXX have a more sophisticated accessible one */
903 /* C99 */{
904 size_t nl, bl;
905 struct n_header_field **hfpp;
907 for(cp = cmd[2]; *cp != '\0'; ++cp)
908 if(!fieldnamechar(*cp)){
909 cp = cmd[2];
910 goto j501cp;
913 for(hfpp = &hp->h_user_headers; *hfpp != NULL;)
914 hfpp = &(*hfpp)->hf_next;
916 nl = strlen(cp = cmd[2]);
917 bl = strlen(cmd[3]) +1;
918 *hfpp = hfp = salloc(n_VSTRUCT_SIZEOF(struct n_header_field, hf_dat
919 ) + nl +1 + bl);
920 hfp->hf_next = NULL;
921 hfp->hf_nl = nl;
922 hfp->hf_bl = bl - 1;
923 memcpy(hfp->hf_dat, cp, nl);
924 hfp->hf_dat[nl++] = '\0';
925 memcpy(hfp->hf_dat + nl, cmd[3], bl);
926 fprintf(stdout, "210 %s\n", cp);
928 goto jleave;
931 goto jecmd;
934 if(is_asccaseprefix(cmd[0], "attachment")){
935 bool_t status;
936 struct attachment *ap;
938 if(cmd[1] == NULL || is_asccaseprefix(cmd[1], "list")){
939 if(cmd[2] != NULL)
940 goto jecmd;
942 if((ap = hp->h_attach) != NULL){
943 fputs("212\n", stdout);
945 fprintf(stdout, "%s\n", ap->a_path_user);
946 while((ap = ap->a_flink) != NULL);
947 putc('\n', stdout);
948 }else
949 fputs("501\n", stdout);
950 goto jleave;
953 if(is_asccaseprefix(cmd[1], "remove")){
954 if(cmd[2] == NULL || cmd[3] != NULL)
955 goto jecmd;
957 if((ap = n_attachment_find(hp->h_attach, cmd[2], &status)) != NULL){
958 if(status == TRUM1)
959 fputs("506\n", stdout);
960 else{
961 hp->h_attach = n_attachment_remove(hp->h_attach, ap);
962 fprintf(stdout, "210 %s\n", cmd[2]);
964 }else
965 fputs("501\n", stdout);
966 goto jleave;
969 if(is_asccaseprefix(cmd[1], "remove-at")){
970 char *eptr;
971 long l;
973 if(cmd[2] == NULL || cmd[3] != NULL)
974 goto jecmd;
976 if((l = strtol(cmd[2], &eptr, 0)) <= 0 || *eptr != '\0')
977 fputs("505\n", stdout);
978 else{
979 for(ap = hp->h_attach; ap != NULL && --l != 0; ap = ap->a_flink)
981 if(ap != NULL){
982 hp->h_attach = n_attachment_remove(hp->h_attach, ap);
983 fprintf(stdout, "210 %s\n", cmd[2]);
984 }else
985 fputs("501\n", stdout);
987 goto jleave;
990 if(is_asccaseprefix(cmd[1], "insert")){
991 enum n_attach_error aerr;
993 if(cmd[2] == NULL || cmd[3] != NULL)
994 goto jecmd;
996 hp->h_attach = n_attachment_append(hp->h_attach, cmd[2], &aerr, &ap);
997 switch(aerr){
998 case n_ATTACH_ERR_FILE_OPEN: cp = "505\n"; goto jatt_ins;
999 case n_ATTACH_ERR_ICONV_FAILED: cp = "506\n"; goto jatt_ins;
1000 case n_ATTACH_ERR_ICONV_NAVAIL:
1001 case n_ATTACH_ERR_OTHER:
1002 default:
1003 cp = "501\n";
1004 jatt_ins:
1005 fputs(cp, stdout);
1006 break;
1007 case n_ATTACH_ERR_NONE:{
1008 size_t i;
1010 for(i = 0; ap != NULL; ++i, ap = ap->a_blink)
1012 fprintf(stdout, "210 %" PRIuZ "\n", i);
1013 } break;
1015 goto jleave;
1018 if(is_asccaseprefix(cmd[1], "attribute")){
1019 if(cmd[2] == NULL || cmd[3] != NULL)
1020 goto jecmd;
1022 if((ap = n_attachment_find(hp->h_attach, cmd[2], NULL)) != NULL){
1023 jatt_att:
1024 fprintf(stdout, "212 %s\n", cmd[2]);
1025 if(ap->a_msgno > 0)
1026 fprintf(stdout, "message-number %d\n\n", ap->a_msgno);
1027 else{
1028 fprintf(stdout, "creation-name %s\nopen-path %s\nfilename %s\n",
1029 ap->a_path_user, ap->a_path, ap->a_name);
1030 if(ap->a_content_description != NULL)
1031 fprintf(stdout, "content-description %s\n",
1032 ap->a_content_description);
1033 if(ap->a_content_id != NULL)
1034 fprintf(stdout, "content-id %s\n", ap->a_content_id->n_name);
1035 if(ap->a_content_type != NULL)
1036 fprintf(stdout, "content-type %s\n", ap->a_content_type);
1037 if(ap->a_content_disposition != NULL)
1038 fprintf(stdout, "content-disposition %s\n",
1039 ap->a_content_disposition);
1040 putc('\n', stdout);
1042 }else
1043 fputs("501\n", stdout);
1044 goto jleave;
1047 if(is_asccaseprefix(cmd[1], "attribute-at")){
1048 char *eptr;
1049 long l;
1051 if(cmd[2] == NULL || cmd[3] != NULL)
1052 goto jecmd;
1054 if((l = strtol(cmd[2], &eptr, 0)) <= 0 || *eptr != '\0')
1055 fputs("505\n", stdout);
1056 else{
1057 for(ap = hp->h_attach; ap != NULL && --l != 0; ap = ap->a_flink)
1059 if(ap != NULL)
1060 goto jatt_att;
1061 else
1062 fputs("501\n", stdout);
1064 goto jleave;
1067 if(is_asccaseprefix(cmd[1], "attribute-set")){
1068 if(cmd[2] == NULL || cmd[3] == NULL)
1069 goto jecmd;
1071 if((ap = n_attachment_find(hp->h_attach, cmd[2], NULL)) != NULL){
1072 jatt_attset:
1073 if(ap->a_msgno > 0)
1074 fputs("505\n", stdout);
1075 else{
1076 char c, *keyw;
1078 cp = cmd[3];
1079 while((c = *cp) != '\0' && !blankchar(c))
1080 ++cp;
1081 keyw = savestrbuf(cmd[3], PTR2SIZE(cp - cmd[3]));
1082 if(c != '\0'){
1083 for(; (c = *++cp) != '\0' && blankchar(c);)
1085 if(c != '\0'){
1086 char *xp;
1088 /* Strip [\r\n] which would render a parameter invalid XXX
1089 * XXX all controls? */
1090 cp = xp = savestr(cp);
1091 for(; (c = *xp) != '\0'; ++xp)
1092 if(c == '\n' || c == '\r')
1093 *xp = ' ';
1094 c = *cp;
1098 if(!asccasecmp(keyw, "filename"))
1099 ap->a_name = (c == '\0') ? ap->a_path_bname : cp;
1100 else if(!asccasecmp(keyw, "content-description"))
1101 ap->a_content_description = (c == '\0') ? NULL : cp;
1102 else if(!asccasecmp(keyw, "content-id")){
1103 ap->a_content_id = NULL;
1105 if(c != '\0'){
1106 struct name *np;
1108 np = checkaddrs(lextract(cp, GREF),
1109 /*EACM_STRICT | TODO '/' valid!! */ EACM_NOLOG |
1110 EACM_NONAME, NULL);
1111 if(np != NULL && np->n_flink == NULL)
1112 ap->a_content_id = np;
1113 else
1114 cp = NULL;
1116 }else if(!asccasecmp(keyw, "content-type"))
1117 ap->a_content_type = (c == '\0') ? NULL : cp;
1118 else if(!asccasecmp(keyw, "content-disposition"))
1119 ap->a_content_disposition = (c == '\0') ? NULL : cp;
1120 else
1121 cp = NULL;
1123 if(cp != NULL){
1124 size_t i;
1126 for(i = 0; ap != NULL; ++i, ap = ap->a_blink)
1128 fprintf(stdout, "210 %" PRIuZ "\n", i);
1129 }else
1130 fputs("505\n", stdout);
1132 }else
1133 fputs("501\n", stdout);
1134 goto jleave;
1137 if(is_asccaseprefix(cmd[1], "attribute-set-at")){
1138 char *eptr;
1139 long l;
1141 if(cmd[2] == NULL || cmd[3] == NULL)
1142 goto jecmd;
1144 if((l = strtol(cmd[2], &eptr, 0)) <= 0 || *eptr != '\0')
1145 fputs("505\n", stdout);
1146 else{
1147 for(ap = hp->h_attach; ap != NULL && --l != 0; ap = ap->a_flink)
1149 if(ap != NULL)
1150 goto jatt_attset;
1151 else
1152 fputs("501\n", stdout);
1154 goto jleave;
1157 goto jecmd;
1160 jecmd:
1161 fputs("500\n", stdout);
1162 ms = NULL;
1163 jleave:
1164 fflush(stdout);
1165 NYD2_LEAVE;
1166 return (ms != NULL);
1168 j501cp:
1169 fputs("501 ", stdout);
1170 fputs(cp, stdout);
1171 putc('\n', stdout);
1172 goto jleave;
1175 static void
1176 _collint(int s)
1178 NYD_X; /* Signal handler */
1180 /* the control flow is subtle, because we can be called from ~q */
1181 if (_coll_hadintr == 0) {
1182 if (ok_blook(ignore)) {
1183 fputs("@\n", stdout);
1184 fflush(stdout);
1185 clearerr(stdin);
1186 } else
1187 _coll_hadintr = 1;
1188 siglongjmp(_coll_jmp, 1);
1190 exit_status |= EXIT_SEND_ERROR;
1191 if (s != 0)
1192 savedeadletter(_coll_fp, TRU1);
1193 /* Aborting message, no need to fflush() .. */
1194 siglongjmp(_coll_abort, 1);
1197 static void
1198 collhup(int s)
1200 NYD_X; /* Signal handler */
1201 n_UNUSED(s);
1203 savedeadletter(_coll_fp, TRU1);
1204 /* Let's pretend nobody else wants to clean up, a true statement at
1205 * this time */
1206 exit(EXIT_ERR);
1209 static int
1210 putesc(char const *s, FILE *stream)
1212 int n = 0, rv = -1;
1213 NYD_ENTER;
1215 while (s[0] != '\0') {
1216 if (s[0] == '\\') {
1217 if (s[1] == 't') {
1218 if (putc('\t', stream) == EOF)
1219 goto jleave;
1220 ++n;
1221 s += 2;
1222 continue;
1224 if (s[1] == 'n') {
1225 if (putc('\n', stream) == EOF)
1226 goto jleave;
1227 ++n;
1228 s += 2;
1229 continue;
1232 if (putc(s[0], stream) == EOF)
1233 goto jleave;
1234 ++n;
1235 ++s;
1237 if (putc('\n', stream) == EOF)
1238 goto jleave;
1239 rv = ++n;
1240 jleave:
1241 NYD_LEAVE;
1242 return rv;
1245 static void
1246 a_coll__hook_setter(void *arg){ /* TODO v15: drop */
1247 struct header *hp;
1248 char const *val;
1249 NYD2_ENTER;
1251 hp = arg;
1253 if((val = detract(hp->h_from, GNAMEONLY)) == NULL)
1254 val = n_empty;
1255 ok_vset(compose_from, val);
1256 if((val = detract(hp->h_sender, 0)) == NULL)
1257 val = n_empty;
1258 ok_vset(compose_sender, val);
1259 if((val = detract(hp->h_to, GNAMEONLY)) == NULL)
1260 val = n_empty;
1261 ok_vset(compose_to, val);
1262 if((val = detract(hp->h_cc, GNAMEONLY)) == NULL)
1263 val = n_empty;
1264 ok_vset(compose_cc, val);
1265 if((val = detract(hp->h_bcc, GNAMEONLY)) == NULL)
1266 val = n_empty;
1267 ok_vset(compose_bcc, val);
1268 if((val = hp->h_subject) == NULL)
1269 val = n_empty;
1270 ok_vset(compose_subject, val);
1271 NYD2_LEAVE;
1274 static int
1275 a_coll_ocds__mac(void){
1276 /* Executes in a fork(2)ed child */
1277 setvbuf(stdout, NULL, _IOLBF, 0);
1278 options &= ~(OPT_TTYIN | OPT_TTYOUT | OPT_INTERACTIVE);
1279 pstate |= PS_COMPOSE_FORKHOOK;
1280 temporary_call_compose_mode_hook(a_coll_ocds__macname, NULL, NULL);
1281 _exit(EXIT_OK);
1284 static void
1285 a_coll_ocds__finalize(void *vp){
1286 /* Note we use this for destruction upon setup errors, thus */
1287 sighandler_type opipe;
1288 sighandler_type oint;
1289 struct a_coll_ocds_arg **coapp, *coap;
1290 NYD2_ENTER;
1292 temporary_call_compose_mode_hook((char*)-1, NULL, NULL);
1294 coap = *(coapp = vp);
1295 *coapp = (struct a_coll_ocds_arg*)-1;
1297 if(coap->coa_stdout != NULL)
1298 if(!Pclose(coap->coa_stdout, FAL0)){
1299 *coap->coa_senderr = TRU1;
1300 n_err(_("*on-compose-done(-shell)?* failed: %s\n"),
1301 n_shexp_quote_cp(coap->coa_cmd, FAL0));
1304 if(coap->coa_stdin != NULL)
1305 Fclose(coap->coa_stdin);
1306 else if(coap->coa_pipe[0] != -1)
1307 close(coap->coa_pipe[0]);
1309 if(coap->coa_pipe[1] != -1)
1310 close(coap->coa_pipe[1]);
1312 opipe = coap->coa_opipe;
1313 oint = coap->coa_oint;
1315 n_lofi_free(coap);
1317 hold_all_sigs();
1318 safe_signal(SIGPIPE, opipe);
1319 safe_signal(SIGINT, oint);
1320 rele_all_sigs();
1321 NYD2_LEAVE;
1324 FL FILE *
1325 collect(struct header *hp, int printheaders, struct message *mp,
1326 char *quotefile, int doprefix, si8_t *checkaddr_err)
1328 struct n_ignore const *quoteitp;
1329 struct a_coll_ocds_arg *coap;
1330 int lc, cc, c;
1331 int volatile t, eofcnt, getfields;
1332 char *linebuf, escape_saved, escape;
1333 char const *cp, *coapm;
1334 size_t i, linesize; /* TODO line pool */
1335 long cnt;
1336 enum sendaction action;
1337 sigset_t oset, nset;
1338 FILE * volatile sigfp;
1339 NYD_ENTER;
1341 _coll_fp = NULL;
1342 sigfp = NULL;
1343 linesize = 0;
1344 linebuf = NULL;
1345 eofcnt = 0;
1346 coapm = NULL;
1347 coap = NULL;
1349 /* Start catching signals from here, but we're still die on interrupts
1350 * until we're in the main loop */
1351 sigfillset(&nset);
1352 sigprocmask(SIG_BLOCK, &nset, &oset);
1353 /* FIXME have dropped handlerpush() and localized onintr() in lex.c! */
1354 if ((_coll_saveint = safe_signal(SIGINT, SIG_IGN)) != SIG_IGN)
1355 safe_signal(SIGINT, &_collint);
1356 if ((_coll_savehup = safe_signal(SIGHUP, SIG_IGN)) != SIG_IGN)
1357 safe_signal(SIGHUP, collhup);
1358 if (sigsetjmp(_coll_abort, 1))
1359 goto jerr;
1360 if (sigsetjmp(_coll_jmp, 1))
1361 goto jerr;
1362 pstate |= PS_COMPOSE_MODE;
1363 sigprocmask(SIG_SETMASK, &oset, (sigset_t*)NULL);
1365 if ((_coll_fp = Ftmp(NULL, "collect", OF_RDWR | OF_UNLINK | OF_REGISTER)) ==
1366 NULL) {
1367 n_perr(_("temporary mail file"), 0);
1368 goto jerr;
1371 /* If we are going to prompt for a subject, refrain from printing a newline
1372 * after the headers (since some people mind) */
1373 getfields = 0;
1374 if (!(options & OPT_t_FLAG)) {
1375 t = GTO | GSUBJECT | GCC | GNL;
1376 if (ok_blook(fullnames))
1377 t |= GCOMMA;
1379 if (options & OPT_INTERACTIVE) {
1380 if (hp->h_subject == NULL && (ok_blook(ask) || ok_blook(asksub)))
1381 t &= ~GNL, getfields |= GSUBJECT;
1383 if (hp->h_to == NULL)
1384 t &= ~GNL, getfields |= GTO;
1386 if (!ok_blook(bsdcompat) && !ok_blook(askatend)) {
1387 if (hp->h_bcc == NULL && ok_blook(askbcc))
1388 t &= ~GNL, getfields |= GBCC;
1389 if (hp->h_cc == NULL && ok_blook(askcc))
1390 t &= ~GNL, getfields |= GCC;
1393 } else {
1394 n_UNINIT(t, 0);
1397 escape_saved = escape = ((cp = ok_vlook(escape)) != NULL) ? *cp : n_ESCAPE;
1398 _coll_hadintr = 0;
1400 if (!sigsetjmp(_coll_jmp, 1)) {
1401 /* Ask for some headers first, as necessary */
1402 if (getfields)
1403 grab_headers(n_LEXINPUT_CTX_COMPOSE, hp, getfields, 1);
1405 /* Execute compose-enter TODO completely v15-compat intermediate!! */
1406 if((cp = ok_vlook(on_compose_enter)) != NULL){
1407 setup_from_and_sender(hp);
1408 temporary_call_compose_mode_hook(cp, &a_coll__hook_setter, hp);
1411 /* Cannot do since it may require turning this into a multipart one */
1412 if(!(options & OPT_Mm_FLAG)){
1413 char const *cp_obsolete = ok_vlook(NAIL_HEAD);
1414 if(cp_obsolete != NULL)
1415 OBSOLETE(_("please use *message-inject-head* "
1416 "instead of *NAIL_HEAD*"));
1418 if(((cp = ok_vlook(message_inject_head)) != NULL ||
1419 (cp = cp_obsolete) != NULL) && putesc(cp, _coll_fp) < 0)
1420 goto jerr;
1422 /* Quote an original message */
1423 if (mp != NULL && (doprefix || (cp = ok_vlook(quote)) != NULL)) {
1424 quoteitp = n_IGNORE_ALL;
1425 action = SEND_QUOTE;
1426 if (doprefix) {
1427 quoteitp = n_IGNORE_FWD;
1428 if ((cp = ok_vlook(fwdheading)) == NULL)
1429 cp = "-------- Original Message --------";
1430 if (*cp != '\0' && fprintf(_coll_fp, "%s\n", cp) < 0)
1431 goto jerr;
1432 } else if (!strcmp(cp, "noheading")) {
1433 /*EMPTY*/;
1434 } else if (!strcmp(cp, "headers")) {
1435 quoteitp = n_IGNORE_TYPE;
1436 } else if (!strcmp(cp, "allheaders")) {
1437 quoteitp = NULL;
1438 action = SEND_QUOTE_ALL;
1439 } else {
1440 cp = hfield1("from", mp);
1441 if (cp != NULL && (cnt = (long)strlen(cp)) > 0) {
1442 if (xmime_write(cp, cnt, _coll_fp, CONV_FROMHDR, TD_NONE) < 0)
1443 goto jerr;
1444 if (fprintf(_coll_fp, _(" wrote:\n\n")) < 0)
1445 goto jerr;
1448 if (fflush(_coll_fp))
1449 goto jerr;
1450 if (doprefix)
1451 cp = NULL;
1452 else if ((cp = ok_vlook(indentprefix)) == NULL)
1453 cp = INDENT_DEFAULT;
1454 if (sendmp(mp, _coll_fp, quoteitp, cp, action, NULL) < 0)
1455 goto jerr;
1459 if (quotefile != NULL) {
1460 if (_include_file(quotefile, &lc, &cc, FAL0) != 0)
1461 goto jerr;
1464 if ((options & (OPT_Mm_FLAG | OPT_INTERACTIVE)) == OPT_INTERACTIVE) {
1465 /* Print what we have sofar also on the terminal (if useful) */
1466 if (!ok_blook(editalong)) {
1467 if (printheaders)
1468 puthead(TRU1, hp, stdout, t, SEND_TODISP, CONV_NONE, NULL, NULL);
1470 rewind(_coll_fp);
1471 while ((c = getc(_coll_fp)) != EOF) /* XXX bytewise, yuck! */
1472 putc(c, stdout);
1473 if (fseek(_coll_fp, 0, SEEK_END))
1474 goto jerr;
1475 } else {
1476 rewind(_coll_fp);
1477 mesedit('e', hp);
1478 /* As mandated by the Mail Reference Manual, print "(continue)" */
1479 jcont:
1480 if(options & OPT_INTERACTIVE)
1481 fputs(_("(continue)\n"), stdout);
1483 fflush(stdout);
1485 } else {
1486 /* Come here for printing the after-signal message. Duplicate messages
1487 * won't be printed because the write is aborted if we get a SIGTTOU */
1488 if (_coll_hadintr)
1489 n_err(_("\n(Interrupt -- one more to kill letter)\n"));
1492 /* If not under shell hook control */
1493 if(coap == NULL){
1494 /* We're done with -M or -m (because we are too simple minded) */
1495 if(options & OPT_Mm_FLAG)
1496 goto jout;
1497 /* No command escapes, interrupts not expected. Simply copy STDIN */
1498 if (!(options & (OPT_INTERACTIVE | OPT_t_FLAG | OPT_TILDE_FLAG))){
1499 linebuf = srealloc(linebuf, linesize = LINESIZE);
1500 while ((i = fread(linebuf, sizeof *linebuf, linesize, stdin)) > 0) {
1501 if (i != fwrite(linebuf, sizeof *linebuf, i, _coll_fp))
1502 goto jerr;
1504 goto jout;
1508 /* The interactive collect loop */
1509 for(;;){
1510 /* C99 */{
1511 enum n_lexinput_flags lif;
1513 lif = n_LEXINPUT_CTX_COMPOSE;
1514 if(options & (OPT_INTERACTIVE | OPT_TILDE_FLAG)){
1515 if(!(options & OPT_t_FLAG))
1516 lif |= n_LEXINPUT_NL_ESC;
1518 cnt = n_lex_input(lif, n_empty, &linebuf, &linesize, NULL);
1521 if (cnt < 0) {
1522 if(coap != NULL)
1523 break;
1524 if (options & OPT_t_FLAG) {
1525 fflush_rewind(_coll_fp);
1526 /* It is important to set PS_t_FLAG before extract_header() *and*
1527 * keep OPT_t_FLAG for the first parse of the message, too! */
1528 pstate |= PS_t_FLAG;
1529 if (makeheader(_coll_fp, hp, checkaddr_err) != OKAY)
1530 goto jerr;
1531 options &= ~OPT_t_FLAG;
1532 continue;
1533 } else if ((options & OPT_INTERACTIVE) &&
1534 ok_blook(ignoreeof) && ++eofcnt < 4) {
1535 printf(_("*ignoreeof* set, use `~.' to terminate letter\n"));
1536 continue;
1538 break;
1541 _coll_hadintr = 0;
1543 cp = linebuf;
1544 if(cnt == 0)
1545 goto jputnl;
1546 else if(coap == NULL){
1547 if(!(options & (OPT_INTERACTIVE | OPT_TILDE_FLAG)))
1548 goto jputline;
1549 else if(cp[0] == '.'){
1550 if(cnt == 1 && (ok_blook(dot) || ok_blook(ignoreeof)))
1551 break;
1554 if(cp[0] != escape){
1555 jputline:
1556 if(fwrite(cp, sizeof *cp, cnt, _coll_fp) != (size_t)cnt)
1557 goto jerr;
1558 /* TODO PS_READLINE_NL is a terrible hack to ensure that _in_all_-
1559 * TODO _code_paths_ a file without trailing newline isn't modified
1560 * TODO to continue one; the "saw-newline" needs to be part of an
1561 * TODO I/O input machinery object */
1562 jputnl:
1563 if(pstate & PS_READLINE_NL){
1564 if(putc('\n', _coll_fp) == EOF)
1565 goto jerr;
1567 continue;
1570 /* Cleanup the input string: like this we can perform a little bit of
1571 * usage testing and also have somewhat normalized history entries */
1572 for(cp = &linebuf[2]; (c = *cp) != '\0' && blankspacechar(c); ++cp)
1573 continue;
1574 if(c == '\0'){
1575 linebuf[2] = '\0';
1576 cnt = 2;
1577 }else{
1578 i = PTR2SIZE(cp - linebuf) - 3;
1579 memmove(&linebuf[3], cp, (cnt -= i));
1580 linebuf[2] = ' ';
1581 linebuf[cnt] = '\0';
1583 if(cnt > 0){ /* TODO v15 no more trailing WS from lex_input please */
1584 cp = &linebuf[cnt];
1586 for(;; --cp){
1587 c = cp[-1];
1588 if(!blankspacechar(c))
1589 break;
1591 ((char*)n_UNCONST(cp))[0] = '\0';
1592 cnt = PTR2SIZE(cp - linebuf);
1596 switch((c = linebuf[1])){
1597 default:
1598 /* On double escape, send a single one. Otherwise, it's an error */
1599 if(c == escape){
1600 cp = &linebuf[1];
1601 --cnt;
1602 goto jputline;
1603 }else{
1604 char buf[sizeof(n_UNIREPL)];
1606 if(asciichar(c))
1607 buf[0] = c, buf[1] = '\0';
1608 else if(options & OPT_UNICODE)
1609 memcpy(buf, n_unirepl, sizeof n_unirepl);
1610 else
1611 buf[0] = '?', buf[1] = '\0';
1612 n_err(_("Unknown command escape: ~%s\n"), buf);
1613 continue;
1615 jearg:
1616 n_err(_("Invalid command escape usage: %s\n"), linebuf);
1617 continue;
1618 case '!':
1619 /* Shell escape, send the balance of line to sh -c */
1620 if(cnt == 2 || coap != NULL)
1621 goto jearg;
1622 c_shell(&linebuf[3]);
1623 goto jhistcont;
1624 case ':':
1625 /* FALLTHRU */
1626 case '_':
1627 /* Escape to command mode, but be nice! *//* TODO command expansion
1628 * TODO should be handled here so that we have unique history! */
1629 if(cnt == 2)
1630 goto jearg;
1631 _execute_command(hp, &linebuf[3], cnt -= 3);
1632 break;
1633 case '.':
1634 /* Simulate end of file on input */
1635 if(cnt != 2 || coap != NULL)
1636 goto jearg;
1637 goto jout;
1638 case 'x':
1639 /* Same as 'q', but no *DEAD* saving */
1640 /* FALLTHRU */
1641 case 'q':
1642 /* Force a quit, act like an interrupt had happened */
1643 if(cnt != 2)
1644 goto jearg;
1645 ++_coll_hadintr;
1646 _collint((c == 'x') ? 0 : SIGINT);
1647 exit(EXIT_ERR);
1648 /*NOTREACHED*/
1649 case 'h':
1650 /* Grab a bunch of headers */
1651 if(cnt != 2)
1652 goto jearg;
1654 grab_headers(n_LEXINPUT_CTX_COMPOSE, hp,
1655 (GTO | GSUBJECT | GCC | GBCC),
1656 (ok_blook(bsdcompat) && ok_blook(bsdorder)));
1657 while(hp->h_to == NULL);
1658 break;
1659 case 'H':
1660 /* Grab extra headers */
1661 if(cnt != 2)
1662 goto jearg;
1664 grab_headers(n_LEXINPUT_CTX_COMPOSE, hp, GEXTRA, 0);
1665 while(check_from_and_sender(hp->h_from, hp->h_sender) == NULL);
1666 break;
1667 case 't':
1668 /* Add to the To: list */
1669 if(cnt == 2)
1670 goto jearg;
1671 hp->h_to = cat(hp->h_to,
1672 checkaddrs(lextract(&linebuf[3], GTO | GFULL), EACM_NORMAL,
1673 NULL));
1674 break;
1675 case 's':
1676 /* Set the Subject list */
1677 if(cnt == 2)
1678 goto jearg;
1679 /* Subject:; take care for Debian #419840 and strip any \r and \n */
1680 if(n_anyof_cp("\n\r", hp->h_subject = savestr(&linebuf[3]))){
1681 char *xp;
1683 n_err(_("-s: normalizing away invalid ASCII NL / CR bytes\n"));
1684 for(xp = hp->h_subject; *xp != '\0'; ++xp)
1685 if(*xp == '\n' || *xp == '\r')
1686 *xp = ' ';
1688 break;
1689 case '@':{
1690 struct attachment *aplist;
1692 /* Edit the attachment list */
1693 aplist = hp->h_attach;
1694 hp->h_attach = NULL;
1695 if(cnt != 2)
1696 hp->h_attach = n_attachment_append_list(aplist, &linebuf[3]);
1697 else
1698 hp->h_attach = n_attachment_list_edit(aplist,
1699 n_LEXINPUT_CTX_COMPOSE);
1700 } break;
1701 case 'c':
1702 /* Add to the CC list */
1703 if(cnt == 2)
1704 goto jearg;
1705 hp->h_cc = cat(hp->h_cc,
1706 checkaddrs(lextract(&linebuf[3], GCC | GFULL), EACM_NORMAL,
1707 NULL));
1708 break;
1709 case 'b':
1710 /* Add stuff to blind carbon copies list */
1711 if(cnt == 2)
1712 goto jearg;
1713 hp->h_bcc = cat(hp->h_bcc,
1714 checkaddrs(lextract(&linebuf[3], GBCC | GFULL), EACM_NORMAL,
1715 NULL));
1716 break;
1717 case 'd':
1718 if(cnt != 2)
1719 goto jearg;
1720 cp = n_getdeadletter();
1721 if(0){
1722 /*FALLTHRU*/
1723 case 'R':
1724 case 'r':
1725 case '<':
1726 /* Invoke a file: Search for the file name, then open it and copy
1727 * the contents to _coll_fp */
1728 if(cnt == 2){
1729 n_err(_("Interpolate what file?\n"));
1730 break;
1732 if(*(cp = &linebuf[3]) == '!'){
1733 insertcommand(_coll_fp, ++cp);
1734 goto jhistcont;
1736 if((cp = fexpand(cp, FEXP_LOCAL | FEXP_NOPROTO)) == NULL)
1737 break;
1739 if(is_dir(cp)){
1740 n_err(_("%s: is a directory\n"), n_shexp_quote_cp(cp, FAL0));
1741 break;
1743 if(_include_file(cp, &lc, &cc, (c == 'R')) != 0){
1744 if(ferror(_coll_fp))
1745 goto jerr;
1746 break;
1748 printf(_("%s %d/%d\n"), n_shexp_quote_cp(cp, FAL0), lc, cc);
1749 break;
1750 case 'i':
1751 /* Insert a variable into the file */
1752 if(cnt == 2)
1753 goto jearg;
1754 if((cp = vok_vlook(&linebuf[3])) == NULL || *cp == '\0')
1755 break;
1756 if(putesc(cp, _coll_fp) < 0) /* TODO v15: user resp upon `set' time */
1757 goto jerr;
1758 if((options & OPT_INTERACTIVE) && putesc(cp, stdout) < 0)
1759 goto jerr;
1760 break;
1761 case 'a':
1762 case 'A':
1763 /* Insert the contents of a signature variable */
1764 if(cnt != 2)
1765 goto jearg;
1766 cp = (c == 'a') ? ok_vlook(sign) : ok_vlook(Sign);
1767 if(cp != NULL && *cp != '\0'){
1768 if(putesc(cp, _coll_fp) < 0) /* TODO v15: user upon `set' time */
1769 goto jerr;
1770 if((options & OPT_INTERACTIVE) && putesc(cp, stdout) < 0)
1771 goto jerr;
1773 break;
1774 case 'w':
1775 /* Write the message on a file */
1776 if(cnt == 2)
1777 goto jearg;
1778 if((cp = fexpand(&linebuf[3], FEXP_LOCAL | FEXP_NOPROTO)) == NULL){
1779 n_err(_("Write what file!?\n"));
1780 break;
1782 rewind(_coll_fp);
1783 if(exwrite(cp, _coll_fp, 1) < 0)
1784 goto jerr;
1785 break;
1786 case 'm':
1787 case 'M':
1788 case 'f':
1789 case 'F':
1790 case 'u':
1791 case 'U':
1792 /* Interpolate the named messages, if we are in receiving mail mode.
1793 * Does the standard list processing garbage. If ~f is given, we
1794 * don't shift over */
1795 if(cnt == 2)
1796 goto jearg;
1797 if(forward(&linebuf[3], _coll_fp, c) < 0)
1798 break;
1799 break;
1800 case 'p':
1801 /* Print current state of the message without altering anything */
1802 if(cnt != 2)
1803 goto jearg;
1804 print_collf(_coll_fp, hp);
1805 break;
1806 case '|':
1807 /* Pipe message through command. Collect output as new message */
1808 if(cnt == 2)
1809 goto jearg;
1810 rewind(_coll_fp);
1811 mespipe(&linebuf[3]);
1812 goto jhistcont;
1813 case 'v':
1814 case 'e':
1815 /* Edit the current message. 'e' -> use EDITOR, 'v' -> use VISUAL */
1816 if(cnt != 2 || coap != NULL)
1817 goto jearg;
1818 rewind(_coll_fp);
1819 mesedit(c, ok_blook(editheaders) ? hp : NULL);
1820 goto jhistcont;
1821 case '^':
1822 if(!a_collect_plumbing(&linebuf[3], hp))
1823 goto jearg;
1824 if(options & OPT_INTERACTIVE)
1825 break;
1826 continue;
1827 case '?':
1828 /* Last the lengthy help string. (Very ugly, but take care for
1829 * compiler supported string lengths :() */
1830 puts(_(
1831 "COMMAND ESCAPES (to be placed after a newline) excerpt:\n"
1832 "~. Commit and send message\n"
1833 "~: <command> Execute a mail command\n"
1834 "~<! <command> Insert output of command\n"
1835 "~@ [<files>] Edit attachment list\n"
1836 "~A Insert *Sign* variable (`~a': insert *sign*)\n"
1837 "~c <users> Add users to Cc: list (`~b': to Bcc:)\n"
1838 "~d Read in $DEAD (dead.letter)\n"
1839 "~e Edit message via $EDITOR"
1841 puts(_(
1842 "~F <msglist> Read in with headers, don't *indentprefix* lines\n"
1843 "~f <msglist> Like ~F, but honour `ignore' / `retain' configuration\n"
1844 "~H Edit From:, Reply-To: and Sender:\n"
1845 "~h Prompt for Subject:, To:, Cc: and \"blind\" Bcc:\n"
1846 "~i <variable> Insert a value and a newline\n"
1847 "~M <msglist> Read in with headers, *indentprefix* (`~m': `retain' etc.)\n"
1848 "~p Show current message compose buffer\n"
1849 "~r <file> Read in a file (`~<': likewise; `~R': *indentprefix* lines)"
1851 puts(_(
1852 "~s <subject> Set Subject:\n"
1853 "~t <users> Add users to To: list\n"
1854 "~u <msglist> Read in message(s) without headers (`~U': indent lines)\n"
1855 "~v Edit message via $VISUAL\n"
1856 "~w <file> Write message onto file\n"
1857 "~x Abort composition, discard message (`~q': save in $DEAD)\n"
1858 "~| <command> Pipe message through shell filter"
1860 if(cnt != 2)
1861 goto jearg;
1862 break;
1865 /* Finally place an entry in history as applicable */
1866 if(0){
1867 jhistcont:
1868 c = '\1';
1869 }else
1870 c = '\0';
1871 if(options & OPT_INTERACTIVE)
1872 n_tty_addhist(linebuf, TRU1);
1873 if(c != '\0')
1874 goto jcont;
1877 jout:
1878 /* Do we have *on-compose-done-shell*, or *on-compose-done*?
1879 * TODO Usual f...ed up state of signals and terminal etc. */
1880 if(coap == NULL && (cp = ok_vlook(on_compose_done_shell)) != NULL) Jocds:{
1881 union {int (*ptf)(void); char const *sh;} u;
1882 char const *cmd;
1884 /* Reset *escape* to be available and guaranteed! */
1885 escape = n_ESCAPE;
1887 if(coapm != NULL){
1888 u.ptf = &a_coll_ocds__mac;
1889 cmd = (char*)-1;
1890 a_coll_ocds__macname = cp = coapm;
1891 }else{
1892 u.sh = ok_vlook(SHELL);
1893 cmd = cp;
1896 i = strlen(cp) +1;
1897 coap = n_lofi_alloc(n_VSTRUCT_SIZEOF(struct a_coll_ocds_arg, coa_cmd
1898 ) + i);
1899 coap->coa_pipe[0] = coap->coa_pipe[1] = -1;
1900 coap->coa_stdin = coap->coa_stdout = NULL;
1901 coap->coa_senderr = checkaddr_err;
1902 memcpy(coap->coa_cmd, cp, i);
1904 hold_all_sigs();
1905 coap->coa_opipe = safe_signal(SIGPIPE, SIG_IGN);
1906 coap->coa_oint = safe_signal(SIGINT, SIG_IGN);
1907 rele_all_sigs();
1909 if(pipe_cloexec(coap->coa_pipe) != -1 &&
1910 (coap->coa_stdin = Fdopen(coap->coa_pipe[0], "r", FAL0)) != NULL &&
1911 (coap->coa_stdout = Popen(cmd, "W", u.sh, NULL, coap->coa_pipe[1])
1912 ) != NULL){
1913 close(coap->coa_pipe[1]);
1914 coap->coa_pipe[1] = -1;
1916 temporary_call_compose_mode_hook(NULL, NULL, NULL);
1917 n_source_slice_hack(coap->coa_cmd, coap->coa_stdin, coap->coa_stdout,
1918 (options & ~(OPT_TTYIN | OPT_TTYOUT | OPT_INTERACTIVE)),
1919 &a_coll_ocds__finalize, &coap);
1920 /* Hook version protocol for ~^: update manual upon change! */
1921 fputs(a_COLL_PLUMBING_VERSION "\n", coap->coa_stdout);
1922 #undef a_COLL_PLUMBING_VERSION
1923 goto jcont;
1926 c = errno;
1927 a_coll_ocds__finalize(coap);
1928 n_perr(_("Cannot invoke *on-compose-done(-shell)?*"), c);
1929 goto jerr;
1931 if(*checkaddr_err != 0){
1932 *checkaddr_err = 0;
1933 goto jerr;
1935 if(coapm == NULL && (coapm = ok_vlook(on_compose_done)) != NULL)
1936 goto Jocds;
1937 escape = escape_saved;
1939 /* Final chance to edit headers, if not already above */
1940 if (ok_blook(bsdcompat) || ok_blook(askatend)) {
1941 if (hp->h_cc == NULL && ok_blook(askcc))
1942 grab_headers(n_LEXINPUT_CTX_COMPOSE, hp, GCC, 1);
1943 if (hp->h_bcc == NULL && ok_blook(askbcc))
1944 grab_headers(n_LEXINPUT_CTX_COMPOSE, hp, GBCC, 1);
1946 if (hp->h_attach == NULL && ok_blook(askattach))
1947 hp->h_attach = n_attachment_list_edit(hp->h_attach,
1948 n_LEXINPUT_CTX_COMPOSE);
1950 /* Add automatic receivers */
1951 if ((cp = ok_vlook(autocc)) != NULL && *cp != '\0')
1952 hp->h_cc = cat(hp->h_cc, checkaddrs(lextract(cp, GCC | GFULL),
1953 EACM_NORMAL, checkaddr_err));
1954 if ((cp = ok_vlook(autobcc)) != NULL && *cp != '\0')
1955 hp->h_bcc = cat(hp->h_bcc, checkaddrs(lextract(cp, GBCC | GFULL),
1956 EACM_NORMAL, checkaddr_err));
1957 if (*checkaddr_err != 0)
1958 goto jerr;
1960 /* Execute compose-leave */
1961 if((cp = ok_vlook(on_compose_leave)) != NULL){
1962 setup_from_and_sender(hp);
1963 temporary_call_compose_mode_hook(cp, &a_coll__hook_setter, hp);
1966 /* TODO Cannot do since it may require turning this into a multipart one */
1967 if(options & OPT_Mm_FLAG)
1968 goto jskiptails;
1970 /* Place signature? */
1971 if((cp = ok_vlook(signature)) != NULL && *cp != '\0'){
1972 char const *cpq;
1974 if((cpq = fexpand(cp, FEXP_LOCAL | FEXP_NOPROTO)) == NULL){
1975 n_err(_("*signature* expands to invalid file: %s\n"),
1976 n_shexp_quote_cp(cp, FAL0));
1977 goto jerr;
1979 cpq = n_shexp_quote_cp(cp = cpq, FAL0);
1981 if((sigfp = Fopen(cp, "r")) == NULL){
1982 n_err(_("Can't open *signature* %s: %s\n"), cpq, strerror(errno));
1983 goto jerr;
1986 if(linebuf == NULL)
1987 linebuf = smalloc(linesize = LINESIZE);
1988 c = '\0';
1989 while((i = fread(linebuf, sizeof *linebuf, linesize, n_UNVOLATILE(sigfp)))
1990 > 0){
1991 c = linebuf[i - 1];
1992 if(i != fwrite(linebuf, sizeof *linebuf, i, _coll_fp))
1993 goto jerr;
1996 /* C99 */{
1997 FILE *x = n_UNVOLATILE(sigfp);
1998 int e = errno, ise = ferror(x);
2000 sigfp = NULL;
2001 Fclose(x);
2003 if(ise){
2004 n_err(_("Errors while reading *signature* %s: %s\n"),
2005 cpq, strerror(e));
2006 goto jerr;
2010 if(c != '\0' && c != '\n')
2011 putc('\n', _coll_fp);
2014 { char const *cp_obsolete = ok_vlook(NAIL_TAIL);
2016 if(cp_obsolete != NULL)
2017 OBSOLETE(_("please use *message-inject-tail* instead of *NAIL_TAIL*"));
2019 if((cp = ok_vlook(message_inject_tail)) != NULL ||
2020 (cp = cp_obsolete) != NULL){
2021 if(putesc(cp, _coll_fp) < 0)
2022 goto jerr;
2023 if((options & OPT_INTERACTIVE) && putesc(cp, stdout) < 0)
2024 goto jerr;
2028 jskiptails:
2029 if(fflush(_coll_fp))
2030 goto jerr;
2031 rewind(_coll_fp);
2033 jleave:
2034 if (linebuf != NULL)
2035 free(linebuf);
2036 sigfillset(&nset);
2037 sigprocmask(SIG_BLOCK, &nset, NULL);
2038 pstate &= ~PS_COMPOSE_MODE;
2039 safe_signal(SIGINT, _coll_saveint);
2040 safe_signal(SIGHUP, _coll_savehup);
2041 sigprocmask(SIG_SETMASK, &oset, NULL);
2042 NYD_LEAVE;
2043 return _coll_fp;
2045 jerr:
2046 if(coap != NULL && coap != (struct a_coll_ocds_arg*)-1)
2047 n_source_slice_hack_remove_after_jump();
2048 if(sigfp != NULL)
2049 Fclose(n_UNVOLATILE(sigfp));
2050 if (_coll_fp != NULL) {
2051 Fclose(_coll_fp);
2052 _coll_fp = NULL;
2054 assert(checkaddr_err != NULL);
2055 /* TODO We don't save in $DEAD upon error because msg not readily composed?
2056 * TODO But this no good, it should go ZOMBIE / DRAFT / POSTPONED or what! */
2057 if(*checkaddr_err != 0)
2058 n_err(_("Some addressees were classified as \"hard error\"\n"));
2059 else if(_coll_hadintr == 0){
2060 *checkaddr_err = TRU1; /* TODO ugly: "sendout_error" now.. */
2061 n_err(_("Failed to prepare composed message (I/O error, disk full?)\n"));
2063 goto jleave;
2066 /* s-it-mode */