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 - 2014 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 #ifndef HAVE_AMALGAMATION
44 /* The following hookiness with global variables is so that on receipt of an
45 * interrupt signal, the partial message can be salted away on *DEAD* */
47 static sighandler_type _coll_saveint
; /* Previous SIGINT value */
48 static sighandler_type _coll_savehup
; /* Previous SIGHUP value */
49 static sighandler_type _coll_savetstp
; /* Previous SIGTSTP value */
50 static sighandler_type _coll_savettou
; /* Previous SIGTTOU value */
51 static sighandler_type _coll_savettin
; /* Previous SIGTTIN value */
52 static FILE *_coll_fp
; /* File for saving away */
53 static int volatile _coll_hadintr
; /* Have seen one SIGINT so far */
54 static sigjmp_buf _coll_jmp
; /* To get back to work */
55 static int _coll_jmp_p
; /* whether to long jump */
56 static sigjmp_buf _coll_abort
; /* To end collection with error */
57 static sigjmp_buf _coll_pipejmp
; /* On broken pipe */
59 /* Handle `~:', `~_' */
60 static void _execute_command(struct header
*hp
, char *linebuf
,
63 /* If *interactive* is set and *doecho* is, too, also dump to *stdout* */
64 static int _include_file(FILE *fbuf
, char const *name
, int *linecount
,
65 int *charcount
, bool_t doecho
);
67 static void _collect_onpipe(int signo
);
69 /* Execute cmd and insert its standard output into fp */
70 static void insertcommand(FILE *fp
, char const *cmd
);
73 static void print_collf(FILE *collf
, struct header
*hp
);
75 /* Write a file, ex-like if f set */
76 static int exwrite(char const *name
, FILE *fp
, int f
);
78 static enum okay
makeheader(FILE *fp
, struct header
*hp
);
80 /* Edit the message being collected on fp. On return, make the edit file the
82 static void mesedit(int c
, struct header
*hp
);
84 /* Pipe the message through the command. Old message is on stdin of command,
85 * new message collected from stdout. Shell must return 0 to accept new msg */
86 static void mespipe(char *cmd
);
88 /* Interpolate the named messages into the current message, possibly doing
89 * indent stuff. The flag argument is one of the tilde escapes: [mMfFuU].
90 * Return a count of the number of characters now in the message, or -1 if an
91 * error is encountered writing the message temporary */
92 static int forward(char *ms
, FILE *fp
, int f
);
94 /* Print (continue) when continued after ^Z */
95 static void collstop(int s
);
97 /* On interrupt, come here to save the partial message in ~/dead.letter.
98 * Then jump out of the collection loop */
99 static void _collint(int s
);
101 static void collhup(int s
);
103 static int putesc(char const *s
, FILE *stream
);
106 _execute_command(struct header
*hp
, char *linebuf
, size_t linesize
)
108 /* The problem arises if there are rfc822 message attachments and the
109 * user uses `~:' to change the current file. TODO Unfortunately we
110 * TODO cannot simply keep a pointer to, or increment a reference count
111 * TODO of the current `file' (mailbox that is) object, because the
112 * TODO codebase doesn't deal with that at all; so, until some far
113 * TODO later time, copy the name of the path, and warn the user if it
114 * TODO changed; we COULD use the AC_TMPFILE attachment type, i.e.,
115 * TODO copy the message attachments over to temporary files, but that
116 * TODO would require more changes so that the user still can recognize
117 * TODO in `~@' etc. that its a rfc822 message attachment; see below */
119 size_t mnlen
= 0 /* silence CC */;
120 struct attachment
*ap
;
123 /* If the above todo is worked, remove or outsource to attachments.c! */
124 if ((ap
= hp
->h_attach
) != NULL
) do
126 mnlen
= strlen(mailname
) +1;
127 mnbuf
= ac_alloc(mnlen
);
128 memcpy(mnbuf
, mailname
, mnlen
);
131 while ((ap
= ap
->a_flink
) != NULL
);
134 execute(linebuf
, TRU1
, linesize
);
137 if (strncmp(mnbuf
, mailname
, mnlen
))
138 fputs(tr(237, "Mailbox changed: it seems existing rfc822 attachments "
139 "became invalid!\n"), stderr
);
146 _include_file(FILE *fbuf
, char const *name
, int *linecount
, int *charcount
,
150 char *linebuf
= NULL
; /* TODO line pool */
151 size_t linesize
= 0, linelen
, cnt
;
155 if ((fbuf
= Fopen(name
, "r")) == NULL
) {
162 *linecount
= *charcount
= 0;
164 while (fgetline(&linebuf
, &linesize
, &cnt
, &linelen
, fbuf
, 0) != NULL
) {
165 if (fwrite(linebuf
, sizeof *linebuf
, linelen
, _coll_fp
) != linelen
)
167 if ((options
& OPT_INTERACTIVE
) && doecho
)
168 fwrite(linebuf
, sizeof *linebuf
, linelen
, stdout
);
170 (*charcount
) += linelen
;
172 if (fflush(_coll_fp
))
186 _collect_onpipe(int signo
)
188 NYD_X
; /* Signal handler */
190 siglongjmp(_coll_pipejmp
, 1);
194 insertcommand(FILE *fp
, char const *cmd
)
201 cp
= ok_vlook(SHELL
);
205 if ((ibuf
= Popen(cmd
, "r", cp
, 0)) != NULL
) {
206 while ((c
= getc(ibuf
)) != EOF
) /* XXX bytewise, yuck! */
215 print_collf(FILE *cf
, struct header
*hp
)
217 char *lbuf
= NULL
; /* TODO line pool */
218 FILE *volatile obuf
= stdout
;
219 struct attachment
*ap
;
222 size_t linecnt
, maxlines
, linesize
= 0, linelen
, cnt
, cnt2
;
227 cnt
= cnt2
= fsize(cf
);
229 if (IS_TTY_SESSION() && (cp
= ok_vlook(crt
)) != NULL
) {
230 for (linecnt
= 0; fgetline(&lbuf
, &linesize
, &cnt2
, NULL
, cf
, 0);
233 maxlines
= (*cp
== '\0' ? screensize() : atoi(cp
));
245 maxlines
-= (myaddrs(hp
) != NULL
|| hp
->h_from
!= NULL
);
246 maxlines
-= (ok_vlook(ORGANIZATION
) !=NULL
|| hp
->h_organization
!=NULL
);
247 maxlines
-= (ok_vlook(replyto
) != NULL
|| hp
->h_replyto
!= NULL
);
248 maxlines
-= (ok_vlook(sender
) != NULL
|| hp
->h_sender
!= NULL
);
249 if ((ssize_t
)maxlines
< 0 || linecnt
> maxlines
) {
251 if (sigsetjmp(_coll_pipejmp
, 1))
253 obuf
= Popen(cp
, "w", NULL
, 1);
258 safe_signal(SIGPIPE
, &_collect_onpipe
);
262 fprintf(obuf
, tr(62, "-------\nMessage contains:\n"));
263 gf
= GIDENT
| GTO
| GSUBJECT
| GCC
| GBCC
| GNL
| GFILES
;
264 if (ok_blook(fullnames
))
266 puthead(hp
, obuf
, gf
, SEND_TODISP
, CONV_NONE
, NULL
, NULL
);
267 while (fgetline(&lbuf
, &linesize
, &cnt
, &linelen
, cf
, 1))
268 prout(lbuf
, linelen
, obuf
);
269 if (hp
->h_attach
!= NULL
) {
270 fputs(tr(63, "-------\nAttachments:\n"), obuf
);
271 for (ap
= hp
->h_attach
; ap
!= NULL
; ap
= ap
->a_flink
) {
273 fprintf(obuf
, " - message %u\n", ap
->a_msgno
);
275 /* TODO after MIME/send layer rewrite we *know*
276 * TODO the details of the attachment here,
277 * TODO so adjust this again, then */
278 char const *cs
, *csi
= "-> ";
280 if ((cs
= ap
->a_charset
) == NULL
&&
281 (csi
= "<- ", cs
= ap
->a_input_charset
) == NULL
)
282 cs
= charset_get_lc();
283 if ((cp
= ap
->a_content_type
) == NULL
)
285 else if (ascncasecmp(cp
, "text/", 5))
287 fprintf(obuf
, " - [%s, %s%s] %s\n", cp
, csi
, cs
, ap
->a_name
);
292 if (obuf
!= stdout
) {
293 safe_signal(SIGPIPE
, SIG_IGN
);
295 safe_signal(SIGPIPE
, dflpipe
);
303 exwrite(char const *name
, FILE *fp
, int f
)
311 printf("\"%s\" ", name
);
314 if ((of
= Fopen(name
, "a")) == NULL
) {
321 while ((c
= getc(fp
)) != EOF
) {
333 printf(tr(65, "%d/%ld\n"), lc
, cc
);
342 makeheader(FILE *fp
, struct header
*hp
)
349 if ((nf
= Ftmp(NULL
, "colhead", OF_RDWR
| OF_UNLINK
| OF_REGISTER
, 0600)) ==
351 perror(tr(66, "temporary mail edit file"));
355 extract_header(fp
, hp
);
356 while ((c
= getc(fp
)) != EOF
) /* XXX bytewise, yuck! */
362 if (check_from_and_sender(hp
->h_from
, hp
->h_sender
))
371 mesedit(int c
, struct header
*hp
)
374 sighandler_type sigint
;
378 saved
= ok_blook(add_file_recipients
);
379 ok_bset(add_file_recipients
, TRU1
);
381 sigint
= safe_signal(SIGINT
, SIG_IGN
);
382 nf
= run_editor(_coll_fp
, (off_t
)-1, c
, 0, hp
, NULL
, SEND_MBOX
, sigint
);
388 fseek(nf
, 0L, SEEK_END
);
393 safe_signal(SIGINT
, sigint
);
395 ok_bset(add_file_recipients
, saved
);
403 sighandler_type sigint
;
407 sigint
= safe_signal(SIGINT
, SIG_IGN
);
409 if ((nf
= Ftmp(NULL
, "colpipe", OF_RDWR
| OF_UNLINK
| OF_REGISTER
, 0600)) ==
411 perror(tr(66, "temporary mail edit file"));
415 /* stdin = current message. stdout = new message */
416 if ((sh
= ok_vlook(SHELL
)) == NULL
)
419 if (run_command(sh
, 0, fileno(_coll_fp
), fileno(nf
), "-c", cmd
, NULL
) < 0) {
424 if (fsize(nf
) == 0) {
425 fprintf(stderr
, tr(67, "No bytes from \"%s\" !?\n"), cmd
);
431 fseek(nf
, 0L, SEEK_END
);
435 safe_signal(SIGINT
, sigint
);
440 forward(char *ms
, FILE *fp
, int f
)
443 struct ignoretab
*ig
;
445 enum sendaction action
;
448 msgvec
= salloc((size_t)(msgCount
+ 1) * sizeof *msgvec
);
449 if (getmsglist(ms
, msgvec
, 0) < 0)
452 *msgvec
= first(0, MMNORM
);
454 fputs(tr(68, "No appropriate messages\n"), stderr
);
460 if (f
== 'f' || f
== 'F' || f
== 'u')
462 else if ((tabst
= ok_vlook(indentprefix
)) == NULL
)
464 if (f
== 'u' || f
== 'U')
467 ig
= upperchar(f
) ? NULL
: ignore
;
468 action
= (upperchar(f
) && f
!= 'U') ? SEND_QUOTE_ALL
: SEND_QUOTE
;
470 printf(tr(69, "Interpolating:"));
471 for (; *msgvec
!= 0; ++msgvec
) {
472 struct message
*mp
= message
+ *msgvec
- 1;
475 printf(" %d", *msgvec
);
476 if (sendmp(mp
, fp
, ig
, tabst
, action
, NULL
) < 0) {
477 perror(tr(70, "temporary mail file"));
491 sighandler_type old_action
;
493 NYD_X
; /* Signal handler */
495 old_action
= safe_signal(s
, SIG_DFL
);
499 sigprocmask(SIG_UNBLOCK
, &nset
, NULL
);
501 sigprocmask(SIG_BLOCK
, &nset
, NULL
);
503 safe_signal(s
, old_action
);
507 siglongjmp(_coll_jmp
, 1);
514 NYD_X
; /* Signal handler */
516 /* the control flow is subtle, because we can be called from ~q */
517 if (_coll_hadintr
== 0) {
518 if (ok_blook(ignore
)) {
524 siglongjmp(_coll_jmp
, 1);
526 exit_status
|= EXIT_SEND_ERROR
;
527 if (ok_blook(save
) && s
!= 0)
528 savedeadletter(_coll_fp
, 1);
529 /* Aborting message, no need to fflush() .. */
530 siglongjmp(_coll_abort
, 1);
536 NYD_X
; /* Signal handler */
539 savedeadletter(_coll_fp
, 1);
540 /* Let's pretend nobody else wants to clean up, a true statement at
546 putesc(char const *s
, FILE *stream
)
551 while (s
[0] != '\0') {
554 if (putc('\t', stream
) == EOF
)
561 if (putc('\n', stream
) == EOF
)
568 if (putc(s
[0], stream
) == EOF
)
573 if (putc('\n', stream
) == EOF
)
582 collect(struct header
*hp
, int printheaders
, struct message
*mp
,
583 char *quotefile
, int doprefix
)
586 struct ignoretab
*quoteig
;
588 int volatile escape
, getfields
;
589 char *linebuf
= NULL
, *quote
= NULL
;
591 size_t linesize
= 0; /* TODO line pool */
593 enum sendaction action
;
595 sighandler_type savedtop
;
599 /* Start catching signals from here, but we're still die on interrupts
600 * until we're in the main loop */
602 sigaddset(&nset
, SIGINT
);
603 sigaddset(&nset
, SIGHUP
);
604 sigprocmask(SIG_BLOCK
, &nset
, &oset
);
605 handlerpush(&_collint
);
606 if ((_coll_saveint
= safe_signal(SIGINT
, SIG_IGN
)) != SIG_IGN
)
607 safe_signal(SIGINT
, &_collint
);
608 if ((_coll_savehup
= safe_signal(SIGHUP
, SIG_IGN
)) != SIG_IGN
)
609 safe_signal(SIGHUP
, collhup
);
610 /* TODO We do a lot of redundant signal handling, especially
611 * TODO with the command line editor(s); try to merge this */
612 _coll_savetstp
= safe_signal(SIGTSTP
, collstop
);
613 _coll_savettou
= safe_signal(SIGTTOU
, collstop
);
614 _coll_savettin
= safe_signal(SIGTTIN
, collstop
);
615 if (sigsetjmp(_coll_abort
, 1))
617 if (sigsetjmp(_coll_jmp
, 1))
619 sigprocmask(SIG_SETMASK
, &oset
, (sigset_t
*)NULL
);
622 if ((_coll_fp
= Ftmp(NULL
, "collect", OF_RDWR
| OF_UNLINK
| OF_REGISTER
,
624 perror(tr(51, "temporary mail file"));
628 if ((cp
= ok_vlook(NAIL_HEAD
)) != NULL
&& putesc(cp
, _coll_fp
) < 0)
631 /* If we are going to prompt for a subject, refrain from printing a newline
632 * after the headers (since some people mind) */
634 if (!(options
& OPT_t_FLAG
)) {
635 t
= GTO
| GSUBJECT
| GCC
| GNL
;
636 if (ok_blook(fullnames
))
638 if (hp
->h_subject
== NULL
&& (options
& OPT_INTERACTIVE
) &&
639 (ok_blook(ask
) || ok_blook(asksub
)))
640 t
&= ~GNL
, getfields
|= GSUBJECT
;
641 if (hp
->h_to
== NULL
&& (options
& OPT_INTERACTIVE
))
642 t
&= ~GNL
, getfields
|= GTO
;
643 if (!ok_blook(bsdcompat
) && !ok_blook(askatend
) &&
644 (options
& OPT_INTERACTIVE
)) {
645 if (hp
->h_bcc
== NULL
&& ok_blook(askbcc
))
646 t
&= ~GNL
, getfields
|= GBCC
;
647 if (hp
->h_cc
== NULL
&& ok_blook(askcc
))
648 t
&= ~GNL
, getfields
|= GCC
;
651 puthead(hp
, stdout
, t
, SEND_TODISP
, CONV_NONE
, NULL
, NULL
);
656 /* Quote an original message */
657 if (mp
!= NULL
&& (doprefix
|| (quote
= ok_vlook(quote
)) != NULL
)) {
662 if ((cp
= ok_vlook(fwdheading
)) == NULL
)
663 cp
= "-------- Original Message --------";
664 if (*cp
!= '\0' && fprintf(_coll_fp
, "%s\n", cp
) < 0)
666 } else if (!strcmp(quote
, "noheading")) {
668 } else if (!strcmp(quote
, "headers")) {
670 } else if (!strcmp(quote
, "allheaders")) {
672 action
= SEND_QUOTE_ALL
;
674 cp
= hfield1("from", mp
);
675 if (cp
!= NULL
&& (cnt
= (long)strlen(cp
)) > 0) {
676 if (xmime_write(cp
, cnt
, _coll_fp
, CONV_FROMHDR
, TD_NONE
,NULL
) < 0)
678 if (fprintf(_coll_fp
, tr(52, " wrote:\n\n")) < 0)
682 if (fflush(_coll_fp
))
684 cp
= ok_vlook(indentprefix
);
685 if (cp
!= NULL
&& *cp
== '\0')
687 if (sendmp(mp
, _coll_fp
, quoteig
, (doprefix
? NULL
: cp
), action
, NULL
)
692 /* Print what we have sofar also on the terminal */
694 while ((c
= getc(_coll_fp
)) != EOF
) /* XXX bytewise, yuck! */
696 if (fseek(_coll_fp
, 0, SEEK_END
))
699 escape
= ((cp
= ok_vlook(escape
)) != NULL
) ? *cp
: ESCAPE
;
702 if (!sigsetjmp(_coll_jmp
, 1)) {
704 grab_headers(hp
, getfields
, 1);
705 if (quotefile
!= NULL
) {
706 if (_include_file(NULL
, quotefile
, &lc
, &cc
, TRU1
) != 0)
709 if ((options
& OPT_INTERACTIVE
) && ok_blook(editalong
)) {
715 /* Come here for printing the after-signal message. Duplicate messages
716 * won't be printed because the write is aborted if we get a SIGTTOU */
719 fprintf(stderr
, tr(53, "\n(Interrupt -- one more to kill letter)\n"));
721 printf(tr(54, "(continue)\n"));
726 /* No tilde escapes, interrupts not expected. Simply copy STDIN */
727 if (!(options
& (OPT_INTERACTIVE
| OPT_t_FLAG
| OPT_TILDE_FLAG
))) {
728 linebuf
= srealloc(linebuf
, linesize
= LINESIZE
);
729 while ((cnt
= fread(linebuf
, sizeof *linebuf
, linesize
, stdin
)) > 0) {
730 if ((size_t)cnt
!= fwrite(linebuf
, sizeof *linebuf
, cnt
, _coll_fp
))
733 if (fflush(_coll_fp
))
738 /* The interactive collect loop */
741 cnt
= readline_input("", FAL0
, &linebuf
, &linesize
, NULL
);
745 if ((options
& OPT_INTERACTIVE
) && ok_blook(ignoreeof
)) {
746 printf(tr(55, "Use \".\" to terminate letter\n"));
751 if ((options
& OPT_t_FLAG
) && cnt
== 0) {
753 if (makeheader(_coll_fp
, hp
) != OKAY
)
756 options
&= ~OPT_t_FLAG
;
761 if (linebuf
[0] == '.' && linebuf
[1] == '\0' &&
762 (options
& (OPT_INTERACTIVE
| OPT_TILDE_FLAG
)) &&
763 (ok_blook(dot
) || ok_blook(ignoreeof
)))
765 if (cnt
== 0 || linebuf
[0] != escape
||
766 !(options
& (OPT_INTERACTIVE
| OPT_TILDE_FLAG
))) {
767 /* TODO calls putline(), which *always* appends LF;
768 * TODO thus, STDIN with -t will ALWAYS end with LF,
769 * TODO even if no trailing LF and QP CTE */
770 if (putline(_coll_fp
, linebuf
, cnt
) < 0)
778 /* On double escape, send a single one. Otherwise, it's an error */
780 if (putline(_coll_fp
, linebuf
+ 1, cnt
- 1) < 0)
785 fputs(tr(56, "Unknown tilde escape.\n"), stderr
);
788 /* Shell escape, send the balance of line to sh -c */
789 c_shell(linebuf
+ 2);
794 /* Escape to command mode, but be nice! */
795 _execute_command(hp
, linebuf
+ 2, cnt
- 2);
798 /* Simulate end of file on input */
801 /* Same as 'q', but no *DEAD* saving */
804 /* Force a quit, act like an interrupt had happened */
806 _collint((c
== 'x') ? 0 : SIGINT
);
810 /* Grab a bunch of headers */
812 grab_headers(hp
, GTO
| GSUBJECT
| GCC
| GBCC
,
813 (ok_blook(bsdcompat
) && ok_blook(bsdorder
)));
814 while (hp
->h_to
== NULL
);
817 /* Grab extra headers */
819 grab_headers(hp
, GEXTRA
, 0);
820 while (check_from_and_sender(hp
->h_from
, hp
->h_sender
));
823 /* Add to the To list */
824 while ((hp
->h_to
= cat(hp
->h_to
,
825 checkaddrs(lextract(linebuf
+ 2, GTO
| GFULL
)))) == NULL
)
829 /* Set the Subject list */
831 while (whitechar(*cp
))
833 hp
->h_subject
= savestr(cp
);
841 /* Edit the attachment list */
842 if (linebuf
[2] != '\0')
843 append_attachments(&hp
->h_attach
, linebuf
+ 2);
845 edit_attachments(&hp
->h_attach
);
848 /* Add to the CC list */
849 hp
->h_cc
= cat(hp
->h_cc
,
850 checkaddrs(lextract(linebuf
+ 2, GCC
| GFULL
)));
853 /* Add stuff to blind carbon copies list */
854 hp
->h_bcc
= cat(hp
->h_bcc
,
855 checkaddrs(lextract(linebuf
+ 2, GBCC
| GFULL
)));
858 strncpy(linebuf
+ 2, getdeadletter(), linesize
- 2);
859 linebuf
[linesize
- 1] = '\0';
863 /* Invoke a file: Search for the file name, then open it and copy the
864 * contents to _coll_fp */
866 while (whitechar(*cp
))
869 fputs(tr(57, "Interpolate what file?\n"), stderr
);
873 insertcommand(_coll_fp
, cp
+ 1);
876 if ((cp
= file_expand(cp
)) == NULL
)
879 fprintf(stderr
, tr(58, "%s: Directory\n"), cp
);
882 if ((fbuf
= Fopen(cp
, "r")) == NULL
) {
886 printf(tr(59, "\"%s\" "), cp
);
888 if (_include_file(fbuf
, cp
, &lc
, &cc
, FAL0
) != 0)
890 printf(tr(60, "%d/%d\n"), lc
, cc
);
893 /* Insert a variable into the file */
895 while (whitechar(*cp
))
897 if ((cp
= vok_vlook(cp
)) == NULL
|| *cp
== '\0')
899 if (putesc(cp
, _coll_fp
) < 0)
901 if ((options
& OPT_INTERACTIVE
) && putesc(cp
, stdout
) < 0)
906 /* Insert the contents of a signature variable */
907 cp
= (c
== 'a') ? ok_vlook(sign
) : ok_vlook(Sign
);
908 if (cp
!= NULL
&& *cp
!= '\0') {
909 if (putesc(cp
, _coll_fp
) < 0)
911 if ((options
& OPT_INTERACTIVE
) && putesc(cp
, stdout
) < 0)
916 /* Write the message on a file */
918 while (blankchar(*cp
))
920 if (*cp
== '\0' || (cp
= file_expand(cp
)) == NULL
) {
921 fputs(tr(61, "Write what file!?\n"), stderr
);
925 if (exwrite(cp
, _coll_fp
, 1) < 0)
934 /* Interpolate the named messages, if we are in receiving mail mode.
935 * Does the standard list processing garbage. If ~f is given, we
936 * don't shift over */
937 if (forward(linebuf
+ 2, _coll_fp
, c
) < 0)
941 /* Print current state of the message without altering anything */
942 print_collf(_coll_fp
, hp
);
945 /* Pipe message through command. Collect output as new message */
947 mespipe(linebuf
+ 2);
951 /* Edit the current message. 'e' -> use EDITOR, 'v' -> use VISUAL */
953 mesedit(c
, ok_blook(editheaders
) ? hp
: NULL
);
956 /* Last the lengthy help string. (Very ugly, but take care for
957 * compiler supported string lengths :() */
959 "-------------------- ~ ESCAPES ----------------------------\n"
960 "~~ Quote a single tilde\n"
961 "~@ [file ...] Edit attachment list\n"
962 "~b users Add users to \"blind\" cc list\n"
963 "~c users Add users to cc list\n"
964 "~d Read in dead.letter\n"
965 "~e Edit the message buffer\n"
966 "~f messages Read in messages without indenting lines\n"
967 "~F messages Same as ~f, but keep all header lines\n"
968 "~h Prompt for to list, subject, cc, and \"blind\" cc list\n"));
970 "~r file Read a file into the message buffer\n"
971 "~p Print the message buffer\n"
972 "~q Abort message composition and save text to dead.letter\n"
973 "~m messages Read in messages with each line indented\n"
974 "~M messages Same as ~m, but keep all header lines\n"
975 "~s subject Set subject\n"
976 "~t users Add users to to list\n"
977 "~u messages Same as ~f, but without any headers\n"
978 "~U messages Same as ~m, but without any headers\n"));
980 "~v Invoke display editor on message\n"
981 "~w file Write message onto file\n"
982 "~x Abort message composition and discard text written so far\n"
983 "~!command Invoke the shell\n"
984 "~:command Execute a regular command\n"
985 "-----------------------------------------------------------\n"));
991 if (_coll_fp
!= NULL
) {
992 if ((cp
= ok_vlook(NAIL_TAIL
)) != NULL
) {
993 if (putesc(cp
, _coll_fp
) < 0)
995 if ((options
& OPT_INTERACTIVE
) && putesc(cp
, stdout
) < 0)
1000 if (linebuf
!= NULL
)
1005 sigaddset(&nset
, SIGINT
);
1006 sigaddset(&nset
, SIGHUP
);
1007 sigprocmask(SIG_BLOCK
, &nset
, NULL
);
1008 safe_signal(SIGINT
, _coll_saveint
);
1009 safe_signal(SIGHUP
, _coll_savehup
);
1010 safe_signal(SIGTSTP
, _coll_savetstp
);
1011 safe_signal(SIGTTOU
, _coll_savettou
);
1012 safe_signal(SIGTTIN
, _coll_savettin
);
1013 sigprocmask(SIG_SETMASK
, &oset
, NULL
);
1018 if (_coll_fp
!= NULL
) {
1026 savedeadletter(FILE *fp
, int fflush_rewind_first
)
1034 if (fflush_rewind_first
) {
1041 cp
= getdeadletter();
1043 dbuf
= Fopen(cp
, "a");
1050 printf("\"%s\" ", cp
);
1051 for (lines
= bytes
= 0; (c
= getc(fp
)) != EOF
; ++bytes
) {
1056 printf("%lu/%lu\n", lines
, bytes
);
1064 /* vim:set fenc=utf-8:s-it-mode */