.TH MAIL 1
.SH NAME
mail, edmail, sendmail, seemail, aliasmail, smtp, smtpd, to, vwhois, vismon \-  mail commands
.SH SYNOPSIS
.B mail
[
.I arg ...
]
.PP
.B upas/edmail
[
.B -cmpre
]
[
.B -[fF]
.I mfile
]
.PP
.B upas/sendmail
[
.B -xr#
]
.I person ...
.PP
.B upas/to
[
.B -x#
]
.PP
.B seemail
[
.B -as
] [
.B -u
.I user
] [
.B -f
.I file
] [
.B -r
.I reminders
]
.PP
.B upas/aliasmail
.I name ...
.PP
.B smtp
[
.B -fdu
]
[
.BI -h host
]
[
.BI -g gateway
]
[
.I .domain
]
.I "address sender rcpt-list"
.PP
.B smtpd
[
.B -d
]
.PP
.B vwhois
.I people ...
.PP
.B vismon
.I system
.SH DESCRIPTION
.SS Mail
Mail invokes
.I edmail
.B -m
when no 
.I persons
appear on the command line.
It invokes
.I sendmail
otherwise.
.SS "Mailbox Editing"
.I Edmail
edits a mailbox.
The default mailbox is
.BI /mail/box/ username /mbox\f1.
The
.B -f
and
.B -F
command line options and the
.B s
and
.B S
editing commands specify an alternate mailbox.
Unrooted path names are interpreted relative to
.BI /mail/box/ username
for
.B -f
and
.B s
and relative to the current directory for
.B -F
and
.BR S .
If the
.I mfile
argument is omitted, the name defaults to
.BR stored .
.PP
The options for
.I edmail
are:
.TF "-F mfile"
.TP
.B -c
Create a mailbox.
.PD 0
.TP
.B -r
Reverse: print mail in first-in, first-out order.
.TP
.B -p
Print all the mail messages without prompting for commands.
.TP
.B -m
Use a manual style of interface, that is, print no messages unless directed to.
.TP
.BI -f " mfile"
Read messages from the specified file (see above) instead of the default mailbox.
.TP
.BI -F " mfile"
same as
.B -f
with different starting point for relative paths (see above).
.TP
.B -e
Check silently if there is anything in the mailbox;
return zero (true) if so, non-zero otherwise.
.PD
.PP
.I Edmail
prints messages one at a time,
prompting between messages.
After printing a prompt
.I edmail
reads a line from the standard input
to direct disposition of the message.
Commands, as in
.IR ed (1),
are of the form
.RI `[ range ]
.I command
.RI [ arguments ]'.
The command is applied to each message in the (optional) range
addressed by message number and/or regular expressions
in the style of
.IR ed (1).
A regular expression in slashes searches among header
(postmark) lines; an expression in percent signs searches on
message content.
.TP 1.1i
.I address
to indicate a single message header
.PD0
.TP
.IB address , address
to indicate a range of contiguous message headers
.TP
.BI g/ expression /
to indicate all message headers matching the regular
.IR expression .
.PD
.PP
The commands are:
.PD 0
.TP 1.1i
.B b
Print the headers for the next ten messages.
.TP
.B d
Mark message to be deleted upon exiting
.IR edmail .
.TP
.B h
Print the disposition, size in characters, and header line of the message.
.TP
.BI m " person ...
Mail the message to the named
.IR persons .
.TP
.BI M " person ...
Same as
.BI m
except that lines typed
on the terminal (terminated by
.BR EOT )
are prefixed to the message.
.TP
.B p
Print message.	An interrupt stops the printing.
.TP
.B r
Reply to the sender of the message.
.TP
.B R
Like 
.L r
but with the message
appended to the reply.
.TP
.BI s " mfile"
(Save) Append the message to the specified mailbox (see above).
.TP
.BI S " mfile"
Same as
.B s
with different starting point for relative paths (see above).
.TP
.B q
Put undeleted mail back in the mailbox and stop.
.TP
EOT (control-D)
Same as 
.LR q .
.TP
.BI w " file
Same as
.B s
with the mail header line(s) stripped.
.TP
.BI W " file
Same as
.B w
with different starting point for relative paths (see above).
.TP
.B u
Remove mark for deletion.
.TP
.B x
Exit, without changing the mailbox file.
.TP
.B ?
Print a command summary.
.TP
.BI | command
Run the
.I command
with the message as standard input.
.TP
.BI ! command
Escape to the shell to do
.IR command .
.TP
.B \&=
Print the number of the current message.
.PD
.ne 5
.SS "Sending Mail
.PP
.I Sendmail
takes the standard input up to an end-of-file
and adds it to each
.I person's
mailbox.
When running in an
.IR 8½ (1)
window,
.I sendmail
automatically puts the window into Hold mode (see
.IR 8½ (1));
this means that the message can be edited freely,
because nothing will be sent to
.I sendmail
until the ESC key is hit to exit Hold mode.
With option
.BR -# ,
.I sendmail
does not send mail, but instead reports
what command would be used to send the mail.
With option
.BR -x ,
.I sendmail
does not send mail, but instead reports
the full mail address of the recipient.
Option
.B -r
tells sendmail that its input is via a pipe from
another program.
It won't turn on Hold mode and will expect a From
line at the start of the message to provide the
name of the sender and timestamp.
.PP
The message is automatically postmarked with the
sender's name and date.
Lines that look like postmarks are
prefixed with 
.LR > .
.PP
.I Person
is a user name on the local system,
a name for which there is an
.IR alias ,
or a network mail address.
.PP
.I To
is a preprocessor for
.IR sendmail .
It takes a mail message as standard input,
looks through it for
.BR To: ,
.BR Cc: ,
and
.B Bcc:
header lines, and calls sendmail with the addresses
in those header lines as destinations.
The
.B Bcc:
header lines are removed before passing the message to
.IR sendmail .
.SS "Addressing Conventions"
The local convention for converting addresses
is given by rewrite rules in
.BR /mail/lib/rewrite ;
see
.IR rewrite (6).
The conventions generally used are:
.IP \-
A
.I person
containing no
.L !
or 
.L @
is considered a local user or local alias.
It is passed as an argument to
.I aliasmail
which returns either the expanded alias or 
.BI local! person
if there is no alias of that name.
.IP \-
A canonical network mail address has the form
.IB machine ! ... ! name\f1,
with one or more machines mentioned.
.SS "Aliasmail"
.I Aliasmail 
expands mail aliases, its arguments, according to alias files.
Each line of an alias file begins with
.B #
(comment) or with a name.
The rest of a name line gives the expansion.
The expansion may contain multiple addresses and may be continued
to another line by appending a backslash.
Items are separated by white space.
.PP
In expanding a name, the sender's personal alias file
.BI /mail/box/ username /names 
is checked first.
Then the system alias files, listed one per line in
.BR /mail/lib/namefiles  ,
are checked in order.
If the name is not found, the expansion is taken to be
.BI local! name\f1.
.SS Mailboxes
Incoming mail for a user
.I username
is put in the file
.BI /mail/box/ username /mbox
unless either the file
.BI /mail/box/ username /forward
or
.BI /mail/box/ username /pipeto
exists.
The mailbox must have append-only and exclusive-access mode
(see
.IR chmod (1)).
A user must create his or her own mailbox using the
.B -c
option of
.IR edmail .
Mailboxes are created writable (append-only) but not readable by others.
.SS Forwarding
If the file
.BI /mail/box/ username /forward
exists and is readable by everyone, incoming mail
will be forwarded to the addresses contained in the first line of the file.
The file may contain multiple addresses.
Forwarding loops are caught and resolved by local delivery.
.SS Filtering
If the file
.BI /mail/box/ username /pipeto
exists and is readable and executable by everyone,
it will be run for each incoming message for the user.
The message will be piped to it rather
than appended to his/her mail box.
The file is run as user
.BR none .
.SS Misc
.PP
The
.I seemail
command notifies when a new message
arrives in your mailbox.
It reads a log
.IR file ,
default
.BR /sys/log/mail ,
of incoming messages.
It runs continuously where it is invoked, displaying the
names and icons of senders of new messages.
The
.B -a
flag causes it to initialize by displaying all the faces in the log;
.B -s
causes it to overwrite multiple appearances of the same face rather
than repeatedly displaying it.
The
.B -u
option displays incoming mail for the specified user instead of yourself.
.PP
.IR Seemail 's
.B -r
option causes it to announce appointments described in the file
.IR reminders .
Each line of the appointment file contains the
month, day, hour, minute and room (any string of non-spaces)
of an appointment, in a format compatible with
.IR calendar (1).
The hour is 24-hour time.  The fields
may be separated by white space, commas, slashes or colons,
and the room may be followed by arbitrary text.
On the day of each appointment,
.I seemail
displays a clock-face icon with the appointment's room and time,
once at midnight (or when the program starts), then an hour before,
then 15 minutes before, then 1 minute
before, then at the appointment time.  At the same time, it displays
the room and any following text on a line below the
clock time at the top of its window.
.PP
.I Vwhois
just displays in the
.I seemail
window
the icons of
.IR people .
.I Vismon
is a version of
.I seemail
that connects to a remote Unix (not Plan 9)
system to look for mail arriving there.
.PP
.I Smtp
sends the mail message from standard input
to the users
.I rcpt-list
on the host at network address
.I address 
using the Simple Mail Transfer Protocol.
The return address of the mail will contain the local
system name from the environment variable
.I sysname
and the user
.IR sender .
If
.I .domain
is given, it is appended to the end of the system name.
The 
.B -u
option sends the mail in the standard Unix format instead
of RFC822 format.
The
.B -f
flag just prints out the converted message rather than
sending it to the destination.
The
.B -g
option specifies a gateway system to pass the message to if smtp can't
find an address or MX entry for the destination system.
The
.B -d
option turns on debugging output to standard error.
.PP
.I Smtpd
receives a message using the Simple Mail Transfer Protocol.
Standard input and output are the protocol connection.
The
.B -d
option turns on debugging output to standard error.
.I Smtpd
is normally run by a network listener such as
.IR listen (8).
.SH FILES
.TF /mail/box/*/dead.letter
.TP
.B /sys/log/mail
mail log file
.TP
.B /mail/box/*
mail directories
.TP
.B /mail/box/*/mbox
mailbox files
.TP
.B /mail/box/*/forward
forwarding address(es)
.TP
.B /mail/box/*/pipeto
mail filter
.TP
.B /mail/box/*/L.reading
mutual exclusion lock for multiple mbox readers
.TP
.B /mail/box/*/L.mbox
mutual exclusion lock for altering mbox
.TP
.B /mail/box/*/dead.letter
unmailable text
.TP
.B /mail/box/*/names
personal alias files
.TP
.B /mail/lib/rewrite
rules for handling addresses
.TP
.B /mail/lib/namefiles
lists files to search for aliases in
.TP
.B /lib/face/48x48x?
directories of icons for
.I seemail
.SH SOURCE
.TF /sys/src/cmd/upas
.TP
.B /rc/bin/mail
.TP
.B /sys/src/cmd/upas
source for commands in
.B /bin/upas
.TP
.B /sys/src/cmd/seemail
.TP
.B /rc/bin/vismon
.TP
.B /rc/bin/vwhois
.SH "SEE ALSO"
.IR face (6),
.IR rewrite (6)
.SH BUGS
.I Edmail
truncates
long headers for searching.
