Skip to main content

Receiving servers' quirks

Some receiving mail servers answer in a way that is valid but wrong in practice. The package elpan-mail-quirks holds rules that correct those answers before the outgoing mail server (Postfix) acts on them. The rules change with the receivers, not with Postfix, so they come in a package of their own. elpan-mail-out requires it, so every server has it.

A full Gmail inbox​

When a Gmail user runs out of storage, Gmail refuses mail for them with a temporary error:

452-4.2.2 The recipient's inbox is out of storage space. Please direct the
452-4.2.2 recipient to 452 4.2.2 https://support.google.com/mail/?p=OverQuotaTemp

A temporary error tells the sending server to try again later, so Postfix keeps the message and retries for five days. In practice the inbox rarely empties that soon. Without the rule, three things happen:

  • The sender hears nothing for five days, then gets a bounce for mail they sent last week.
  • The message takes disk space in the queue the whole time. So does every other message sent to that address.
  • The Outgoing Mail Queue fills with these messages, and the deferrals that need your attention are harder to see.

The shipped rule makes that answer permanent, 5.2.2. The recipient bounces on the first attempt, and the sender gets the bounce within seconds. Its text is Gmail's, followed by (Elpan: a full Gmail inbox is treated as permanent), so the sender, the Email Traffic Log and the mail log all show why. The rule applies to any domain whose mail Google handles: gmail.com, googlemail.com and every Google Workspace domain.

Gmail's permanent form of the same refusal (552 5.2.2, "out of storage space and inactive") already bounces at once and has no rule.

A message that was already waiting when the package was installed meets the same answer at its next retry, within about an hour, and bounces then.

How the rules work​

Postfix has a setting for this, smtp_delivery_status_filter. After each delivery attempt to a recipient, it looks up one line, the status code and the receiving server's answer:

4.2.2 host gmail-smtp-in.l.google.com[142.250.141.26] said: 452-4.2.2 The recipient's inbox is out of storage space. ... (in reply to RCPT TO command)

The first rule that matches replaces the line. A rule can turn a temporary failure (4.x.x) into a permanent one (5.x.x) or change the text. It can't turn a delivery into a failure, nor a failure into a delivery.

The package sets the filter to two tables, read in this order:

FileWhat
/etc/elpan/mail-quirks/smtp-delivery-status.pcreYour rules. Empty when installed, and upgrades don't overwrite it.
/usr/share/elpan/mail-quirks/smtp-delivery-status.pcreThe shipped rules. Upgrades replace this file, so don't edit it.

The setting itself is in /var/lib/elpan/mail-out/config/main.cf.d/40-mail-quirks.cf.

Adding a rule​

Add the rule to /etc/elpan/mail-quirks/smtp-delivery-status.pcre. It's a Postfix pcre table: a pattern, then the result on a line that starts with spaces. For example, to bounce at once the full mailboxes of a provider that answers 452 for them:

/^4\.[0-9]+\.[0-9]+ (host [^ ]+\.example\.net\[[^]]+\] said: .*mailbox is full.*)$/
5.2.2 $1 (a full mailbox at example.net is treated as permanent)

Match on the receiving server's name as well as its text, so that the rule can't catch another provider's answer. Only rewrite answers that you've seen stay the same until the message expired. A server that asks you to slow down, for instance, means it, and a bounce would lose the mail.

Then reload the outgoing mail server, which reads the tables when its processes start:

systemctl reload elpan-mail-out

Turning off a shipped rule​

Your rules come first, and the first match wins. To turn a shipped rule off, add a rule that matches the same answer and returns it unchanged:

/^(4\.[0-9]+\.[0-9]+ host [^ ]+\.google\.com\[[^]]+\] said: .*\?p=OverQuotaTemp\b.*)$/
$1

Reload the outgoing mail server afterwards.

Checking the rules​

elpan-mail-quirks-check with no argument runs the package's test cases against the shipped rules and checks that the outgoing mail server uses both tables. With a line as its argument, it shows what the filter makes of it and which table matched:

elpan-mail-quirks-check '4.2.2 host mx.example.net[192.0.2.10] said: 452 4.2.2 Mailbox is full (in reply to RCPT TO command)'

To build the line from the mail log (/var/log/elpan/mail/maillog), take the dsn= code, a space, and the text in parentheses after status=deferred.

man elpan-mail-quirks has the same as this page.