From d9ff5e4ffa6de4b4c743988b235bcaf776c22cb0 Mon Sep 17 00:00:00 2001 From: Daniel Brahneborg Date: Mon, 24 Mar 2025 15:37:40 +0100 Subject: [PATCH] plugin smtputf8 --- plugins/smtputf8/README.md | 37 ++++++++++++++++++++++++++++++++++++ plugins/smtputf8/smtputf8.pl | 15 +++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 plugins/smtputf8/README.md create mode 100644 plugins/smtputf8/smtputf8.pl diff --git a/plugins/smtputf8/README.md b/plugins/smtputf8/README.md new file mode 100644 index 0000000..4da711d --- /dev/null +++ b/plugins/smtputf8/README.md @@ -0,0 +1,37 @@ +# Route some emails to a specific connector + +As of version 8.0.4, EMG supports internationalized email addresses, as specified by RFCs 6530 and 6531. +The most important case is when the username part contains a non-ascii character, such as `åsa@example.se`. +Such destinations can only be used with SMTP servers supporting the `SMTPUTF8` extension. +If your default downstreams SMTP server supports that, you do not need to do anything. +However, you may have a situation where your default SMTP server does not support this, but you have a secondary server that does. +It may be more expensive, preventing it from being your primary server. +In this case you can use the plugin here. + +## Usage + +Let's say you have two outgoing SMTP servers, named `smtp-out-primary` and `smtp-out-utf8`. +You're using a routing file to route destinations containing the '@' character to `smtp-out-primary`: + +```` +>/.*@.* smtp-out-primary +```` + +Now you tell EMG about this new plugin. + +```` +PLUGIN smtputf8 < +LIBRARY=smtputf8.pl +> +```` + +Next, let it redirect messages that require it. +You do this by adding a new line before the existing one. + +```` +!smtputf8 +>/.*@.* smtp-out-primary +```` + +If the destination address does not contain a '@' character, or the username contains only ascii characters, the plugin just returns 0 and let the rule(s) below make a decision. + diff --git a/plugins/smtputf8/smtputf8.pl b/plugins/smtputf8/smtputf8.pl new file mode 100644 index 0000000..7c5e367 --- /dev/null +++ b/plugins/smtputf8/smtputf8.pl @@ -0,0 +1,15 @@ +sub route { + my ($request, $response) = @_; + my $sms = ${$request}{qe}; + my $dest = $sms->{DESTADDR}; + my @parts = split('@', $dest); + return 0 if (scalar @parts < 2); + foreach $ch (split //, $parts[0]) { + if (ord($ch) > 127) { + $response->{route} = 'smtp-out-utf8'; + return 0; + } + } + return 0; +} +