1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Collect input from standard input, handling ~ escapes.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 - 2015 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
8 * Copyright (c) 1980, 1993
9 * The Regents of the University of California. All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 #define n_FILE collect
42 #ifndef HAVE_AMALGAMATION
46 /* The following hookiness with global variables is so that on receipt of an
47 * interrupt signal, the partial message can be salted away on *DEAD* */
49 static sighandler_type _coll_saveint
; /* Previous SIGINT value */
50 static sighandler_type _coll_savehup
; /* Previous SIGHUP value */
51 static sighandler_type _coll_savetstp
; /* Previous SIGTSTP value */
52 static sighandler_type _coll_savettou
; /* Previous SIGTTOU value */
53 static sighandler_type _coll_savettin
; /* Previous SIGTTIN value */
54 static FILE *_coll_fp
; /* File for saving away */
55 static int volatile _coll_hadintr
; /* Have seen one SIGINT so far */
56 static sigjmp_buf _coll_jmp
; /* To get back to work */
57 static int _coll_jmp_p
; /* whether to long jump */
58 static sigjmp_buf _coll_abort
; /* To end collection with error */
59 static sigjmp_buf _coll_pipejmp
; /* On broken pipe */
61 /* Handle `~:', `~_' */
62 static void _execute_command(struct header
*hp
, char *linebuf
,
65 /* If *interactive* is set and *doecho* is, too, also dump to *stdout* */
66 static int _include_file(char const *name
, int *linecount
,
67 int *charcount
, bool_t doecho
, bool_t indent
);
69 static void _collect_onpipe(int signo
);
71 /* Execute cmd and insert its standard output into fp */
72 static void insertcommand(FILE *fp
, char const *cmd
);
75 static void print_collf(FILE *collf
, struct header
*hp
);
77 /* Write a file, ex-like if f set */
78 static int exwrite(char const *name
, FILE *fp
, int f
);
80 static enum okay
makeheader(FILE *fp
, struct header
*hp
);
82 /* Edit the message being collected on fp. On return, make the edit file the
84 static void mesedit(int c
, struct header
*hp
);
86 /* Pipe the message through the command. Old message is on stdin of command,
87 * new message collected from stdout. Shell must return 0 to accept new msg */
88 static void mespipe(char *cmd
);
90 /* Interpolate the named messages into the current message, possibly doing
91 * indent stuff. The flag argument is one of the tilde escapes: [mMfFuU].
92 * Return a count of the number of characters now in the message, or -1 if an
93 * error is encountered writing the message temporary */
94 static int forward(char *ms
, FILE *fp
, int f
);
96 /* Print (continue) when continued after ^Z */
97 static void collstop(int s
);
99 /* On interrupt, come here to save the partial message in ~/dead.letter.
100 * Then jump out of the collection loop */
101 static void _collint(int s
);
103 static void collhup(int s
);
105 static int putesc(char const *s
, FILE *stream
);
108 _execute_command(struct header
*hp
, char *linebuf
, size_t linesize
)
110 /* The problem arises if there are rfc822 message attachments and the
111 * user uses `~:' to change the current file. TODO Unfortunately we
112 * TODO cannot simply keep a pointer to, or increment a reference count
113 * TODO of the current `file' (mailbox that is) object, because the
114 * TODO codebase doesn't deal with that at all; so, until some far
115 * TODO later time, copy the name of the path, and warn the user if it
116 * TODO changed; we COULD use the AC_TMPFILE attachment type, i.e.,
117 * TODO copy the message attachments over to temporary files, but that
118 * TODO would require more changes so that the user still can recognize
119 * TODO in `~@' etc. that its a rfc822 message attachment; see below */
121 size_t mnlen
= 0 /* silence CC */;
122 struct attachment
*ap
;
125 /* If the above todo is worked, remove or outsource to attachments.c! */
126 if ((ap
= hp
->h_attach
) != NULL
) do
128 mnlen
= strlen(mailname
) +1;
129 mnbuf
= ac_alloc(mnlen
);
130 memcpy(mnbuf
, mailname
, mnlen
);
133 while ((ap
= ap
->a_flink
) != NULL
);
135 pstate
&= ~PS_HOOK_MASK
;
136 execute(linebuf
, TRU1
, linesize
);
139 if (strncmp(mnbuf
, mailname
, mnlen
))
140 n_err(_("Mailbox changed: it is likely that existing "
141 "rfc822 attachments became invalid!\n"));
148 _include_file(char const *name
, int *linecount
, int *charcount
,
149 bool_t doecho
, bool_t indent
)
154 char *linebuf
= NULL
; /* TODO line pool */
155 size_t linesize
= 0, indl
, linelen
, cnt
;
158 if ((fbuf
= Fopen(name
, "r")) == NULL
) {
164 indb
= NULL
, indl
= 0;
166 if ((indb
= ok_vlook(indentprefix
)) == NULL
)
167 indb
= INDENT_DEFAULT
;
171 *linecount
= *charcount
= 0;
173 while (fgetline(&linebuf
, &linesize
, &cnt
, &linelen
, fbuf
, 0) != NULL
) {
174 if (indl
> 0 && fwrite(indb
, sizeof *indb
, indl
, _coll_fp
) != indl
)
176 if (fwrite(linebuf
, sizeof *linebuf
, linelen
, _coll_fp
) != linelen
)
179 (*charcount
) += linelen
+ indl
;
180 if ((options
& OPT_INTERACTIVE
) && doecho
) {
182 fwrite(indb
, sizeof *indb
, indl
, stdout
);
183 fwrite(linebuf
, sizeof *linebuf
, linelen
, stdout
);
186 if (fflush(_coll_fp
))
188 if ((options
& OPT_INTERACTIVE
) && doecho
)
202 _collect_onpipe(int signo
)
204 NYD_X
; /* Signal handler */
206 siglongjmp(_coll_pipejmp
, 1);
210 insertcommand(FILE *fp
, char const *cmd
)
217 cp
= ok_vlook(SHELL
);
221 if ((ibuf
= Popen(cmd
, "r", cp
, NULL
, 0)) != NULL
) {
222 while ((c
= getc(ibuf
)) != EOF
) /* XXX bytewise, yuck! */
231 print_collf(FILE *cf
, struct header
*hp
)
233 char *lbuf
= NULL
; /* TODO line pool */
234 sighandler_type sigint
;
235 FILE *volatile obuf
= stdout
;
236 struct attachment
*ap
;
239 size_t linesize
= 0, linelen
, cnt
, cnt2
;
243 cnt
= cnt2
= fsize(cf
);
245 sigint
= safe_signal(SIGINT
, SIG_IGN
);
247 if (IS_TTY_SESSION() && (cp
= ok_vlook(crt
)) != NULL
) {
251 if (hp
->h_to
!= NULL
)
253 if (hp
->h_subject
!= NULL
)
255 if (hp
->h_cc
!= NULL
)
257 if (hp
->h_bcc
!= NULL
)
259 if (hp
->h_attach
!= NULL
)
261 m
+= (hp
->h_from
!= NULL
|| myaddrs(hp
) != NULL
);
262 m
+= (hp
->h_sender
!= NULL
|| ok_vlook(sender
) != NULL
);
263 m
+= (hp
->h_replyto
!= NULL
|| ok_vlook(replyto
) != NULL
);
264 m
+= (hp
->h_organization
!= NULL
|| ok_vlook(ORGANIZATION
) != NULL
);
266 l
= (*cp
== '\0') ? screensize() : atoi(cp
);
271 for (m
= 0; fgetline(&lbuf
, &linesize
, &cnt2
, NULL
, cf
, 0); ++m
)
276 cp
= get_pager(NULL
);
277 if (sigsetjmp(_coll_pipejmp
, 1))
279 obuf
= Popen(cp
, "w", NULL
, NULL
, 1);
284 safe_signal(SIGPIPE
, &_collect_onpipe
);
288 fprintf(obuf
, _("-------\nMessage contains:\n"));
289 gf
= GIDENT
| GTO
| GSUBJECT
| GCC
| GBCC
| GNL
| GFILES
| GCOMMA
;
290 puthead(hp
, obuf
, gf
, SEND_TODISP
, CONV_NONE
, NULL
, NULL
);
291 while (fgetline(&lbuf
, &linesize
, &cnt
, &linelen
, cf
, 1))
292 prout(lbuf
, linelen
, obuf
);
293 if (hp
->h_attach
!= NULL
) {
294 fputs(_("-------\nAttachments:\n"), obuf
);
295 for (ap
= hp
->h_attach
; ap
!= NULL
; ap
= ap
->a_flink
) {
297 fprintf(obuf
, " - message %u\n", ap
->a_msgno
);
299 /* TODO after MIME/send layer rewrite we *know*
300 * TODO the details of the attachment here,
301 * TODO so adjust this again, then */
302 char const *cs
, *csi
= "-> ";
304 if ((cs
= ap
->a_charset
) == NULL
&&
305 (csi
= "<- ", cs
= ap
->a_input_charset
) == NULL
)
306 cs
= charset_get_lc();
307 if ((cp
= ap
->a_content_type
) == NULL
)
309 else if (ascncasecmp(cp
, "text/", 5))
311 fprintf(obuf
, " - [%s, %s%s] %s\n", cp
, csi
, cs
, ap
->a_name
);
317 if (obuf
!= stdout
) {
318 safe_signal(SIGPIPE
, SIG_IGN
);
320 safe_signal(SIGPIPE
, dflpipe
);
324 safe_signal(SIGINT
, sigint
);
329 exwrite(char const *name
, FILE *fp
, int f
)
337 printf("\"%s\" ", name
);
340 if ((of
= Fopen(name
, "a")) == NULL
) {
347 while ((c
= getc(fp
)) != EOF
) {
359 printf(_("%d/%ld\n"), lc
, cc
);
368 makeheader(FILE *fp
, struct header
*hp
)
375 if ((nf
= Ftmp(NULL
, "colhead", OF_RDWR
| OF_UNLINK
| OF_REGISTER
, 0600)) ==
377 n_perr(_("temporary mail edit file"), 0);
381 extract_header(fp
, hp
);
382 while ((c
= getc(fp
)) != EOF
) /* XXX bytewise, yuck! */
388 if (check_from_and_sender(hp
->h_from
, hp
->h_sender
) == NULL
)
397 mesedit(int c
, struct header
*hp
)
400 sighandler_type sigint
;
404 saved
= ok_blook(add_file_recipients
);
405 ok_bset(add_file_recipients
, TRU1
);
407 sigint
= safe_signal(SIGINT
, SIG_IGN
);
408 nf
= run_editor(_coll_fp
, (off_t
)-1, c
, 0, hp
, NULL
, SEND_MBOX
, sigint
);
414 fseek(nf
, 0L, SEEK_END
);
419 safe_signal(SIGINT
, sigint
);
421 ok_bset(add_file_recipients
, saved
);
429 sighandler_type sigint
;
433 sigint
= safe_signal(SIGINT
, SIG_IGN
);
435 if ((nf
= Ftmp(NULL
, "colpipe", OF_RDWR
| OF_UNLINK
| OF_REGISTER
, 0600)) ==
437 n_perr(_("temporary mail edit file"), 0);
441 /* stdin = current message. stdout = new message */
442 if ((sh
= ok_vlook(SHELL
)) == NULL
)
445 if (run_command(sh
, 0, fileno(_coll_fp
), fileno(nf
), "-c", cmd
, NULL
) < 0) {
450 if (fsize(nf
) == 0) {
451 n_err(_("No bytes from \"%s\" !?\n"), cmd
);
457 fseek(nf
, 0L, SEEK_END
);
461 safe_signal(SIGINT
, sigint
);
466 forward(char *ms
, FILE *fp
, int f
)
469 struct ignoretab
*ig
;
471 enum sendaction action
;
474 msgvec
= salloc((size_t)(msgCount
+ 1) * sizeof *msgvec
);
475 if (getmsglist(ms
, msgvec
, 0) < 0)
478 *msgvec
= first(0, MMNORM
);
480 n_err(_("No appropriate messages\n"));
486 if (f
== 'f' || f
== 'F' || f
== 'u')
488 else if ((tabst
= ok_vlook(indentprefix
)) == NULL
)
489 tabst
= INDENT_DEFAULT
;
490 if (f
== 'u' || f
== 'U')
493 ig
= upperchar(f
) ? NULL
: ignore
;
494 action
= (upperchar(f
) && f
!= 'U') ? SEND_QUOTE_ALL
: SEND_QUOTE
;
496 printf(_("Interpolating:"));
497 for (; *msgvec
!= 0; ++msgvec
) {
498 struct message
*mp
= message
+ *msgvec
- 1;
501 printf(" %d", *msgvec
);
503 if (sendmp(mp
, fp
, ig
, tabst
, action
, NULL
) < 0) {
504 n_perr(_("temporary mail file"), 0);
518 sighandler_type old_action
;
520 NYD_X
; /* Signal handler */
522 old_action
= safe_signal(s
, SIG_DFL
);
526 sigprocmask(SIG_UNBLOCK
, &nset
, NULL
);
528 sigprocmask(SIG_BLOCK
, &nset
, NULL
);
530 safe_signal(s
, old_action
);
534 siglongjmp(_coll_jmp
, 1);
541 NYD_X
; /* Signal handler */
543 /* the control flow is subtle, because we can be called from ~q */
544 if (_coll_hadintr
== 0) {
545 if (ok_blook(ignore
)) {
551 siglongjmp(_coll_jmp
, 1);
553 exit_status
|= EXIT_SEND_ERROR
;
554 if (ok_blook(save
) && s
!= 0)
555 savedeadletter(_coll_fp
, 1);
556 /* Aborting message, no need to fflush() .. */
557 siglongjmp(_coll_abort
, 1);
563 NYD_X
; /* Signal handler */
566 savedeadletter(_coll_fp
, 1);
567 /* Let's pretend nobody else wants to clean up, a true statement at
573 putesc(char const *s
, FILE *stream
)
578 while (s
[0] != '\0') {
581 if (putc('\t', stream
) == EOF
)
588 if (putc('\n', stream
) == EOF
)
595 if (putc(s
[0], stream
) == EOF
)
600 if (putc('\n', stream
) == EOF
)
609 collect(struct header
*hp
, int printheaders
, struct message
*mp
,
610 char *quotefile
, int doprefix
)
612 struct ignoretab
*quoteig
;
614 int volatile escape
, getfields
;
615 char *linebuf
= NULL
, *quote
= NULL
;
617 size_t linesize
= 0; /* TODO line pool */
619 enum sendaction action
;
621 sighandler_type savedtop
;
625 /* Start catching signals from here, but we're still die on interrupts
626 * until we're in the main loop */
628 sigaddset(&nset
, SIGINT
);
629 sigaddset(&nset
, SIGHUP
);
630 sigprocmask(SIG_BLOCK
, &nset
, &oset
);
631 handlerpush(&_collint
);
632 if ((_coll_saveint
= safe_signal(SIGINT
, SIG_IGN
)) != SIG_IGN
)
633 safe_signal(SIGINT
, &_collint
);
634 if ((_coll_savehup
= safe_signal(SIGHUP
, SIG_IGN
)) != SIG_IGN
)
635 safe_signal(SIGHUP
, collhup
);
636 /* TODO We do a lot of redundant signal handling, especially
637 * TODO with the command line editor(s); try to merge this */
638 _coll_savetstp
= safe_signal(SIGTSTP
, collstop
);
639 _coll_savettou
= safe_signal(SIGTTOU
, collstop
);
640 _coll_savettin
= safe_signal(SIGTTIN
, collstop
);
641 if (sigsetjmp(_coll_abort
, 1))
643 if (sigsetjmp(_coll_jmp
, 1))
645 sigprocmask(SIG_SETMASK
, &oset
, (sigset_t
*)NULL
);
648 if ((_coll_fp
= Ftmp(NULL
, "collect", OF_RDWR
| OF_UNLINK
| OF_REGISTER
,
650 n_perr(_("temporary mail file"), 0);
654 if ((cp
= ok_vlook(NAIL_HEAD
)) != NULL
&& putesc(cp
, _coll_fp
) < 0)
657 /* If we are going to prompt for a subject, refrain from printing a newline
658 * after the headers (since some people mind) */
660 if (!(options
& OPT_t_FLAG
)) {
661 t
= GTO
| GSUBJECT
| GCC
| GNL
;
662 if (ok_blook(fullnames
))
665 if (options
& OPT_INTERACTIVE
) {
666 if (hp
->h_subject
== NULL
&& (ok_blook(ask
) || ok_blook(asksub
)))
667 t
&= ~GNL
, getfields
|= GSUBJECT
;
669 if (hp
->h_to
== NULL
)
670 t
&= ~GNL
, getfields
|= GTO
;
672 if (!ok_blook(bsdcompat
) && !ok_blook(askatend
)) {
673 if (hp
->h_bcc
== NULL
&& ok_blook(askbcc
))
674 t
&= ~GNL
, getfields
|= GBCC
;
675 if (hp
->h_cc
== NULL
&& ok_blook(askcc
))
676 t
&= ~GNL
, getfields
|= GCC
;
680 if (printheaders
&& !ok_blook(editalong
)) {
681 puthead(hp
, stdout
, t
, SEND_TODISP
, CONV_NONE
, NULL
, NULL
);
686 /* Quote an original message */
687 if (mp
!= NULL
&& (doprefix
|| (quote
= ok_vlook(quote
)) != NULL
)) {
692 if ((cp
= ok_vlook(fwdheading
)) == NULL
)
693 cp
= "-------- Original Message --------";
694 if (*cp
!= '\0' && fprintf(_coll_fp
, "%s\n", cp
) < 0)
696 } else if (!strcmp(quote
, "noheading")) {
698 } else if (!strcmp(quote
, "headers")) {
700 } else if (!strcmp(quote
, "allheaders")) {
702 action
= SEND_QUOTE_ALL
;
704 cp
= hfield1("from", mp
);
705 if (cp
!= NULL
&& (cnt
= (long)strlen(cp
)) > 0) {
706 if (xmime_write(cp
, cnt
, _coll_fp
, CONV_FROMHDR
, TD_NONE
) < 0)
708 if (fprintf(_coll_fp
, _(" wrote:\n\n")) < 0)
712 if (fflush(_coll_fp
))
716 else if ((cp
= ok_vlook(indentprefix
)) == NULL
)
718 if (sendmp(mp
, _coll_fp
, quoteig
, cp
, action
, NULL
) < 0)
722 /* Print what we have sofar also on the terminal (if useful) */
723 if ((options
& OPT_INTERACTIVE
) && !ok_blook(editalong
)) {
725 while ((c
= getc(_coll_fp
)) != EOF
) /* XXX bytewise, yuck! */
727 if (fseek(_coll_fp
, 0, SEEK_END
))
729 /* Ensure this is clean xxx not really necessary? */
733 escape
= ((cp
= ok_vlook(escape
)) != NULL
) ? *cp
: ESCAPE
;
736 if (!sigsetjmp(_coll_jmp
, 1)) {
738 grab_headers(hp
, getfields
, 1);
739 if (quotefile
!= NULL
) {
740 if (_include_file(quotefile
, &lc
, &cc
, TRU1
, FAL0
) != 0)
743 if ((options
& OPT_INTERACTIVE
) && ok_blook(editalong
)) {
749 /* Come here for printing the after-signal message. Duplicate messages
750 * won't be printed because the write is aborted if we get a SIGTTOU */
752 n_err(_("\n(Interrupt -- one more to kill letter)\n"));
755 printf(_("(continue)\n"));
760 /* No tilde escapes, interrupts not expected. Simply copy STDIN */
761 if (!(options
& (OPT_INTERACTIVE
| OPT_t_FLAG
| OPT_TILDE_FLAG
))) {
762 linebuf
= srealloc(linebuf
, linesize
= LINESIZE
);
763 while ((cnt
= fread(linebuf
, sizeof *linebuf
, linesize
, stdin
)) > 0) {
764 if ((size_t)cnt
!= fwrite(linebuf
, sizeof *linebuf
, cnt
, _coll_fp
))
767 if (fflush(_coll_fp
))
772 /* The interactive collect loop.
773 * All commands which come here are forbidden when sourcing! */
774 assert(_coll_hadintr
|| !(pstate
& PS_SOURCING
));
777 cnt
= readline_input("", FAL0
, &linebuf
, &linesize
, NULL
);
781 assert(!(pstate
& PS_SOURCING
));
782 if (options
& OPT_t_FLAG
) {
783 fflush_rewind(_coll_fp
);
785 if (makeheader(_coll_fp
, hp
) != OKAY
)
788 options
&= ~OPT_t_FLAG
;
790 } else if ((options
& OPT_INTERACTIVE
) && ok_blook(ignoreeof
)) {
791 printf(_("*ignoreeof* set, use \".\" to terminate letter\n"));
799 if (cnt
== 0 || !(options
& (OPT_INTERACTIVE
| OPT_TILDE_FLAG
))) {
801 /* TODO calls putline(), which *always* appends LF;
802 * TODO thus, STDIN with -t will ALWAYS end with LF,
803 * TODO even if no trailing LF and QP encoding.
804 * TODO when finally changed, update cc-test.sh */
805 if (putline(_coll_fp
, linebuf
, cnt
) < 0)
808 } else if (linebuf
[0] == '.') {
809 if (linebuf
[1] == '\0' && (ok_blook(dot
) || ok_blook(ignoreeof
)))
812 if (linebuf
[0] != escape
)
815 tty_addhist(linebuf
, TRU1
);
820 /* On double escape, send a single one. Otherwise, it's an error */
822 if (putline(_coll_fp
, linebuf
+ 1, cnt
- 1) < 0)
827 n_err(_("Unknown tilde escape: ~%c\n"), asciichar(c
) ? c
: '?');
830 /* Shell escape, send the balance of line to sh -c */
831 c_shell(linebuf
+ 2);
836 /* Escape to command mode, but be nice! */
837 _execute_command(hp
, linebuf
+ 2, cnt
- 2);
840 /* Simulate end of file on input */
843 /* Same as 'q', but no *DEAD* saving */
846 /* Force a quit, act like an interrupt had happened */
848 _collint((c
== 'x') ? 0 : SIGINT
);
852 /* Grab a bunch of headers */
854 grab_headers(hp
, GTO
| GSUBJECT
| GCC
| GBCC
,
855 (ok_blook(bsdcompat
) && ok_blook(bsdorder
)));
856 while (hp
->h_to
== NULL
);
859 /* Grab extra headers */
861 grab_headers(hp
, GEXTRA
, 0);
862 while (check_from_and_sender(hp
->h_from
, hp
->h_sender
) == NULL
);
865 /* Add to the To list */
866 hp
->h_to
= cat(hp
->h_to
,
867 checkaddrs(lextract(linebuf
+ 2, GTO
| GFULL
), EACM_NORMAL
,
871 /* Set the Subject list */
873 while (whitechar(*cp
))
875 hp
->h_subject
= savestr(cp
);
883 /* Edit the attachment list */
884 if (linebuf
[2] != '\0')
885 append_attachments(&hp
->h_attach
, linebuf
+ 2);
887 edit_attachments(&hp
->h_attach
);
890 /* Add to the CC list */
891 hp
->h_cc
= cat(hp
->h_cc
,
892 checkaddrs(lextract(linebuf
+ 2, GCC
| GFULL
), EACM_NORMAL
,
896 /* Add stuff to blind carbon copies list */
897 hp
->h_bcc
= cat(hp
->h_bcc
,
898 checkaddrs(lextract(linebuf
+ 2, GBCC
| GFULL
), EACM_NORMAL
,
902 strncpy(linebuf
+ 2, getdeadletter(), linesize
- 2);
903 linebuf
[linesize
- 1] = '\0';
908 /* Invoke a file: Search for the file name, then open it and copy the
909 * contents to _coll_fp */
911 while (whitechar(*cp
))
914 n_err(_("Interpolate what file?\n"));
918 insertcommand(_coll_fp
, cp
+ 1);
921 if ((cp
= file_expand(cp
)) == NULL
)
924 n_err(_("\"%s\": Directory\n"), cp
);
927 printf(_("\"%s\" "), cp
);
929 if (_include_file(cp
, &lc
, &cc
, FAL0
, (c
== 'R')) != 0)
931 printf(_("%d/%d\n"), lc
, cc
);
934 /* Insert a variable into the file */
936 while (whitechar(*cp
))
938 if ((cp
= vok_vlook(cp
)) == NULL
|| *cp
== '\0')
940 if (putesc(cp
, _coll_fp
) < 0)
942 if ((options
& OPT_INTERACTIVE
) && putesc(cp
, stdout
) < 0)
947 /* Insert the contents of a signature variable */
948 cp
= (c
== 'a') ? ok_vlook(sign
) : ok_vlook(Sign
);
949 if (cp
!= NULL
&& *cp
!= '\0') {
950 if (putesc(cp
, _coll_fp
) < 0)
952 if ((options
& OPT_INTERACTIVE
) && putesc(cp
, stdout
) < 0)
957 /* Write the message on a file */
959 while (blankchar(*cp
))
961 if (*cp
== '\0' || (cp
= file_expand(cp
)) == NULL
) {
962 n_err(_("Write what file!?\n"));
966 if (exwrite(cp
, _coll_fp
, 1) < 0)
975 /* Interpolate the named messages, if we are in receiving mail mode.
976 * Does the standard list processing garbage. If ~f is given, we
977 * don't shift over */
978 if (forward(linebuf
+ 2, _coll_fp
, c
) < 0)
982 /* Print current state of the message without altering anything */
983 print_collf(_coll_fp
, hp
);
986 /* Pipe message through command. Collect output as new message */
988 mespipe(linebuf
+ 2);
992 /* Edit the current message. 'e' -> use EDITOR, 'v' -> use VISUAL */
994 mesedit(c
, ok_blook(editheaders
) ? hp
: NULL
);
997 /* Last the lengthy help string. (Very ugly, but take care for
998 * compiler supported string lengths :() */
1000 "-------------------- ~ ESCAPES ----------------------------\n"
1001 "~~ Quote a single tilde\n"
1002 "~@ [file ...] Edit attachment list\n"
1003 "~b users Add users to \"blind\" Bcc: list\n"
1004 "~c users Add users to Cc: list\n"
1005 "~d Read in dead.letter\n"
1006 "~e Edit the message buffer\n"
1007 "~F messages Read in messages including all headers, don't indent lines\n"
1008 "~f messages Like ~F, but honour the `ignore' / `retain' configuration\n"
1009 "~h Prompt for Subject:, To:, Cc: and \"blind\" Bcc:\n"));
1011 "~R file Read in a file, indent lines\n"
1012 "~r file Read in a file\n"
1013 "~p Print the message buffer\n"
1014 "~q Abort message composition and save text to DEAD\n"
1015 "~M messages Read in messages, keep all header lines, indent lines\n"
1016 "~m messages Like ~M, but honour the `ignore' / `retain' configuration\n"
1017 "~s subject Set Subject:\n"
1018 "~t users Add users to To: list\n"));
1020 "~U messages Read in message(s) without any headers, indent lines\n"
1021 "~u messages Read in message(s) without any headers\n"
1022 "~v Invoke alternate editor ($VISUAL) on message\n"
1023 "~w file Write message onto file\n"
1024 "~x Abort message composition and discard message\n"
1025 "~!command Invoke the shell\n"
1026 "~:command Execute a regular command\n"
1027 "-----------------------------------------------------------\n"));
1033 if (_coll_fp
!= NULL
) {
1034 if ((cp
= ok_vlook(NAIL_TAIL
)) != NULL
) {
1035 if (putesc(cp
, _coll_fp
) < 0)
1037 if ((options
& OPT_INTERACTIVE
) && putesc(cp
, stdout
) < 0)
1042 if (linebuf
!= NULL
)
1047 sigaddset(&nset
, SIGINT
);
1048 sigaddset(&nset
, SIGHUP
);
1049 sigprocmask(SIG_BLOCK
, &nset
, NULL
);
1050 safe_signal(SIGINT
, _coll_saveint
);
1051 safe_signal(SIGHUP
, _coll_savehup
);
1052 safe_signal(SIGTSTP
, _coll_savetstp
);
1053 safe_signal(SIGTTOU
, _coll_savettou
);
1054 safe_signal(SIGTTIN
, _coll_savettin
);
1055 sigprocmask(SIG_SETMASK
, &oset
, NULL
);
1060 if (_coll_fp
!= NULL
) {
1068 savedeadletter(FILE *fp
, int fflush_rewind_first
)
1076 if (fflush_rewind_first
) {
1083 cp
= getdeadletter();
1085 dbuf
= Fopen(cp
, "a");
1092 printf("\"%s\" ", cp
);
1093 for (lines
= bytes
= 0; (c
= getc(fp
)) != EOF
; ++bytes
) {
1098 printf("%lu/%lu\n", lines
, bytes
);