Change *on-compose-{enter,leave}* environment + fixes..
[s-mailx.git] / collect.c
blob1e42c772dc590c7ca6a573f26ffdbf112a817be2
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_ocs_arg{
44 sighandler_type coa_opipe;
45 sighandler_type coa_oint;
46 FILE *coa_stdin; /* The descriptor (pipe(2)+Fdopen()) we read from */
47 FILE *coa_stdout; /* The Popen()ed pipe through which we write to the hook */
48 int coa_pipe[2]; /* ..backing .coa_stdin */
49 si8_t *coa_senderr; /* Set to 1 on failure */
50 char coa_cmd[n_VFIELD_SIZE(0)];
53 /* The following hookiness with global variables is so that on receipt of an
54 * interrupt signal, the partial message can be salted away on *DEAD* */
56 static sighandler_type _coll_saveint; /* Previous SIGINT value */
57 static sighandler_type _coll_savehup; /* Previous SIGHUP value */
58 static FILE *_coll_fp; /* File for saving away */
59 static int volatile _coll_hadintr; /* Have seen one SIGINT so far */
60 static sigjmp_buf _coll_jmp; /* To get back to work */
61 static sigjmp_buf _coll_abort; /* To end collection with error */
62 static char const *a_coll_ocs__macname; /* *on-compose-splice* */
64 /* Handle `~:', `~_' and some hooks; hp may be NULL */
65 static void _execute_command(struct header *hp, char const *linebuf,
66 size_t linesize);
68 /* Return errno */
69 static si32_t a_coll_include_file(char const *name, bool_t indent,
70 bool_t writestat);
72 /* Execute cmd and insert its standard output into fp, return errno */
73 static si32_t a_coll_insert_cmd(FILE *fp, char const *cmd);
75 /* ~p command */
76 static void print_collf(FILE *collf, struct header *hp);
78 /* Write a file, ex-like if f set */
79 static si32_t a_coll_write(char const *name, FILE *fp, int f);
81 /* *message-inject-head* */
82 static bool_t a_coll_message_inject_head(FILE *fp);
84 /* Parse off the message header from fp and store relevant fields in hp,
85 * replace _coll_fp with a shiny new version without any header */
86 static bool_t a_coll_makeheader(FILE *fp, struct header *hp,
87 si8_t *checkaddr_err, bool_t do_delayed_due_t);
89 /* Edit the message being collected on fp. On return, make the edit file the
90 * new temp file. Return errno */
91 static si32_t a_coll_edit(int c, struct header *hp);
93 /* Pipe the message through the command. Old message is on stdin of command,
94 * new message collected from stdout. Shell must return 0 to accept new msg */
95 static si32_t a_coll_pipe(char const *cmd);
97 /* Interpolate the named messages into the current message, possibly doing
98 * indent stuff. The flag argument is one of the command escapes: [mMfFuU].
99 * Return errno */
100 static si32_t a_coll_forward(char const *ms, FILE *fp, int f);
102 /* ~^ mode */
103 static bool_t a_collect_plumbing(char const *ms, struct header *p);
105 static bool_t a_collect__plumb_header(char const *cp, struct header *p,
106 char const *cmd[4]);
107 static bool_t a_collect__plumb_attach(char const *cp, struct header *p,
108 char const *cmd[4]);
110 /* On interrupt, come here to save the partial message in ~/dead.letter.
111 * Then jump out of the collection loop */
112 static void _collint(int s);
114 static void collhup(int s);
116 static int putesc(char const *s, FILE *stream); /* TODO wysh set! */
118 /* *on-compose-splice* driver and *on-compose-splice(-shell)?* finalizer */
119 static int a_coll_ocs__mac(void);
120 static void a_coll_ocs__finalize(void *vp);
122 static void
123 _execute_command(struct header *hp, char const *linebuf, size_t linesize){
124 /* The problem arises if there are rfc822 message attachments and the
125 * user uses `~:' to change the current file. TODO Unfortunately we
126 * TODO cannot simply keep a pointer to, or increment a reference count
127 * TODO of the current `file' (mailbox that is) object, because the
128 * TODO codebase doesn't deal with that at all; so, until some far
129 * TODO later time, copy the name of the path, and warn the user if it
130 * TODO changed; we COULD use the AC_TMPFILE attachment type, i.e.,
131 * TODO copy the message attachments over to temporary files, but that
132 * TODO would require more changes so that the user still can recognize
133 * TODO in `~@' etc. that its a rfc822 message attachment; see below */
134 struct n_sigman sm;
135 struct attachment *ap;
136 char * volatile mnbuf;
137 NYD_ENTER;
139 n_UNUSED(linesize);
140 mnbuf = NULL;
142 n_SIGMAN_ENTER_SWITCH(&sm, n_SIGMAN_HUP | n_SIGMAN_INT | n_SIGMAN_QUIT){
143 case 0:
144 break;
145 default:
146 n_pstate_err_no = n_ERR_INTR;
147 n_pstate_ex_no = 1;
148 goto jleave;
151 /* If the above todo is worked, remove or outsource to attachment.c! */
152 if(hp != NULL && (ap = hp->h_attach) != NULL) do
153 if(ap->a_msgno){
154 mnbuf = sstrdup(mailname);
155 break;
157 while((ap = ap->a_flink) != NULL);
159 n_go_command(n_GO_INPUT_CTX_COMPOSE, linebuf);
161 n_sigman_cleanup_ping(&sm);
162 jleave:
163 if(mnbuf != NULL){
164 if(strcmp(mnbuf, mailname))
165 n_err(_("Mailbox changed: it is likely that existing "
166 "rfc822 attachments became invalid!\n"));
167 free(mnbuf);
169 NYD_LEAVE;
170 n_sigman_leave(&sm, n_SIGMAN_VIPSIGS_NTTYOUT);
173 static si32_t
174 a_coll_include_file(char const *name, bool_t indent, bool_t writestat){
175 FILE *fbuf;
176 bool_t quoted;
177 char const *heredb, *indb;
178 size_t linesize, heredl, indl, cnt, linelen;
179 char *linebuf;
180 si64_t lc, cc;
181 si32_t rv;
182 NYD_ENTER;
184 rv = n_ERR_NONE;
185 lc = cc = 0;
186 linebuf = NULL; /* TODO line pool */
187 linesize = 0;
188 heredb = NULL;
189 heredl = 0;
190 quoted = FAL0;
192 /* The -M case is special */
193 if(name == (char*)-1){
194 fbuf = n_stdin;
195 name = "-";
196 }else if(name[0] == '-' &&
197 (name[1] == '\0' || blankspacechar(name[1]))){
198 fbuf = n_stdin;
199 if(name[1] == '\0'){
200 if(!(n_psonce & n_PSO_INTERACTIVE)){
201 n_err(_("~< -: HERE-delimiter required in non-interactive mode\n"));
202 rv = n_ERR_INVAL;
203 goto jleave;
205 }else{
206 for(heredb = &name[2]; *heredb != '\0' && blankspacechar(*heredb);
207 ++heredb)
209 if((heredl = strlen(heredb)) == 0){
210 jdelim_empty:
211 n_err(_("~< - HERE-delimiter: delimiter must not be empty\n"));
212 rv = n_ERR_INVAL;
213 goto jleave;
216 if((quoted = (*heredb == '\''))){
217 for(indb = ++heredb; *indb != '\0' && *indb != '\''; ++indb)
219 if(*indb == '\0'){
220 n_err(_("~< - HERE-delimiter: missing trailing quote\n"));
221 rv = n_ERR_INVAL;
222 goto jleave;
223 }else if(indb[1] != '\0'){
224 n_err(_("~< - HERE-delimiter: trailing characters after "
225 "quote\n"));
226 rv = n_ERR_INVAL;
227 goto jleave;
229 if((heredl = PTR2SIZE(indb - heredb)) == 0)
230 goto jdelim_empty;
231 heredb = savestrbuf(heredb, heredl);
234 name = "-";
235 }else if((fbuf = Fopen(name, "r")) == NULL){
236 n_perr(name, rv = n_err_no);
237 goto jleave;
240 if(!indent)
241 indl = 0;
242 else{
243 if((indb = ok_vlook(indentprefix)) == NULL)
244 indb = INDENT_DEFAULT;
245 indl = strlen(indb);
248 if(fbuf != n_stdin)
249 cnt = fsize(fbuf);
250 while(fgetline(&linebuf, &linesize, (fbuf == n_stdin ? NULL : &cnt),
251 &linelen, fbuf, 0) != NULL){
252 if(heredl > 0 && heredl == linelen - 1 &&
253 !memcmp(heredb, linebuf, heredl)){
254 heredb = NULL;
255 break;
258 if(indl > 0){
259 if(fwrite(indb, sizeof *indb, indl, _coll_fp) != indl){
260 rv = n_err_no;
261 goto jleave;
263 cc += indl;
266 if(fwrite(linebuf, sizeof *linebuf, linelen, _coll_fp) != linelen){
267 rv = n_err_no;
268 goto jleave;
270 cc += linelen;
271 ++lc;
273 if(fflush(_coll_fp)){
274 rv = n_err_no;
275 goto jleave;
278 if(heredb != NULL)
279 rv = n_ERR_NOTOBACCO;
280 jleave:
281 if(linebuf != NULL)
282 free(linebuf);
283 if(fbuf != NULL){
284 if(fbuf != n_stdin)
285 Fclose(fbuf);
286 else if(heredl > 0)
287 clearerr(n_stdin);
290 if(writestat)
291 fprintf(n_stdout, "%s%s %" PRId64 "/%" PRId64 "\n",
292 n_shexp_quote_cp(name, FAL0), (rv ? " " n_ERROR : n_empty), lc, cc);
293 NYD_LEAVE;
294 return rv;
297 static si32_t
298 a_coll_insert_cmd(FILE *fp, char const *cmd){
299 FILE *ibuf;
300 si64_t lc, cc;
301 si32_t rv;
302 NYD_ENTER;
304 rv = n_ERR_NONE;
305 lc = cc = 0;
307 if((ibuf = Popen(cmd, "r", ok_vlook(SHELL), NULL, 0)) != NULL){
308 int c;
310 while((c = getc(ibuf)) != EOF){ /* XXX bytewise, yuck! */
311 if(putc(c, fp) == EOF){
312 rv = n_err_no;
313 break;
315 ++cc;
316 if(c == '\n')
317 ++lc;
319 if(!feof(ibuf) || ferror(ibuf)){
320 if(rv == n_ERR_NONE)
321 rv = n_ERR_IO;
323 if(!Pclose(ibuf, TRU1)){
324 if(rv == n_ERR_NONE)
325 rv = n_ERR_IO;
327 }else
328 n_perr(cmd, rv = n_err_no);
330 fprintf(n_stdout, "CMD%s %" PRId64 "/%" PRId64 "\n",
331 (rv == n_ERR_NONE ? n_empty : " " n_ERROR), lc, cc);
332 NYD_LEAVE;
333 return rv;
336 static void
337 print_collf(FILE *cf, struct header *hp)
339 char *lbuf;
340 FILE *obuf;
341 size_t cnt, linesize, linelen;
342 NYD_ENTER;
344 fflush_rewind(cf);
345 cnt = (size_t)fsize(cf);
347 if((obuf = Ftmp(NULL, "collfp", OF_RDWR | OF_UNLINK | OF_REGISTER)) == NULL){
348 n_perr(_("Can't create temporary file for `~p' command"), 0);
349 goto jleave;
352 hold_all_sigs();
354 fprintf(obuf, _("-------\nMessage contains:\n"));
355 puthead(TRU1, hp, obuf,
356 (GIDENT | GTO | GSUBJECT | GCC | GBCC | GNL | GFILES | GCOMMA),
357 SEND_TODISP, CONV_NONE, NULL, NULL);
359 lbuf = NULL;
360 linesize = 0;
361 while(fgetline(&lbuf, &linesize, &cnt, &linelen, cf, 1))
362 prout(lbuf, linelen, obuf);
363 if(lbuf != NULL)
364 free(lbuf);
366 if(hp->h_attach != NULL){
367 fputs(_("-------\nAttachments:\n"), obuf);
368 n_attachment_list_print(hp->h_attach, obuf);
371 rele_all_sigs();
373 page_or_print(obuf, 0);
374 jleave:
375 Fclose(obuf);
376 NYD_LEAVE;
379 static si32_t
380 a_coll_write(char const *name, FILE *fp, int f)
382 FILE *of;
383 int c;
384 si64_t lc, cc;
385 si32_t rv;
386 NYD_ENTER;
388 rv = n_ERR_NONE;
390 if(f) {
391 fprintf(n_stdout, "%s ", n_shexp_quote_cp(name, FAL0));
392 fflush(n_stdout);
395 if ((of = Fopen(name, "a")) == NULL) {
396 n_perr(name, rv = n_err_no);
397 goto jerr;
400 lc = cc = 0;
401 while ((c = getc(fp)) != EOF) {
402 ++cc;
403 if (c == '\n')
404 ++lc;
405 if (putc(c, of) == EOF) {
406 n_perr(name, rv = n_err_no);
407 goto jerr;
410 fprintf(n_stdout, _("%" PRId64 "/%" PRId64 "\n"), lc, cc);
412 jleave:
413 if(of != NULL)
414 Fclose(of);
415 fflush(n_stdout);
416 NYD_LEAVE;
417 return rv;
418 jerr:
419 putc('-', n_stdout);
420 putc('\n', n_stdout);
421 goto jleave;
424 static bool_t
425 a_coll_message_inject_head(FILE *fp){
426 bool_t rv;
427 char const *cp, *cp_obsolete;
428 NYD2_ENTER;
430 cp_obsolete = ok_vlook(NAIL_HEAD);
431 if(cp_obsolete != NULL)
432 n_OBSOLETE(_("please use *message-inject-head*, not *NAIL_HEAD*"));
434 if(((cp = ok_vlook(message_inject_head)) != NULL ||
435 (cp = cp_obsolete) != NULL) && putesc(cp, fp) < 0)
436 rv = FAL0;
437 else
438 rv = TRU1;
439 NYD2_LEAVE;
440 return rv;
443 static bool_t
444 a_coll_makeheader(FILE *fp, struct header *hp, si8_t *checkaddr_err,
445 bool_t do_delayed_due_t)
447 FILE *nf;
448 int c;
449 bool_t rv;
450 NYD_ENTER;
452 rv = FAL0;
454 if ((nf = Ftmp(NULL, "colhead", OF_RDWR | OF_UNLINK | OF_REGISTER)) ==NULL) {
455 n_perr(_("temporary mail edit file"), 0);
456 goto jleave;
459 extract_header(fp, hp, checkaddr_err);
460 if (checkaddr_err != NULL && *checkaddr_err != 0)
461 goto jleave;
463 /* In template mode some things have been delayed until the template has
464 * been read */
465 if(do_delayed_due_t){
466 char const *cp;
468 if((cp = ok_vlook(on_compose_enter)) != NULL){
469 setup_from_and_sender(hp);
470 temporary_compose_mode_hook_call(cp, &n_temporary_compose_hook_varset,
471 hp);
474 if(!a_coll_message_inject_head(nf))
475 goto jleave;
478 while ((c = getc(fp)) != EOF) /* XXX bytewise, yuck! */
479 putc(c, nf);
481 if (fp != _coll_fp)
482 Fclose(_coll_fp);
483 Fclose(fp);
484 _coll_fp = nf;
486 if (check_from_and_sender(hp->h_from, hp->h_sender) == NULL)
487 goto jleave;
488 rv = TRU1;
489 jleave:
490 NYD_LEAVE;
491 return rv;
494 static si32_t
495 a_coll_edit(int c, struct header *hp) /* TODO error(return) weird */
497 struct n_sigman sm;
498 FILE *nf;
499 sighandler_type volatile sigint;
500 bool_t saved;
501 si32_t volatile rv;
502 NYD_ENTER;
504 rv = n_ERR_NONE;
506 if(!(saved = ok_blook(add_file_recipients)))
507 ok_bset(add_file_recipients);
509 n_SIGMAN_ENTER_SWITCH(&sm, n_SIGMAN_ALL){
510 case 0:
511 sigint = safe_signal(SIGINT, SIG_IGN);
512 break;
513 default:
514 rv = n_ERR_INTR;
515 goto jleave;
518 nf = run_editor(_coll_fp, (off_t)-1, c, FAL0, hp, NULL, SEND_MBOX, sigint);
519 if (nf != NULL) {
520 if (hp) {
521 if(!a_coll_makeheader(nf, hp, NULL, FAL0))
522 rv = n_ERR_INVAL;
523 } else {
524 fseek(nf, 0L, SEEK_END);
525 Fclose(_coll_fp);
526 _coll_fp = nf;
528 } else
529 rv = n_ERR_CHILD;
531 n_sigman_cleanup_ping(&sm);
532 jleave:
533 if(!saved)
534 ok_bclear(add_file_recipients);
535 safe_signal(SIGINT, sigint);
536 NYD_LEAVE;
537 n_sigman_leave(&sm, n_SIGMAN_VIPSIGS_NTTYOUT);
538 return rv;
541 static si32_t
542 a_coll_pipe(char const *cmd)
544 int ws;
545 FILE *nf;
546 sighandler_type sigint;
547 si32_t rv;
548 NYD_ENTER;
550 rv = n_ERR_NONE;
551 sigint = safe_signal(SIGINT, SIG_IGN);
553 if ((nf = Ftmp(NULL, "colpipe", OF_RDWR | OF_UNLINK | OF_REGISTER)) ==NULL) {
554 n_perr(_("temporary mail edit file"), rv = n_err_no);
555 goto jout;
558 /* stdin = current message. stdout = new message */
559 fflush(_coll_fp);
560 if (n_child_run(ok_vlook(SHELL), 0, fileno(_coll_fp), fileno(nf), "-c",
561 cmd, NULL, NULL, &ws) < 0 || WEXITSTATUS(ws) != 0) {
562 Fclose(nf);
563 rv = n_ERR_CHILD;
564 goto jout;
567 if (fsize(nf) == 0) {
568 n_err(_("No bytes from %s !?\n"), n_shexp_quote_cp(cmd, FAL0));
569 Fclose(nf);
570 rv = n_ERR_NODATA;
571 goto jout;
574 /* Take new files */
575 fseek(nf, 0L, SEEK_END);
576 Fclose(_coll_fp);
577 _coll_fp = nf;
578 jout:
579 safe_signal(SIGINT, sigint);
580 NYD_LEAVE;
581 return rv;
584 static si32_t
585 a_coll_forward(char const *ms, FILE *fp, int f)
587 int *msgvec, rv = 0;
588 struct n_ignore const *itp;
589 char const *tabst;
590 enum sendaction action;
591 NYD_ENTER;
593 msgvec = salloc((size_t)(msgCount + 1) * sizeof *msgvec);
594 if (getmsglist(ms, msgvec, 0) < 0) {
595 rv = n_ERR_NOENT; /* XXX not really, should be handled there! */
596 goto jleave;
598 if (*msgvec == 0) {
599 *msgvec = first(0, MMNORM);
600 if (*msgvec == 0) {
601 n_err(_("No appropriate messages\n"));
602 rv = n_ERR_NOENT;
603 goto jleave;
605 msgvec[1] = 0;
608 if (f == 'f' || f == 'F' || f == 'u')
609 tabst = NULL;
610 else if ((tabst = ok_vlook(indentprefix)) == NULL)
611 tabst = INDENT_DEFAULT;
612 if (f == 'u' || f == 'U')
613 itp = n_IGNORE_ALL;
614 else
615 itp = upperchar(f) ? NULL : n_IGNORE_TYPE;
616 action = (upperchar(f) && f != 'U') ? SEND_QUOTE_ALL : SEND_QUOTE;
618 fprintf(n_stdout, _("Interpolating:"));
619 srelax_hold();
620 for (; *msgvec != 0; ++msgvec) {
621 struct message *mp = message + *msgvec - 1;
623 touch(mp);
624 fprintf(n_stdout, " %d", *msgvec);
625 fflush(n_stdout);
626 if (sendmp(mp, fp, itp, tabst, action, NULL) < 0) {
627 n_perr(_("temporary mail file"), 0);
628 rv = n_ERR_IO;
629 break;
631 srelax();
633 srelax_rele();
634 fprintf(n_stdout, "\n");
635 jleave:
636 NYD_LEAVE;
637 return rv;
640 static bool_t
641 a_collect_plumbing(char const *ms, struct header *hp){
642 /* TODO _collect_plumbing: instead of fields the basic headers should
643 * TODO be in an array and have IDs, like in termcap etc., so then this
644 * TODO could be simplified as table-walks. Also true for arg-checks! */
645 bool_t rv;
646 char const *cp, *cmd[4];
647 NYD2_ENTER;
649 /* Protcol version for *on-compose-splice** -- update manual on change! */
650 #define a_COLL_PLUMBING_VERSION "0 0 1"
651 cp = ms;
653 /* C99 */{
654 size_t i;
656 for(i = 0; i < n_NELEM(cmd); ++i){ /* TODO trim+strlist_split(_ifs?)() */
657 while(blankchar(*cp))
658 ++cp;
659 if(*cp == '\0')
660 cmd[i] = NULL;
661 else{
662 if(i < n_NELEM(cmd) - 1)
663 for(cmd[i] = cp++; *cp != '\0' && !blankchar(*cp); ++cp)
665 else{
666 /* Last slot takes all the rest of the line, less trailing WS */
667 for(cmd[i] = cp++; *cp != '\0'; ++cp)
669 while(blankchar(cp[-1]))
670 --cp;
672 cmd[i] = savestrbuf(cmd[i], PTR2SIZE(cp - cmd[i]));
677 if(n_UNLIKELY(cmd[0] == NULL))
678 goto jecmd;
679 if(is_asccaseprefix(cmd[0], "header"))
680 rv = a_collect__plumb_header(cp, hp, cmd);
681 else if(is_asccaseprefix(cmd[0], "attachment"))
682 rv = a_collect__plumb_attach(cp, hp, cmd);
683 else{
684 jecmd:
685 fputs("500\n", n_stdout);
686 rv = FAL0;
688 fflush(n_stdout);
690 NYD2_LEAVE;
691 return rv;
694 static bool_t
695 a_collect__plumb_header(char const *cp, struct header *hp,
696 char const *cmd[4]){
697 uiz_t i;
698 struct n_header_field *hfp;
699 struct name *np, **npp;
700 NYD2_ENTER;
702 if(cmd[1] == NULL)
703 goto jdefault;
705 if(is_asccaseprefix(cmd[1], "insert")){ /* TODO LOGIC BELONGS head.c
706 * TODO That is: Header::factory(string) -> object (blahblah).
707 * TODO I.e., as long as we don't have regular RFC compliant parsers
708 * TODO which differentiate in between structured and unstructured
709 * TODO header fields etc., a little workaround */
710 struct name *xnp;
711 si8_t aerr;
712 enum expand_addr_check_mode eacm;
713 enum gfield ntype;
714 bool_t mult_ok;
716 if(cmd[2] == NULL || cmd[3] == NULL)
717 goto jecmd;
719 /* Strip [\r\n] which would render a body invalid XXX all controls? */
720 /* C99 */{
721 char *xp, c;
723 cmd[3] = xp = savestr(cmd[3]);
724 for(; (c = *xp) != '\0'; ++xp)
725 if(c == '\n' || c == '\r')
726 *xp = ' ';
729 if(!asccasecmp(cmd[2], cp = "Subject")){
730 if(cmd[3][0] != '\0'){
731 if(hp->h_subject != NULL)
732 hp->h_subject = savecatsep(hp->h_subject, ' ', cmd[3]);
733 else
734 hp->h_subject = n_UNCONST(cmd[3]);
735 fprintf(n_stdout, "210 %s 1\n", cp);
736 goto jleave;
737 }else
738 goto j501cp;
741 mult_ok = TRU1;
742 ntype = GEXTRA | GFULL | GFULLEXTRA;
743 eacm = EACM_STRICT;
745 if(!asccasecmp(cmd[2], cp = "From")){
746 npp = &hp->h_from;
747 jins:
748 aerr = 0;
749 if((np = lextract(cmd[3], ntype)) == NULL)
750 goto j501cp;
752 if((np = checkaddrs(np, eacm, &aerr), aerr != 0)){
753 fprintf(n_stdout, "505 %s\n", cp);
754 goto jleave;
757 /* Go to the end of the list, track whether it contains any
758 * non-deleted entries */
759 i = 0;
760 if((xnp = *npp) != NULL)
761 for(;; xnp = xnp->n_flink){
762 if(!(xnp->n_type & GDEL))
763 ++i;
764 if(xnp->n_flink == NULL)
765 break;
768 if(!mult_ok && (i != 0 || np->n_flink != NULL))
769 fprintf(n_stdout, "506 %s\n", cp);
770 else{
771 if(xnp == NULL)
772 *npp = np;
773 else
774 xnp->n_flink = np;
775 np->n_blink = xnp;
776 fprintf(n_stdout, "210 %s %" PRIuZ "\n", cp, ++i);
778 goto jleave;
780 if(!asccasecmp(cmd[2], cp = "Sender")){
781 mult_ok = FAL0;
782 npp = &hp->h_sender;
783 goto jins;
785 if(!asccasecmp(cmd[2], cp = "To")){
786 npp = &hp->h_to;
787 ntype = GTO | GFULL;
788 eacm = EACM_NORMAL | EAF_NAME;
789 goto jins;
791 if(!asccasecmp(cmd[2], cp = "Cc")){
792 npp = &hp->h_cc;
793 ntype = GCC | GFULL;
794 eacm = EACM_NORMAL | EAF_NAME;
795 goto jins;
797 if(!asccasecmp(cmd[2], cp = "Bcc")){
798 npp = &hp->h_bcc;
799 ntype = GBCC | GFULL;
800 eacm = EACM_NORMAL | EAF_NAME;
801 goto jins;
803 if(!asccasecmp(cmd[2], cp = "Reply-To")){
804 npp = &hp->h_replyto;
805 eacm = EACM_NONAME;
806 goto jins;
808 if(!asccasecmp(cmd[2], cp = "Mail-Followup-To")){
809 npp = &hp->h_mft;
810 eacm = EACM_NONAME;
811 goto jins;
813 if(!asccasecmp(cmd[2], cp = "Message-ID")){
814 mult_ok = FAL0;
815 npp = &hp->h_message_id;
816 ntype = GREF;
817 eacm = EACM_NONAME;
818 goto jins;
820 if(!asccasecmp(cmd[2], cp = "References")){
821 npp = &hp->h_ref;
822 ntype = GREF;
823 eacm = EACM_NONAME;
824 goto jins;
826 if(!asccasecmp(cmd[2], cp = "In-Reply-To")){
827 npp = &hp->h_in_reply_to;
828 ntype = GREF;
829 eacm = EACM_NONAME;
830 goto jins;
833 if(!asccasecmp(cmd[2], cp = "Mailx-Orig-To") ||
834 !asccasecmp(cmd[2], cp = "Mailx-Orig-Cc") ||
835 !asccasecmp(cmd[2], cp = "Mailx-Orig-Bcc")){
836 fprintf(n_stdout, "505 %s\n", cp);
837 goto jleave;
840 /* Free-form header fields (note j501cp may print non-normalized name) */
841 /* C99 */{
842 size_t nl, bl;
843 struct n_header_field **hfpp;
845 for(cp = cmd[2]; *cp != '\0'; ++cp)
846 if(!fieldnamechar(*cp)){
847 cp = cmd[2];
848 goto j501cp;
851 for(i = 0, hfpp = &hp->h_user_headers; *hfpp != NULL; ++i)
852 hfpp = &(*hfpp)->hf_next;
854 nl = strlen(cp = cmd[2]) +1;
855 bl = strlen(cmd[3]) +1;
856 *hfpp = hfp = salloc(n_VSTRUCT_SIZEOF(struct n_header_field, hf_dat
857 ) + nl + bl);
858 hfp->hf_next = NULL;
859 hfp->hf_nl = --nl;
860 hfp->hf_bl = bl - 1;
861 hfp->hf_dat[nl = 0] = upperconv(*cp);
862 while(*cp++ != '\0')
863 hfp->hf_dat[++nl] = lowerconv(*cp);
864 memcpy(&hfp->hf_dat[++nl], cmd[3], bl);
865 fprintf(n_stdout, "210 %s %" PRIuZ "\n", &hfp->hf_dat[0], ++i);
867 goto jleave;
870 if(is_asccaseprefix(cmd[1], "list")){
871 jdefault:
872 if(cmd[2] == NULL){
873 fputs("210", n_stdout);
874 if(hp->h_subject != NULL) fputs(" Subject", n_stdout);
875 if(hp->h_from != NULL) fputs(" From", n_stdout);
876 if(hp->h_sender != NULL) fputs(" Sender", n_stdout);
877 if(hp->h_to != NULL) fputs(" To", n_stdout);
878 if(hp->h_cc != NULL) fputs(" Cc", n_stdout);
879 if(hp->h_bcc != NULL) fputs(" Bcc", n_stdout);
880 if(hp->h_replyto != NULL) fputs(" Reply-To", n_stdout);
881 if(hp->h_mft != NULL) fputs(" Mail-Followup-To", n_stdout);
882 if(hp->h_message_id != NULL) fputs(" Message-ID", n_stdout);
883 if(hp->h_ref != NULL) fputs(" References", n_stdout);
884 if(hp->h_in_reply_to != NULL) fputs(" In-Reply-To", n_stdout);
885 if(hp->h_mailx_orig_to != NULL) fputs(" Mailx-Orig-To", n_stdout);
886 if(hp->h_mailx_orig_cc != NULL) fputs(" Mailx-Orig-Cc", n_stdout);
887 if(hp->h_mailx_orig_bcc != NULL) fputs(" Mailx-Orig-Bcc", n_stdout);
889 /* Print only one instance of each free-form header */
890 for(hfp = hp->h_user_headers; hfp != NULL; hfp = hfp->hf_next){
891 struct n_header_field *hfpx;
893 for(hfpx = hp->h_user_headers;; hfpx = hfpx->hf_next)
894 if(hfpx == hfp){
895 putc(' ', n_stdout);
896 fputs(&hfp->hf_dat[0], n_stdout);
897 break;
898 }else if(!strcmp(&hfpx->hf_dat[0], &hfp->hf_dat[0]))
899 break;
901 putc('\n', n_stdout);
902 goto jleave;
905 if(cmd[3] != NULL)
906 goto jecmd;
908 if(!asccasecmp(cmd[2], cp = "Subject")){
909 np = (hp->h_subject != NULL) ? (struct name*)-1 : NULL;
910 goto jlist;
912 if(!asccasecmp(cmd[2], cp = "From")){
913 np = hp->h_from;
914 jlist:
915 fprintf(n_stdout, "%s %s\n", (np == NULL ? "501" : "210"), cp);
916 goto jleave;
918 if(!asccasecmp(cmd[2], cp = "Sender")){
919 np = hp->h_sender;
920 goto jlist;
922 if(!asccasecmp(cmd[2], cp = "To")){
923 np = hp->h_to;
924 goto jlist;
926 if(!asccasecmp(cmd[2], cp = "Cc")){
927 np = hp->h_cc;
928 goto jlist;
930 if(!asccasecmp(cmd[2], cp = "Bcc")){
931 np = hp->h_bcc;
932 goto jlist;
934 if(!asccasecmp(cmd[2], cp = "Reply-To")){
935 np = hp->h_replyto;
936 goto jlist;
938 if(!asccasecmp(cmd[2], cp = "Mail-Followup-To")){
939 np = hp->h_mft;
940 goto jlist;
942 if(!asccasecmp(cmd[2], cp = "Message-ID")){
943 np = hp->h_message_id;
944 goto jlist;
946 if(!asccasecmp(cmd[2], cp = "References")){
947 np = hp->h_ref;
948 goto jlist;
950 if(!asccasecmp(cmd[2], cp = "In-Reply-To")){
951 np = hp->h_in_reply_to;
952 goto jlist;
955 if(!asccasecmp(cmd[2], cp = "Mailx-Orig-To")){
956 np = hp->h_mailx_orig_to;
957 goto jlist;
959 if(!asccasecmp(cmd[2], cp = "Mailx-Orig-Cc")){
960 np = hp->h_mailx_orig_cc;
961 goto jlist;
963 if(!asccasecmp(cmd[2], cp = "Mailx-Orig-Bcc")){
964 np = hp->h_mailx_orig_bcc;
965 goto jlist;
968 /* Free-form header fields (note j501cp may print non-normalized name) */
969 for(cp = cmd[2]; *cp != '\0'; ++cp)
970 if(!fieldnamechar(*cp)){
971 cp = cmd[2];
972 goto j501cp;
974 cp = cmd[2];
975 for(hfp = hp->h_user_headers;; hfp = hfp->hf_next){
976 if(hfp == NULL)
977 goto j501cp;
978 else if(!asccasecmp(cp, &hfp->hf_dat[0])){
979 fprintf(n_stdout, "210 %s\n", &hfp->hf_dat[0]);
980 break;
983 goto jleave;
986 if(is_asccaseprefix(cmd[1], "remove")){
987 if(cmd[2] == NULL || cmd[3] != NULL)
988 goto jecmd;
990 if(!asccasecmp(cmd[2], cp = "Subject")){
991 if(hp->h_subject != NULL){
992 hp->h_subject = NULL;
993 fprintf(n_stdout, "210 %s\n", cp);
994 goto jleave;
995 }else
996 goto j501cp;
999 if(!asccasecmp(cmd[2], cp = "From")){
1000 npp = &hp->h_from;
1001 jrem:
1002 if(*npp != NULL){
1003 *npp = NULL;
1004 fprintf(n_stdout, "210 %s\n", cp);
1005 goto jleave;
1006 }else
1007 goto j501cp;
1009 if(!asccasecmp(cmd[2], cp = "Sender")){
1010 npp = &hp->h_sender;
1011 goto jrem;
1013 if(!asccasecmp(cmd[2], cp = "To")){
1014 npp = &hp->h_to;
1015 goto jrem;
1017 if(!asccasecmp(cmd[2], cp = "Cc")){
1018 npp = &hp->h_cc;
1019 goto jrem;
1021 if(!asccasecmp(cmd[2], cp = "Bcc")){
1022 npp = &hp->h_bcc;
1023 goto jrem;
1025 if(!asccasecmp(cmd[2], cp = "Reply-To")){
1026 npp = &hp->h_replyto;
1027 goto jrem;
1029 if(!asccasecmp(cmd[2], cp = "Mail-Followup-To")){
1030 npp = &hp->h_mft;
1031 goto jrem;
1033 if(!asccasecmp(cmd[2], cp = "Message-ID")){
1034 npp = &hp->h_message_id;
1035 goto jrem;
1037 if(!asccasecmp(cmd[2], cp = "References")){
1038 npp = &hp->h_ref;
1039 goto jrem;
1041 if(!asccasecmp(cmd[2], cp = "In-Reply-To")){
1042 npp = &hp->h_in_reply_to;
1043 goto jrem;
1046 if(!asccasecmp(cmd[2], cp = "Mailx-Orig-To") ||
1047 !asccasecmp(cmd[2], cp = "Mailx-Orig-Cc") ||
1048 !asccasecmp(cmd[2], cp = "Mailx-Orig-Bcc")){
1049 fprintf(n_stdout, "505 %s\n", cp);
1050 goto jleave;
1053 /* Free-form header fields (note j501cp may print non-normalized name) */
1054 /* C99 */{
1055 struct n_header_field **hfpp;
1056 bool_t any;
1058 for(cp = cmd[2]; *cp != '\0'; ++cp)
1059 if(!fieldnamechar(*cp)){
1060 cp = cmd[2];
1061 goto j501cp;
1063 cp = cmd[2];
1065 for(any = FAL0, hfpp = &hp->h_user_headers; (hfp = *hfpp) != NULL;){
1066 if(!asccasecmp(cp, &hfp->hf_dat[0])){
1067 *hfpp = hfp->hf_next;
1068 if(!any)
1069 fprintf(n_stdout, "210 %s\n", &hfp->hf_dat[0]);
1070 any = TRU1;
1071 }else
1072 hfp = *(hfpp = &hfp->hf_next);
1074 if(!any)
1075 goto j501cp;
1077 goto jleave;
1080 if(is_asccaseprefix(cmd[1], "remove-at")){
1081 if(cmd[2] == NULL || cmd[3] == NULL)
1082 goto jecmd;
1084 if((n_idec_uiz_cp(&i, cmd[3], 0, NULL
1085 ) & (n_IDEC_STATE_EMASK | n_IDEC_STATE_CONSUMED)
1086 ) != n_IDEC_STATE_CONSUMED || i == 0){
1087 fputs("505\n", n_stdout);
1088 goto jleave;
1091 if(!asccasecmp(cmd[2], cp = "Subject")){
1092 if(hp->h_subject != NULL && i == 1){
1093 hp->h_subject = NULL;
1094 fprintf(n_stdout, "210 %s 1\n", cp);
1095 goto jleave;
1096 }else
1097 goto j501cp;
1100 if(!asccasecmp(cmd[2], cp = "From")){
1101 npp = &hp->h_from;
1102 jremat:
1103 if((np = *npp) == NULL)
1104 goto j501cp;
1105 while(--i != 0 && np != NULL)
1106 np = np->n_flink;
1107 if(np == NULL)
1108 goto j501cp;
1110 if(np->n_blink != NULL)
1111 np->n_blink->n_flink = np->n_flink;
1112 else
1113 *npp = np->n_flink;
1114 if(np->n_flink != NULL)
1115 np->n_flink->n_blink = np->n_blink;
1117 fprintf(n_stdout, "210 %s\n", cp);
1118 goto jleave;
1120 if(!asccasecmp(cmd[2], cp = "Sender")){
1121 npp = &hp->h_sender;
1122 goto jremat;
1124 if(!asccasecmp(cmd[2], cp = "To")){
1125 npp = &hp->h_to;
1126 goto jremat;
1128 if(!asccasecmp(cmd[2], cp = "Cc")){
1129 npp = &hp->h_cc;
1130 goto jremat;
1132 if(!asccasecmp(cmd[2], cp = "Bcc")){
1133 npp = &hp->h_bcc;
1134 goto jremat;
1136 if(!asccasecmp(cmd[2], cp = "Reply-To")){
1137 npp = &hp->h_replyto;
1138 goto jremat;
1140 if(!asccasecmp(cmd[2], cp = "Mail-Followup-To")){
1141 npp = &hp->h_mft;
1142 goto jremat;
1144 if(!asccasecmp(cmd[2], cp = "Message-ID")){
1145 npp = &hp->h_message_id;
1146 goto jremat;
1148 if(!asccasecmp(cmd[2], cp = "References")){
1149 npp = &hp->h_ref;
1150 goto jremat;
1152 if(!asccasecmp(cmd[2], cp = "In-Reply-To")){
1153 npp = &hp->h_in_reply_to;
1154 goto jremat;
1157 if(!asccasecmp(cmd[2], cp = "Mailx-Orig-To") ||
1158 !asccasecmp(cmd[2], cp = "Mailx-Orig-Cc") ||
1159 !asccasecmp(cmd[2], cp = "Mailx-Orig-Bcc")){
1160 fprintf(n_stdout, "505 %s\n", cp);
1161 goto jleave;
1164 /* Free-form header fields (note j501cp may print non-normalized name) */
1165 /* C99 */{
1166 struct n_header_field **hfpp;
1168 for(cp = cmd[2]; *cp != '\0'; ++cp)
1169 if(!fieldnamechar(*cp)){
1170 cp = cmd[2];
1171 goto j501cp;
1173 cp = cmd[2];
1175 for(hfpp = &hp->h_user_headers; (hfp = *hfpp) != NULL;){
1176 if(--i == 0){
1177 *hfpp = hfp->hf_next;
1178 fprintf(n_stdout, "210 %s %" PRIuZ "\n", &hfp->hf_dat[0], i);
1179 break;
1180 }else
1181 hfp = *(hfpp = &hfp->hf_next);
1183 if(hfp == NULL)
1184 goto j501cp;
1186 goto jleave;
1189 if(is_asccaseprefix(cmd[1], "show")){
1190 if(cmd[2] == NULL || cmd[3] != NULL)
1191 goto jecmd;
1193 if(!asccasecmp(cmd[2], cp = "Subject")){
1194 if(hp->h_subject != NULL)
1195 fprintf(n_stdout, "212 %s\n%s\n\n", cp, hp->h_subject);
1196 else
1197 fprintf(n_stdout, "501 %s\n", cp);
1198 goto jleave;
1201 if(!asccasecmp(cmd[2], cp = "From")){
1202 np = hp->h_from;
1203 jshow:
1204 if(np != NULL){
1205 fprintf(n_stdout, "211 %s\n", cp);
1206 do if(!(np->n_type & GDEL))
1207 fprintf(n_stdout, "%s %s\n", np->n_name, np->n_fullname);
1208 while((np = np->n_flink) != NULL);
1209 putc('\n', n_stdout);
1210 goto jleave;
1211 }else
1212 goto j501cp;
1214 if(!asccasecmp(cmd[2], cp = "Sender")){
1215 np = hp->h_sender;
1216 goto jshow;
1218 if(!asccasecmp(cmd[2], cp = "To")){
1219 np = hp->h_to;
1220 goto jshow;
1222 if(!asccasecmp(cmd[2], cp = "Cc")){
1223 np = hp->h_cc;
1224 goto jshow;
1226 if(!asccasecmp(cmd[2], cp = "Bcc")){
1227 np = hp->h_bcc;
1228 goto jshow;
1230 if(!asccasecmp(cmd[2], cp = "Reply-To")){
1231 np = hp->h_replyto;
1232 goto jshow;
1234 if(!asccasecmp(cmd[2], cp = "Mail-Followup-To")){
1235 np = hp->h_mft;
1236 goto jshow;
1238 if(!asccasecmp(cmd[2], cp = "Message-ID")){
1239 np = hp->h_message_id;
1240 goto jshow;
1242 if(!asccasecmp(cmd[2], cp = "References")){
1243 np = hp->h_ref;
1244 goto jshow;
1246 if(!asccasecmp(cmd[2], cp = "In-Reply-To")){
1247 np = hp->h_in_reply_to;
1248 goto jshow;
1251 if(!asccasecmp(cmd[2], cp = "Mailx-Orig-To")){
1252 np = hp->h_mailx_orig_to;
1253 goto jshow;
1255 if(!asccasecmp(cmd[2], cp = "Mailx-Orig-Cc")){
1256 np = hp->h_mailx_orig_cc;
1257 goto jshow;
1259 if(!asccasecmp(cmd[2], cp = "Mailx-Orig-Bcc")){
1260 np = hp->h_mailx_orig_bcc;
1261 goto jshow;
1264 /* Free-form header fields (note j501cp may print non-normalized name) */
1265 /* C99 */{
1266 bool_t any;
1268 for(cp = cmd[2]; *cp != '\0'; ++cp)
1269 if(!fieldnamechar(*cp)){
1270 cp = cmd[2];
1271 goto j501cp;
1273 cp = cmd[2];
1275 for(any = FAL0, hfp = hp->h_user_headers; hfp != NULL;
1276 hfp = hfp->hf_next){
1277 if(!asccasecmp(cp, &hfp->hf_dat[0])){
1278 if(!any)
1279 fprintf(n_stdout, "212 %s\n", &hfp->hf_dat[0]);
1280 any = TRU1;
1281 fprintf(n_stdout, "%s\n", &hfp->hf_dat[hfp->hf_nl +1]);
1284 if(any)
1285 putc('\n', n_stdout);
1286 else
1287 goto j501cp;
1289 goto jleave;
1292 jecmd:
1293 fputs("500\n", n_stdout);
1294 cp = NULL;
1295 jleave:
1296 NYD2_LEAVE;
1297 return (cp != NULL);
1299 j501cp:
1300 fputs("501 ", n_stdout);
1301 fputs(cp, n_stdout);
1302 putc('\n', n_stdout);
1303 goto jleave;
1306 static bool_t
1307 a_collect__plumb_attach(char const *cp, struct header *hp,
1308 char const *cmd[4]){
1309 bool_t status;
1310 struct attachment *ap;
1311 NYD2_ENTER;
1313 if(cmd[1] == NULL)
1314 goto jdefault;
1316 if(is_asccaseprefix(cmd[1], "attribute")){
1317 if(cmd[2] == NULL || cmd[3] != NULL)
1318 goto jecmd;
1320 if((ap = n_attachment_find(hp->h_attach, cmd[2], NULL)) != NULL){
1321 jatt_att:
1322 fprintf(n_stdout, "212 %s\n", cmd[2]);
1323 if(ap->a_msgno > 0)
1324 fprintf(n_stdout, "message-number %d\n\n", ap->a_msgno);
1325 else{
1326 fprintf(n_stdout,
1327 "creation-name %s\nopen-path %s\nfilename %s\n",
1328 ap->a_path_user, ap->a_path, ap->a_name);
1329 if(ap->a_content_description != NULL)
1330 fprintf(n_stdout, "content-description %s\n",
1331 ap->a_content_description);
1332 if(ap->a_content_id != NULL)
1333 fprintf(n_stdout, "content-id %s\n",
1334 ap->a_content_id->n_name);
1335 if(ap->a_content_type != NULL)
1336 fprintf(n_stdout, "content-type %s\n", ap->a_content_type);
1337 if(ap->a_content_disposition != NULL)
1338 fprintf(n_stdout, "content-disposition %s\n",
1339 ap->a_content_disposition);
1340 putc('\n', n_stdout);
1342 }else
1343 fputs("501\n", n_stdout);
1344 goto jleave;
1347 if(is_asccaseprefix(cmd[1], "attribute-at")){
1348 uiz_t i;
1350 if(cmd[2] == NULL || cmd[3] != NULL)
1351 goto jecmd;
1353 if((n_idec_uiz_cp(&i, cmd[2], 0, NULL
1354 ) & (n_IDEC_STATE_EMASK | n_IDEC_STATE_CONSUMED)
1355 ) != n_IDEC_STATE_CONSUMED || i == 0)
1356 fputs("505\n", n_stdout);
1357 else{
1358 for(ap = hp->h_attach; ap != NULL && --i != 0; ap = ap->a_flink)
1360 if(ap != NULL)
1361 goto jatt_att;
1362 else
1363 fputs("501\n", n_stdout);
1365 goto jleave;
1368 if(is_asccaseprefix(cmd[1], "attribute-set")){
1369 if(cmd[2] == NULL || cmd[3] == NULL)
1370 goto jecmd;
1372 if((ap = n_attachment_find(hp->h_attach, cmd[2], NULL)) != NULL){
1373 jatt_attset:
1374 if(ap->a_msgno > 0)
1375 fputs("505\n", n_stdout);
1376 else{
1377 char c, *keyw;
1379 cp = cmd[3];
1380 while((c = *cp) != '\0' && !blankchar(c))
1381 ++cp;
1382 keyw = savestrbuf(cmd[3], PTR2SIZE(cp - cmd[3]));
1383 if(c != '\0'){
1384 for(; (c = *++cp) != '\0' && blankchar(c);)
1386 if(c != '\0'){
1387 char *xp;
1389 /* Strip [\r\n] which would render a parameter invalid XXX
1390 * XXX all controls? */
1391 cp = xp = savestr(cp);
1392 for(; (c = *xp) != '\0'; ++xp)
1393 if(c == '\n' || c == '\r')
1394 *xp = ' ';
1395 c = *cp;
1399 if(!asccasecmp(keyw, "filename"))
1400 ap->a_name = (c == '\0') ? ap->a_path_bname : cp;
1401 else if(!asccasecmp(keyw, "content-description"))
1402 ap->a_content_description = (c == '\0') ? NULL : cp;
1403 else if(!asccasecmp(keyw, "content-id")){
1404 ap->a_content_id = NULL;
1406 if(c != '\0'){
1407 struct name *np;
1409 np = checkaddrs(lextract(cp, GREF),
1410 /*EACM_STRICT | TODO '/' valid!! */ EACM_NOLOG |
1411 EACM_NONAME, NULL);
1412 if(np != NULL && np->n_flink == NULL)
1413 ap->a_content_id = np;
1414 else
1415 cp = NULL;
1417 }else if(!asccasecmp(keyw, "content-type"))
1418 ap->a_content_type = (c == '\0') ? NULL : cp;
1419 else if(!asccasecmp(keyw, "content-disposition"))
1420 ap->a_content_disposition = (c == '\0') ? NULL : cp;
1421 else
1422 cp = NULL;
1424 if(cp != NULL){
1425 size_t i;
1427 for(i = 0; ap != NULL; ++i, ap = ap->a_blink)
1429 fprintf(n_stdout, "210 %" PRIuZ "\n", i);
1430 }else
1431 fputs("505\n", n_stdout);
1433 }else
1434 fputs("501\n", n_stdout);
1435 goto jleave;
1438 if(is_asccaseprefix(cmd[1], "attribute-set-at")){
1439 uiz_t i;
1441 if(cmd[2] == NULL || cmd[3] == NULL)
1442 goto jecmd;
1444 if((n_idec_uiz_cp(&i, cmd[2], 0, NULL
1445 ) & (n_IDEC_STATE_EMASK | n_IDEC_STATE_CONSUMED)
1446 ) != n_IDEC_STATE_CONSUMED || i == 0)
1447 fputs("505\n", n_stdout);
1448 else{
1449 for(ap = hp->h_attach; ap != NULL && --i != 0; ap = ap->a_flink)
1451 if(ap != NULL)
1452 goto jatt_attset;
1453 else
1454 fputs("501\n", n_stdout);
1456 goto jleave;
1459 if(is_asccaseprefix(cmd[1], "insert")){
1460 enum n_attach_error aerr;
1462 if(cmd[2] == NULL || cmd[3] != NULL)
1463 goto jecmd;
1465 hp->h_attach = n_attachment_append(hp->h_attach, cmd[2], &aerr, &ap);
1466 switch(aerr){
1467 case n_ATTACH_ERR_FILE_OPEN: cp = "505\n"; goto jatt_ins;
1468 case n_ATTACH_ERR_ICONV_FAILED: cp = "506\n"; goto jatt_ins;
1469 case n_ATTACH_ERR_ICONV_NAVAIL:
1470 case n_ATTACH_ERR_OTHER:
1471 default:
1472 cp = "501\n";
1473 jatt_ins:
1474 fputs(cp, n_stdout);
1475 break;
1476 case n_ATTACH_ERR_NONE:{
1477 size_t i;
1479 for(i = 0; ap != NULL; ++i, ap = ap->a_blink)
1481 fprintf(n_stdout, "210 %" PRIuZ "\n", i);
1482 } break;
1484 goto jleave;
1487 if(is_asccaseprefix(cmd[1], "list")){
1488 jdefault:
1489 if(cmd[2] != NULL)
1490 goto jecmd;
1492 if((ap = hp->h_attach) != NULL){
1493 fputs("212\n", n_stdout);
1495 fprintf(n_stdout, "%s\n", ap->a_path_user);
1496 while((ap = ap->a_flink) != NULL);
1497 putc('\n', n_stdout);
1498 }else
1499 fputs("501\n", n_stdout);
1500 goto jleave;
1503 if(is_asccaseprefix(cmd[1], "remove")){
1504 if(cmd[2] == NULL || cmd[3] != NULL)
1505 goto jecmd;
1507 if((ap = n_attachment_find(hp->h_attach, cmd[2], &status)) != NULL){
1508 if(status == TRUM1)
1509 fputs("506\n", n_stdout);
1510 else{
1511 hp->h_attach = n_attachment_remove(hp->h_attach, ap);
1512 fprintf(n_stdout, "210 %s\n", cmd[2]);
1514 }else
1515 fputs("501\n", n_stdout);
1516 goto jleave;
1519 if(is_asccaseprefix(cmd[1], "remove-at")){
1520 uiz_t i;
1522 if(cmd[2] == NULL || cmd[3] != NULL)
1523 goto jecmd;
1525 if((n_idec_uiz_cp(&i, cmd[2], 0, NULL
1526 ) & (n_IDEC_STATE_EMASK | n_IDEC_STATE_CONSUMED)
1527 ) != n_IDEC_STATE_CONSUMED || i == 0)
1528 fputs("505\n", n_stdout);
1529 else{
1530 for(ap = hp->h_attach; ap != NULL && --i != 0; ap = ap->a_flink)
1532 if(ap != NULL){
1533 hp->h_attach = n_attachment_remove(hp->h_attach, ap);
1534 fprintf(n_stdout, "210 %s\n", cmd[2]);
1535 }else
1536 fputs("501\n", n_stdout);
1538 goto jleave;
1541 jecmd:
1542 fputs("500\n", n_stdout);
1543 cp = NULL;
1544 jleave:
1545 NYD2_LEAVE;
1546 return (cp != NULL);
1549 static void
1550 _collint(int s)
1552 NYD_X; /* Signal handler */
1554 /* the control flow is subtle, because we can be called from ~q */
1555 if (_coll_hadintr == 0) {
1556 if (ok_blook(ignore)) {
1557 fputs("@\n", n_stdout);
1558 fflush(n_stdout);
1559 clearerr(n_stdin);
1560 } else
1561 _coll_hadintr = 1;
1562 siglongjmp(_coll_jmp, 1);
1564 n_exit_status |= n_EXIT_SEND_ERROR;
1565 if (s != 0)
1566 savedeadletter(_coll_fp, TRU1);
1567 /* Aborting message, no need to fflush() .. */
1568 siglongjmp(_coll_abort, 1);
1571 static void
1572 collhup(int s)
1574 NYD_X; /* Signal handler */
1575 n_UNUSED(s);
1577 savedeadletter(_coll_fp, TRU1);
1578 /* Let's pretend nobody else wants to clean up, a true statement at
1579 * this time */
1580 exit(n_EXIT_ERR);
1583 static int
1584 putesc(char const *s, FILE *stream) /* TODO: v15: drop */
1586 int n = 0, rv = -1;
1587 NYD_ENTER;
1589 while (s[0] != '\0') {
1590 if (s[0] == '\\') {
1591 if (s[1] == 't') {
1592 if (putc('\t', stream) == EOF)
1593 goto jleave;
1594 ++n;
1595 s += 2;
1596 continue;
1598 if (s[1] == 'n') {
1599 if (putc('\n', stream) == EOF)
1600 goto jleave;
1601 ++n;
1602 s += 2;
1603 continue;
1606 if (putc(s[0], stream) == EOF)
1607 goto jleave;
1608 ++n;
1609 ++s;
1611 if (putc('\n', stream) == EOF)
1612 goto jleave;
1613 rv = ++n;
1614 jleave:
1615 NYD_LEAVE;
1616 return rv;
1619 static int
1620 a_coll_ocs__mac(void){
1621 /* Executes in a fork(2)ed child TODO if remains, global MASKs for those! */
1622 setvbuf(n_stdin, NULL, _IOLBF, 0);
1623 setvbuf(n_stdout, NULL, _IOLBF, 0);
1624 n_psonce &= ~(n_PSO_INTERACTIVE | n_PSO_TTYIN | n_PSO_TTYOUT);
1625 n_pstate |= n_PS_COMPOSE_FORKHOOK;
1626 n_readctl_overlay = NULL; /* TODO we need OnForkEvent! See c_readctl() */
1627 if(n_poption & n_PO_D_VV){
1628 char buf[128];
1630 snprintf(buf, sizeof buf, "[%d]%s", getpid(), ok_vlook(log_prefix));
1631 ok_vset(log_prefix, buf);
1633 /* TODO If that uses `!' it will effectively SIG_IGN SIGINT, ...and such */
1634 temporary_compose_mode_hook_call(a_coll_ocs__macname, NULL, NULL);
1635 return 0;
1638 static void
1639 a_coll_ocs__finalize(void *vp){
1640 /* Note we use this for destruction upon setup errors, thus */
1641 sighandler_type opipe;
1642 sighandler_type oint;
1643 struct a_coll_ocs_arg **coapp, *coap;
1644 NYD2_ENTER;
1646 temporary_compose_mode_hook_call((char*)-1, NULL, NULL);
1648 coap = *(coapp = vp);
1649 *coapp = (struct a_coll_ocs_arg*)-1;
1651 if(coap->coa_stdin != NULL)
1652 Fclose(coap->coa_stdin);
1653 else if(coap->coa_pipe[0] != -1)
1654 close(coap->coa_pipe[0]);
1656 if(coap->coa_stdout != NULL && !Pclose(coap->coa_stdout, TRU1))
1657 *coap->coa_senderr = 111;
1658 if(coap->coa_pipe[1] != -1)
1659 close(coap->coa_pipe[1]);
1661 opipe = coap->coa_opipe;
1662 oint = coap->coa_oint;
1664 n_lofi_free(coap);
1666 hold_all_sigs();
1667 safe_signal(SIGPIPE, opipe);
1668 safe_signal(SIGINT, oint);
1669 rele_all_sigs();
1670 NYD2_LEAVE;
1673 FL void
1674 n_temporary_compose_hook_varset(void *arg){ /* TODO v15: drop */
1675 struct header *hp;
1676 char const *val;
1677 NYD2_ENTER;
1679 hp = arg;
1681 if((val = hp->h_subject) == NULL)
1682 val = n_empty;
1683 ok_vset(mailx_subject, val);
1684 if((val = detract(hp->h_from, GNAMEONLY)) == NULL)
1685 val = n_empty;
1686 ok_vset(mailx_from, val);
1687 if((val = detract(hp->h_sender, GNAMEONLY)) == NULL)
1688 val = n_empty;
1689 ok_vset(mailx_sender, val);
1690 if((val = detract(hp->h_to, GNAMEONLY)) == NULL)
1691 val = n_empty;
1692 ok_vset(mailx_to, val);
1693 if((val = detract(hp->h_cc, GNAMEONLY)) == NULL)
1694 val = n_empty;
1695 ok_vset(mailx_cc, val);
1696 if((val = detract(hp->h_bcc, GNAMEONLY)) == NULL)
1697 val = n_empty;
1698 ok_vset(mailx_bcc, val);
1699 if((val = detract(hp->h_mailx_orig_to, GNAMEONLY)) == NULL)
1700 val = n_empty;
1701 ok_vset(mailx_orig_to, val);
1702 if((val = detract(hp->h_mailx_orig_cc, GNAMEONLY)) == NULL)
1703 val = n_empty;
1704 ok_vset(mailx_orig_cc, val);
1705 if((val = detract(hp->h_mailx_orig_bcc, GNAMEONLY)) == NULL)
1706 val = n_empty;
1707 ok_vset(mailx_orig_bcc, val);
1708 NYD2_LEAVE;
1711 FL FILE *
1712 collect(struct header *hp, int printheaders, struct message *mp,
1713 char const *quotefile, int doprefix, si8_t *checkaddr_err)
1715 struct n_string s, * volatile sp;
1716 struct n_ignore const *quoteitp;
1717 struct a_coll_ocs_arg *coap;
1718 int c;
1719 int volatile t, eofcnt, getfields;
1720 char volatile escape;
1721 enum{
1722 a_NONE,
1723 a_ERREXIT = 1u<<0,
1724 a_IGNERR = 1u<<1,
1725 a_COAP_NOSIGTERM = 1u<<8
1726 #define a_HARDERR() ((flags & (a_ERREXIT | a_IGNERR)) == a_ERREXIT)
1727 } volatile flags;
1728 char *linebuf;
1729 char const *cp, *cp_base, * volatile coapm, * volatile ifs_saved;
1730 size_t i, linesize; /* TODO line pool */
1731 long cnt;
1732 enum sendaction action;
1733 sigset_t oset, nset;
1734 FILE * volatile sigfp;
1735 NYD_ENTER;
1737 _coll_fp = NULL;
1738 sigfp = NULL;
1739 linesize = 0;
1740 linebuf = NULL;
1741 eofcnt = 0;
1742 ifs_saved = coapm = NULL;
1743 coap = NULL;
1745 /* Start catching signals from here, but we're still die on interrupts
1746 * until we're in the main loop */
1747 sigfillset(&nset);
1748 sigprocmask(SIG_BLOCK, &nset, &oset);
1749 if ((_coll_saveint = safe_signal(SIGINT, SIG_IGN)) != SIG_IGN)
1750 safe_signal(SIGINT, &_collint);
1751 if ((_coll_savehup = safe_signal(SIGHUP, SIG_IGN)) != SIG_IGN)
1752 safe_signal(SIGHUP, collhup);
1753 if (sigsetjmp(_coll_abort, 1))
1754 goto jerr;
1755 if (sigsetjmp(_coll_jmp, 1))
1756 goto jerr;
1757 n_pstate |= n_PS_COMPOSE_MODE;
1758 sigprocmask(SIG_SETMASK, &oset, (sigset_t*)NULL);
1760 if ((_coll_fp = Ftmp(NULL, "collect", OF_RDWR | OF_UNLINK | OF_REGISTER)) ==
1761 NULL) {
1762 n_perr(_("temporary mail file"), 0);
1763 goto jerr;
1766 /* If we are going to prompt for a subject, refrain from printing a newline
1767 * after the headers (since some people mind) */
1768 getfields = 0;
1769 if (!(n_poption & n_PO_t_FLAG)) {
1770 t = GTO | GSUBJECT | GCC | GNL;
1771 if (ok_blook(fullnames))
1772 t |= GCOMMA;
1774 if (n_psonce & n_PSO_INTERACTIVE) {
1775 if (hp->h_subject == NULL && (ok_blook(ask) || ok_blook(asksub)))
1776 t &= ~GNL, getfields |= GSUBJECT;
1778 if (hp->h_to == NULL)
1779 t &= ~GNL, getfields |= GTO;
1781 if (!ok_blook(bsdcompat) && !ok_blook(askatend)) {
1782 if (hp->h_bcc == NULL && ok_blook(askbcc))
1783 t &= ~GNL, getfields |= GBCC;
1784 if (hp->h_cc == NULL && ok_blook(askcc))
1785 t &= ~GNL, getfields |= GCC;
1788 } else {
1789 n_UNINIT(t, 0);
1792 _coll_hadintr = 0;
1794 if (!sigsetjmp(_coll_jmp, 1)) {
1795 /* Ask for some headers first, as necessary */
1796 if (getfields)
1797 grab_headers(n_GO_INPUT_CTX_COMPOSE, hp, getfields, 1);
1799 /* Execute compose-enter; delayed for -t mode */
1800 if(!(n_poption & n_PO_t_FLAG) &&
1801 (cp = ok_vlook(on_compose_enter)) != NULL){
1802 setup_from_and_sender(hp);
1803 temporary_compose_mode_hook_call(cp, &n_temporary_compose_hook_varset,
1804 hp);
1807 /* TODO Mm: nope since it may require turning this into a multipart one */
1808 if(!(n_poption & (n_PO_Mm_FLAG | n_PO_t_FLAG))){
1809 if(!a_coll_message_inject_head(_coll_fp))
1810 goto jerr;
1812 /* Quote an original message */
1813 if (mp != NULL && (doprefix || (cp = ok_vlook(quote)) != NULL)) {
1814 quoteitp = n_IGNORE_ALL;
1815 action = SEND_QUOTE;
1816 if (doprefix) {
1817 quoteitp = n_IGNORE_FWD;
1818 if ((cp = ok_vlook(fwdheading)) == NULL)
1819 cp = "-------- Original Message --------";
1820 if (*cp != '\0' && fprintf(_coll_fp, "%s\n", cp) < 0)
1821 goto jerr;
1822 } else if (!strcmp(cp, "noheading")) {
1823 /*EMPTY*/;
1824 } else if (!strcmp(cp, "headers")) {
1825 quoteitp = n_IGNORE_TYPE;
1826 } else if (!strcmp(cp, "allheaders")) {
1827 quoteitp = NULL;
1828 action = SEND_QUOTE_ALL;
1829 } else {
1830 cp = hfield1("from", mp);
1831 if (cp != NULL && (cnt = (long)strlen(cp)) > 0) {
1832 if (xmime_write(cp, cnt, _coll_fp, CONV_FROMHDR, TD_NONE) < 0)
1833 goto jerr;
1834 if (fprintf(_coll_fp, _(" wrote:\n\n")) < 0)
1835 goto jerr;
1838 if (fflush(_coll_fp))
1839 goto jerr;
1840 if (doprefix)
1841 cp = NULL;
1842 else if ((cp = ok_vlook(indentprefix)) == NULL)
1843 cp = INDENT_DEFAULT;
1844 if (sendmp(mp, _coll_fp, quoteitp, cp, action, NULL) < 0)
1845 goto jerr;
1849 if (quotefile != NULL) {
1850 if((n_pstate_err_no = a_coll_include_file(quotefile, FAL0, FAL0)
1851 ) != n_ERR_NONE)
1852 goto jerr;
1855 sp = NULL;
1856 if(n_psonce & n_PSO_INTERACTIVE){
1857 if(!(n_pstate & n_PS_SOURCING)){
1858 sp = n_string_creat_auto(&s);
1859 sp = n_string_reserve(sp, 80);
1862 if(!(n_poption & n_PO_Mm_FLAG)){
1863 /* Print what we have sofar also on the terminal (if useful) */
1864 if (!ok_blook(editalong)) {
1865 if (printheaders)
1866 puthead(TRU1, hp, n_stdout, t,
1867 SEND_TODISP, CONV_NONE, NULL, NULL);
1869 rewind(_coll_fp);
1870 while ((c = getc(_coll_fp)) != EOF) /* XXX bytewise, yuck! */
1871 putc(c, n_stdout);
1872 if (fseek(_coll_fp, 0, SEEK_END))
1873 goto jerr;
1874 } else {
1875 rewind(_coll_fp);
1876 if(a_coll_edit('e', hp) != n_ERR_NONE)
1877 goto jerr;
1878 /* Print msg mandated by the Mail Reference Manual */
1879 jcont:
1880 if(n_psonce & n_PSO_INTERACTIVE)
1881 fputs(_("(continue)\n"), n_stdout);
1883 fflush(n_stdout);
1886 } else {
1887 /* Come here for printing the after-signal message. Duplicate messages
1888 * won't be printed because the write is aborted if we get a SIGTTOU */
1889 if (_coll_hadintr)
1890 n_err(_("\n(Interrupt -- one more to kill letter)\n"));
1893 /* If not under shell hook control */
1894 if(coap == NULL){
1895 /* We're done with -M or -m TODO because: we are too stupid yet, above */
1896 if(n_poption & n_PO_Mm_FLAG)
1897 goto jout;
1898 /* No command escapes, interrupts not expected. Simply copy STDIN */
1899 if(!(n_psonce & n_PSO_INTERACTIVE) &&
1900 !(n_poption & (n_PO_t_FLAG | n_PO_TILDE_FLAG))){
1901 linebuf = srealloc(linebuf, linesize = LINESIZE);
1902 while ((i = fread(linebuf, sizeof *linebuf, linesize, n_stdin)) > 0) {
1903 if (i != fwrite(linebuf, sizeof *linebuf, i, _coll_fp))
1904 goto jerr;
1906 goto jout;
1910 /* The interactive collect loop */
1911 if(coap == NULL)
1912 escape = *ok_vlook(escape);
1913 flags = ok_blook(errexit) ? a_ERREXIT : a_NONE;
1915 for(;;){
1916 enum {a_HIST_NONE, a_HIST_ADD = 1u<<0, a_HIST_GABBY = 1u<<1} hist;
1918 /* C99 */{
1919 enum n_go_input_flags gif;
1920 bool_t histadd;
1922 gif = n_GO_INPUT_CTX_COMPOSE;
1923 histadd = (sp != NULL);
1924 if((n_psonce & n_PSO_INTERACTIVE) || (n_poption & n_PO_TILDE_FLAG)){
1925 if(!(n_poption & n_PO_t_FLAG))
1926 gif |= n_GO_INPUT_NL_ESC;
1928 cnt = n_go_input(gif, n_empty, &linebuf, &linesize, NULL, &histadd);
1929 hist = histadd ? a_HIST_ADD | a_HIST_GABBY : a_HIST_NONE;
1932 if(cnt < 0){
1933 if(coap != NULL)
1934 break;
1935 if(n_poption & n_PO_t_FLAG){
1936 fflush_rewind(_coll_fp);
1937 /* It is important to set n_PSO_t_FLAG before extract_header()
1938 * *and* keep n_PO_t_FLAG for the first parse of the message!
1939 * TODO This is a hack, we need a clean approach for this */
1940 n_psonce |= n_PSO_t_FLAG;
1941 if(!a_coll_makeheader(_coll_fp, hp, checkaddr_err, TRU1))
1942 goto jerr;
1943 n_poption &= ~n_PO_t_FLAG;
1944 continue;
1945 }else if((n_psonce & n_PSO_INTERACTIVE) && ok_blook(ignoreeof) &&
1946 ++eofcnt < 4){
1947 fprintf(n_stdout,
1948 _("*ignoreeof* set, use `~.' to terminate letter\n"));
1949 n_go_input_clearerr();
1950 continue;
1952 break;
1955 _coll_hadintr = 0;
1957 cp = linebuf;
1958 if(cnt == 0)
1959 goto jputnl;
1960 else if(coap == NULL){
1961 if(!(n_psonce & n_PSO_INTERACTIVE) && !(n_poption & n_PO_TILDE_FLAG))
1962 goto jputline;
1963 else if(cp[0] == '.'){
1964 if(cnt == 1 && (ok_blook(dot) ||
1965 (ok_blook(posix) && ok_blook(ignoreeof))))
1966 break;
1969 if(cp[0] != escape){
1970 jputline:
1971 if(fwrite(cp, sizeof *cp, cnt, _coll_fp) != (size_t)cnt)
1972 goto jerr;
1973 /* TODO n_PS_READLINE_NL is a terrible hack to ensure that _in_all_-
1974 * TODO _code_paths_ a file without trailing newline isn't modified
1975 * TODO to contain one; the "saw-newline" needs to be part of an
1976 * TODO I/O input machinery object */
1977 jputnl:
1978 if(n_pstate & n_PS_READLINE_NL){
1979 if(putc('\n', _coll_fp) == EOF)
1980 goto jerr;
1982 continue;
1985 c = *(cp_base = ++cp);
1986 if(--cnt == 0)
1987 goto jearg;
1989 /* Avoid history entry? */
1990 while(spacechar(c)){
1991 hist = a_HIST_NONE;
1992 c = *(cp_base = ++cp);
1993 if(--cnt == 0)
1994 goto jearg;
1997 /* It may just be an escaped escaped character, do that quick */
1998 if(c == escape)
1999 goto jputline;
2001 /* Avoid hard *errexit*? */
2002 flags &= ~a_IGNERR;
2003 if(c == '-'){
2004 flags ^= a_IGNERR;
2005 c = *++cp;
2006 if(--cnt == 0)
2007 goto jearg;
2010 /* Trim input, also to gain a somewhat normalized history entry */
2011 ++cp;
2012 if(--cnt > 0){
2013 struct str x;
2015 x.s = n_UNCONST(cp);
2016 x.l = (size_t)cnt;
2017 n_str_trim_ifs(&x, TRU1);
2018 x.s[x.l] = '\0';
2019 cp = x.s;
2020 cnt = (int)/*XXX*/x.l;
2023 if(hist != a_HIST_NONE){
2024 sp = n_string_assign_c(sp, escape);
2025 if(flags & a_IGNERR)
2026 sp = n_string_push_c(sp, '-');
2027 sp = n_string_push_c(sp, c);
2028 if(cnt > 0){
2029 sp = n_string_push_c(sp, ' ');
2030 sp = n_string_push_buf(sp, cp, cnt);
2034 switch(c){
2035 default:
2036 if(1){
2037 char buf[sizeof(n_UNIREPL)];
2039 if(asciichar(c))
2040 buf[0] = c, buf[1] = '\0';
2041 else if(n_psonce & n_PSO_UNICODE)
2042 memcpy(buf, n_unirepl, sizeof n_unirepl);
2043 else
2044 buf[0] = '?', buf[1] = '\0';
2045 n_err(_("Unknown command escape: `%c%s'\n"), escape, buf);
2046 }else
2047 jearg:
2048 n_err(_("Invalid command escape usage: %s\n"),
2049 n_shexp_quote_cp(linebuf, FAL0));
2050 if(a_HARDERR())
2051 goto jerr;
2052 n_pstate_err_no = n_ERR_INVAL;
2053 n_pstate_ex_no = 1;
2054 continue;
2055 case '!':
2056 /* Shell escape, send the balance of line to sh -c */
2057 if(cnt == 0 || coap != NULL)
2058 goto jearg;
2059 else{
2060 char const *argv[2];
2062 argv[0] = cp;
2063 argv[1] = NULL;
2064 n_pstate_ex_no = c_shell(argv); /* TODO history norm.; errexit? */
2066 goto jhistcont;
2067 case ':':
2068 /* FALLTHRU */
2069 case '_':
2070 /* Escape to command mode, but be nice! *//* TODO command expansion
2071 * TODO should be handled here so that we have unique history! */
2072 if(cnt == 0)
2073 goto jearg;
2074 _execute_command(hp, cp, cnt);
2075 if(ok_blook(errexit))
2076 flags |= a_ERREXIT;
2077 else
2078 flags &= ~a_ERREXIT;
2079 if(n_pstate_ex_no != 0 && a_HARDERR())
2080 goto jerr;
2081 if(coap == NULL)
2082 escape = *ok_vlook(escape);
2083 break;
2084 case '.':
2085 /* Simulate end of file on input */
2086 if(cnt != 0 || coap != NULL)
2087 goto jearg;
2088 goto jout; /* TODO does not enter history, thus */
2089 case 'x':
2090 /* Same as 'q', but no *DEAD* saving */
2091 /* FALLTHRU */
2092 case 'q':
2093 /* Force a quit, act like an interrupt had happened */
2094 if(cnt != 0)
2095 goto jearg;
2096 /* If we are running a splice hook, assume it quits on its own now,
2097 * otherwise we (no true out-of-band IPC to signal this state, XXX sic)
2098 * have to SIGTERM it in order to stop this wild beast */
2099 flags |= a_COAP_NOSIGTERM;
2100 ++_coll_hadintr;
2101 _collint((c == 'x') ? 0 : SIGINT);
2102 exit(n_EXIT_ERR);
2103 /*NOTREACHED*/
2104 case 'h':
2105 /* Grab a bunch of headers */
2106 if(cnt != 0)
2107 goto jearg;
2109 grab_headers(n_GO_INPUT_CTX_COMPOSE, hp,
2110 (GTO | GSUBJECT | GCC | GBCC),
2111 (ok_blook(bsdcompat) && ok_blook(bsdorder)));
2112 while(hp->h_to == NULL);
2113 n_pstate_err_no = n_ERR_NONE; /* XXX */
2114 n_pstate_ex_no = 0; /* XXX */
2115 break;
2116 case 'H':
2117 /* Grab extra headers */
2118 if(cnt != 0)
2119 goto jearg;
2121 grab_headers(n_GO_INPUT_CTX_COMPOSE, hp, GEXTRA, 0);
2122 while(check_from_and_sender(hp->h_from, hp->h_sender) == NULL);
2123 n_pstate_err_no = n_ERR_NONE; /* XXX */
2124 n_pstate_ex_no = 0; /* XXX */
2125 break;
2126 case 't':
2127 /* Add to the To: list */
2128 if(cnt == 0)
2129 goto jearg;
2130 hp->h_to = cat(hp->h_to,
2131 checkaddrs(lextract(cp, GTO | GFULL), EACM_NORMAL, NULL));
2132 n_pstate_err_no = n_ERR_NONE; /* XXX */
2133 n_pstate_ex_no = 0; /* XXX */
2134 hist &= ~a_HIST_GABBY;
2135 break;
2136 case 's':
2137 /* Set the Subject list */
2138 if(cnt == 0)
2139 goto jearg;
2140 /* Subject:; take care for Debian #419840 and strip any \r and \n */
2141 if(n_anyof_cp("\n\r", hp->h_subject = savestr(cp))){
2142 char *xp;
2144 n_err(_("-s: normalizing away invalid ASCII NL / CR bytes\n"));
2145 for(xp = hp->h_subject; *xp != '\0'; ++xp)
2146 if(*xp == '\n' || *xp == '\r')
2147 *xp = ' ';
2148 n_pstate_err_no = n_ERR_INVAL;
2149 n_pstate_ex_no = 1;
2150 }else{
2151 n_pstate_err_no = n_ERR_NONE;
2152 n_pstate_ex_no = 0;
2154 break;
2155 case '@':{
2156 struct attachment *aplist;
2158 /* Edit the attachment list */
2159 aplist = hp->h_attach;
2160 hp->h_attach = NULL;
2161 if(cnt != 0)
2162 hp->h_attach = n_attachment_append_list(aplist, cp);
2163 else
2164 hp->h_attach = n_attachment_list_edit(aplist,
2165 n_GO_INPUT_CTX_COMPOSE);
2166 n_pstate_err_no = n_ERR_NONE; /* XXX ~@ does NOT handle $!/$?! */
2167 n_pstate_ex_no = 0; /* XXX */
2168 } break;
2169 case 'c':
2170 /* Add to the CC list */
2171 if(cnt == 0)
2172 goto jearg;
2173 hp->h_cc = cat(hp->h_cc,
2174 checkaddrs(lextract(cp, GCC | GFULL), EACM_NORMAL, NULL));
2175 n_pstate_err_no = n_ERR_NONE; /* XXX */
2176 n_pstate_ex_no = 0; /* XXX */
2177 hist &= ~a_HIST_GABBY;
2178 break;
2179 case 'b':
2180 /* Add stuff to blind carbon copies list */
2181 if(cnt == 0)
2182 goto jearg;
2183 hp->h_bcc = cat(hp->h_bcc,
2184 checkaddrs(lextract(cp, GBCC | GFULL), EACM_NORMAL, NULL));
2185 n_pstate_err_no = n_ERR_NONE; /* XXX */
2186 n_pstate_ex_no = 0; /* XXX */
2187 hist &= ~a_HIST_GABBY;
2188 break;
2189 case 'd':
2190 if(cnt != 0)
2191 goto jearg;
2192 cp = n_getdeadletter();
2193 if(0){
2194 /*FALLTHRU*/
2195 case 'R':
2196 case 'r':
2197 case '<':
2198 /* Invoke a file: Search for the file name, then open it and copy
2199 * the contents to _coll_fp */
2200 if(cnt == 0){
2201 n_err(_("Interpolate what file?\n"));
2202 if(a_HARDERR())
2203 goto jerr;
2204 n_pstate_err_no = n_ERR_NOENT;
2205 n_pstate_ex_no = 1;
2206 break;
2208 if(*cp == '!' && c == '<'){
2209 /* TODO hist. normalization */
2210 if((n_pstate_err_no = a_coll_insert_cmd(_coll_fp, ++cp)
2211 ) != n_ERR_NONE){
2212 if(ferror(_coll_fp))
2213 goto jerr;
2214 if(a_HARDERR())
2215 goto jerr;
2216 n_pstate_ex_no = 1;
2217 break;
2219 goto jhistcont;
2221 /* Note this also expands things like
2222 * !:vput vexpr delim random 0
2223 * !< - $delim */
2224 if((cp = fexpand(cp, FEXP_LOCAL | FEXP_NOPROTO | FEXP_NSHELL)
2225 ) == NULL){
2226 if(a_HARDERR())
2227 goto jerr;
2228 n_pstate_err_no = n_ERR_INVAL;
2229 n_pstate_ex_no = 1;
2230 break;
2233 if(n_is_dir(cp, FAL0)){
2234 n_err(_("%s: is a directory\n"), n_shexp_quote_cp(cp, FAL0));
2235 if(a_HARDERR())
2236 goto jerr;
2237 n_pstate_err_no = n_ERR_ISDIR;
2238 n_pstate_ex_no = 1;
2239 break;
2241 if((n_pstate_err_no = a_coll_include_file(cp, (c == 'R'), TRU1)
2242 ) != n_ERR_NONE){
2243 if(ferror(_coll_fp))
2244 goto jerr;
2245 if(a_HARDERR())
2246 goto jerr;
2247 n_pstate_ex_no = 1;
2248 break;
2250 n_pstate_err_no = n_ERR_NONE; /* XXX */
2251 n_pstate_ex_no = 0; /* XXX */
2252 break;
2253 case 'i':
2254 /* Insert a variable into the file */
2255 if(cnt == 0)
2256 goto jearg;
2257 if((cp = n_var_vlook(cp, TRU1)) == NULL || *cp == '\0')
2258 break;
2259 if(putesc(cp, _coll_fp) < 0) /* TODO v15: user resp upon `set' time */
2260 goto jerr;
2261 if((n_psonce & n_PSO_INTERACTIVE) && putesc(cp, n_stdout) < 0)
2262 goto jerr;
2263 n_pstate_err_no = n_ERR_NONE; /* XXX */
2264 n_pstate_ex_no = 0; /* XXX */
2265 break;
2266 case 'a':
2267 case 'A':
2268 /* Insert the contents of a signature variable */
2269 if(cnt != 0)
2270 goto jearg;
2271 cp = (c == 'a') ? ok_vlook(sign) : ok_vlook(Sign);
2272 if(cp != NULL && *cp != '\0'){
2273 if(putesc(cp, _coll_fp) < 0) /* TODO v15: user upon `set' time */
2274 goto jerr;
2275 if((n_psonce & n_PSO_INTERACTIVE) && putesc(cp, n_stdout) < 0)
2276 goto jerr;
2278 n_pstate_err_no = n_ERR_NONE; /* XXX */
2279 n_pstate_ex_no = 0; /* XXX */
2280 break;
2281 case 'w':
2282 /* Write the message on a file */
2283 if(cnt == 0)
2284 goto jearg;
2285 if((cp = fexpand(cp, FEXP_LOCAL | FEXP_NOPROTO)) == NULL){
2286 n_err(_("Write what file!?\n"));
2287 if(a_HARDERR())
2288 goto jerr;
2289 n_pstate_err_no = n_ERR_INVAL;
2290 n_pstate_ex_no = 1;
2291 break;
2293 rewind(_coll_fp);
2294 if((n_pstate_err_no = a_coll_write(cp, _coll_fp, 1)) == n_ERR_NONE)
2295 n_pstate_ex_no = 0;
2296 else if(ferror(_coll_fp))
2297 goto jerr;
2298 else if(a_HARDERR())
2299 goto jerr;
2300 else
2301 n_pstate_ex_no = 1;
2302 break;
2303 case 'm':
2304 case 'M':
2305 case 'f':
2306 case 'F':
2307 case 'u':
2308 case 'U':
2309 /* Interpolate the named messages, if we are in receiving mail mode.
2310 * Does the standard list processing garbage. If ~f is given, we
2311 * don't shift over */
2312 if(cnt == 0)
2313 goto jearg;
2314 if((n_pstate_err_no = a_coll_forward(cp, _coll_fp, c)) == n_ERR_NONE)
2315 n_pstate_ex_no = 0;
2316 else if(ferror(_coll_fp))
2317 goto jerr;
2318 else if(a_HARDERR())
2319 goto jerr;
2320 else
2321 n_pstate_ex_no = 1;
2322 break;
2323 case 'p':
2324 /* Print current state of the message without altering anything */
2325 if(cnt != 0)
2326 goto jearg;
2327 print_collf(_coll_fp, hp); /* XXX pstate_err_no ++ */
2328 if(ferror(_coll_fp))
2329 goto jerr;
2330 n_pstate_err_no = n_ERR_NONE; /* XXX */
2331 n_pstate_ex_no = 0; /* XXX */
2332 break;
2333 case '|':
2334 /* Pipe message through command. Collect output as new message */
2335 if(cnt == 0)
2336 goto jearg;
2337 rewind(_coll_fp);
2338 if((n_pstate_err_no = a_coll_pipe(cp)) == n_ERR_NONE)
2339 n_pstate_ex_no = 0;
2340 else if(a_HARDERR())
2341 goto jerr;
2342 else
2343 n_pstate_ex_no = 1;
2344 hist &= ~a_HIST_GABBY;
2345 goto jhistcont;
2346 case 'v':
2347 case 'e':
2348 /* Edit the current message. 'e' -> use EDITOR, 'v' -> use VISUAL */
2349 if(cnt != 0 || coap != NULL)
2350 goto jearg;
2351 rewind(_coll_fp);
2352 if((n_pstate_err_no = a_coll_edit(c, ok_blook(editheaders) ? hp : NULL)
2353 ) == n_ERR_NONE)
2354 n_pstate_ex_no = 0;
2355 else if(ferror(_coll_fp))
2356 goto jerr;
2357 else if(a_HARDERR())
2358 goto jerr;
2359 else
2360 n_pstate_ex_no = 1;
2361 goto jhistcont;
2362 case '^':
2363 if(!a_collect_plumbing(cp, hp)){
2364 if(ferror(_coll_fp))
2365 goto jerr;
2366 goto jearg;
2368 n_pstate_err_no = n_ERR_NONE; /* XXX */
2369 n_pstate_ex_no = 0; /* XXX */
2370 hist &= ~a_HIST_GABBY;
2371 break;
2372 case '?':
2373 /* Last the lengthy help string. (Very ugly, but take care for
2374 * compiler supported string lengths :() */
2375 fputs(_(
2376 "COMMAND ESCAPES (to be placed after a newline) excerpt:\n"
2377 "~. Commit and send message\n"
2378 "~: <command> Execute an internal command\n"
2379 "~< <file> Insert <file> (\"~<! <command>\" inserts shell command)\n"
2380 "~@ [<files>] Edit[/Add] attachments (file[=input-charset[#output-charset]])\n"
2381 "~A Insert *Sign* variable (`~a': insert *sign*)\n"
2382 "~c <users> Add users to Cc: list (`~b': to Bcc:)\n"
2383 "~d Read in $DEAD (dead.letter)\n"
2384 "~e Edit message via $EDITOR\n"
2385 ), n_stdout);
2386 fputs(_(
2387 "~F <msglist> Read in with headers, do not *indentprefix* lines\n"
2388 "~f <msglist> Like ~F, but honour `ignore' / `retain' configuration\n"
2389 "~H Edit From:, Reply-To: and Sender:\n"
2390 "~h Prompt for Subject:, To:, Cc: and \"blind\" Bcc:\n"
2391 "~i <variable> Insert a value and a newline\n"
2392 "~M <msglist> Read in with headers, *indentprefix* (`~m': `retain' etc.)\n"
2393 "~p Show current message compose buffer\n"
2394 "~r <file> Insert <file> (`~R': likewise, but *indentprefix* lines)\n"
2395 ), n_stdout);
2396 fputs(_(
2397 "~s <subject> Set Subject:\n"
2398 "~t <users> Add users to To: list\n"
2399 "~u <msglist> Read in message(s) without headers (`~U': indent lines)\n"
2400 "~v Edit message via $VISUAL\n"
2401 "~w <file> Write message onto file\n"
2402 "~x Abort composition, discard message (`~q': save in $DEAD)\n"
2403 "~| <command> Pipe message through shell filter\n"
2404 ), n_stdout);
2405 if(cnt != 0)
2406 goto jearg;
2407 n_pstate_err_no = n_ERR_NONE;
2408 n_pstate_ex_no = 0;
2409 break;
2412 /* Finally place an entry in history as applicable */
2413 if(0){
2414 jhistcont:
2415 c = '\1';
2416 }else
2417 c = '\0';
2418 if(hist & a_HIST_ADD)
2419 n_tty_addhist(n_string_cp(sp), ((hist & a_HIST_GABBY) != 0));
2420 if(c != '\0')
2421 goto jcont;
2424 jout:
2425 /* Do we have *on-compose-splice-shell*, or *on-compose-splice*?
2426 * TODO Usual f...ed up state of signals and terminal etc. */
2427 if(coap == NULL && (cp = ok_vlook(on_compose_splice_shell)) != NULL) Jocs:{
2428 union {int (*ptf)(void); char const *sh;} u;
2429 char const *cmd;
2431 /* Reset *escape* and more to their defaults. On change update manual! */
2432 if(ifs_saved == NULL)
2433 ifs_saved = savestr(ok_vlook(ifs));
2434 escape = n_ESCAPE[0];
2435 ok_vclear(ifs);
2437 if(coapm != NULL){
2438 /* XXX Due Popen() fflush(NULL) in PTF mode, ensure nothing to flush */
2439 /*if(!n_real_seek(_coll_fp, 0, SEEK_END))
2440 * goto jerr;*/
2441 u.ptf = &a_coll_ocs__mac;
2442 cmd = (char*)-1;
2443 a_coll_ocs__macname = cp = coapm;
2444 }else{
2445 u.sh = ok_vlook(SHELL);
2446 cmd = cp;
2449 i = strlen(cp) +1;
2450 coap = n_lofi_alloc(n_VSTRUCT_SIZEOF(struct a_coll_ocs_arg, coa_cmd
2451 ) + i);
2452 coap->coa_pipe[0] = coap->coa_pipe[1] = -1;
2453 coap->coa_stdin = coap->coa_stdout = NULL;
2454 coap->coa_senderr = checkaddr_err;
2455 memcpy(coap->coa_cmd, cp, i);
2457 hold_all_sigs();
2458 coap->coa_opipe = safe_signal(SIGPIPE, SIG_IGN);
2459 coap->coa_oint = safe_signal(SIGINT, SIG_IGN);
2460 rele_all_sigs();
2462 if(pipe_cloexec(coap->coa_pipe) != -1 &&
2463 (coap->coa_stdin = Fdopen(coap->coa_pipe[0], "r", FAL0)) != NULL &&
2464 (coap->coa_stdout = Popen(cmd, "W", u.sh, NULL, coap->coa_pipe[1])
2465 ) != NULL){
2466 close(coap->coa_pipe[1]);
2467 coap->coa_pipe[1] = -1;
2469 temporary_compose_mode_hook_call(NULL, NULL, NULL);
2470 n_go_splice_hack(coap->coa_cmd, coap->coa_stdin, coap->coa_stdout,
2471 (n_psonce & ~(n_PSO_INTERACTIVE | n_PSO_TTYIN | n_PSO_TTYOUT)),
2472 &a_coll_ocs__finalize, &coap);
2473 /* Hook version protocol for ~^: update manual upon change! */
2474 fputs(a_COLL_PLUMBING_VERSION "\n", coap->coa_stdout);
2475 #undef a_COLL_PLUMBING_VERSION
2476 goto jcont;
2479 c = n_err_no;
2480 a_coll_ocs__finalize(coap);
2481 n_perr(_("Cannot invoke *on-compose-splice(-shell)?*"), c);
2482 goto jerr;
2484 if(*checkaddr_err != 0){
2485 *checkaddr_err = 0;
2486 goto jerr;
2488 if(coapm == NULL && (coapm = ok_vlook(on_compose_splice)) != NULL)
2489 goto Jocs;
2490 if(coap != NULL){
2491 ok_vset(ifs, ifs_saved);
2492 ifs_saved = NULL;
2495 /* Final chance to edit headers, if not already above */
2496 if (ok_blook(bsdcompat) || ok_blook(askatend)) {
2497 if (hp->h_cc == NULL && ok_blook(askcc))
2498 grab_headers(n_GO_INPUT_CTX_COMPOSE, hp, GCC, 1);
2499 if (hp->h_bcc == NULL && ok_blook(askbcc))
2500 grab_headers(n_GO_INPUT_CTX_COMPOSE, hp, GBCC, 1);
2502 if (hp->h_attach == NULL && ok_blook(askattach))
2503 hp->h_attach = n_attachment_list_edit(hp->h_attach,
2504 n_GO_INPUT_CTX_COMPOSE);
2506 /* Execute compose-leave */
2507 if((cp = ok_vlook(on_compose_leave)) != NULL){
2508 setup_from_and_sender(hp);
2509 temporary_compose_mode_hook_call(cp, &n_temporary_compose_hook_varset,
2510 hp);
2513 /* Add automatic receivers */
2514 if ((cp = ok_vlook(autocc)) != NULL && *cp != '\0')
2515 hp->h_cc = cat(hp->h_cc, checkaddrs(lextract(cp, GCC | GFULL),
2516 EACM_NORMAL, checkaddr_err));
2517 if ((cp = ok_vlook(autobcc)) != NULL && *cp != '\0')
2518 hp->h_bcc = cat(hp->h_bcc, checkaddrs(lextract(cp, GBCC | GFULL),
2519 EACM_NORMAL, checkaddr_err));
2520 if (*checkaddr_err != 0)
2521 goto jerr;
2523 /* TODO Cannot do since it may require turning this into a multipart one */
2524 if(n_poption & n_PO_Mm_FLAG)
2525 goto jskiptails;
2527 /* Place signature? */
2528 if((cp = ok_vlook(signature)) != NULL && *cp != '\0'){
2529 char const *cpq;
2531 if((cpq = fexpand(cp, FEXP_LOCAL | FEXP_NOPROTO)) == NULL){
2532 n_err(_("*signature* expands to invalid file: %s\n"),
2533 n_shexp_quote_cp(cp, FAL0));
2534 goto jerr;
2536 cpq = n_shexp_quote_cp(cp = cpq, FAL0);
2538 if((sigfp = Fopen(cp, "r")) == NULL){
2539 n_err(_("Can't open *signature* %s: %s\n"),
2540 cpq, n_err_to_doc(n_err_no));
2541 goto jerr;
2544 if(linebuf == NULL)
2545 linebuf = smalloc(linesize = LINESIZE);
2546 c = '\0';
2547 while((i = fread(linebuf, sizeof *linebuf, linesize, n_UNVOLATILE(sigfp)))
2548 > 0){
2549 c = linebuf[i - 1];
2550 if(i != fwrite(linebuf, sizeof *linebuf, i, _coll_fp))
2551 goto jerr;
2554 /* C99 */{
2555 FILE *x = n_UNVOLATILE(sigfp);
2556 int e = n_err_no, ise = ferror(x);
2558 sigfp = NULL;
2559 Fclose(x);
2561 if(ise){
2562 n_err(_("Errors while reading *signature* %s: %s\n"),
2563 cpq, n_err_to_doc(e));
2564 goto jerr;
2568 if(c != '\0' && c != '\n')
2569 putc('\n', _coll_fp);
2572 { char const *cp_obsolete = ok_vlook(NAIL_TAIL);
2574 if(cp_obsolete != NULL)
2575 n_OBSOLETE(_("please use *message-inject-tail*, not *NAIL_TAIL*"));
2577 if((cp = ok_vlook(message_inject_tail)) != NULL ||
2578 (cp = cp_obsolete) != NULL){
2579 if(putesc(cp, _coll_fp) < 0)
2580 goto jerr;
2581 if((n_psonce & n_PSO_INTERACTIVE) && putesc(cp, n_stdout) < 0)
2582 goto jerr;
2586 jskiptails:
2587 if(fflush(_coll_fp))
2588 goto jerr;
2589 rewind(_coll_fp);
2591 jleave:
2592 if (linebuf != NULL)
2593 free(linebuf);
2594 sigprocmask(SIG_BLOCK, &nset, NULL);
2595 n_pstate &= ~n_PS_COMPOSE_MODE;
2596 safe_signal(SIGINT, _coll_saveint);
2597 safe_signal(SIGHUP, _coll_savehup);
2598 sigprocmask(SIG_SETMASK, &oset, NULL);
2599 NYD_LEAVE;
2600 return _coll_fp;
2602 jerr:
2603 hold_all_sigs();
2605 if(coap != NULL && coap != (struct a_coll_ocs_arg*)-1){
2606 if(!(flags & a_COAP_NOSIGTERM))
2607 n_psignal(coap->coa_stdout, SIGTERM);
2608 n_go_splice_hack_remove_after_jump();
2609 coap = NULL;
2611 if(ifs_saved != NULL){
2612 ok_vset(ifs, ifs_saved);
2613 ifs_saved = NULL;
2615 if(sigfp != NULL){
2616 Fclose(n_UNVOLATILE(sigfp));
2617 sigfp = NULL;
2619 if(_coll_fp != NULL){
2620 Fclose(_coll_fp);
2621 _coll_fp = NULL;
2624 rele_all_sigs();
2626 assert(checkaddr_err != NULL);
2627 /* TODO We don't save in $DEAD upon error because msg not readily composed?
2628 * TODO But this no good, it should go ZOMBIE / DRAFT / POSTPONED or what! */
2629 if(*checkaddr_err != 0){
2630 if(*checkaddr_err == 111)
2631 n_err(_("Compose mode splice hook failure\n"));
2632 else
2633 n_err(_("Some addressees were classified as \"hard error\"\n"));
2634 }else if(_coll_hadintr == 0){
2635 *checkaddr_err = TRU1; /* TODO ugly: "sendout_error" now.. */
2636 n_err(_("Failed to prepare composed message (I/O error, disk full?)\n"));
2638 goto jleave;
2640 #undef a_HARDERR
2643 /* s-it-mode */