]> git.proxmox.com Git - pmg-api.git/blobdiff - PMG/SMTP.pm
SMTP.pm: SMTPUTF8 is always passed with "mail" command
[pmg-api.git] / PMG / SMTP.pm
index ea4a013757b97c7d6d32a8af3ea38fc7aacf73d1..a2a6c480251cab43e28bfeb9cf6460bc6f2cfe01 100644 (file)
@@ -3,6 +3,7 @@ package PMG::SMTP;
 use strict;
 use warnings;
 use IO::Socket;
+use Encode;
 
 use PVE::SafeSyslog;
 
@@ -32,6 +33,7 @@ sub reset {
     $self->{from} = undef;
     $self->{to} = [];
     $self->{queue} = undef;
+    delete $self->{smtputf8};
     delete $self->{xforward};
     delete $self->{status};
 }
@@ -72,6 +74,7 @@ sub loop {
            $self->reply ("250-PIPELINING");
            $self->reply ("250-ENHANCEDSTATUSCODES");
            $self->reply ("250-8BITMIME");
+           $self->reply ("250-SMTPUTF8");
            $self->reply ("250-XFORWARD NAME ADDR PROTO HELO");
            $self->reply ("250 OK.");
            $self->{lmtp} = 1 if ($cmd eq 'lhlo');
@@ -95,9 +98,14 @@ sub loop {
            $self->reply ("250 2.5.0 OK");
            next;
        } elsif ($cmd eq 'mail') {
-           if ($args =~ m/^from:\s*<([^\s\>]*)>[^>]*$/i) {
+           if ($args =~ m/^from:\s*<([^\s\>]*)>([^>]*)$/i) {
                delete $self->{to};
-               $self->{from} = $1;
+               my ($from, $opts) = ($1, $2);
+               if ($opts =~ m/\sSMTPUTF8/) {
+                   $self->{smtputf8} = 1;
+                   $from = decode('UTF-8', $from);
+               }
+               $self->{from} = $from;
                $self->reply ('250 2.5.0 OK');
                next;
            } else {
@@ -106,7 +114,8 @@ sub loop {
            }
        } elsif ($cmd eq 'rcpt') {
            if ($args =~ m/^to:\s*<([^\s\>]+)>[^>]*$/i) {
-               push @{$self->{to}} , $1;
+               my $to = $self->{smtputf8} ? decode('UTF-8', $1) : $1;
+               push @{$self->{to}} , $to;
                $self->reply ('250 2.5.0 OK');
                next;
            } else {