# FORMAIL - mail (re)formatter - man - [phpMan]

[_FORMAIL_(1)](https://www.chedong.com/phpMan.php/man/FORMAIL/1/markdown)                             General Commands Manual                            [_FORMAIL_(1)](https://www.chedong.com/phpMan.php/man/FORMAIL/1/markdown)

## NAME
       formail - mail (re)formatter

## SYNOPSIS
       **formail **[**+_**skip_] [**-_**total_] [**-bczfrktedqBY**] [**-p _**prefix_]
            [**-D _**maxlen_ _idcache_]
            [**-l _**folder_]
            [**-x _**headerfield_] [**-X _**headerfield_]
            [**-a _**headerfield_] [**-A _**headerfield_]
            [**-i _**headerfield_] [**-I _**headerfield_]
            [**-u _**headerfield_] [**-U _**headerfield_]
            [**-R _**oldfield_ _newfield_]
            [**-n **[_maxprocs_ ]] [**-m _**minfields_] [**-s **[_command_ [_arg_ ...]]]
### formail -v

## DESCRIPTION
       **formail  **is  a filter that can be used to force mail into mailbox format, perform `From ' es‐
       caping, generate auto-replying headers, do simple header munging/extracting  or  split  up  a
       mailbox/digest/articles file.  The mail/mailbox/article contents will be expected on stdin.

       If  formail  is  supposed  to determine the sender of the mail, but is unable to find any, it
       will substitute `foo@bar'.

       If formail is started without any command line options, it will force any  mail  coming  from
       stdin into mailbox format and will escape **all **bogus `From ' lines with a `>'.

## OPTIONS
### -v   

### -b   

### -p _
            Define a different quotation prefix.  If unspecified it defaults to `>'.

### -Y   

### -c   
            mail with standard (line oriented) text utilities.

### -z   
            only  a  single whitespace character.  Zap leading and trailing whitespace on fields ex‐
            tracted with **-x**.

### -f   
            ' line as the first line).

### -r   
            (except X-Loop:) in the original message, fields you wish to preserve need to  be  named
            using the **-i **option.  If you use this option in conjunction with **-k**, you can prevent the
            body from being `escaped' by also specifying **-b**.

### -k   

### -t   
            to  select  the _header_ _sender_ instead of the _envelope_ _sender_ for the reply.  This option
            should be used when generating auto-reply headers from news articles or when the  sender
            of the message is expecting a reply.

### -s   
            one (a new program is started for every part).  **-s **has to be the last option  specified,
            the first argument following it is expected to be the name of a program, any other argu‐
            ments  will  be  passed  along to it.  If you omit the program, then formail will simply
            concatenate the split mails on stdout again.  See **FILENO**.

### -n _
            Tell formail not to wait for every program to finish before starting  the  next  (causes
            splits  to  be  processed in parallel).  _Maxprocs_ optionally specifies an upper limit on
            the number of concurrently running processes.

### -e   
            sages could start on every line).

### -d   
            format (i.e., allows you to split digests/articles  or  non-standard  mailbox  formats).
            This disables recognition of the **Content-Length: **field.

### -l folder
            Generate  a log summary in the same style as procmail.  This includes the entire "From "
            line, the Subject: header field, the folder, and the size of the message in bytes.   The
            mailstat command can be used to summarize logs in this format.

### -B   

### -m _
            Allows  you  to specify the number of consecutive headerfields formail needs to find be‐
            fore it decides it found the start of a new message, it defaults to 2.

### -q   
            mismatched **Content-Length: **fields.  This option is on by default, to make it display the
            messages use **-q-**.

### -D _
            Formail will detect if the Message-ID of the current message has already been seen using
            an  _idcache_ file of approximately _maxlen_ size.  If not splitting, it will return success
            if a duplicate has been found.  If splitting, it will not output duplicate messages.  If
            used in conjunction with **-r**, formail will look at  the  _mail_  _address_  of  the  envelope
            sender _instead_ at the Message-ID.

### -x _
            Extract  the  contents  of this _headerfield_ from the header.  Line continuations will be
            left intact; if you want the value on a single line then you'll also need the **-c **option.

### -X _
            Same as **-x**, but also preserves/includes the field name.

### -a _
            Append a custom _headerfield_ onto the header; but only if a similar field does not  exist
            yet.   If  you  specify  either one of the field names **Message-ID: **or **Resent-Message-ID:**
            with no field contents, then formail will generate a unique message-ID for you.

