FORMAIL(1)
β¨ NAME β¨
formail β mail (re)formatter. the girl who fixes your mail's outfit before it goes out π
π¦ 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 π
okay so bestie, <cyan>formail</cyan> is a filter. like, it sits there and it can:
- force mail into mailbox format β¨
- do
`From `escaping (the escape room of email, no cap) - generate auto-replying headers
- do simple header munging / extracting
- split up a mailbox / digest / articles file
The mail / mailbox / article contents are expected on stdin. yes, standard input, the classic. π
If formail is supposed to determine the sender of the mail but literally cannot find any, it will substitute `foo@bar'. iconic placeholder behavior, honestly.
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 `>'. that's the default vibe check it does for free. π«
πΈ OPTIONS πΈ
-vβformailwill print its version number and exit. short, sweet, self-aware. π-bβ Don't escape any bogus mailbox headers (i.e., lines starting with`From '). hands off, it's fine.-p prefixβ Define a different quotation prefix. If unspecified it defaults to`>'. yes you can pick your own little arrow, main character energy.-Yβ Assume traditional Berkeley mailbox format, ignoring anyContent-Length:fields. old school, but make it on purpose.-cβ Concatenate continued fields in the header. Might be convenient when postprocessing mail with standard (line oriented) text utilities. unwraps the header like a lil gift π-zβ Ensure a whitespace exists between field name and content. Zap fields which contain only a single whitespace character. Zap leading and trailing whitespace on fields extracted with-x. three zaps in one flag, ate.-fβ Forceformailto simply pass along any non-mailbox format (i.e., don't generate a`From 'line as the first line). no adding, no editorializing.-rβ Generate an auto-reply header. This will normally throw away all the existing fields (exceptX-Loop:) in the original message, fields you wish to preserve need to be named using the-ioption. If you use this option in conjunction with-k, you can prevent the body from being`escaped'by also specifying-b. β οΈ heads up, this one is a lil destructive by design β it bins the old fields unless you name them.-kβ When generating the auto-reply header or when extracting fields, keep the body as well. body stays. periodt.-tβ Trust the sender to have used a valid return address in his header. This causesformailto 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. trusting era π«Ά-sβ The input will be split up into separate mail messages, and piped into a program one by one (a new program is started for every part).-shas to be the last option specified, the first argument following it is expected to be the name of a program, any other arguments will be passed along to it. If you omit the program, thenformailwill simply concatenate the split mails onstdoutagain. See FILENO.-n [maxprocs]β Tellformailnot 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. parallel processing? we love a multitasking queen π₯-eβ Do not require empty lines to be preceding the header of a new message (i.e., the messages could start on every line). chaos-friendly.-dβ Tellformailthat the messages it is supposed to split need not be in strict mailbox format (i.e., allows you to split digests / articles or non-standard mailbox formats). This disables recognition of theContent-Length:field. non-standard? still valid to me.-l folderβ Generate a log summary in the same style asprocmail. This includes the entire"From "line, theSubject:header field, the folder, and the size of the message in bytes. Themailstatcommand can be used to summarize logs in this format. receipts πβ¨-Bβ Makesformailassume that it is splitting up a BABYL rmail file. deep lore.-m minfieldsβ Allows you to specify the number of consecutive headerfieldsformailneeds to find before it decides it found the start of a new message, it defaults to2. two strikes and you're a new message, iykyk.-qβ Tellsformailto (still detect but) be quiet about write errors, duplicate messages and mismatchedContent-Length:fields. This option is on by default, to make it display the messages use-q-. π€« quiet by default, gossip mode via-q--D maxlen idcacheβformailwill detect if theMessage-IDof 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,formailwill look at the mail address of the envelope sender instead at theMessage-ID. duplicate detection, the bouncer at the club π-x headerfieldβ 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-coption. scoop out just the goods.-X headerfieldβ Same as-x, but also preserves / includes the field name. name tag stays on π-a headerfieldβ 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 namesMessage-ID:orResent-Message-ID:with no field contents, thenformailwill generate a unique message-ID for you. glow-up, only if it's not already there.-A headerfieldβ Append a custom headerfield onto the header in any case. no conditions. it's going on. periodt.-i headerfieldβ Same as-A, except that any existing similar fields are renamed by prepending anOld-'' `` prefix. If headerfield consists only of a field-name, it will not be appended. the old ones get sent to theOld-retirement home, respectfully.-I headerfieldβ 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. gone. deleted. not even a goodbye text.-u headerfieldβ Make the first occurrence of this field unique, and thus delete all subsequent occurrences of it. first one wins, everyone else go home.-U headerfieldβ Make the last occurrence of this field unique, and thus delete all preceding occurrences of it. last one wins, history erased.-R oldfield newfieldβ Renames all occurrences of the fieldname oldfield into newfield. rebranding arc β¨+skipβ Skip the first skip messages while splitting. scroll past the ones you don't need.-totalβ Output at most total messages while splitting. know your limits bestie.
π§ NOTES π§
When renaming, removing, or extracting fields, partial fieldnames may be used to specify all fields that start with the specified value. prefix matching, we love a flexible queen.
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 option should be used. so like, pick your sender based on the actual situation, ngl.
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 headers 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 established 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,formailassigns the message number currently being output to this variable. By presettingFILENO, you can change the initial message number being used and the width of the zero-padded output. IfFILENOis unset it will default to000. IfFILENOis non-empty and does not contain a number,FILENOgeneration is disabled. numbering your babies β¨
π 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), sendmail(8), procmail(1), sed(1), sh(1), RFC822, RFC2822, RFC1123 πβ¨ππ¦
π DIAGNOSTICS π
okay bestie, this is the "what went wrong" section. every single one of these is formail yelling at you, and here's the translation π«Ά
Can't forkβ too many processes on this machine, fr fr. it ran out of room to spawn.Content-Length: field exceeds actual length by nnn bytesβ theContent-Length:field in the header said the body was longer than the body actually is π. which means this message goes and absorbs a whole bunch of the messages that come after it in the same mailbox. messy.Couldn't write to stdoutβ the program formail was trying to pipe into straight up didn't accept all the data formail sent it π . you can shut this diagnostic up with the-qoption.Duplicate key found: xβ theMessage-IDor senderxin this message was already sitting in the idcache, we been knew π. suppressible with-qtoo.Failed to execute "x"β program not in path, or not executable. literally that.File table fullβ too many open files on this machine. not the vibe.Invalid field-name: "x"β the field-namexyou gave has control characters in it, or it just can't be a partial field-name for this option π.
β οΈ WARNINGS β οΈ
girl. listen. you can save yourself and everyone else a LOT of grief if you avoid using this autoreply feature on mails coming through mailinglists. depending on the format of the incoming mail (which itself depends on the original sender's mail agent AND the mailinglist setup), formail could decide to generate an autoreply header that replies to the list. imagine. the chaos.
in the grand tradition of UN*X utilities, formail will do exactly what you ask it to, even if that results in a message that is not RFC822 compliant π. specifically: formail will let you generate header fields whose name ends in a space instead of a colon. while that's correct for the leading From line, that line is not so much a header field as it is the message separator for the mbox mailbox format. multiple occurrences of such a line β or any other colonless header field β will be read by many mail programs (formail itself included) as the beginning of a new message. others will just consider the message corrupt π.
because of all that, you should not use the -i option with the From line, since 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_:. periodt β¨
π BUGS π
- when formail has to generate a leading
Fromline, it normally contains the current date. if formail is given the option-a Date:, it will use the date from theDate:field in the header instead (if present). BUT β since formail copies it verbatim, the format will differ from what most mail readers expect π. - if formail is instructed to delete or rename the leading
Fromline, it will not automatically 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's told to split the input into several messages, then formail will not terminate until the program it receives the input from closes its output or terminates itself. the way that it justβ¦ waits π
- if formail is instructed to generate an autoreply mail, it will never put more than one address in the
To:field.
π MISCELLANEOUS π
Formail is eight-bit clean. iconic behavior, honestly π
when formail has to figure out the sender's address, every RFC822 conforming mail address is allowed. formail will always strip the address down to its minimal form (deleting excessive comments and whitespace) β glow-up, but for email addresses π
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 (except when splitting digests, or when 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 into normal RFC822 continuations. cute little transformation β¨
π NOTES π
calling up formail with the -h or -? options will cause it to display a command-line help page. yes bestie, the help page is right there π«Ά
π¦ 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 subscription request to
procmail-announce-request@procmail.org
(this is a readonly list β lurker energy only, no posting π)
π AUTHORS π
Stephen R. van den Berg <srb@cuci.nl>
and that's the whole page, bestie!! π footer says BuGless at the bottom, it's FORMAIL(1), and the whole thing rides along with the procmail v3.24 mail-processing-package and its date. go forth and process some mail, you absolute legend πβ¨
π¦ where this page comes from
- centos-stream 10: procmail 3.24-8.el10 Β· gpl-2.0-or-later
- fedora 43: procmail 3.24-9.fc43 Β· gpl-2.0-or-later
- fedora 44: procmail 3.24-10.fc44 Β· gpl-2.0-or-later
- nixos 26.05: procmail 3.24
- nixpkgs unstable: procmail 3.24
- opensuse-leap 16.0: procmail 3.24-160000.2.2 Β· Artistic-1.0 OR GPL-2.0-or-later
- opensuse-leap 16.0: procmail 3.24-160000.2.2 Β· Artistic-1.0 OR GPL-2.0-or-later
- opensuse-leap 16.0: procmail 3.24-160000.2.2 Β· Artistic-1.0 OR GPL-2.0-or-later
- opensuse-leap 16.0: procmail 3.24-160000.2.2 Β· Artistic-1.0 OR GPL-2.0-or-later
- ubuntu noble: procmail 3.24-1ubuntu2
- ubuntu questing: procmail 3.24-1ubuntu4
- ubuntu resolute: procmail 3.24-1ubuntu5
- ubuntu stonking: procmail 3.24-1ubuntu6
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms