LinuxCommandLibrary

formail

TLDR

Extract headers from email

$ formail -x [Subject:] < [email.txt]
copy
Add header to email
$ formail -a "[X-Custom: value]" < [email.txt]
copy
Split mbox into messages
$ formail -s [command] < [mbox]
copy
Extract From line
$ formail -x From: < [email.txt]
copy
Force addition of header
$ formail -A "[X-Custom: value]" < [email.txt]
copy
Generate auto-reply
$ formail -r < [email.txt]
copy

SYNOPSIS

formail [options] [output] < input

DESCRIPTION

formail is a mail processing utility from the procmail suite. It extracts headers, adds or modifies headers, splits mbox files, and helps generate automated replies.
The tool reads from stdin and writes to stdout, designed for use in pipelines and procmail recipes. It handles RFC 822 mail format intricacies.

PARAMETERS

-x header

Extract specific header.
-X header
Extract header with continuation lines.
-a header
Add header if not present.
-A header
Add header always.
-i header
Replace header.
-u header
Make header unique.
-r
Generate reply headers.
-s command
Split and process with command.
-b
Don't escape body "From " lines.
-n count
Output only first n messages.

EXAMPLES

$ # Split mbox and save each message
formail -s procmail < mbox

# Extract sender address
formail -x From: < message | head -1

# Add header for filtering
formail -a "X-Filtered: yes" < message
copy

CAVEATS

Part of procmail suite which is no longer actively developed. MIME handling is limited. Complex headers may need careful extraction. Consider modern alternatives for new projects.

HISTORY

formail was developed by Stephen van den Berg as part of the procmail mail processing suite in the 1990s. While procmail is no longer actively maintained, formail remains useful for mail processing scripts.

SEE ALSO

procmail(1), mail(1), mailx(1), mbox(5)

Copied to clipboard