Knowledge base

body-pattern-file

<email-patterns>

A file with a pattern for parsing a non-standard report
in the configuration this is a linebody-pattern-fileinside the block <email-patterns>
When a receiver sends a report in its own way

Major mailbox providers send bounces and complaints in standard formats, and the engine parses them itself. Some do not. The line sets a file with a pattern by which accounting fields are pulled out of the body of such a message. The line is repeatable: there can be several files.

The pattern is a regular expression with named groups, and the group name is the accounting field name. The manual’s example: Email from (?<dlvSourceIp>[0-9\.]+) — the sending address is pulled out of a line of the message, the very one the message once went out from.

What is extracted goes into accounting — into the complaint or bounce record, next to the fields the engine found itself. That is, a non-standard report becomes indistinguishable from a standard one in analytics.

The block is nested in a processor. <email-patterns> is written inside <bounce-processor> or <feedback-loop-processor> — and each has its own set of patterns.

With several files, the order and the match are visible only through log-match-info: without it, it is unclear which pattern fired, and that determines what exactly was extracted.

The main trap is writing a pattern for one message. Reports from the same receiver differ in small details: spaces, line order, line breaks. A pattern taken from a single example will stop matching on the next one — and this will look like missing complaints, not like a pattern error.
What the Hub does. It does not write it: we have no pattern sets of our own, and parsing uses the built-in ones.

🔎 The line will be needed when a receiver turns up whose complaints do not reach the dashboard: its spam rate will be understated, and there will be nothing to explain it. The sign is that messages to fbl@fbl.<domain> arrive, while there are no complaint records for this receiver in accounting.

Recommended values

A file per format, not per receiver:

What Note
file format one regular expression
group names equal to accounting field names
how many files as many as formats, the line is repeatable
where the block goes inside a processor, not at the root of the file

Test the pattern on several messages, not on one.

The pattern format, named groups as accounting field names and the repeatability of the line come from the manual (§ 3.3.6.1, § 13.10). The advice to test on several messages is ours.
Example configuration
# the block is nested in a processor, not written at the root of the file
<feedback-loop-processor>
    <email-patterns>
        body-pattern-file /etc/pmta/report-pattern.txt        log-match-info true
    </email-patterns>
</feedback-loop-processor>

# the file holds one regular expression with a named group:
#     Email from (?<dlvSourceIp>[0-9\.]+)
The group name dlvSourceIp is the accounting field name. The extracted value will go into the complaint record next to what the engine found itself.
yellow — — directive names, blue — blocks. They are highlighted the same way in the text of the card.
▲

Common mistakes and problems

what people get wrong and how it ends2 mistakes▶

Taking a pattern from one message

our experience

What it costsReports from the same receiver differ in small details. The pattern stops matching on the next message, and this receiver’s complaints disappear from the statistics.
How to spot itThere were complaints for a receiver, and then they suddenly stopped.
How to do it rightCollect several messages and test the pattern on all of them; enable log-match-info for the duration of the setup.

Writing the pattern block at the root of the file

§ 13.10

What it costsThe block is nested in a processor. Written at the root, it belongs to neither bounces nor complaints, and the patterns are not applied.
How to spot itA pattern is set, but there are no matches in the log.
How to do it rightMove the block inside <bounce-processor> or <feedback-loop-processor>.
Compatibility
PowerMTA 6.0
described in the manual of this version · platform: any
The vendor does not state the first version for every directive — there is no note here. The name also appears in the 5.0 edition of the manual.
Reference data
Syntax
body-pattern-file <path>
Values
a path to a file with a regular expression
Applying
reload, no restart needed
Queue
will not touch what is already queued
Where to write it
<email-patterns>
How many times
may be repeated
Everything here comes from the manual, with the section.
Inheritance
There is no inheritance: the line lives inside <email-patterns>, which lives inside a processor. The bounce processor and the complaint processor have their own pattern sets, with nothing in common.
How to check on the node
Check it by the log — the neighboring line shows which pattern matched:
grep -i "pattern" /var/log/pmta/log | tail -20
A line like matched body-pattern defined in file:… names the file that fired. Nothing means no pattern matched, and the message went to the unrecognized ones.
In the Hub
Cost of a mistake
reversible: harms only while it is set
Scenarios
Bounce classification · Receiving inbound mail