reformail - reformat mail
SYNOPSIS
reformail [-d] -s program arg arg ...
reformail -D len filename
reformail -x header: -x header: ...
reformail -X header: -X header: ...
reformail [options] ...
DESCRIPTION
The reformail program reads a message on standard input, reformats it
in some way, and writes the message to standard output.
Splitting mailboxes into individual messages
The -s option splits the mbox-formatted mailbox file on standard input into
individual messages. The specified external program is executed for each
message. The contents of each individual message will be provided to the
program on standard input.
If the FILENO
environment variable is set to a number,
reformail will consecutively increment the FILENO
environment variable each time the program is executed for each individual
message.
If FILENO
is not set, it's initial value will be "000". If
FILENO
is set to a non-numeric value, FILENO
will
remain unchanged.
Detecting duplicate messages
The -D option implements a simple way to delete duplicate messages in incoming
mail. filename is a file that will be approximately 'len' bytes long.
This file will be used by reformail to contain a list of message IDs seen in
recent mail. reformail reads the message on standard input. If the
message has a Message-ID: header that's already in the cache file,
reformail terminates with the exit code set to 0. Otherwise,
reformail terminates with the exit code set to 1.
Extracting headers
The -x and -X options extract the indicated headers from the message, and
print them to standard output. Multiple -x and -X options can be specified at
the same time, and may be intermixed.
The -x option extracts and prints the contents of the header. The -X option
prints the name of the header as well.
In all other situations, reformail will simply copy the message on
its standard input to the standard output, reformatting the message as
follows:
OPTIONS
- -a'header: value' - appends a custom header to the message if this
header does not already exist. If header is either Message-ID: or
Resent-Message-ID: and the value is empty, reformail will generate
a (hopefully) unique message ID for you.
- -A'header: value' - appends a custom header to the message even if this
header already exists. If header is either Message-ID: or
Resent-Message-ID: and the value is empty, reformail will generate
a (hopefully) unique message ID for you.
- -c - concatenate multi-line headers. Headers split on multiple lines are
concatenated into a single line (each).
- -dn - if n is 1, each line will be terminated with CRLF. If n is 0
(default), each line will be terminated with LF. reformail reads a
message with either line terminator, and will force the message to have
the specified line termination.
- -f0 - remove the "From " line from the message, if it's there.
- -f1 - add the "From " line to the message, if it's not there.
reformail will attempt to generate the "From " line from any
Errors-To:, Return-Path:, or From: headers in the message. If
reformail is unable to determine the return address, "root" will be
used.
- -i'header: value' - appends a custom header to the message. If this
header already exists it is renamed by prepending "Old-" to the name of
the header.
- -I'header: value' - appends a custom header to the message. If this
header already exists in the message, the old header is completely
removed. If the value is empty, any existing header is completely removed,
and nothing gets appended.
- -k - after generating an auto-reply header using the -r option, keep the
contents of the message itself in the auto-reply.
- -p'prefix' - when both -r and -k options are used, the -p option can be
used to change the quoting prefix for each line from its default value of
"> ".
- -P'salutation' - when both -r and -k options are used, the -P option is
used to specify the salutation that begins the contents of the message.
See AUTOREPLIES below.
- -r - generates headers for an auto-reply to this message. This option
can be used to create replies to both E-mail and Usenet messages
(reformail create both In-Reply-To: and References: headers). When
generating replies to Usenet messages, you'll probably have to always use
the -t option also.
- -t - use user-generated headers in order to determine the return address
for the -r option. Otherwise, reformail will use machine generated
headers.
- -R oldheader: newheader: - renames the indicated header.
- -u'header:' - if this header occurs multiple times in the message,
remove all occurrences except the first one.
- -U'header:' - if this header occurs multiple times in the message,
remove all occurrences except the last one.
AUTOREPLIES
The -r option generates a set of headers for an automatic reply to the
message, instead of producing just a reformatted copy of the message. As an
enhancement, the -r option is smart enough to be able to properly generate an
auto-reply to either an E-mail message, or a Usenet message ( reformail
will generate both an In-Reply-To: and References: header).
The To: header is set to the apparent sender of the message. To determine
the sender of the message, reformail prefers to look at
machine-generated headers, such as Errors-To: and Return-Path:, instead of
user-generated headers, such as From: or Reply-To:.
The -t option makes reformail use user-generated headers instead of
machine-generated headers.
The -ra option copies To: headers from the original message into the
auto-reply. The -rA option copies To: and Cc: headers.
Normally, the contents of the original message are removed. The -k option
copies the contents of the original message, which each line prefixed by "> ".
Use the "-p" option to specify a different prefix.
The contents of the message are preceded by a salutation specified by the
-P option. If not specified, the salutation defaults to "%F writes:%n". Within
the salutation, each occurrence of % followed by another character is replaced
by some information from the original message, as follows:
%C
- replaced by the contents of any X-Newsgroup: header in
the original message.
%d
- replaced by the contents of any Date: header in the
original message.
%f
- replaced by the E-mail address of the sender of the
original message.
%F
- replaced by the name of the sender of the original
message. If no name was given, the E-mail address is used.
%i
- replaced by the contents of any Message-ID: header in
the original message.
%n
- %n will cause reformail to insert a line break
here.
%N
- replaced by the contents of any Newsgroups: header in
the original message.
%s
- replaced by the contents of any Subject: header in the
original message.
BUGS
For the -a, -A, and -I options, a space after the header name and the colon is
considered to be a non-empty field.
Do not provide the same header to more than one family of header-modifying
options, such as -u/-U and -a/-A. Doing so yields unpredictable results. If
you have a need to do so, run reformail several times (use a pipe,
perhaps).
SEE ALSO
courier(8), sendmail(8), maildrop(1)