From Anon Ymous:
1) Statification of modules.
2) Implement the 'detach' and 'Detach' commands for extracting mime
parts from messages.
3) Teach mail to output "In-Reply-To" and "References" header fields
when replying so others can thread us.
4) Implement threading, sorting, and tagging, supported by the
following commands: 'flatten', 'reverse', 'sort', 'thread',
'unthread', 'down', 'tset', 'up', 'expose', 'hide', 'tag',
'untag', 'invtags', 'tagbelow', 'hidetags', 'showtags'.
See the manpage for details (when available - soon).
5) Implement a 'deldups' command to delete duplicate messages based on
their "Message-Id" field, e.g., in replies to a mailing list that
are also CCed to a subscriber. (This can also be accomplished with
the threading and tagging commands.)
6) Implement 'ifdef' and 'ifndef' commands, and make the conditionals
nestable (i.e., implement a conditional stack). The if/else/endif
commands existed before, but they were primitive and undocumented.
The 'if' command currently recognizes the "receiving", "sending",
and "headersonly" mode keywords.
7) Teach the message selecting routine to understand regular
expressions if "regex-search" is defined. Otherwise only case
insensitive substring matches are done (as in the past).
8) Teach the message selection routine to understand boolean
expressions. Improved "colon-modifier" support. See the manpage
for details (when available - soon).
9) Extend paging to all commands (where relevant).
10) Add shell like piping and redirection of (standard) output (if
"enable-piping" is defined). Extend completion to these contexts.
11) The manpage should follow soon!!!!
2006-11-28 21:45:32 +03:00
|
|
|
/* $NetBSD: tty.c,v 1.27 2006/11/28 18:45:32 christos Exp $ */
|
1996-06-08 23:48:09 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-06-29 09:09:04 +04:00
|
|
|
* Copyright (c) 1980, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 15:13:06 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-10-19 09:02:57 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1996-06-08 23:48:09 +04:00
|
|
|
#if 0
|
1996-12-28 10:10:57 +03:00
|
|
|
static char sccsid[] = "@(#)tty.c 8.2 (Berkeley) 6/6/93";
|
1996-06-08 23:48:09 +04:00
|
|
|
#else
|
From Anon Ymous:
1) Statification of modules.
2) Implement the 'detach' and 'Detach' commands for extracting mime
parts from messages.
3) Teach mail to output "In-Reply-To" and "References" header fields
when replying so others can thread us.
4) Implement threading, sorting, and tagging, supported by the
following commands: 'flatten', 'reverse', 'sort', 'thread',
'unthread', 'down', 'tset', 'up', 'expose', 'hide', 'tag',
'untag', 'invtags', 'tagbelow', 'hidetags', 'showtags'.
See the manpage for details (when available - soon).
5) Implement a 'deldups' command to delete duplicate messages based on
their "Message-Id" field, e.g., in replies to a mailing list that
are also CCed to a subscriber. (This can also be accomplished with
the threading and tagging commands.)
6) Implement 'ifdef' and 'ifndef' commands, and make the conditionals
nestable (i.e., implement a conditional stack). The if/else/endif
commands existed before, but they were primitive and undocumented.
The 'if' command currently recognizes the "receiving", "sending",
and "headersonly" mode keywords.
7) Teach the message selecting routine to understand regular
expressions if "regex-search" is defined. Otherwise only case
insensitive substring matches are done (as in the past).
8) Teach the message selection routine to understand boolean
expressions. Improved "colon-modifier" support. See the manpage
for details (when available - soon).
9) Extend paging to all commands (where relevant).
10) Add shell like piping and redirection of (standard) output (if
"enable-piping" is defined). Extend completion to these contexts.
11) The manpage should follow soon!!!!
2006-11-28 21:45:32 +03:00
|
|
|
__RCSID("$NetBSD: tty.c,v 1.27 2006/11/28 18:45:32 christos Exp $");
|
1996-06-08 23:48:09 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mail -- a mail program
|
|
|
|
*
|
|
|
|
* Generally useful tty stuff.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "rcv.h"
|
1994-06-29 09:09:04 +04:00
|
|
|
#include "extern.h"
|
2006-10-22 01:37:20 +04:00
|
|
|
#ifdef USE_EDITLINE
|
Jumbo mail patch from our anonymous user:
1) Use editline [optional]:
Most of this code was borrowed from src/usr.bin/ftp. It does the
appropriate editing, history, and completion for all mail commands
(from cmdtab[]) and also does editing on header strings ('~h' inside
the mail editor).
2) '-B' flag:
This will suppress the "To:" line passed to sendmail. In most
configurations it will lead to sendmail adding "To: undisclosed
recipients;". Currently, AFAIK mail requires at least one exposed
recipient address.
3) Comments in rcfile:
Currently, comments in .mailrc are only supported if the first
(non-white) character on a line is '#' followed by white space,
i.e., '#' is a 'nop' command. This (trivial) patch allows the more
normal/expected use of '#' as a comment character. It does not
respect quoting, so that might be an objection which I should fix.
4) Sendmail option editing:
This adds the sendmail option string to the strings editable by the
'~h' command within the mail editor. Currently, you can only set
this string from the command-line, which is particularly annoying
when replying to mail.
5) Reply from:
When replying to a message, grab the "To:" address from the message
and, if there is only one such address and it does not match a list of
allowed addresses (set in the "ReplyFrom" variable), pass it to
sendmail as the "From:" address for the reply (with the '-f' option).
I often make aliases for myself so that my primary address is not
given out; if the alias gets out, I know who to blame. Unfortunately,
a reply to such a message would normally use the primary address
without this patch. A warning is displayed when this is going to
happen so that it can be modified with '~h'.
6) CC and BCC lists:
Allow '-c' and '-b' to accept white-space or ',' delimited lists.
Currently, a white-space delimited list of addresses work, but a
list of aliases will not get expanded. For example, currently:
mail -c "foo bar" christos
will fail to send mail to 'foo' and 'bar' if these are mail aliases
(in ~/.mailrc); sendmail aliases (in /etc/aliases) do work.
7) pipe command:
This pipes the current message into a shell command. I use this for
quick decoding of uuencoded mail, but I can imagine it might be
useful for decrypting encrypted mail, too.
8) show command:
This command takes a list of variables and shows their values. It
is probably stupid as the 'set' command without any argument
displays all variable values. Of course, if there are a lot of
variables you have to sift through the list for the one(s) you want.
2006-09-18 23:46:21 +04:00
|
|
|
#include "complete.h"
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2006-10-22 01:37:20 +04:00
|
|
|
#if !defined(USE_EDITLINE) || !defined(TIOCSTI)
|
1995-05-02 05:40:14 +04:00
|
|
|
static cc_t c_erase; /* Current erase char */
|
|
|
|
static cc_t c_kill; /* Current kill char */
|
2006-10-22 01:37:20 +04:00
|
|
|
#endif
|
|
|
|
#ifndef USE_EDITLINE
|
1993-03-21 12:45:37 +03:00
|
|
|
static jmp_buf rewrite; /* Place to go when continued */
|
2006-10-22 01:37:20 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
static jmp_buf intjmp; /* Place to go when interrupted */
|
|
|
|
#ifndef TIOCSTI
|
|
|
|
static int ttyset; /* We must now do erase/kill */
|
|
|
|
#endif
|
|
|
|
|
2006-09-29 18:59:31 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
From Anon Ymous:
1) Statification of modules.
2) Implement the 'detach' and 'Detach' commands for extracting mime
parts from messages.
3) Teach mail to output "In-Reply-To" and "References" header fields
when replying so others can thread us.
4) Implement threading, sorting, and tagging, supported by the
following commands: 'flatten', 'reverse', 'sort', 'thread',
'unthread', 'down', 'tset', 'up', 'expose', 'hide', 'tag',
'untag', 'invtags', 'tagbelow', 'hidetags', 'showtags'.
See the manpage for details (when available - soon).
5) Implement a 'deldups' command to delete duplicate messages based on
their "Message-Id" field, e.g., in replies to a mailing list that
are also CCed to a subscriber. (This can also be accomplished with
the threading and tagging commands.)
6) Implement 'ifdef' and 'ifndef' commands, and make the conditionals
nestable (i.e., implement a conditional stack). The if/else/endif
commands existed before, but they were primitive and undocumented.
The 'if' command currently recognizes the "receiving", "sending",
and "headersonly" mode keywords.
7) Teach the message selecting routine to understand regular
expressions if "regex-search" is defined. Otherwise only case
insensitive substring matches are done (as in the past).
8) Teach the message selection routine to understand boolean
expressions. Improved "colon-modifier" support. See the manpage
for details (when available - soon).
9) Extend paging to all commands (where relevant).
10) Add shell like piping and redirection of (standard) output (if
"enable-piping" is defined). Extend completion to these contexts.
11) The manpage should follow soon!!!!
2006-11-28 21:45:32 +03:00
|
|
|
* Read up a header from standard input.
|
|
|
|
* The source string has the preliminary contents to
|
|
|
|
* be read.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifdef USE_EDITLINE
|
|
|
|
static char *
|
|
|
|
readtty(const char pr[], char src[])
|
|
|
|
{
|
|
|
|
char *line;
|
|
|
|
line = my_gets(&elm.string, pr, src);
|
|
|
|
#if 0
|
|
|
|
return line ? savestr(line) : __UNCONST("");
|
|
|
|
#else
|
|
|
|
if (line)
|
|
|
|
return savestr(line);
|
|
|
|
else
|
|
|
|
return __UNCONST("");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* USE_EDITLINE */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receipt continuation.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
From Anon Ymous:
1) Statification of modules.
2) Implement the 'detach' and 'Detach' commands for extracting mime
parts from messages.
3) Teach mail to output "In-Reply-To" and "References" header fields
when replying so others can thread us.
4) Implement threading, sorting, and tagging, supported by the
following commands: 'flatten', 'reverse', 'sort', 'thread',
'unthread', 'down', 'tset', 'up', 'expose', 'hide', 'tag',
'untag', 'invtags', 'tagbelow', 'hidetags', 'showtags'.
See the manpage for details (when available - soon).
5) Implement a 'deldups' command to delete duplicate messages based on
their "Message-Id" field, e.g., in replies to a mailing list that
are also CCed to a subscriber. (This can also be accomplished with
the threading and tagging commands.)
6) Implement 'ifdef' and 'ifndef' commands, and make the conditionals
nestable (i.e., implement a conditional stack). The if/else/endif
commands existed before, but they were primitive and undocumented.
The 'if' command currently recognizes the "receiving", "sending",
and "headersonly" mode keywords.
7) Teach the message selecting routine to understand regular
expressions if "regex-search" is defined. Otherwise only case
insensitive substring matches are done (as in the past).
8) Teach the message selection routine to understand boolean
expressions. Improved "colon-modifier" support. See the manpage
for details (when available - soon).
9) Extend paging to all commands (where relevant).
10) Add shell like piping and redirection of (standard) output (if
"enable-piping" is defined). Extend completion to these contexts.
11) The manpage should follow soon!!!!
2006-11-28 21:45:32 +03:00
|
|
|
static void
|
|
|
|
ttystop(int s)
|
|
|
|
{
|
|
|
|
sig_t old_action = signal(s, SIG_DFL);
|
|
|
|
sigset_t nset;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
From Anon Ymous:
1) Statification of modules.
2) Implement the 'detach' and 'Detach' commands for extracting mime
parts from messages.
3) Teach mail to output "In-Reply-To" and "References" header fields
when replying so others can thread us.
4) Implement threading, sorting, and tagging, supported by the
following commands: 'flatten', 'reverse', 'sort', 'thread',
'unthread', 'down', 'tset', 'up', 'expose', 'hide', 'tag',
'untag', 'invtags', 'tagbelow', 'hidetags', 'showtags'.
See the manpage for details (when available - soon).
5) Implement a 'deldups' command to delete duplicate messages based on
their "Message-Id" field, e.g., in replies to a mailing list that
are also CCed to a subscriber. (This can also be accomplished with
the threading and tagging commands.)
6) Implement 'ifdef' and 'ifndef' commands, and make the conditionals
nestable (i.e., implement a conditional stack). The if/else/endif
commands existed before, but they were primitive and undocumented.
The 'if' command currently recognizes the "receiving", "sending",
and "headersonly" mode keywords.
7) Teach the message selecting routine to understand regular
expressions if "regex-search" is defined. Otherwise only case
insensitive substring matches are done (as in the past).
8) Teach the message selection routine to understand boolean
expressions. Improved "colon-modifier" support. See the manpage
for details (when available - soon).
9) Extend paging to all commands (where relevant).
10) Add shell like piping and redirection of (standard) output (if
"enable-piping" is defined). Extend completion to these contexts.
11) The manpage should follow soon!!!!
2006-11-28 21:45:32 +03:00
|
|
|
(void)sigemptyset(&nset);
|
|
|
|
(void)sigaddset(&nset, s);
|
|
|
|
(void)sigprocmask(SIG_BLOCK, &nset, NULL);
|
|
|
|
(void)kill(0, s);
|
|
|
|
(void)sigprocmask(SIG_UNBLOCK, &nset, NULL);
|
|
|
|
(void)signal(s, old_action);
|
|
|
|
longjmp(rewrite, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
readtty(const char pr[], char src[])
|
|
|
|
{
|
|
|
|
/* XXX - watch for potential setjmp/longjmp clobbering!
|
|
|
|
* Currently there appear to be none.
|
|
|
|
*/
|
|
|
|
char canonb[LINESIZE];
|
|
|
|
int c;
|
|
|
|
char *cp, *cp2;
|
|
|
|
#ifdef TIOCSTI
|
|
|
|
char ch;
|
|
|
|
static char empty[] = "";
|
|
|
|
#endif
|
|
|
|
(void)fputs(pr, stdout);
|
|
|
|
(void)fflush(stdout);
|
|
|
|
if (src != NULL && strlen(src) > sizeof(canonb) - 2) {
|
|
|
|
(void)printf("too long to edit\n");
|
|
|
|
return src;
|
|
|
|
}
|
|
|
|
#ifndef TIOCSTI
|
|
|
|
if (src != NULL)
|
|
|
|
cp = copy(src, canonb);
|
|
|
|
else
|
|
|
|
cp = copy("", canonb);
|
|
|
|
(void)fputs(canonb, stdout);
|
|
|
|
(void)fflush(stdout);
|
|
|
|
#else
|
|
|
|
cp = src == NULL ? empty : src;
|
|
|
|
while ((c = *cp++) != '\0') {
|
|
|
|
if ((c_erase != _POSIX_VDISABLE && c == c_erase) ||
|
|
|
|
(c_kill != _POSIX_VDISABLE && c == c_kill)) {
|
|
|
|
ch = '\\';
|
|
|
|
(void)ioctl(0, TIOCSTI, &ch);
|
|
|
|
}
|
|
|
|
ch = c;
|
|
|
|
(void)ioctl(0, TIOCSTI, &ch);
|
|
|
|
}
|
|
|
|
cp = canonb;
|
|
|
|
*cp = 0;
|
|
|
|
#endif
|
|
|
|
cp2 = cp;
|
|
|
|
while (cp2 < canonb + sizeof(canonb))
|
|
|
|
*cp2++ = 0;
|
|
|
|
cp2 = cp;
|
|
|
|
if (setjmp(rewrite))
|
|
|
|
goto redo;
|
|
|
|
(void)signal(SIGTSTP, ttystop);
|
|
|
|
(void)signal(SIGTTOU, ttystop);
|
|
|
|
(void)signal(SIGTTIN, ttystop);
|
|
|
|
clearerr(stdin);
|
|
|
|
while (cp2 < canonb + sizeof(canonb)) {
|
|
|
|
c = getc(stdin);
|
|
|
|
if (c == EOF || c == '\n')
|
|
|
|
break;
|
|
|
|
*cp2++ = c;
|
|
|
|
}
|
|
|
|
*cp2 = 0;
|
|
|
|
(void)signal(SIGTSTP, SIG_DFL);
|
|
|
|
(void)signal(SIGTTOU, SIG_DFL);
|
|
|
|
(void)signal(SIGTTIN, SIG_DFL);
|
|
|
|
if (c == EOF && ferror(stdin)) {
|
|
|
|
redo:
|
|
|
|
cp = strlen(canonb) > 0 ? canonb : NULL;
|
|
|
|
clearerr(stdin);
|
|
|
|
return readtty(pr, cp);
|
|
|
|
}
|
|
|
|
#ifndef TIOCSTI
|
|
|
|
if (cp == NULL || *cp == '\0')
|
|
|
|
return src;
|
|
|
|
cp2 = cp;
|
|
|
|
if (!ttyset)
|
|
|
|
return strlen(canonb) > 0 ? savestr(canonb) : NULL;
|
|
|
|
while (*cp != '\0') {
|
|
|
|
c = *cp++;
|
|
|
|
if (c_erase != _POSIX_VDISABLE && c == c_erase) {
|
|
|
|
if (cp2 == canonb)
|
|
|
|
continue;
|
|
|
|
if (cp2[-1] == '\\') {
|
|
|
|
cp2[-1] = c;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cp2--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (c_kill != _POSIX_VDISABLE && c == c_kill) {
|
|
|
|
if (cp2 == canonb)
|
|
|
|
continue;
|
|
|
|
if (cp2[-1] == '\\') {
|
|
|
|
cp2[-1] = c;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cp2 = canonb;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*cp2++ = c;
|
|
|
|
}
|
|
|
|
*cp2 = '\0';
|
|
|
|
#endif
|
|
|
|
if (equal("", canonb))
|
|
|
|
return NULL;
|
|
|
|
return savestr(canonb);
|
|
|
|
}
|
|
|
|
#endif /* USE_EDITLINE */
|
|
|
|
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
static void
|
|
|
|
ttyint(int s __unused)
|
|
|
|
{
|
|
|
|
longjmp(intjmp, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read all relevant header fields.
|
|
|
|
*/
|
|
|
|
PUBLIC int
|
2002-03-02 17:59:35 +03:00
|
|
|
grabh(struct header *hp, int gflags)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1995-05-02 05:40:14 +04:00
|
|
|
struct termios ttybuf;
|
2006-09-29 18:59:31 +04:00
|
|
|
|
2006-10-22 01:37:20 +04:00
|
|
|
/* The following are declared volatile to avoid longjmp
|
|
|
|
* clobbering, though they seem safe without it! */
|
|
|
|
sig_t volatile saveint;
|
|
|
|
sig_t volatile savetstp;
|
|
|
|
sig_t volatile savettou;
|
|
|
|
sig_t volatile savettin;
|
1998-12-19 19:35:10 +03:00
|
|
|
#ifndef TIOCSTI
|
2006-10-22 01:37:20 +04:00
|
|
|
sig_t volatile savequit;
|
1998-12-19 19:35:10 +03:00
|
|
|
#else
|
|
|
|
# ifdef TIOCEXT
|
2006-10-22 01:37:20 +04:00
|
|
|
int volatile extproc;
|
1998-12-19 19:35:10 +03:00
|
|
|
# endif /* TIOCEXT */
|
|
|
|
#endif /* TIOCSTI */
|
2006-10-31 23:07:32 +03:00
|
|
|
int retval;
|
1998-12-19 19:35:10 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
savetstp = signal(SIGTSTP, SIG_DFL);
|
|
|
|
savettou = signal(SIGTTOU, SIG_DFL);
|
|
|
|
savettin = signal(SIGTTIN, SIG_DFL);
|
|
|
|
#ifndef TIOCSTI
|
|
|
|
ttyset = 0;
|
|
|
|
#endif
|
1995-05-02 05:40:14 +04:00
|
|
|
if (tcgetattr(fileno(stdin), &ttybuf) < 0) {
|
2002-03-06 00:29:30 +03:00
|
|
|
warn("tcgetattr");
|
From Anon Ymous:
1) Statification of modules.
2) Implement the 'detach' and 'Detach' commands for extracting mime
parts from messages.
3) Teach mail to output "In-Reply-To" and "References" header fields
when replying so others can thread us.
4) Implement threading, sorting, and tagging, supported by the
following commands: 'flatten', 'reverse', 'sort', 'thread',
'unthread', 'down', 'tset', 'up', 'expose', 'hide', 'tag',
'untag', 'invtags', 'tagbelow', 'hidetags', 'showtags'.
See the manpage for details (when available - soon).
5) Implement a 'deldups' command to delete duplicate messages based on
their "Message-Id" field, e.g., in replies to a mailing list that
are also CCed to a subscriber. (This can also be accomplished with
the threading and tagging commands.)
6) Implement 'ifdef' and 'ifndef' commands, and make the conditionals
nestable (i.e., implement a conditional stack). The if/else/endif
commands existed before, but they were primitive and undocumented.
The 'if' command currently recognizes the "receiving", "sending",
and "headersonly" mode keywords.
7) Teach the message selecting routine to understand regular
expressions if "regex-search" is defined. Otherwise only case
insensitive substring matches are done (as in the past).
8) Teach the message selection routine to understand boolean
expressions. Improved "colon-modifier" support. See the manpage
for details (when available - soon).
9) Extend paging to all commands (where relevant).
10) Add shell like piping and redirection of (standard) output (if
"enable-piping" is defined). Extend completion to these contexts.
11) The manpage should follow soon!!!!
2006-11-28 21:45:32 +03:00
|
|
|
return -1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2006-10-22 01:37:20 +04:00
|
|
|
#if !defined(USE_EDITLINE) || !defined(TIOCSTI)
|
1995-05-02 05:40:14 +04:00
|
|
|
c_erase = ttybuf.c_cc[VERASE];
|
|
|
|
c_kill = ttybuf.c_cc[VKILL];
|
2006-10-22 01:37:20 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef TIOCSTI
|
1997-10-19 20:49:15 +04:00
|
|
|
ttybuf.c_cc[VERASE] = _POSIX_VDISABLE;
|
|
|
|
ttybuf.c_cc[VKILL] = _POSIX_VDISABLE;
|
1993-03-21 12:45:37 +03:00
|
|
|
if ((saveint = signal(SIGINT, SIG_IGN)) == SIG_DFL)
|
2005-07-20 03:07:10 +04:00
|
|
|
(void)signal(SIGINT, SIG_DFL);
|
1993-03-21 12:45:37 +03:00
|
|
|
if ((savequit = signal(SIGQUIT, SIG_IGN)) == SIG_DFL)
|
2005-07-20 03:07:10 +04:00
|
|
|
(void)signal(SIGQUIT, SIG_DFL);
|
1993-03-21 12:45:37 +03:00
|
|
|
#else
|
1996-12-28 10:10:57 +03:00
|
|
|
# ifdef TIOCEXT
|
|
|
|
extproc = ((ttybuf.c_lflag & EXTPROC) ? 1 : 0);
|
|
|
|
if (extproc) {
|
2006-10-22 01:37:20 +04:00
|
|
|
int flag;
|
1996-12-28 10:10:57 +03:00
|
|
|
flag = 0;
|
|
|
|
if (ioctl(fileno(stdin), TIOCEXT, &flag) < 0)
|
2002-03-06 00:29:30 +03:00
|
|
|
warn("TIOCEXT: off");
|
1996-12-28 10:10:57 +03:00
|
|
|
}
|
|
|
|
# endif /* TIOCEXT */
|
2006-10-22 01:37:20 +04:00
|
|
|
saveint = signal(SIGINT, ttyint); /* must precede setjmp to be saved */
|
2006-10-31 23:07:32 +03:00
|
|
|
if ((retval = setjmp(intjmp)) != 0) {
|
2006-09-29 18:59:31 +04:00
|
|
|
(void)fputc('\n', stdout);
|
1993-03-21 12:45:37 +03:00
|
|
|
goto out;
|
2006-09-27 03:33:23 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
if (gflags & GTO) {
|
|
|
|
#ifndef TIOCSTI
|
2002-03-04 06:16:10 +03:00
|
|
|
if (!ttyset && hp->h_to != NULL)
|
1995-05-02 05:40:14 +04:00
|
|
|
ttyset++, tcsetattr(fileno(stdin), TCSADRAIN, &ttybuf);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
hp->h_to =
|
|
|
|
extract(readtty("To: ", detract(hp->h_to, 0)), GTO);
|
|
|
|
}
|
|
|
|
if (gflags & GSUBJECT) {
|
|
|
|
#ifndef TIOCSTI
|
2002-03-04 06:07:25 +03:00
|
|
|
if (!ttyset && hp->h_subject != NULL)
|
1995-05-02 05:40:14 +04:00
|
|
|
ttyset++, tcsetattr(fileno(stdin), TCSADRAIN, &ttybuf);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
hp->h_subject = readtty("Subject: ", hp->h_subject);
|
|
|
|
}
|
|
|
|
if (gflags & GCC) {
|
|
|
|
#ifndef TIOCSTI
|
2002-03-04 06:16:10 +03:00
|
|
|
if (!ttyset && hp->h_cc != NULL)
|
1995-05-02 05:40:14 +04:00
|
|
|
ttyset++, tcsetattr(fileno(stdin), TCSADRAIN, &ttybuf);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
hp->h_cc =
|
|
|
|
extract(readtty("Cc: ", detract(hp->h_cc, 0)), GCC);
|
|
|
|
}
|
|
|
|
if (gflags & GBCC) {
|
|
|
|
#ifndef TIOCSTI
|
2002-03-04 06:16:10 +03:00
|
|
|
if (!ttyset && hp->h_bcc != NULL)
|
1995-05-02 05:40:14 +04:00
|
|
|
ttyset++, tcsetattr(fileno(stdin), TCSADRAIN, &ttybuf);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
hp->h_bcc =
|
|
|
|
extract(readtty("Bcc: ", detract(hp->h_bcc, 0)), GBCC);
|
|
|
|
}
|
Jumbo mail patch from our anonymous user:
1) Use editline [optional]:
Most of this code was borrowed from src/usr.bin/ftp. It does the
appropriate editing, history, and completion for all mail commands
(from cmdtab[]) and also does editing on header strings ('~h' inside
the mail editor).
2) '-B' flag:
This will suppress the "To:" line passed to sendmail. In most
configurations it will lead to sendmail adding "To: undisclosed
recipients;". Currently, AFAIK mail requires at least one exposed
recipient address.
3) Comments in rcfile:
Currently, comments in .mailrc are only supported if the first
(non-white) character on a line is '#' followed by white space,
i.e., '#' is a 'nop' command. This (trivial) patch allows the more
normal/expected use of '#' as a comment character. It does not
respect quoting, so that might be an objection which I should fix.
4) Sendmail option editing:
This adds the sendmail option string to the strings editable by the
'~h' command within the mail editor. Currently, you can only set
this string from the command-line, which is particularly annoying
when replying to mail.
5) Reply from:
When replying to a message, grab the "To:" address from the message
and, if there is only one such address and it does not match a list of
allowed addresses (set in the "ReplyFrom" variable), pass it to
sendmail as the "From:" address for the reply (with the '-f' option).
I often make aliases for myself so that my primary address is not
given out; if the alias gets out, I know who to blame. Unfortunately,
a reply to such a message would normally use the primary address
without this patch. A warning is displayed when this is going to
happen so that it can be modified with '~h'.
6) CC and BCC lists:
Allow '-c' and '-b' to accept white-space or ',' delimited lists.
Currently, a white-space delimited list of addresses work, but a
list of aliases will not get expanded. For example, currently:
mail -c "foo bar" christos
will fail to send mail to 'foo' and 'bar' if these are mail aliases
(in ~/.mailrc); sendmail aliases (in /etc/aliases) do work.
7) pipe command:
This pipes the current message into a shell command. I use this for
quick decoding of uuencoded mail, but I can imagine it might be
useful for decrypting encrypted mail, too.
8) show command:
This command takes a list of variables and shows their values. It
is probably stupid as the 'set' command without any argument
displays all variable values. Of course, if there are a lot of
variables you have to sift through the list for the one(s) you want.
2006-09-18 23:46:21 +04:00
|
|
|
if (gflags & GSMOPTS) {
|
|
|
|
char *smopts;
|
|
|
|
#ifndef TIOCSTI
|
|
|
|
if (!ttyset && hp->h_smopts != NULL)
|
|
|
|
ttyset++, tcsetattr(fileno(stdin), TCSADRAIN, &ttybuf);
|
|
|
|
#endif
|
|
|
|
smopts = readtty("Smopts: ", detract(hp->h_smopts, GSMOPTS));
|
|
|
|
|
|
|
|
/* Parse smopts with getrawlist() rather than expand()
|
|
|
|
* to get a shell-like expansion.
|
|
|
|
*/
|
|
|
|
hp->h_smopts = NULL;
|
|
|
|
if (smopts) {
|
2006-10-22 01:37:20 +04:00
|
|
|
struct name *np, *t;
|
|
|
|
char *argv[MAXARGC];
|
|
|
|
int argc, i;
|
|
|
|
|
Jumbo mail patch from our anonymous user:
1) Use editline [optional]:
Most of this code was borrowed from src/usr.bin/ftp. It does the
appropriate editing, history, and completion for all mail commands
(from cmdtab[]) and also does editing on header strings ('~h' inside
the mail editor).
2) '-B' flag:
This will suppress the "To:" line passed to sendmail. In most
configurations it will lead to sendmail adding "To: undisclosed
recipients;". Currently, AFAIK mail requires at least one exposed
recipient address.
3) Comments in rcfile:
Currently, comments in .mailrc are only supported if the first
(non-white) character on a line is '#' followed by white space,
i.e., '#' is a 'nop' command. This (trivial) patch allows the more
normal/expected use of '#' as a comment character. It does not
respect quoting, so that might be an objection which I should fix.
4) Sendmail option editing:
This adds the sendmail option string to the strings editable by the
'~h' command within the mail editor. Currently, you can only set
this string from the command-line, which is particularly annoying
when replying to mail.
5) Reply from:
When replying to a message, grab the "To:" address from the message
and, if there is only one such address and it does not match a list of
allowed addresses (set in the "ReplyFrom" variable), pass it to
sendmail as the "From:" address for the reply (with the '-f' option).
I often make aliases for myself so that my primary address is not
given out; if the alias gets out, I know who to blame. Unfortunately,
a reply to such a message would normally use the primary address
without this patch. A warning is displayed when this is going to
happen so that it can be modified with '~h'.
6) CC and BCC lists:
Allow '-c' and '-b' to accept white-space or ',' delimited lists.
Currently, a white-space delimited list of addresses work, but a
list of aliases will not get expanded. For example, currently:
mail -c "foo bar" christos
will fail to send mail to 'foo' and 'bar' if these are mail aliases
(in ~/.mailrc); sendmail aliases (in /etc/aliases) do work.
7) pipe command:
This pipes the current message into a shell command. I use this for
quick decoding of uuencoded mail, but I can imagine it might be
useful for decrypting encrypted mail, too.
8) show command:
This command takes a list of variables and shows their values. It
is probably stupid as the 'set' command without any argument
displays all variable values. Of course, if there are a lot of
variables you have to sift through the list for the one(s) you want.
2006-09-18 23:46:21 +04:00
|
|
|
np = NULL;
|
|
|
|
argc = getrawlist(smopts, argv, sizeof(argv)/sizeof(*argv));
|
2006-10-22 01:37:20 +04:00
|
|
|
for (i = 0; i < argc; i++) {
|
Jumbo mail patch from our anonymous user:
1) Use editline [optional]:
Most of this code was borrowed from src/usr.bin/ftp. It does the
appropriate editing, history, and completion for all mail commands
(from cmdtab[]) and also does editing on header strings ('~h' inside
the mail editor).
2) '-B' flag:
This will suppress the "To:" line passed to sendmail. In most
configurations it will lead to sendmail adding "To: undisclosed
recipients;". Currently, AFAIK mail requires at least one exposed
recipient address.
3) Comments in rcfile:
Currently, comments in .mailrc are only supported if the first
(non-white) character on a line is '#' followed by white space,
i.e., '#' is a 'nop' command. This (trivial) patch allows the more
normal/expected use of '#' as a comment character. It does not
respect quoting, so that might be an objection which I should fix.
4) Sendmail option editing:
This adds the sendmail option string to the strings editable by the
'~h' command within the mail editor. Currently, you can only set
this string from the command-line, which is particularly annoying
when replying to mail.
5) Reply from:
When replying to a message, grab the "To:" address from the message
and, if there is only one such address and it does not match a list of
allowed addresses (set in the "ReplyFrom" variable), pass it to
sendmail as the "From:" address for the reply (with the '-f' option).
I often make aliases for myself so that my primary address is not
given out; if the alias gets out, I know who to blame. Unfortunately,
a reply to such a message would normally use the primary address
without this patch. A warning is displayed when this is going to
happen so that it can be modified with '~h'.
6) CC and BCC lists:
Allow '-c' and '-b' to accept white-space or ',' delimited lists.
Currently, a white-space delimited list of addresses work, but a
list of aliases will not get expanded. For example, currently:
mail -c "foo bar" christos
will fail to send mail to 'foo' and 'bar' if these are mail aliases
(in ~/.mailrc); sendmail aliases (in /etc/aliases) do work.
7) pipe command:
This pipes the current message into a shell command. I use this for
quick decoding of uuencoded mail, but I can imagine it might be
useful for decrypting encrypted mail, too.
8) show command:
This command takes a list of variables and shows their values. It
is probably stupid as the 'set' command without any argument
displays all variable values. Of course, if there are a lot of
variables you have to sift through the list for the one(s) you want.
2006-09-18 23:46:21 +04:00
|
|
|
t = nalloc(argv[i], GSMOPTS);
|
|
|
|
if (hp->h_smopts == NULL)
|
|
|
|
hp->h_smopts = t;
|
|
|
|
else
|
|
|
|
np->n_flink = t;
|
|
|
|
t->n_blink = np;
|
|
|
|
np = t;
|
|
|
|
}
|
|
|
|
}
|
2006-10-22 01:37:20 +04:00
|
|
|
#ifdef MIME_SUPPORT
|
|
|
|
if (hp->h_attach) {
|
|
|
|
struct attachment *ap;
|
|
|
|
int i;
|
|
|
|
i = 0;
|
|
|
|
for (ap = hp->h_attach; ap; ap = ap->a_flink)
|
|
|
|
i++;
|
|
|
|
(void)printf("Attachment%s: %d\n", i > 1 ? "s" : "", i);
|
|
|
|
}
|
|
|
|
#endif
|
Jumbo mail patch from our anonymous user:
1) Use editline [optional]:
Most of this code was borrowed from src/usr.bin/ftp. It does the
appropriate editing, history, and completion for all mail commands
(from cmdtab[]) and also does editing on header strings ('~h' inside
the mail editor).
2) '-B' flag:
This will suppress the "To:" line passed to sendmail. In most
configurations it will lead to sendmail adding "To: undisclosed
recipients;". Currently, AFAIK mail requires at least one exposed
recipient address.
3) Comments in rcfile:
Currently, comments in .mailrc are only supported if the first
(non-white) character on a line is '#' followed by white space,
i.e., '#' is a 'nop' command. This (trivial) patch allows the more
normal/expected use of '#' as a comment character. It does not
respect quoting, so that might be an objection which I should fix.
4) Sendmail option editing:
This adds the sendmail option string to the strings editable by the
'~h' command within the mail editor. Currently, you can only set
this string from the command-line, which is particularly annoying
when replying to mail.
5) Reply from:
When replying to a message, grab the "To:" address from the message
and, if there is only one such address and it does not match a list of
allowed addresses (set in the "ReplyFrom" variable), pass it to
sendmail as the "From:" address for the reply (with the '-f' option).
I often make aliases for myself so that my primary address is not
given out; if the alias gets out, I know who to blame. Unfortunately,
a reply to such a message would normally use the primary address
without this patch. A warning is displayed when this is going to
happen so that it can be modified with '~h'.
6) CC and BCC lists:
Allow '-c' and '-b' to accept white-space or ',' delimited lists.
Currently, a white-space delimited list of addresses work, but a
list of aliases will not get expanded. For example, currently:
mail -c "foo bar" christos
will fail to send mail to 'foo' and 'bar' if these are mail aliases
(in ~/.mailrc); sendmail aliases (in /etc/aliases) do work.
7) pipe command:
This pipes the current message into a shell command. I use this for
quick decoding of uuencoded mail, but I can imagine it might be
useful for decrypting encrypted mail, too.
8) show command:
This command takes a list of variables and shows their values. It
is probably stupid as the 'set' command without any argument
displays all variable values. Of course, if there are a lot of
variables you have to sift through the list for the one(s) you want.
2006-09-18 23:46:21 +04:00
|
|
|
}
|
2006-10-22 01:37:20 +04:00
|
|
|
#ifdef TIOCSTI
|
1993-03-21 12:45:37 +03:00
|
|
|
out:
|
2006-10-22 01:37:20 +04:00
|
|
|
#endif
|
2005-07-20 03:07:10 +04:00
|
|
|
(void)signal(SIGTSTP, savetstp);
|
|
|
|
(void)signal(SIGTTOU, savettou);
|
|
|
|
(void)signal(SIGTTIN, savettin);
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef TIOCSTI
|
1995-05-02 05:40:14 +04:00
|
|
|
ttybuf.c_cc[VERASE] = c_erase;
|
|
|
|
ttybuf.c_cc[VKILL] = c_kill;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (ttyset)
|
1995-05-02 05:40:14 +04:00
|
|
|
tcsetattr(fileno(stdin), TCSADRAIN, &ttybuf);
|
2005-07-20 03:07:10 +04:00
|
|
|
(void)signal(SIGQUIT, savequit);
|
1996-12-28 10:10:57 +03:00
|
|
|
#else
|
|
|
|
# ifdef TIOCEXT
|
|
|
|
if (extproc) {
|
2006-10-22 01:37:20 +04:00
|
|
|
int flag;
|
1996-12-28 10:10:57 +03:00
|
|
|
flag = 1;
|
|
|
|
if (ioctl(fileno(stdin), TIOCEXT, &flag) < 0)
|
2002-03-06 00:29:30 +03:00
|
|
|
warn("TIOCEXT: on");
|
1996-12-28 10:10:57 +03:00
|
|
|
}
|
|
|
|
# endif /* TIOCEXT */
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
2005-07-20 03:07:10 +04:00
|
|
|
(void)signal(SIGINT, saveint);
|
2006-10-31 23:07:32 +03:00
|
|
|
return retval;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|