I’d recently moved my commercial email provider from Ionos to Purelymail. This was for two reasons: cost and freeing the email domain name from the clutches of Ionos.

Purelymail offer something they term "symbolic addressing", where everything in the local part of a To: address that follows a symbol character (i.e. not alphanumeric) is ignored for the purposes of routing. I used this feature to update my email address held by numerous providers to make it unique to the provider - something I’d long been meaning to do. Maybe that will help with identifying those companies who leak email addresses.

That made me wonder. Could I provide the same capability for the hydrus mail server? The MTA is Exim4 and it turns out to be quite easy.

The Debian configuration for Exim4 defines a router called system_aliases. This is defined in the file /etc/exim4/conf.d/routers/400_exim4-config_system_aliases. The key portion in the router definition is this line:

driver = redirect
data = ${lookup{$local_part}lsearch{/etc/aliases}}

The lookup type lsearch uses the /etc/aliases file to redirect mail based on the local_part of an accepted email address. To implement symbolic addressing, replace lsearch with wildlsearch. This instructs the router to use regular expressions (PCRE2 variety) when looking up local_part names. Then add a definition to /etc/aliases with the following form:

user\\W.*: user

This will make Exim4 deliver an accepted mail with a local_part of user suffixed by a non-alphanumeric (e.g. user+hmrc@example.com) to user@example.com.

In order to make future upgrades easier, I did not change etc/exim4/conf.d/routers/400_exim4-config_system_aliases but instead created a new router in 390_exim4-config_system_aliases based on it. The key part of this now looks like:

wild_system_aliases:
  debug_print = "R: wild system_aliases for $local_part@$domain"
  driver = redirect
  domains = +local_domains
  allow_fail
  allow_defer
  data = ${lookup{$local_part}wildlsearch{/etc/aliases}}

The wild_system_aliases router is defined before the system_aliases router and will therefore take precedence.

Updating the system

The new Exim4 configuration template can be created and installed with the following commands:

sudo update-exim4.conf.template -r
sudo update-exim4.conf

Restart Exim4 with:

sudo systemctl restart exim4