summaryrefslogtreecommitdiffstats
path: root/usr.bin/mail
diff options
context:
space:
mode:
authormikeh <mikeh@FreeBSD.org>2001-12-22 22:16:48 +0000
committermikeh <mikeh@FreeBSD.org>2001-12-22 22:16:48 +0000
commit45093b4f56780dd2852dac2d7dfeb54e78706467 (patch)
tree50abcee3a5e95121651201fd9a3d75129eb969ea /usr.bin/mail
parent08acd7caeb322942ff644c754ae06c404dda892a (diff)
downloadFreeBSD-src-45093b4f56780dd2852dac2d7dfeb54e78706467.zip
FreeBSD-src-45093b4f56780dd2852dac2d7dfeb54e78706467.tar.gz
Add support for ~_, ~x, ~i, ~a, ~A, ~<, and ~r! tilde-escapes. Improve
tilde-escapes documentation. Mostly obtained from: NetBSD
Diffstat (limited to 'usr.bin/mail')
-rw-r--r--usr.bin/mail/collect.c97
-rw-r--r--usr.bin/mail/mail.144
-rw-r--r--usr.bin/mail/misc/mail.tildehelp24
3 files changed, 138 insertions, 27 deletions
diff --git a/usr.bin/mail/collect.c b/usr.bin/mail/collect.c
index 6fc7493..aa552ba 100644
--- a/usr.bin/mail/collect.c
+++ b/usr.bin/mail/collect.c
@@ -47,6 +47,7 @@ static const char rcsid[] =
*/
#include "rcv.h"
+#include <fcntl.h>
#include "extern.h"
/*
@@ -213,6 +214,7 @@ cont:
shell(&linebuf[2]);
break;
case ':':
+ case '_':
/*
* Escape to command mode, but be nice!
*/
@@ -231,6 +233,11 @@ cont:
hadintr++;
collint(SIGINT);
exit(1);
+ case 'x':
+ /*
+ * Exit, do not save in dead.letter.
+ */
+ goto err;
case 'h':
/*
* Grab a bunch of headers.
@@ -269,18 +276,52 @@ cont:
break;
case 'b':
/*
- * Add stuff to blind carbon copies list.
+ * Add to the BCC list.
*/
hp->h_bcc = cat(hp->h_bcc, extract(&linebuf[2], GBCC));
break;
+ case 'i':
+ case 'A':
+ case 'a':
+ /*
+ * Insert named variable in message
+ */
+ switch(c) {
+ case 'i':
+ cp = &linebuf[2];
+ while(isspace((unsigned char)*cp))
+ cp++;
+ break;
+ case 'a':
+ cp = "sign";
+ break;
+ case 'A':
+ cp = "Sign";
+ break;
+ default:
+ goto err;
+ }
+
+ if(*cp != '\0' && (cp = value(cp)) != NULL) {
+ printf("%s\n", cp);
+ if(putline(collf, cp, 1) < 0)
+ goto err;
+ }
+
+ break;
case 'd':
- if (strlcpy(linebuf + 2, getdeadletter(), sizeof(linebuf) - 2)
+ /*
+ * Read in the dead letter file.
+ */
+ if (strlcpy(linebuf + 2, getdeadletter(),
+ sizeof(linebuf) - 2)
>= sizeof(linebuf) - 2) {
printf("Line buffer overflow\n");
break;
}
- /* fall into . . . */
+ /* FALLTHROUGH */
case 'r':
+ case '<':
/*
* Invoke a file:
* Search for the file name,
@@ -296,11 +337,55 @@ cont:
cp = expand(cp);
if (cp == NULL)
break;
- if (isdir(cp)) {
+ if (*cp == '!') {
+ /*
+ * Insert stdout of command.
+ */
+ char *sh;
+ int nullfd, tempfd, rc;
+ char tempname2[PATHSIZE];
+
+ if ((nullfd = open("/dev/null", O_RDONLY, 0))
+ == -1) {
+ warn("/dev/null");
+ break;
+ }
+
+ (void)snprintf(tempname2, sizeof(tempname2),
+ "%s/mail.ReXXXXXXXXXX", tmpdir);
+ if ((tempfd = mkstemp(tempname2)) == -1 ||
+ (fbuf = Fdopen(tempfd, "w+")) == NULL) {
+ warn("%s", tempname2);
+ break;
+ }
+ (void)unlink(tempname2);
+
+ if ((sh = value("SHELL")) == NULL)
+ sh = _PATH_CSHELL;
+
+ rc = run_command(sh, 0, nullfd, fileno(fbuf),
+ "-c", cp+1, NULL);
+
+ close(nullfd);
+
+ if (rc < 0) {
+ (void)Fclose(fbuf);
+ break;
+ }
+
+ if (fsize(fbuf) == 0) {
+ fprintf(stderr,
+ "No bytes from command \"%s\"\n",
+ cp+1);
+ (void)Fclose(fbuf);
+ break;
+ }
+
+ rewind(fbuf);
+ } else if (isdir(cp)) {
printf("%s: Directory\n", cp);
break;
- }
- if ((fbuf = Fopen(cp, "r")) == NULL) {
+ } else if ((fbuf = Fopen(cp, "r")) == NULL) {
warn("%s", cp);
break;
}
diff --git a/usr.bin/mail/mail.1 b/usr.bin/mail/mail.1
index 0b68435..00ed574 100644
--- a/usr.bin/mail/mail.1
+++ b/usr.bin/mail/mail.1
@@ -728,12 +728,14 @@ is somewhat of a misnomer since the actual escape character can be set
by the option
.Ic escape .
.Bl -tag -width Ds
-.It Ic \&~! Ns Ar command
-Execute the indicated shell command, then return to the message.
-.It Ic \&~b Ns Ar name ...
+.It Ic \&~a
+Inserts the autograph string from the sign= option into the message.
+.It Ic \&~A
+Inserts the autograph string from the Sign= option into the message.
+.It Ic \&~b Ar name ...
Add the given names to the list of carbon copy recipients but do not make
the names visible in the Cc: line ("blind" carbon copy).
-.It Ic \&~c Ns Ar name ...
+.It Ic \&~c Ar name ...
Add the given names to the list of carbon copy recipients.
.It Ic \&~d
Read the file
@@ -744,7 +746,7 @@ Invoke the text editor on the message collected so far.
After the
editing session is finished, you may continue appending text to the
message.
-.It Ic \&~f Ns Ar messages
+.It Ic \&~f Ar messages
Read the named messages into the message being sent.
If no messages are specified, read in the current message.
Message headers currently being ignored (by the
@@ -752,7 +754,7 @@ Message headers currently being ignored (by the
or
.Ic retain
command) are not included.
-.It Ic \&~F Ns Ar messages
+.It Ic \&~F Ar messages
Identical to
.Ic \&~f ,
except all message headers are included.
@@ -760,7 +762,9 @@ except all message headers are included.
Edit the message header fields by typing each one in turn and allowing
the user to append text to the end or modify the field by using the
current terminal erase and kill characters.
-.It Ic \&~m Ns Ar messages
+.It Ic \&~i Ar string
+Inserts the value of the named option into the text of the message.
+.It Ic \&~m Ar messages
Read the named messages into the message being sent, indented by a
tab or by the value of
.Ar indentprefix .
@@ -771,7 +775,7 @@ Message headers currently being ignored (by the
or
.Ic retain
command) are not included.
-.It Ic \&~M Ns Ar messages
+.It Ic \&~M Ar messages
Identical to
.Ic \&~m ,
except all message headers are included.
@@ -784,15 +788,19 @@ Abort the message being sent, copying the message to
in your home directory if
.Ic save
is set.
-.It Ic \&~r Ns Ar filename
+.It Ic \&~r Ar filename , Ic \&~r Ar !command
+.It Ic \&~< Ar filename , Ic \&~< Ar !command
Read the named file into the message.
-.It Ic \&~R Ns Ar string
+If the argument begins with a !,
+the rest of the string is taken as an arbitrary system command and is
+executed, with the standard output inserted into the message.
+.It Ic \&~R Ar string
Use
.Ar string
as the Reply-To field.
-.It Ic \&~s Ns Ar string
+.It Ic \&~s Ar string
Cause the named string to become the current subject field.
-.It Ic \&~\&t Ns Ar name ...
+.It Ic \&~\&t Ar name ...
Add the given names to the direct recipient list.
.It Ic \&~\&v
Invoke an alternative editor (defined by the
@@ -803,9 +811,13 @@ Usually, the alternative editor will be a
screen editor.
After you quit the editor, you may resume appending
text to the end of your message.
-.It Ic \&~w Ns Ar filename
+.It Ic \&~w Ar filename
Write the message onto the named file.
-.It Ic \&~\&| Ns Ar command
+.It Ic \&~x
+Exits as with \&~q, except the message is not saved in dead.letter.
+.It Ic \&~! Ar command
+Execute the indicated shell command, then return to the message.
+.It Ic \&~\&| Ar command , Ic \&~^ Ar command
Pipe the message through the command as a filter.
If the command gives
no output or terminates abnormally, retain the original text of the
@@ -815,10 +827,10 @@ The command
is often used as
.Ic command
to rejustify the message.
-.It Ic \&~: Ns Ar mail-command
+.It Ic \&~: Ar mail-command , Ic \&~_ Ar mail-command
Execute the given mail command.
Not all commands, however, are allowed.
-.It Ic \&~~ Ns Ar string
+.It Ic \&~~ Ar string
Insert the string of text in the message prefaced by a single ~.
If
you have changed the escape character, then you should double
diff --git a/usr.bin/mail/misc/mail.tildehelp b/usr.bin/mail/misc/mail.tildehelp
index 9c17176..66543b7 100644
--- a/usr.bin/mail/misc/mail.tildehelp
+++ b/usr.bin/mail/misc/mail.tildehelp
@@ -1,23 +1,37 @@
-----------------------------------------------------------
The following ~ escapes are defined:
+~? Print this message
~~ Quote a single tilde
+~. Same as .
+~A Equivalent to: ~i Sign
+~a Equivalent to: ~i sign
~b users Add users to "blind" cc list
~c users Add users to cc list
+~C Dump core
~d Read in dead.letter
~e Edit the message buffer
~f messages Read in messages
~F messages Same as ~f, but keep all header lines
~h Prompt for to list, subject and cc list
-~r file Read a file into the message buffer
-~p Print the message buffer
+~i name Insert the value of the named variable
~m messages Read in messages, right shifted by a tab
~M messages Same as ~m, but keep all header lines
+~p Print the message buffer
+~q Quit, save partial message in dead.letter
+~r file Read a file into the message buffer
+~r !command Insert the output of the command in the message
+~< file Same as ~r
+~< !command Same as ~r
~R address Set reply-to
~s subject Set subject
-~t users Add users to to list
+~t users Add users to the To list
~v Invoke display editor on message
~w file Write message onto file.
+~x Quit, do not save to dead.letter
~? Print this message
-~!command Invoke the shell
-~|command Pipe the message through the command
+~! command Invoke the shell
+~| command Pipe the message through the command
+~^ command Same as ~|
+~_ mail-cmd Perform the command-level request
+~: mail-cmd Same as ~_
-----------------------------------------------------------
OpenPOWER on IntegriCloud