FIX [1c4b8c918] (Address struct name memory usage.., 2015-07-08)..
[s-mailx.git] / collect.c
blob73439825e0a81b23b5350296deb68d98806dc85e
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;
507 if(is_asccaseprefix(cmd[0], "header")){
508 struct n_header_field *hfp;
509 struct name *np, **npp;
511 if(cmd[1] == NULL || is_asccaseprefix(cmd[1], "list")){
512 if(cmd[2] == NULL){
513 fputs("210", stdout);
514 if(hp->h_from != NULL) fputs(" From", stdout);
515 if(hp->h_sender != NULL) fputs(" Sender", stdout);
516 if(hp->h_to != NULL) fputs(" To", stdout);
517 if(hp->h_cc != NULL) fputs(" Cc", stdout);
518 if(hp->h_bcc != NULL) fputs(" Bcc", stdout);
519 if(hp->h_subject != NULL) fputs(" Subject", stdout);
520 if(hp->h_replyto != NULL) fputs(" Reply-To", stdout);
521 if(hp->h_mft != NULL) fputs(" Mail-Followup-To", stdout);
522 if(hp->h_message_id != NULL) fputs(" Message-ID", stdout);
523 if(hp->h_ref != NULL) fputs(" References", stdout);
524 if(hp->h_in_reply_to != NULL) fputs(" In-Reply-To", stdout);
525 for(hfp = hp->h_user_headers; hfp != NULL; hfp = hfp->hf_next){
526 putc(' ', stdout);
527 fputs(&hfp->hf_dat[0], stdout);
529 putc('\n', stdout);
530 }else{
531 if(cmd[3] != NULL)
532 goto jecmd;
534 if(!asccasecmp(cmd[2], "from")){
535 np = hp->h_from;
536 jlist:
537 fprintf(stdout, "%s %s\n", (np == NULL ? "501" : "210"), cp);
538 }else if(!asccasecmp(cmd[2], cp = "Sender")){
539 np = hp->h_sender;
540 goto jlist;
541 }else if(!asccasecmp(cmd[2], cp = "To")){
542 np = hp->h_to;
543 goto jlist;
544 }else if(!asccasecmp(cmd[2], cp = "Cc")){
545 np = hp->h_cc;
546 goto jlist;
547 }else if(!asccasecmp(cmd[2], cp = "Bcc")){
548 np = hp->h_bcc;
549 goto jlist;
550 }else if(!asccasecmp(cmd[2], cp = "Subject")){
551 np = (struct name*)-1;
552 goto jlist;
553 }else if(!asccasecmp(cmd[2], cp = "Reply-To")){
554 np = hp->h_replyto;
555 goto jlist;
556 }else if(!asccasecmp(cmd[2], cp = "Mail-Followup-To")){
557 np = hp->h_mft;
558 goto jlist;
559 }else if(!asccasecmp(cmd[2], cp = "Message-ID")){
560 np = hp->h_message_id;
561 goto jlist;
562 }else if(!asccasecmp(cmd[2], cp = "References")){
563 np = hp->h_ref;
564 goto jlist;
565 }else if(!asccasecmp(cmd[2], cp = "In-Reply-To")){
566 np = hp->h_in_reply_to;
567 goto jlist;
568 }else{
569 /* Primitive name normalization XXX header object should
570 * XXX have a more sophisticated accessible one */
571 char *xp;
573 cp = xp = savestr(cmd[2]);
574 xp[0] = upperchar(xp[0]);
575 while(*++xp != '\0')
576 xp[0] = lowerchar(xp[0]);
578 for(hfp = hp->h_user_headers;; hfp = hfp->hf_next){
579 if(hfp == NULL)
580 goto j501cp;
581 else if(!asccasecmp(cp, &hfp->hf_dat[0])){
582 fprintf(stdout, "210 %s\n", cp);
583 break;
588 }else if(is_asccaseprefix(cmd[1], "show")){
589 if(cmd[2] == NULL || cmd[3] != NULL)
590 goto jecmd;
592 if(!asccasecmp(cmd[2], "from")){
593 np = hp->h_from;
594 jshow:
595 if(np != NULL){
596 fprintf(stdout, "211 %s\n", cp);
598 fprintf(stdout, "%s %s\n", np->n_name, np->n_fullname);
599 while((np = np->n_flink) != NULL);
600 putc('\n', stdout);
601 }else
602 goto j501cp;
603 }else if(!asccasecmp(cmd[2], cp = "Sender")){
604 np = hp->h_sender;
605 goto jshow;
606 }else if(!asccasecmp(cmd[2], cp = "To")){
607 np = hp->h_to;
608 goto jshow;
609 }else if(!asccasecmp(cmd[2], cp = "Cc")){
610 np = hp->h_cc;
611 goto jshow;
612 }else if(!asccasecmp(cmd[2], cp = "Bcc")){
613 np = hp->h_bcc;
614 goto jshow;
615 }else if(!asccasecmp(cmd[2], cp = "Reply-To")){
616 np = hp->h_replyto;
617 goto jshow;
618 }else if(!asccasecmp(cmd[2], cp = "Mail-Followup-To")){
619 np = hp->h_mft;
620 goto jshow;
621 }else if(!asccasecmp(cmd[2], cp = "Message-ID")){
622 np = hp->h_message_id;
623 goto jshow;
624 }else if(!asccasecmp(cmd[2], cp = "References")){
625 np = hp->h_ref;
626 goto jshow;
627 }else if(!asccasecmp(cmd[2], cp = "In-Reply-To")){
628 np = hp->h_in_reply_to;
629 goto jshow;
630 }else if(!asccasecmp(cmd[2], cp = "Subject")){
631 if(hp->h_subject != NULL)
632 fprintf(stdout, "212 %s\n%s\n\n", cp, hp->h_subject);
633 else
634 fprintf(stdout, "501 %s\n", cp);
635 }else{
636 /* Primitive name normalization XXX header object should
637 * XXX have a more sophisticated accessible one */
638 bool_t any;
639 char *xp;
641 cp = xp = savestr(cmd[2]);
642 xp[0] = upperchar(xp[0]);
643 while(*++xp != '\0')
644 xp[0] = lowerchar(xp[0]);
646 for(any = FAL0, hfp = hp->h_user_headers; hfp != NULL;
647 hfp = hfp->hf_next){
648 if(!asccasecmp(cp, &hfp->hf_dat[0])){
649 if(!any)
650 fprintf(stdout, "212 %s\n", cp);
651 any = TRU1;
652 fprintf(stdout, "%s\n", &hfp->hf_dat[hfp->hf_nl +1]);
655 if(any)
656 putc('\n', stdout);
657 else
658 goto j501cp;
660 }else if(is_asccaseprefix(cmd[1], "remove")){
661 if(cmd[2] == NULL || cmd[3] != NULL)
662 goto jecmd;
664 if(!asccasecmp(cmd[2], "from")){
665 npp = &hp->h_from;
666 jrem:
667 if(*npp != NULL){
668 *npp = NULL;
669 fprintf(stdout, "210 %s\n", cp);
670 }else
671 goto j501cp;
672 }else if(!asccasecmp(cmd[2], cp = "Sender")){
673 npp = &hp->h_sender;
674 goto jrem;
675 }else if(!asccasecmp(cmd[2], cp = "To")){
676 npp = &hp->h_to;
677 goto jrem;
678 }else if(!asccasecmp(cmd[2], cp = "Cc")){
679 npp = &hp->h_cc;
680 goto jrem;
681 }else if(!asccasecmp(cmd[2], cp = "Bcc")){
682 npp = &hp->h_bcc;
683 goto jrem;
684 }else if(!asccasecmp(cmd[2], cp = "Reply-To")){
685 npp = &hp->h_replyto;
686 goto jrem;
687 }else if(!asccasecmp(cmd[2], cp = "Mail-Followup-To")){
688 npp = &hp->h_mft;
689 goto jrem;
690 }else if(!asccasecmp(cmd[2], cp = "Message-ID")){
691 npp = &hp->h_message_id;
692 goto jrem;
693 }else if(!asccasecmp(cmd[2], cp = "References")){
694 npp = &hp->h_ref;
695 goto jrem;
696 }else if(!asccasecmp(cmd[2], cp = "In-Reply-To")){
697 npp = &hp->h_in_reply_to;
698 goto jrem;
699 }else if(!asccasecmp(cmd[2], cp = "Subject")){
700 if(hp->h_subject != NULL){
701 hp->h_subject = NULL;
702 fprintf(stdout, "210 %s\n", cp);
703 }else
704 goto j501cp;
705 }else{
706 /* Primitive name normalization XXX header object should
707 * XXX have a more sophisticated accessible one */
708 struct n_header_field **hfpp;
709 bool_t any;
710 char *xp;
712 cp = xp = savestr(cmd[2]);
713 xp[0] = upperchar(xp[0]);
714 while(*++xp != '\0')
715 xp[0] = lowerchar(xp[0]);
717 for(any = FAL0, hfpp = &hp->h_user_headers; (hfp = *hfpp) != NULL;){
718 if(!asccasecmp(cp, &hfp->hf_dat[0])){
719 *hfpp = hfp->hf_next;
720 if(!any)
721 fprintf(stdout, "210 %s\n", cp);
722 any = TRU1;
723 }else
724 hfp = *(hfpp = &hfp->hf_next);
726 if(!any)
727 goto j501cp;
729 }else if(is_asccaseprefix(cmd[1], "insert")){ /* TODO LOGIC BELONGS head.c
730 * TODO That is: Header::factory(string) -> object (blahblah).
731 * TODO I.e., as long as we don't have regular RFC compliant parsers
732 * TODO which differentiate in between structured and unstructured
733 * TODO header fields etc., a little workaround */
734 si8_t aerr;
735 enum expand_addr_check_mode eacm;
736 enum gfield ntype;
737 bool_t mult_ok;
739 if(cmd[2] == NULL || cmd[3] == NULL)
740 goto jecmd;
742 /* Strip [\r\n] which would render a body invalid XXX all controls? */
743 /* C99 */{
744 char *xp, c;
746 cmd[3] = xp = savestr(cmd[3]);
747 for(; (c = *xp) != '\0'; ++xp)
748 if(c == '\n' || c == '\r')
749 *xp = ' ';
752 mult_ok = TRU1;
753 ntype = GEXTRA | GFULL | GFULLEXTRA;
754 eacm = EACM_STRICT;
756 if(!asccasecmp(cmd[2], "from")){
757 npp = &hp->h_from;
758 jins:
759 aerr = 0;
760 if((np = lextract(cmd[3], ntype)) == NULL)
761 goto j501cp;
762 else if((np = checkaddrs(np, eacm, &aerr), aerr != 0))
763 fprintf(stdout, "505 %s\n", cp);
764 else if(!mult_ok && (np->n_flink != NULL || *npp != NULL))
765 fprintf(stdout, "506 %s\n", cp);
766 else{
767 *npp = cat(*npp, np);
768 fprintf(stdout, "210 %s\n", cp);
770 }else if(!asccasecmp(cmd[2], cp = "Sender")){
771 mult_ok = FAL0;
772 npp = &hp->h_sender;
773 goto jins;
774 }else if(!asccasecmp(cmd[2], cp = "To")){
775 npp = &hp->h_to;
776 ntype = GTO | GFULL;
777 eacm = EACM_NORMAL | EAF_NAME;
778 goto jins;
779 }else if(!asccasecmp(cmd[2], cp = "Cc")){
780 npp = &hp->h_cc;
781 ntype = GCC | GFULL;
782 eacm = EACM_NORMAL | EAF_NAME;
783 goto jins;
784 }else if(!asccasecmp(cmd[2], cp = "Bcc")){
785 npp = &hp->h_bcc;
786 ntype = GCC | GFULL;
787 eacm = EACM_NORMAL | EAF_NAME;
788 goto jins;
789 }else if(!asccasecmp(cmd[2], cp = "Reply-To")){
790 npp = &hp->h_replyto;
791 goto jins;
792 }else if(!asccasecmp(cmd[2], cp = "Mail-Followup-To")){
793 npp = &hp->h_mft;
794 eacm = EACM_NONAME;
795 goto jins;
796 }else if(!asccasecmp(cmd[2], cp = "Message-ID")){
797 mult_ok = FAL0;
798 npp = &hp->h_message_id;
799 eacm = EACM_NONAME;
800 goto jins;
801 }else if(!asccasecmp(cmd[2], cp = "References")){
802 npp = &hp->h_ref;
803 ntype = GREF;
804 eacm = EACM_NONAME;
805 goto jins;
806 }else if(!asccasecmp(cmd[2], cp = "In-Reply-To")){
807 npp = &hp->h_in_reply_to;
808 ntype = GREF;
809 eacm = EACM_NONAME;
810 goto jins;
811 }else if(!asccasecmp(cmd[2], cp = "Subject")){
812 if(cmd[3][0] != '\0'){
813 if(hp->h_subject != NULL)
814 hp->h_subject = savecatsep(hp->h_subject, ' ', cmd[3]);
815 else
816 hp->h_subject = n_UNCONST(cmd[3]);
817 fprintf(stdout, "210 %s\n", cp);
818 }else
819 goto j501cp;
820 }else{
821 /* Primitive name normalization XXX header object should
822 * XXX have a more sophisticated accessible one */
823 size_t nl, bl;
824 struct n_header_field **hfpp;
826 for(cp = cmd[2]; *cp != '\0'; ++cp)
827 if(!fieldnamechar(*cp)){
828 cp = cmd[2];
829 goto j501cp;
832 for(hfpp = &hp->h_user_headers; *hfpp != NULL;)
833 hfpp = &(*hfpp)->hf_next;
835 nl = strlen(cp = cmd[2]);
836 bl = strlen(cmd[3]) +1;
837 *hfpp = hfp = salloc(n_VSTRUCT_SIZEOF(struct n_header_field, hf_dat
838 ) + nl +1 + bl);
839 hfp->hf_next = NULL;
840 hfp->hf_nl = nl;
841 hfp->hf_bl = bl - 1;
842 memcpy(hfp->hf_dat, cp, nl);
843 hfp->hf_dat[nl++] = '\0';
844 memcpy(hfp->hf_dat + nl, cmd[3], bl);
845 fprintf(stdout, "210 %s\n", cp);
847 }else
848 goto jecmd;
849 }else if(is_asccaseprefix(cmd[0], "attachment")){
850 bool_t status;
851 struct attachment *ap;
853 if(cmd[1] == NULL || is_asccaseprefix(cmd[1], "list")){
854 if(cmd[2] != NULL)
855 goto jecmd;
857 if((ap = hp->h_attach) != NULL){
858 fputs("212\n", stdout);
860 fprintf(stdout, "%s\n", ap->a_path_user);
861 while((ap = ap->a_flink) != NULL);
862 putc('\n', stdout);
863 }else
864 fputs("501\n", stdout);
865 }else if(is_asccaseprefix(cmd[1], "remove")){
866 if(cmd[2] == NULL || cmd[3] != NULL)
867 goto jecmd;
869 if((ap = n_attachment_find(hp->h_attach, cmd[2], &status)) != NULL){
870 if(status == TRUM1)
871 fputs("506\n", stdout);
872 else{
873 hp->h_attach = n_attachment_remove(hp->h_attach, ap);
874 fprintf(stdout, "210 %s\n", cmd[2]);
876 }else
877 fputs("501\n", stdout);
878 }else if(is_asccaseprefix(cmd[1], "remove-at")){
879 char *eptr;
880 long l;
882 if(cmd[2] == NULL || cmd[3] != NULL)
883 goto jecmd;
885 if((l = strtol(cmd[2], &eptr, 0)) <= 0 || *eptr != '\0')
886 fputs("505\n", stdout);
887 else{
888 for(ap = hp->h_attach; ap != NULL && --l != 0; ap = ap->a_flink)
890 if(ap != NULL){
891 hp->h_attach = n_attachment_remove(hp->h_attach, ap);
892 fprintf(stdout, "210 %s\n", cmd[2]);
893 }else
894 fputs("501\n", stdout);
896 }else if(is_asccaseprefix(cmd[1], "insert")){
897 enum n_attach_error aerr;
899 if(cmd[2] == NULL || cmd[3] != NULL)
900 goto jecmd;
902 hp->h_attach = n_attachment_append(hp->h_attach, cmd[2], &aerr, &ap);
903 switch(aerr){
904 case n_ATTACH_ERR_FILE_OPEN: cp = "505\n"; goto jatt_ins;
905 case n_ATTACH_ERR_ICONV_FAILED: cp = "506\n"; goto jatt_ins;
906 case n_ATTACH_ERR_ICONV_NAVAIL:
907 case n_ATTACH_ERR_OTHER:
908 default:
909 cp = "501\n";
910 jatt_ins:
911 fputs(cp, stdout);
912 break;
913 case n_ATTACH_ERR_NONE:{
914 size_t i;
916 for(i = 0; ap != NULL; ++i, ap = ap->a_blink)
918 fprintf(stdout, "210 %" PRIuZ "\n", i);
919 } break;
921 }else if(is_asccaseprefix(cmd[1], "attribute")){
922 if(cmd[2] == NULL || cmd[3] != NULL)
923 goto jecmd;
925 if((ap = n_attachment_find(hp->h_attach, cmd[2], NULL)) != NULL){
926 jatt_att:
927 fprintf(stdout, "212 %s\n", cmd[2]);
928 if(ap->a_msgno > 0)
929 fprintf(stdout, "message-number %d\n\n", ap->a_msgno);
930 else{
931 fprintf(stdout, "creation-name %s\nopen-path %s\nfilename %s\n",
932 ap->a_path_user, ap->a_path, ap->a_name);
933 if(ap->a_content_description != NULL)
934 fprintf(stdout, "content-description %s\n",
935 ap->a_content_description);
936 if(ap->a_content_id != NULL)
937 fprintf(stdout, "content-id %s\n", ap->a_content_id->n_name);
938 if(ap->a_content_type != NULL)
939 fprintf(stdout, "content-type %s\n", ap->a_content_type);
940 if(ap->a_content_disposition != NULL)
941 fprintf(stdout, "content-disposition %s\n",
942 ap->a_content_disposition);
943 putc('\n', stdout);
945 }else
946 fputs("501\n", stdout);
947 }else if(is_asccaseprefix(cmd[1], "attribute-at")){
948 char *eptr;
949 long l;
951 if(cmd[2] == NULL || cmd[3] != NULL)
952 goto jecmd;
954 if((l = strtol(cmd[2], &eptr, 0)) <= 0 || *eptr != '\0')
955 fputs("505\n", stdout);
956 else{
957 for(ap = hp->h_attach; ap != NULL && --l != 0; ap = ap->a_flink)
959 if(ap != NULL)
960 goto jatt_att;
961 else
962 fputs("501\n", stdout);
964 }else if(is_asccaseprefix(cmd[1], "attribute-set")){
965 if(cmd[2] == NULL || cmd[3] == NULL)
966 goto jecmd;
968 if((ap = n_attachment_find(hp->h_attach, cmd[2], NULL)) != NULL){
969 jatt_attset:
970 if(ap->a_msgno > 0)
971 fputs("505\n", stdout);
972 else{
973 char c, *keyw;
975 cp = cmd[3];
976 while((c = *cp) != '\0' && !blankchar(c))
977 ++cp;
978 keyw = savestrbuf(cmd[3], PTR2SIZE(cp - cmd[3]));
979 if(c != '\0'){
980 for(; (c = *++cp) != '\0' && blankchar(c);)
982 if(c != '\0'){
983 char *xp;
985 /* Strip [\r\n] which would render a parameter invalid XXX
986 * XXX all controls? */
987 cp = xp = savestr(cp);
988 for(; (c = *xp) != '\0'; ++xp)
989 if(c == '\n' || c == '\r')
990 *xp = ' ';
991 c = *cp;
995 if(!asccasecmp(keyw, "filename"))
996 ap->a_name = (c == '\0') ? ap->a_path_bname : cp;
997 else if(!asccasecmp(keyw, "content-description"))
998 ap->a_content_description = (c == '\0') ? NULL : cp;
999 else if(!asccasecmp(keyw, "content-id")){
1000 ap->a_content_id = NULL;
1002 if(c != '\0'){
1003 struct name *np;
1005 np = checkaddrs(lextract(cp, GREF),
1006 /*EACM_STRICT | TODO '/' valid!! */ EACM_NOLOG |
1007 EACM_NONAME, NULL);
1008 if(np != NULL && np->n_flink == NULL)
1009 ap->a_content_id = np;
1010 else
1011 cp = NULL;
1013 }else if(!asccasecmp(keyw, "content-type"))
1014 ap->a_content_type = (c == '\0') ? NULL : cp;
1015 else if(!asccasecmp(keyw, "content-disposition"))
1016 ap->a_content_disposition = (c == '\0') ? NULL : cp;
1017 else
1018 cp = NULL;
1020 if(cp != NULL){
1021 size_t i;
1023 for(i = 0; ap != NULL; ++i, ap = ap->a_blink)
1025 fprintf(stdout, "210 %" PRIuZ "\n", i);
1026 }else
1027 fputs("505\n", stdout);
1029 }else
1030 fputs("501\n", stdout);
1031 }else if(is_asccaseprefix(cmd[1], "attribute-set-at")){
1032 char *eptr;
1033 long l;
1035 if(cmd[2] == NULL || cmd[3] == NULL)
1036 goto jecmd;
1038 if((l = strtol(cmd[2], &eptr, 0)) <= 0 || *eptr != '\0')
1039 fputs("505\n", stdout);
1040 else{
1041 for(ap = hp->h_attach; ap != NULL && --l != 0; ap = ap->a_flink)
1043 if(ap != NULL)
1044 goto jatt_attset;
1045 else
1046 fputs("501\n", stdout);
1048 }else
1049 goto jecmd;
1050 }else{
1051 jecmd:
1052 fputs("500\n", stdout);
1053 ms = NULL;
1056 jleave:
1057 fflush(stdout);
1058 NYD2_LEAVE;
1059 return (ms != NULL);
1061 j501cp:
1062 fputs("501 ", stdout);
1063 fputs(cp, stdout);
1064 putc('\n', stdout);
1065 goto jleave;
1068 static void
1069 _collint(int s)
1071 NYD_X; /* Signal handler */
1073 /* the control flow is subtle, because we can be called from ~q */
1074 if (_coll_hadintr == 0) {
1075 if (ok_blook(ignore)) {
1076 fputs("@\n", stdout);
1077 fflush(stdout);
1078 clearerr(stdin);
1079 } else
1080 _coll_hadintr = 1;
1081 siglongjmp(_coll_jmp, 1);
1083 exit_status |= EXIT_SEND_ERROR;
1084 if (s != 0)
1085 savedeadletter(_coll_fp, TRU1);
1086 /* Aborting message, no need to fflush() .. */
1087 siglongjmp(_coll_abort, 1);
1090 static void
1091 collhup(int s)
1093 NYD_X; /* Signal handler */
1094 n_UNUSED(s);
1096 savedeadletter(_coll_fp, TRU1);
1097 /* Let's pretend nobody else wants to clean up, a true statement at
1098 * this time */
1099 exit(EXIT_ERR);
1102 static int
1103 putesc(char const *s, FILE *stream)
1105 int n = 0, rv = -1;
1106 NYD_ENTER;
1108 while (s[0] != '\0') {
1109 if (s[0] == '\\') {
1110 if (s[1] == 't') {
1111 if (putc('\t', stream) == EOF)
1112 goto jleave;
1113 ++n;
1114 s += 2;
1115 continue;
1117 if (s[1] == 'n') {
1118 if (putc('\n', stream) == EOF)
1119 goto jleave;
1120 ++n;
1121 s += 2;
1122 continue;
1125 if (putc(s[0], stream) == EOF)
1126 goto jleave;
1127 ++n;
1128 ++s;
1130 if (putc('\n', stream) == EOF)
1131 goto jleave;
1132 rv = ++n;
1133 jleave:
1134 NYD_LEAVE;
1135 return rv;
1138 static void
1139 a_coll__hook_setter(void *arg){ /* TODO v15: drop */
1140 struct header *hp;
1141 char const *val;
1142 NYD2_ENTER;
1144 hp = arg;
1146 if((val = detract(hp->h_from, GNAMEONLY)) == NULL)
1147 val = n_empty;
1148 ok_vset(compose_from, val);
1149 if((val = detract(hp->h_sender, 0)) == NULL)
1150 val = n_empty;
1151 ok_vset(compose_sender, val);
1152 if((val = detract(hp->h_to, GNAMEONLY)) == NULL)
1153 val = n_empty;
1154 ok_vset(compose_to, val);
1155 if((val = detract(hp->h_cc, GNAMEONLY)) == NULL)
1156 val = n_empty;
1157 ok_vset(compose_cc, val);
1158 if((val = detract(hp->h_bcc, GNAMEONLY)) == NULL)
1159 val = n_empty;
1160 ok_vset(compose_bcc, val);
1161 if((val = hp->h_subject) == NULL)
1162 val = n_empty;
1163 ok_vset(compose_subject, val);
1164 NYD2_LEAVE;
1167 static int
1168 a_coll_ocds__mac(void){
1169 /* Executes in a fork(2)ed child */
1170 setvbuf(stdout, NULL, _IOLBF, 0);
1171 options &= ~(OPT_TTYIN | OPT_TTYOUT | OPT_INTERACTIVE);
1172 pstate |= PS_COMPOSE_FORKHOOK;
1173 temporary_call_compose_mode_hook(a_coll_ocds__macname, NULL, NULL);
1174 _exit(EXIT_OK);
1177 static void
1178 a_coll_ocds__finalize(void *vp){
1179 /* Note we use this for destruction upon setup errors, thus */
1180 sighandler_type opipe;
1181 sighandler_type oint;
1182 struct a_coll_ocds_arg **coapp, *coap;
1183 NYD2_ENTER;
1185 temporary_call_compose_mode_hook((char*)-1, NULL, NULL);
1187 coap = *(coapp = vp);
1188 *coapp = (struct a_coll_ocds_arg*)-1;
1190 if(coap->coa_stdout != NULL)
1191 if(!Pclose(coap->coa_stdout, FAL0)){
1192 *coap->coa_senderr = TRU1;
1193 n_err(_("*on-compose-done(-shell)?* failed: %s\n"),
1194 n_shexp_quote_cp(coap->coa_cmd, FAL0));
1197 if(coap->coa_stdin != NULL)
1198 Fclose(coap->coa_stdin);
1199 else if(coap->coa_pipe[0] != -1)
1200 close(coap->coa_pipe[0]);
1202 if(coap->coa_pipe[1] != -1)
1203 close(coap->coa_pipe[1]);
1205 opipe = coap->coa_opipe;
1206 oint = coap->coa_oint;
1208 n_lofi_free(coap);
1210 hold_all_sigs();
1211 safe_signal(SIGPIPE, opipe);
1212 safe_signal(SIGINT, oint);
1213 rele_all_sigs();
1214 NYD2_LEAVE;
1217 FL FILE *
1218 collect(struct header *hp, int printheaders, struct message *mp,
1219 char *quotefile, int doprefix, si8_t *checkaddr_err)
1221 struct n_ignore const *quoteitp;
1222 struct a_coll_ocds_arg *coap;
1223 int lc, cc, c;
1224 int volatile t, eofcnt, getfields;
1225 char *linebuf, escape_saved, escape;
1226 char const *cp, *coapm;
1227 size_t i, linesize; /* TODO line pool */
1228 long cnt;
1229 enum sendaction action;
1230 sigset_t oset, nset;
1231 FILE * volatile sigfp;
1232 NYD_ENTER;
1234 _coll_fp = NULL;
1235 sigfp = NULL;
1236 linesize = 0;
1237 linebuf = NULL;
1238 eofcnt = 0;
1239 coapm = NULL;
1240 coap = NULL;
1242 /* Start catching signals from here, but we're still die on interrupts
1243 * until we're in the main loop */
1244 sigfillset(&nset);
1245 sigprocmask(SIG_BLOCK, &nset, &oset);
1246 /* FIXME have dropped handlerpush() and localized onintr() in lex.c! */
1247 if ((_coll_saveint = safe_signal(SIGINT, SIG_IGN)) != SIG_IGN)
1248 safe_signal(SIGINT, &_collint);
1249 if ((_coll_savehup = safe_signal(SIGHUP, SIG_IGN)) != SIG_IGN)
1250 safe_signal(SIGHUP, collhup);
1251 if (sigsetjmp(_coll_abort, 1))
1252 goto jerr;
1253 if (sigsetjmp(_coll_jmp, 1))
1254 goto jerr;
1255 pstate |= PS_COMPOSE_MODE;
1256 sigprocmask(SIG_SETMASK, &oset, (sigset_t*)NULL);
1258 if ((_coll_fp = Ftmp(NULL, "collect", OF_RDWR | OF_UNLINK | OF_REGISTER)) ==
1259 NULL) {
1260 n_perr(_("temporary mail file"), 0);
1261 goto jerr;
1264 /* If we are going to prompt for a subject, refrain from printing a newline
1265 * after the headers (since some people mind) */
1266 getfields = 0;
1267 if (!(options & OPT_t_FLAG)) {
1268 t = GTO | GSUBJECT | GCC | GNL;
1269 if (ok_blook(fullnames))
1270 t |= GCOMMA;
1272 if (options & OPT_INTERACTIVE) {
1273 if (hp->h_subject == NULL && (ok_blook(ask) || ok_blook(asksub)))
1274 t &= ~GNL, getfields |= GSUBJECT;
1276 if (hp->h_to == NULL)
1277 t &= ~GNL, getfields |= GTO;
1279 if (!ok_blook(bsdcompat) && !ok_blook(askatend)) {
1280 if (hp->h_bcc == NULL && ok_blook(askbcc))
1281 t &= ~GNL, getfields |= GBCC;
1282 if (hp->h_cc == NULL && ok_blook(askcc))
1283 t &= ~GNL, getfields |= GCC;
1286 } else {
1287 n_UNINIT(t, 0);
1290 escape_saved = escape = ((cp = ok_vlook(escape)) != NULL) ? *cp : n_ESCAPE;
1291 _coll_hadintr = 0;
1293 if (!sigsetjmp(_coll_jmp, 1)) {
1294 /* Ask for some headers first, as necessary */
1295 if (getfields)
1296 grab_headers(n_LEXINPUT_CTX_COMPOSE, hp, getfields, 1);
1298 /* Execute compose-enter TODO completely v15-compat intermediate!! */
1299 if((cp = ok_vlook(on_compose_enter)) != NULL){
1300 setup_from_and_sender(hp);
1301 temporary_call_compose_mode_hook(cp, &a_coll__hook_setter, hp);
1304 /* Cannot do since it may require turning this into a multipart one */
1305 if(!(options & OPT_Mm_FLAG)){
1306 char const *cp_obsolete = ok_vlook(NAIL_HEAD);
1307 if(cp_obsolete != NULL)
1308 OBSOLETE(_("please use *message-inject-head* "
1309 "instead of *NAIL_HEAD*"));
1311 if(((cp = ok_vlook(message_inject_head)) != NULL ||
1312 (cp = cp_obsolete) != NULL) && putesc(cp, _coll_fp) < 0)
1313 goto jerr;
1315 /* Quote an original message */
1316 if (mp != NULL && (doprefix || (cp = ok_vlook(quote)) != NULL)) {
1317 quoteitp = n_IGNORE_ALL;
1318 action = SEND_QUOTE;
1319 if (doprefix) {
1320 quoteitp = n_IGNORE_FWD;
1321 if ((cp = ok_vlook(fwdheading)) == NULL)
1322 cp = "-------- Original Message --------";
1323 if (*cp != '\0' && fprintf(_coll_fp, "%s\n", cp) < 0)
1324 goto jerr;
1325 } else if (!strcmp(cp, "noheading")) {
1326 /*EMPTY*/;
1327 } else if (!strcmp(cp, "headers")) {
1328 quoteitp = n_IGNORE_TYPE;
1329 } else if (!strcmp(cp, "allheaders")) {
1330 quoteitp = NULL;
1331 action = SEND_QUOTE_ALL;
1332 } else {
1333 cp = hfield1("from", mp);
1334 if (cp != NULL && (cnt = (long)strlen(cp)) > 0) {
1335 if (xmime_write(cp, cnt, _coll_fp, CONV_FROMHDR, TD_NONE) < 0)
1336 goto jerr;
1337 if (fprintf(_coll_fp, _(" wrote:\n\n")) < 0)
1338 goto jerr;
1341 if (fflush(_coll_fp))
1342 goto jerr;
1343 if (doprefix)
1344 cp = NULL;
1345 else if ((cp = ok_vlook(indentprefix)) == NULL)
1346 cp = INDENT_DEFAULT;
1347 if (sendmp(mp, _coll_fp, quoteitp, cp, action, NULL) < 0)
1348 goto jerr;
1352 if (quotefile != NULL) {
1353 if (_include_file(quotefile, &lc, &cc, FAL0) != 0)
1354 goto jerr;
1357 if ((options & (OPT_Mm_FLAG | OPT_INTERACTIVE)) == OPT_INTERACTIVE) {
1358 /* Print what we have sofar also on the terminal (if useful) */
1359 if (!ok_blook(editalong)) {
1360 if (printheaders)
1361 puthead(TRU1, hp, stdout, t, SEND_TODISP, CONV_NONE, NULL, NULL);
1363 rewind(_coll_fp);
1364 while ((c = getc(_coll_fp)) != EOF) /* XXX bytewise, yuck! */
1365 putc(c, stdout);
1366 if (fseek(_coll_fp, 0, SEEK_END))
1367 goto jerr;
1368 } else {
1369 rewind(_coll_fp);
1370 mesedit('e', hp);
1371 /* As mandated by the Mail Reference Manual, print "(continue)" */
1372 jcont:
1373 if(options & OPT_INTERACTIVE)
1374 fputs(_("(continue)\n"), stdout);
1376 fflush(stdout);
1378 } else {
1379 /* Come here for printing the after-signal message. Duplicate messages
1380 * won't be printed because the write is aborted if we get a SIGTTOU */
1381 if (_coll_hadintr)
1382 n_err(_("\n(Interrupt -- one more to kill letter)\n"));
1385 /* If not under shell hook control */
1386 if(coap == NULL){
1387 /* We're done with -M or -m (because we are too simple minded) */
1388 if(options & OPT_Mm_FLAG)
1389 goto jout;
1390 /* No command escapes, interrupts not expected. Simply copy STDIN */
1391 if (!(options & (OPT_INTERACTIVE | OPT_t_FLAG | OPT_TILDE_FLAG))){
1392 linebuf = srealloc(linebuf, linesize = LINESIZE);
1393 while ((i = fread(linebuf, sizeof *linebuf, linesize, stdin)) > 0) {
1394 if (i != fwrite(linebuf, sizeof *linebuf, i, _coll_fp))
1395 goto jerr;
1397 goto jout;
1401 /* The interactive collect loop */
1402 for(;;){
1403 /* C99 */{
1404 enum n_lexinput_flags lif;
1406 lif = n_LEXINPUT_CTX_COMPOSE;
1407 if(options & (OPT_INTERACTIVE | OPT_TILDE_FLAG)){
1408 if(!(options & OPT_t_FLAG))
1409 lif |= n_LEXINPUT_NL_ESC;
1411 cnt = n_lex_input(lif, n_empty, &linebuf, &linesize, NULL);
1414 if (cnt < 0) {
1415 if(coap != NULL)
1416 break;
1417 if (options & OPT_t_FLAG) {
1418 fflush_rewind(_coll_fp);
1419 /* It is important to set PS_t_FLAG before extract_header() *and*
1420 * keep OPT_t_FLAG for the first parse of the message, too! */
1421 pstate |= PS_t_FLAG;
1422 if (makeheader(_coll_fp, hp, checkaddr_err) != OKAY)
1423 goto jerr;
1424 options &= ~OPT_t_FLAG;
1425 continue;
1426 } else if ((options & OPT_INTERACTIVE) &&
1427 ok_blook(ignoreeof) && ++eofcnt < 4) {
1428 printf(_("*ignoreeof* set, use `~.' to terminate letter\n"));
1429 continue;
1431 break;
1434 _coll_hadintr = 0;
1436 cp = linebuf;
1437 if(cnt == 0)
1438 goto jputnl;
1439 else if(coap == NULL){
1440 if(!(options & (OPT_INTERACTIVE | OPT_TILDE_FLAG)))
1441 goto jputline;
1442 else if(cp[0] == '.'){
1443 if(cnt == 1 && (ok_blook(dot) || ok_blook(ignoreeof)))
1444 break;
1447 if(cp[0] != escape){
1448 jputline:
1449 if(fwrite(cp, sizeof *cp, cnt, _coll_fp) != (size_t)cnt)
1450 goto jerr;
1451 /* TODO PS_READLINE_NL is a terrible hack to ensure that _in_all_-
1452 * TODO _code_paths_ a file without trailing newline isn't modified
1453 * TODO to continue one; the "saw-newline" needs to be part of an
1454 * TODO I/O input machinery object */
1455 jputnl:
1456 if(pstate & PS_READLINE_NL){
1457 if(putc('\n', _coll_fp) == EOF)
1458 goto jerr;
1460 continue;
1463 /* Cleanup the input string: like this we can perform a little bit of
1464 * usage testing and also have somewhat normalized history entries */
1465 for(cp = &linebuf[2]; (c = *cp) != '\0' && blankspacechar(c); ++cp)
1466 continue;
1467 if(c == '\0'){
1468 linebuf[2] = '\0';
1469 cnt = 2;
1470 }else{
1471 i = PTR2SIZE(cp - linebuf) - 3;
1472 memmove(&linebuf[3], cp, (cnt -= i));
1473 linebuf[2] = ' ';
1474 linebuf[cnt] = '\0';
1476 if(cnt > 0){ /* TODO v15 no more trailing WS from lex_input please */
1477 cp = &linebuf[cnt];
1479 for(;; --cp){
1480 c = cp[-1];
1481 if(!blankspacechar(c))
1482 break;
1484 ((char*)n_UNCONST(cp))[0] = '\0';
1485 cnt = PTR2SIZE(cp - linebuf);
1489 switch((c = linebuf[1])){
1490 default:
1491 /* On double escape, send a single one. Otherwise, it's an error */
1492 if(c == escape){
1493 cp = &linebuf[1];
1494 --cnt;
1495 goto jputline;
1496 }else{
1497 char buf[sizeof(n_UNIREPL)];
1499 if(asciichar(c))
1500 buf[0] = c, buf[1] = '\0';
1501 else if(options & OPT_UNICODE)
1502 memcpy(buf, n_unirepl, sizeof n_unirepl);
1503 else
1504 buf[0] = '?', buf[1] = '\0';
1505 n_err(_("Unknown command escape: ~%s\n"), buf);
1506 continue;
1508 jearg:
1509 n_err(_("Invalid command escape usage: %s\n"), linebuf);
1510 continue;
1511 case '!':
1512 /* Shell escape, send the balance of line to sh -c */
1513 if(cnt == 2 || coap != NULL)
1514 goto jearg;
1515 c_shell(&linebuf[3]);
1516 goto jhistcont;
1517 case ':':
1518 /* FALLTHRU */
1519 case '_':
1520 /* Escape to command mode, but be nice! *//* TODO command expansion
1521 * TODO should be handled here so that we have unique history! */
1522 if(cnt == 2)
1523 goto jearg;
1524 _execute_command(hp, &linebuf[3], cnt -= 3);
1525 break;
1526 case '.':
1527 /* Simulate end of file on input */
1528 if(cnt != 2 || coap != NULL)
1529 goto jearg;
1530 goto jout;
1531 case 'x':
1532 /* Same as 'q', but no *DEAD* saving */
1533 /* FALLTHRU */
1534 case 'q':
1535 /* Force a quit, act like an interrupt had happened */
1536 if(cnt != 2)
1537 goto jearg;
1538 ++_coll_hadintr;
1539 _collint((c == 'x') ? 0 : SIGINT);
1540 exit(EXIT_ERR);
1541 /*NOTREACHED*/
1542 case 'h':
1543 /* Grab a bunch of headers */
1544 if(cnt != 2)
1545 goto jearg;
1547 grab_headers(n_LEXINPUT_CTX_COMPOSE, hp,
1548 (GTO | GSUBJECT | GCC | GBCC),
1549 (ok_blook(bsdcompat) && ok_blook(bsdorder)));
1550 while(hp->h_to == NULL);
1551 break;
1552 case 'H':
1553 /* Grab extra headers */
1554 if(cnt != 2)
1555 goto jearg;
1557 grab_headers(n_LEXINPUT_CTX_COMPOSE, hp, GEXTRA, 0);
1558 while(check_from_and_sender(hp->h_from, hp->h_sender) == NULL);
1559 break;
1560 case 't':
1561 /* Add to the To: list */
1562 if(cnt == 2)
1563 goto jearg;
1564 hp->h_to = cat(hp->h_to,
1565 checkaddrs(lextract(&linebuf[3], GTO | GFULL), EACM_NORMAL,
1566 NULL));
1567 break;
1568 case 's':
1569 /* Set the Subject list */
1570 if(cnt == 2)
1571 goto jearg;
1572 /* Subject:; take care for Debian #419840 and strip any \r and \n */
1573 if(n_anyof_cp("\n\r", hp->h_subject = savestr(&linebuf[3]))){
1574 char *xp;
1576 n_err(_("-s: normalizing away invalid ASCII NL / CR bytes\n"));
1577 for(xp = hp->h_subject; *xp != '\0'; ++xp)
1578 if(*xp == '\n' || *xp == '\r')
1579 *xp = ' ';
1581 break;
1582 case '@':{
1583 struct attachment *aplist;
1585 /* Edit the attachment list */
1586 aplist = hp->h_attach;
1587 hp->h_attach = NULL;
1588 if(cnt != 2)
1589 hp->h_attach = n_attachment_append_list(aplist, &linebuf[3]);
1590 else
1591 hp->h_attach = n_attachment_list_edit(aplist,
1592 n_LEXINPUT_CTX_COMPOSE);
1593 } break;
1594 case 'c':
1595 /* Add to the CC list */
1596 if(cnt == 2)
1597 goto jearg;
1598 hp->h_cc = cat(hp->h_cc,
1599 checkaddrs(lextract(&linebuf[3], GCC | GFULL), EACM_NORMAL,
1600 NULL));
1601 break;
1602 case 'b':
1603 /* Add stuff to blind carbon copies list */
1604 if(cnt == 2)
1605 goto jearg;
1606 hp->h_bcc = cat(hp->h_bcc,
1607 checkaddrs(lextract(&linebuf[3], GBCC | GFULL), EACM_NORMAL,
1608 NULL));
1609 break;
1610 case 'd':
1611 if(cnt != 2)
1612 goto jearg;
1613 cp = n_getdeadletter();
1614 if(0){
1615 /*FALLTHRU*/
1616 case 'R':
1617 case 'r':
1618 case '<':
1619 /* Invoke a file: Search for the file name, then open it and copy
1620 * the contents to _coll_fp */
1621 if(cnt == 2){
1622 n_err(_("Interpolate what file?\n"));
1623 break;
1625 if(*(cp = &linebuf[3]) == '!'){
1626 insertcommand(_coll_fp, ++cp);
1627 goto jhistcont;
1629 if((cp = fexpand(cp, FEXP_LOCAL | FEXP_NOPROTO)) == NULL)
1630 break;
1632 if(is_dir(cp)){
1633 n_err(_("%s: is a directory\n"), n_shexp_quote_cp(cp, FAL0));
1634 break;
1636 if(_include_file(cp, &lc, &cc, (c == 'R')) != 0){
1637 if(ferror(_coll_fp))
1638 goto jerr;
1639 break;
1641 printf(_("%s %d/%d\n"), n_shexp_quote_cp(cp, FAL0), lc, cc);
1642 break;
1643 case 'i':
1644 /* Insert a variable into the file */
1645 if(cnt == 2)
1646 goto jearg;
1647 if((cp = vok_vlook(&linebuf[3])) == NULL || *cp == '\0')
1648 break;
1649 if(putesc(cp, _coll_fp) < 0) /* TODO v15: user resp upon `set' time */
1650 goto jerr;
1651 if((options & OPT_INTERACTIVE) && putesc(cp, stdout) < 0)
1652 goto jerr;
1653 break;
1654 case 'a':
1655 case 'A':
1656 /* Insert the contents of a signature variable */
1657 if(cnt != 2)
1658 goto jearg;
1659 cp = (c == 'a') ? ok_vlook(sign) : ok_vlook(Sign);
1660 if(cp != NULL && *cp != '\0'){
1661 if(putesc(cp, _coll_fp) < 0) /* TODO v15: user upon `set' time */
1662 goto jerr;
1663 if((options & OPT_INTERACTIVE) && putesc(cp, stdout) < 0)
1664 goto jerr;
1666 break;
1667 case 'w':
1668 /* Write the message on a file */
1669 if(cnt == 2)
1670 goto jearg;
1671 if((cp = fexpand(&linebuf[3], FEXP_LOCAL | FEXP_NOPROTO)) == NULL){
1672 n_err(_("Write what file!?\n"));
1673 break;
1675 rewind(_coll_fp);
1676 if(exwrite(cp, _coll_fp, 1) < 0)
1677 goto jerr;
1678 break;
1679 case 'm':
1680 case 'M':
1681 case 'f':
1682 case 'F':
1683 case 'u':
1684 case 'U':
1685 /* Interpolate the named messages, if we are in receiving mail mode.
1686 * Does the standard list processing garbage. If ~f is given, we
1687 * don't shift over */
1688 if(cnt == 2)
1689 goto jearg;
1690 if(forward(&linebuf[3], _coll_fp, c) < 0)
1691 break;
1692 break;
1693 case 'p':
1694 /* Print current state of the message without altering anything */
1695 if(cnt != 2)
1696 goto jearg;
1697 print_collf(_coll_fp, hp);
1698 break;
1699 case '|':
1700 /* Pipe message through command. Collect output as new message */
1701 if(cnt == 2)
1702 goto jearg;
1703 rewind(_coll_fp);
1704 mespipe(&linebuf[3]);
1705 goto jhistcont;
1706 case 'v':
1707 case 'e':
1708 /* Edit the current message. 'e' -> use EDITOR, 'v' -> use VISUAL */
1709 if(cnt != 2 || coap != NULL)
1710 goto jearg;
1711 rewind(_coll_fp);
1712 mesedit(c, ok_blook(editheaders) ? hp : NULL);
1713 goto jhistcont;
1714 case '^':
1715 if(!a_collect_plumbing(&linebuf[3], hp))
1716 goto jearg;
1717 if(options & OPT_INTERACTIVE)
1718 break;
1719 continue;
1720 case '?':
1721 /* Last the lengthy help string. (Very ugly, but take care for
1722 * compiler supported string lengths :() */
1723 puts(_(
1724 "COMMAND ESCAPES (to be placed after a newline) excerpt:\n"
1725 "~. Commit and send message\n"
1726 "~: <command> Execute a mail command\n"
1727 "~<! <command> Insert output of command\n"
1728 "~@ [<files>] Edit attachment list\n"
1729 "~A Insert *Sign* variable (`~a': insert *sign*)\n"
1730 "~c <users> Add users to Cc: list (`~b': to Bcc:)\n"
1731 "~d Read in $DEAD (dead.letter)\n"
1732 "~e Edit message via $EDITOR"
1734 puts(_(
1735 "~F <msglist> Read in with headers, don't *indentprefix* lines\n"
1736 "~f <msglist> Like ~F, but honour `ignore' / `retain' configuration\n"
1737 "~H Edit From:, Reply-To: and Sender:\n"
1738 "~h Prompt for Subject:, To:, Cc: and \"blind\" Bcc:\n"
1739 "~i <variable> Insert a value and a newline\n"
1740 "~M <msglist> Read in with headers, *indentprefix* (`~m': `retain' etc.)\n"
1741 "~p Show current message compose buffer\n"
1742 "~r <file> Read in a file (`~<': likewise; `~R': *indentprefix* lines)"
1744 puts(_(
1745 "~s <subject> Set Subject:\n"
1746 "~t <users> Add users to To: list\n"
1747 "~u <msglist> Read in message(s) without headers (`~U': indent lines)\n"
1748 "~v Edit message via $VISUAL\n"
1749 "~w <file> Write message onto file\n"
1750 "~x Abort composition, discard message (`~q': save in $DEAD)\n"
1751 "~| <command> Pipe message through shell filter"
1753 if(cnt != 2)
1754 goto jearg;
1755 break;
1758 /* Finally place an entry in history as applicable */
1759 if(0){
1760 jhistcont:
1761 c = '\1';
1762 }else
1763 c = '\0';
1764 if(options & OPT_INTERACTIVE)
1765 n_tty_addhist(linebuf, TRU1);
1766 if(c != '\0')
1767 goto jcont;
1770 jout:
1771 /* Do we have *on-compose-done-shell*, or *on-compose-done*?
1772 * TODO Usual f...ed up state of signals and terminal etc. */
1773 if(coap == NULL && (cp = ok_vlook(on_compose_done_shell)) != NULL) Jocds:{
1774 union {int (*ptf)(void); char const *sh;} u;
1775 char const *cmd;
1777 /* Reset *escape* to be available and guaranteed! */
1778 escape = n_ESCAPE;
1780 if(coapm != NULL){
1781 u.ptf = &a_coll_ocds__mac;
1782 cmd = (char*)-1;
1783 a_coll_ocds__macname = cp = coapm;
1784 }else{
1785 u.sh = ok_vlook(SHELL);
1786 cmd = cp;
1789 i = strlen(cp) +1;
1790 coap = n_lofi_alloc(n_VSTRUCT_SIZEOF(struct a_coll_ocds_arg, coa_cmd
1791 ) + i);
1792 coap->coa_pipe[0] = coap->coa_pipe[1] = -1;
1793 coap->coa_stdin = coap->coa_stdout = NULL;
1794 coap->coa_senderr = checkaddr_err;
1795 memcpy(coap->coa_cmd, cp, i);
1797 hold_all_sigs();
1798 coap->coa_opipe = safe_signal(SIGPIPE, SIG_IGN);
1799 coap->coa_oint = safe_signal(SIGINT, SIG_IGN);
1800 rele_all_sigs();
1802 if(pipe_cloexec(coap->coa_pipe) != -1 &&
1803 (coap->coa_stdin = Fdopen(coap->coa_pipe[0], "r", FAL0)) != NULL &&
1804 (coap->coa_stdout = Popen(cmd, "W", u.sh, NULL, coap->coa_pipe[1])
1805 ) != NULL){
1806 close(coap->coa_pipe[1]);
1807 coap->coa_pipe[1] = -1;
1809 temporary_call_compose_mode_hook(NULL, NULL, NULL);
1810 n_source_slice_hack(coap->coa_cmd, coap->coa_stdin, coap->coa_stdout,
1811 (options & ~(OPT_TTYIN | OPT_TTYOUT | OPT_INTERACTIVE)),
1812 &a_coll_ocds__finalize, &coap);
1813 /* Hook version protocol for ~^: update manual upon change! */
1814 fputs(a_COLL_PLUMBING_VERSION "\n", coap->coa_stdout);
1815 #undef a_COLL_PLUMBING_VERSION
1816 goto jcont;
1819 c = errno;
1820 a_coll_ocds__finalize(coap);
1821 n_perr(_("Cannot invoke *on-compose-done(-shell)?*"), c);
1822 goto jerr;
1824 if(*checkaddr_err != 0){
1825 *checkaddr_err = 0;
1826 goto jerr;
1828 if(coapm == NULL && (coapm = ok_vlook(on_compose_done)) != NULL)
1829 goto Jocds;
1830 escape = escape_saved;
1832 /* Final chance to edit headers, if not already above */
1833 if (ok_blook(bsdcompat) || ok_blook(askatend)) {
1834 if (hp->h_cc == NULL && ok_blook(askcc))
1835 grab_headers(n_LEXINPUT_CTX_COMPOSE, hp, GCC, 1);
1836 if (hp->h_bcc == NULL && ok_blook(askbcc))
1837 grab_headers(n_LEXINPUT_CTX_COMPOSE, hp, GBCC, 1);
1839 if (hp->h_attach == NULL && ok_blook(askattach))
1840 hp->h_attach = n_attachment_list_edit(hp->h_attach,
1841 n_LEXINPUT_CTX_COMPOSE);
1843 /* Add automatic receivers */
1844 if ((cp = ok_vlook(autocc)) != NULL && *cp != '\0')
1845 hp->h_cc = cat(hp->h_cc, checkaddrs(lextract(cp, GCC | GFULL),
1846 EACM_NORMAL, checkaddr_err));
1847 if ((cp = ok_vlook(autobcc)) != NULL && *cp != '\0')
1848 hp->h_bcc = cat(hp->h_bcc, checkaddrs(lextract(cp, GBCC | GFULL),
1849 EACM_NORMAL, checkaddr_err));
1850 if (*checkaddr_err != 0)
1851 goto jerr;
1853 /* Execute compose-leave */
1854 if((cp = ok_vlook(on_compose_leave)) != NULL){
1855 setup_from_and_sender(hp);
1856 temporary_call_compose_mode_hook(cp, &a_coll__hook_setter, hp);
1859 /* TODO Cannot do since it may require turning this into a multipart one */
1860 if(options & OPT_Mm_FLAG)
1861 goto jskiptails;
1863 /* Place signature? */
1864 if((cp = ok_vlook(signature)) != NULL && *cp != '\0'){
1865 char const *cpq;
1867 if((cpq = fexpand(cp, FEXP_LOCAL | FEXP_NOPROTO)) == NULL){
1868 n_err(_("*signature* expands to invalid file: %s\n"),
1869 n_shexp_quote_cp(cp, FAL0));
1870 goto jerr;
1872 cpq = n_shexp_quote_cp(cp = cpq, FAL0);
1874 if((sigfp = Fopen(cp, "r")) == NULL){
1875 n_err(_("Can't open *signature* %s: %s\n"), cpq, strerror(errno));
1876 goto jerr;
1879 if(linebuf == NULL)
1880 linebuf = smalloc(linesize = LINESIZE);
1881 c = '\0';
1882 while((i = fread(linebuf, sizeof *linebuf, linesize, n_UNVOLATILE(sigfp)))
1883 > 0){
1884 c = linebuf[i - 1];
1885 if(i != fwrite(linebuf, sizeof *linebuf, i, _coll_fp))
1886 goto jerr;
1889 /* C99 */{
1890 FILE *x = n_UNVOLATILE(sigfp);
1891 int e = errno, ise = ferror(x);
1893 sigfp = NULL;
1894 Fclose(x);
1896 if(ise){
1897 n_err(_("Errors while reading *signature* %s: %s\n"),
1898 cpq, strerror(e));
1899 goto jerr;
1903 if(c != '\0' && c != '\n')
1904 putc('\n', _coll_fp);
1907 { char const *cp_obsolete = ok_vlook(NAIL_TAIL);
1909 if(cp_obsolete != NULL)
1910 OBSOLETE(_("please use *message-inject-tail* instead of *NAIL_TAIL*"));
1912 if((cp = ok_vlook(message_inject_tail)) != NULL ||
1913 (cp = cp_obsolete) != NULL){
1914 if(putesc(cp, _coll_fp) < 0)
1915 goto jerr;
1916 if((options & OPT_INTERACTIVE) && putesc(cp, stdout) < 0)
1917 goto jerr;
1921 jskiptails:
1922 if(fflush(_coll_fp))
1923 goto jerr;
1924 rewind(_coll_fp);
1926 jleave:
1927 if (linebuf != NULL)
1928 free(linebuf);
1929 sigfillset(&nset);
1930 sigprocmask(SIG_BLOCK, &nset, NULL);
1931 pstate &= ~PS_COMPOSE_MODE;
1932 safe_signal(SIGINT, _coll_saveint);
1933 safe_signal(SIGHUP, _coll_savehup);
1934 sigprocmask(SIG_SETMASK, &oset, NULL);
1935 NYD_LEAVE;
1936 return _coll_fp;
1938 jerr:
1939 if(coap != NULL && coap != (struct a_coll_ocds_arg*)-1)
1940 n_source_slice_hack_remove_after_jump();
1941 if(sigfp != NULL)
1942 Fclose(n_UNVOLATILE(sigfp));
1943 if (_coll_fp != NULL) {
1944 Fclose(_coll_fp);
1945 _coll_fp = NULL;
1947 assert(checkaddr_err != NULL);
1948 /* TODO We don't save in $DEAD upon error because msg not readily composed?
1949 * TODO But this no good, it should go ZOMBIE / DRAFT / POSTPONED or what! */
1950 if(*checkaddr_err != 0)
1951 n_err(_("Some addressees were classified as \"hard error\"\n"));
1952 else if(_coll_hadintr == 0){
1953 *checkaddr_err = TRU1; /* TODO ugly: "sendout_error" now.. */
1954 n_err(_("Failed to prepare composed message (I/O error, disk full?)\n"));
1956 goto jleave;
1959 /* s-it-mode */