### -A _
            Append a custom _headerfield_ onto the header in any case.

### -i _
            Same as **-A**, except that any  existing  similar  fields  are  renamed  by  prepending  an
            ``Old-'' prefix.  If _headerfield_ consists only of a field-name, it will not be appended.

### -I _
            Same  as **-i**, except that any existing similar fields are simply removed.  If _headerfield_
            consists only of a field-name, it effectively deletes the field.

### -u _
            Make the first occurrence of this field unique, and thus delete  all  subsequent  occur‐
            rences of it.

### -U _
            Make the last occurrence of this field unique, and thus delete all preceding occurrences
            of it.

### -R _
            Renames all occurrences of the fieldname _oldfield_ into _newfield_.

       **+_**skip_
            Skip the first _skip_ messages while splitting.

### -_
            Output at most _total_ messages while splitting.

## NOTES
       When  renaming, removing, or extracting fields, partial fieldnames may be used to specify all
       fields that start with the specified value.

       By default, when generating an auto-reply header formail selects the envelope sender from the
       input message.  This is correct for vacation messages and other automatic  replies  regarding
       the  routing  or delivery of the original message.  If the sender is expecting a reply or the
       reply is being generated in response to the contents of the original message then the -t  op‐
       tion should be used.

       **RFC822**, the original standard governing the format of Internet mail messages, did not specify
       whether Resent header fields (those that begin with `Resent-', such as `Resent-From:') should
       be considered when generating a reply.  Since then, the recommended usage of the Resent head‐
       ers  has  evolved  to consider them as purely informational and not for use when generating a
       reply.  This has been codified in **RFC2822**, the new Internet Message  Format  standard,  which
       states in part:

              Resent  fields  are  used  to  identify a message as having been reintroduced into the
              transport system by a user.  The purpose of using resent fields is to have the message
              appear to the final recipient as if it were sent directly by the original sender, with
              all of the original fields remaining the same....They MUST NOT be used in  the  normal
              processing of replies or other such automatic actions on messages.

       While  formail now ignores Resent headers when generating header replies, versions of formail
       prior to 3.14 gave such headers a high precedence.  If the old behavior is needed for  estab‐
       lished  applications  it  can be specified by calling formail with the option `-a Resent-' in
       addition to the -r and -t options.  This usage is deprecated and should not be  used  in  new
       applications.

## ENVIRONMENT
       **FILENO**
            While splitting, formail assigns the message number currently being output to this vari‐
            able.   By  presetting  FILENO, you can change the initial message number being used and
            the width of the zero-padded output.  If FILENO is unset it will  default  to  000.   If
            FILENO is non-empty and does not contain a number, FILENO generation is disabled.

## EXAMPLES
       To split up a digest one usually uses:
              formail +1 -ds >>the_mailbox_of_your_choice
       or
              formail +1 -ds procmail

       To remove all Received: fields from the header:
              formail -I Received:

       To remove all fields except From: and Subject: from the header:
              formail -k -X From: -X Subject:

       To supersede the Reply-To: field in a header you could use:
              formail -i "Reply-To: foo@bar"

       To convert a non-standard mailbox file into a standard mailbox file you can use:
              formail -ds <old_mailbox >>new_mailbox

       Or, if you have a very tolerant mailer:
              formail -a Date: -ds <old_mailbox >>new_mailbox

       To extract the header from a message:
              formail -X ""
       or
              sed -e '/^$/ q'

       To extract the body from a message:
              formail -I ""
       or
              sed -e '1,/^$/ d'

## SEE ALSO
       [**mail**(1)](https://www.chedong.com/phpMan.php/man/mail/1/markdown), [**sendmail**(8)](https://www.chedong.com/phpMan.php/man/sendmail/8/markdown), [**procmail**(1)](https://www.chedong.com/phpMan.php/man/procmail/1/markdown), [**sed**(1)](https://www.chedong.com/phpMan.php/man/sed/1/markdown), [**sh**(1)](https://www.chedong.com/phpMan.php/man/sh/1/markdown), **RFC822**, **RFC2822**, **RFC1123**

## DIAGNOSTICS
       Can't fork             Too many processes on this machine.

       Content-Length: field exceeds actual length by nnn bytes
                              The  Content-Length:  field  in the header specified a length that was
                              longer than the actual body.  This causes this  message  to  absorb  a
                              number of subsequent messages following it in the same mailbox.

       Couldn't write to stdout
                              The program that formail was trying to pipe into didn't accept all the
                              data  formail  sent to it; this diagnostic can be suppressed by the **-q**
                              option.

       Duplicate key found: x The Message-ID or sender x in this message was found in  the  idcache;
                              this diagnostic can be suppressed by the **-q **option.

       Failed to execute "x"  Program not in path, or not executable.

       File table full        Too many open files on this machine.

       Invalid field-name: "x"
                              The specified field-name "x" contains control characters, or cannot be
                              a partial field-name for this option.

## WARNINGS
       You can save yourself and others a lot of grief if you try to avoid using this autoreply fea‐
       ture  on  mails  coming  through  mailinglists.  Depending on the format of the incoming mail
       (which in turn depends on both the original sender's mail agent and  the  mailinglist  setup)
       formail could decide to generate an autoreply header that replies to the list.

       In  the  tradition  of UN*X utilities, formail will do exactly what you ask it to, even if it
       results in a non-**RFC822 **compliant message.  In particular,  formail  will  let  you  generate
       header  fields  whose name ends in a space instead of a colon.  While this is correct for the
       leading `From ' line, that line is not a header field so much as the  message  separator  for
       the  mbox  mailbox format.  Multiple occurrences of such a line or any other colonless header
       field will be considered by many mail programs, including formail itself, as the beginning of
       a new message.  Others will consider the message to be corrupt.  Because of this, you  should
       not  use the **-i **option with the `From ' line as the resulting renamed line, `Old-From ', will
       probably not do what you want it to.  If you want to save the original `From '  line,  rename
       it with the **-R **option to a legal header field such as `X-From_:'.

## BUGS
       When  formail  has  to  generate  a leading `From ' line it normally will contain the current
       date.  If formail is given the option `-a Date:', it will use the date from the `Date:' field
       in the header (if present).  However, since formail copies it verbatim, the format will  dif‐
       fer from that expected by most mail readers.

       If  formail is instructed to delete or rename the leading `From ' line, it will not automati‐
       cally regenerate it as usual.  To force formail to regenerate it in  this  case,  include  **-a**
       **'From '**.

       If  formail is not called as the first program in a pipe and it is told to split up the input
       in several messages, then formail will not terminate until the program it receives the  input
       from closes its output or terminates itself.

       If  formail  is instructed to generate an autoreply mail, it will **never **put more than one ad‐
       dress in the `To:' field.

## MISCELLANEOUS
       Formail is eight-bit clean.

       When formail has to determine the sender's address, every **RFC822 **conforming mail  address  is
       allowed.   Formail will always strip down the address to its minimal form (deleting excessive
       comments and whitespace).

       The regular expression that is used to find `real' postmarks is:
              "\n\nFrom [\t ]*[^\t\n ]+[\t ]+[^\n\t ]"

       If a **Content-Length: **field is found in a header, formail will copy the  number  of  specified
       bytes  in  the body verbatim before resuming the regular scanning for message boundaries (ex‐
       cept when splitting digests or Berkeley mailbox format is assumed).

       Any header lines immediately following the leading `From ' line that start with `>From '  are
       considered  to  be  a  continuation of the `From ' line.  If instructed to rename the `From '
       line, formail will change each leading `>' into a space, thereby transforming those lines in‐
       to normal **RFC822 **continuations.

## NOTES
       Calling up formail with the -h or -? options will cause it to  display  a  command-line  help
       page.

## SOURCE
       This   program   is  part  of  the  _procmail_  _mail-processing-package_  (v3.24)  available  at
       <http://www.procmail.org/> or ftp.procmail.org in **pub/procmail/**.

## MAILINGLIST
       There exists a mailinglist for questions relating to any program in the procmail package:
              <<procmail-users@procmail.org>>
                     for submitting questions/answers.
              <<procmail-users-request@procmail.org>>
                     for subscription requests.

       If you would like to stay informed about new versions and official patches send  a  subscrip‐
       tion request to
              <procmail-announce-request@procmail.org>
       (this is a readonly list).

## AUTHORS
       Stephen R. van den Berg
              <<srb@cuci.nl>>

                                               BuGless                                    [_FORMAIL_(1)](https://www.chedong.com/phpMan.php/man/FORMAIL/1/markdown)
