From 27e336cd2c04cbde7a729f05fb9a32aa1c46fb0b Mon Sep 17 00:00:00 2001 From: tkempf Date: Fri, 14 Jul 2017 10:22:50 +0200 Subject: [PATCH 01/11] Added novacation_pattern regexp to prevent sending vacation messages for specific recipient addresses --- VIRTUAL_VACATION/vacation.pl | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/VIRTUAL_VACATION/vacation.pl b/VIRTUAL_VACATION/vacation.pl index b6558625..8d9ce3a2 100644 --- a/VIRTUAL_VACATION/vacation.pl +++ b/VIRTUAL_VACATION/vacation.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -X +#!/usr/bin/perl # Note - 2017/02/08 DG : # Yes - I know -X (^) is not ideal. # Patches are welcome to remove the dependency on Mail::Sender. @@ -86,6 +86,11 @@ # Add capability to include the subject of the original mail in the subject of the vacation message. # A good vacation subject could be: 'Re: $SUBJECT' # Also corrected log entry about "Already informed ..." to show the $orig_from, not $email +# +# 2017-07-14 Thomas Kempf +# Add configuration parameter $novacation_pattern in order to exlude specific alias-recipients from +# sending vacation mails, even if one or multiple of the recipients the alias points to has vacation +# currently active # # Requirements - the following perl modules are required: @@ -207,6 +212,13 @@ our $interval = 0; our $custom_noreply_pattern = 0; our $noreply_pattern = 'bounce|do-not-reply|facebook|linkedin|list-|myspace|twitter'; +# Never send vacation mails for the following recipient email addresses. +# Useful e.g. aliases pointing to multiple recipients which have vacation +# which should not trigger vacation messages. +# By default vacation email addresses will be sent for all recipients. +# default = '' +our $novacation_pattern = ''; + # instead of changing this script, you can put your settings to /etc/mail/postfixadmin/vacation.conf # or /etc/postfixadmin/vacation.conf just use Perl syntax there to fill the variables listed above @@ -695,6 +707,12 @@ if(!$from || !$to || !$messageid || !$smtp_sender || !$smtp_recipient) { exit(0); } $logger->debug("Email headers have to: '$to' and From: '$from'"); + +if ($to =~ ~ /^.*($novacation_pattern).*/i) { + $logger->debug("Will not send vacation reply for messages to $to"); + exit(0); +} + $to = strip_address($to); $cc = strip_address($cc); $from = check_and_clean_from_address($from); From b781195526bf8ff0d4907e308b0fe16294827140 Mon Sep 17 00:00:00 2001 From: tkempf Date: Mon, 17 Jul 2017 13:11:50 +0200 Subject: [PATCH 02/11] Replace deprecated Mail::Sender by Email::Sender Add searchpath for local vacation.conf --- VIRTUAL_VACATION/vacation.pl | 108 ++++++++++++++++++++--------------- 1 file changed, 61 insertions(+), 47 deletions(-) diff --git a/VIRTUAL_VACATION/vacation.pl b/VIRTUAL_VACATION/vacation.pl index 8d9ce3a2..2c076407 100644 --- a/VIRTUAL_VACATION/vacation.pl +++ b/VIRTUAL_VACATION/vacation.pl @@ -95,7 +95,7 @@ # Requirements - the following perl modules are required: # DBD::Pg or DBD::mysql -# Mail::Sender, Email::Valid MIME::Charset, Log::Log4perl, Log::Dispatch, MIME::EncWords and GetOpt::Std +# EMail::Sender, Email::Valid MIME::Charset, Log::Log4perl, Log::Dispatch, MIME::EncWords and GetOpt::Std # # You may install these via CPAN, or through your package tool. # CPAN: 'perl -MCPAN -e shell', then 'install Module::Whatever' @@ -131,10 +131,14 @@ use Encode qw(encode decode); use MIME::EncWords qw(:all); use Email::Valid; use strict; -use Mail::Sender; use Getopt::Std; use Log::Log4perl qw(get_logger :levels); use File::Basename; +use Email::Sender::Simple qw(sendmail); +use Email::Sender::Transport::SMTPS; +use Email::Simple; +use Email::Simple::Creator; +use Try::Tiny; # ========== begin configuration ========== @@ -164,11 +168,22 @@ our $smtp_server_port = 25; # depending upon what smtp helo restrictions you have in place within Postfix. our $smtp_client = 'localhost'; -# SMTP authentication protocol used for sending. -# Can be 'PLAIN', 'LOGIN', 'CRAM-MD5' or 'NTLM' -# see "perldoc Mail::Sender" (search for "auth") for more options and details +# SMTP encryption protocol used for sending. +# Can be '', 'starttls' or 'ssl' +# see "perldoc Email::Sender" (search for "ssl") for details # Leave it blank if you don't use authentication -our $smtp_auth = undef; +our $smtp_ssl = ''; + +# Options passed to Net::SMTPS constructor for 'ssl' connections or to starttls for 'starttls' connections; should contain extra options for IO::Socket::SSL +# see "perldoc Email::Sender" (search for "ssl_options") for details + +our $smtp_ssl_options = ''; + +# Maximum time in secs to wait for server; default is 120 +# see "perldoc Email::Sender" (search for "timeout") for details + +our $smtp_timeout = '120'; + # username used to login to the server our $smtp_authid = 'someuser'; # password used to login to the server @@ -181,9 +196,6 @@ our $smtp_authpwd = 'somepass'; # From: Some Friendly Name our $friendly_from = ''; -# use TLS for the SMTP connection? -# while in general this would be a good idea, TLS with Mail::Sender 0.8.22 is buggy - https://rt.cpan.org/Public/Bug/Display.html?id=85438 -our $smtp_tls_allowed = 0; # Set to 1 to enable logging to syslog. our $syslog = 0; @@ -213,8 +225,8 @@ our $custom_noreply_pattern = 0; our $noreply_pattern = 'bounce|do-not-reply|facebook|linkedin|list-|myspace|twitter'; # Never send vacation mails for the following recipient email addresses. -# Useful e.g. aliases pointing to multiple recipients which have vacation -# which should not trigger vacation messages. +# Useful for e.g. aliases pointing to multiple recipients which have vacation active +# hence an email to the alias should not trigger vacation messages. # By default vacation email addresses will be sent for all recipients. # default = '' our $novacation_pattern = ''; @@ -228,6 +240,8 @@ if (-f '/etc/mail/postfixadmin/vacation.conf') { require '/etc/mail/postfixadmin/vacation.conf'; } elsif (-f '/etc/postfixadmin/vacation.conf') { require '/etc/postfixadmin/vacation.conf'; +} elsif (-f './vacation.conf') { + require './vacation.conf'; } # =========== end configuration =========== @@ -548,47 +562,47 @@ sub send_vacation_email { my $body = $row[1]; my $from = $email; my $to = $orig_from; - my %smtp_connection; - %smtp_connection = ( - 'smtp' => $smtp_server, - 'port' => $smtp_server_port, - 'auth' => $smtp_auth, - 'authid' => $smtp_authid, - 'authpwd' => $smtp_authpwd, - 'tls_allowed' => $smtp_tls_allowed, - 'smtp_client' => $smtp_client, - 'skip_bad_recipients' => 'true', - 'encoding' => 'Base64', - 'ctype' => 'text/plain; charset=UTF-8', - 'headers' => 'Precedence: junk', - 'headers' => 'X-Loop: Postfix Admin Virtual Vacation', - 'on_errors' => 'die', # raise exception on error - ); - my %mail; - %mail = ( - 'subject' => encode_mimewords($subject, 'Charset', 'UTF-8'), - 'from' => $from, - 'fake_from' => $friendly_from . " <$from>", - 'to' => $to, - 'msg' => encode_base64(encode("UTF-8", $body)) + + my $transport = Email::Sender::Transport::SMTPS->new({ + host => $smtp_server, + ssl => $smtp_ssl, + ssl_options => $smtp_ssl_options, + timeout => $smtp_timeout, + port => $smtp_server_port, + sasl_username => $smtp_authid, + sasl_password => $smtp_authpwd, + + localaddr => $smtp_client, + debug => 1, + }); + + my $email = Email::Simple->create( + header => [ + To => $to, + From => $from, + Subject => encode_mimewords($subject, 'Charset', 'UTF-8'), + Precedence => 'junk', + 'X-Loop' => 'Postfix Admin Virtual Vacation', + ], + body => encode("UTF-8", $body), ); + if($test_mode == 1) { $logger->info("** TEST MODE ** : Vacation response sent to $to from $from subject $subject (not) sent\n"); - $logger->info(%mail); + $logger->info($email); return 0; } - eval { - $Mail::Sender::NO_X_MAILER = 1; - my $sender = new Mail::Sender({%smtp_connection}); - $sender->Open({%mail}); - $sender->SendLineEnc($body); - $sender->Close(); - $logger->debug("Vacation response sent to $to, from $from"); - }; - if ($@) { - $logger->error("Failed to send vacation response: $@ / " . $Mail::Sender::Error); - } - } + + try { + sendmail($email, { transport => $transport }); + } finally { + if (@_) { + $logger->error("Failed to send vacation response: @_"); + } else { + $logger->debug("Vacation response sent to $to, from $from"); + } + } + } } # Convert a (list of) email address(es) from RFC 822 style addressing to From 1653e5839849715778973c0098e445bf7fd92c7d Mon Sep 17 00:00:00 2001 From: tkempf Date: Tue, 18 Jul 2017 10:00:49 +0200 Subject: [PATCH 03/11] Bump Version to 4.1 Sending Mail now works at least without encryption --- VIRTUAL_VACATION/vacation.pl | 89 +++++++++++++++++------------------- 1 file changed, 42 insertions(+), 47 deletions(-) diff --git a/VIRTUAL_VACATION/vacation.pl b/VIRTUAL_VACATION/vacation.pl index 2c076407..4a984c56 100644 --- a/VIRTUAL_VACATION/vacation.pl +++ b/VIRTUAL_VACATION/vacation.pl @@ -1,11 +1,6 @@ #!/usr/bin/perl -# Note - 2017/02/08 DG : -# Yes - I know -X (^) is not ideal. -# Patches are welcome to remove the dependency on Mail::Sender. -# Until then, we need -X to stop it failing with warnings like -# defined(@array) is deprecated at .../perl5/Mail/Sender.pm line 318. # -# Virtual Vacation 4.0 +# Virtual Vacation 4.1 # # $Revision$ # Originally by Mischa Peters @@ -88,28 +83,31 @@ # Also corrected log entry about "Already informed ..." to show the $orig_from, not $email # # 2017-07-14 Thomas Kempf +# Replacing deprecated Mail::Sender by Email::Sender # Add configuration parameter $novacation_pattern in order to exlude specific alias-recipients from # sending vacation mails, even if one or multiple of the recipients the alias points to has vacation -# currently active +# currently active. # # Requirements - the following perl modules are required: # DBD::Pg or DBD::mysql -# EMail::Sender, Email::Valid MIME::Charset, Log::Log4perl, Log::Dispatch, MIME::EncWords and GetOpt::Std +# EMail::Sender,Email::Simple,Email::Valid,Try::Tiny,MIME::Charset, Log::Log4perl, Log::Dispatch, MIME::EncWords and GetOpt::Std # # You may install these via CPAN, or through your package tool. # CPAN: 'perl -MCPAN -e shell', then 'install Module::Whatever' # # On Debian based systems : -# libmail-sender-perl -# libdbd-pg-perl +# libemail-sender-perl +# libemail-simple-perl # libemail-valid-perl +# libtry-tiny-perl +# libdbd-pg-perl # libmime-perl # liblog-log4perl-perl # liblog-dispatch-perl # libgetopt-argvfile-perl -# libmime-charset-perl (currently in testing, see instructions below) -# libmime-encwords-perl (currently in testing, see instructions below) +# libmime-charset-perl +# libmime-encwords-perl # # Note: When you use this module, you may start seeing error messages # like "Cannot insert a duplicate key into unique index @@ -123,7 +121,6 @@ # One such package collection (for Linux) is: # http://dag.wieers.com/home-made/apt/packages.php # - use utf8; use DBI; use MIME::Base64 qw(encode_base64); @@ -132,13 +129,13 @@ use MIME::EncWords qw(:all); use Email::Valid; use strict; use Getopt::Std; -use Log::Log4perl qw(get_logger :levels); -use File::Basename; use Email::Sender::Simple qw(sendmail); -use Email::Sender::Transport::SMTPS; +use Email::Sender::Transport::SMTP; use Email::Simple; use Email::Simple::Creator; use Try::Tiny; +use Log::Log4perl qw(get_logger :levels); +use File::Basename; # ========== begin configuration ========== @@ -162,32 +159,24 @@ our $vacation_domain = 'autoreply.example.org'; # smtp server used to send vacation e-mails our $smtp_server = 'localhost'; +# port to connect to; defaults to 25 for non-SSL, 465 for 'ssl', 587 for 'starttls' our $smtp_server_port = 25; # this is the helo we [the vacation script] use on connection; you may need to change this to your hostname or something, # depending upon what smtp helo restrictions you have in place within Postfix. our $smtp_client = 'localhost'; -# SMTP encryption protocol used for sending. -# Can be '', 'starttls' or 'ssl' -# see "perldoc Email::Sender" (search for "ssl") for details -# Leave it blank if you don't use authentication +# send mail encrypted or plaintext +# if 'starttls', use STARTTLS; if 'ssl' (or 1), connect securely; otherwise, no security our $smtp_ssl = ''; -# Options passed to Net::SMTPS constructor for 'ssl' connections or to starttls for 'starttls' connections; should contain extra options for IO::Socket::SSL -# see "perldoc Email::Sender" (search for "ssl_options") for details - -our $smtp_ssl_options = ''; - -# Maximum time in secs to wait for server; default is 120 -# see "perldoc Email::Sender" (search for "timeout") for details - +# maximum time in secs to wait for server; default is 120 our $smtp_timeout = '120'; -# username used to login to the server -our $smtp_authid = 'someuser'; -# password used to login to the server -our $smtp_authpwd = 'somepass'; +# sasl_username: the username to use for auth; optional +our $smtp_authid = ''; +# sasl_password: the password to use for auth; required if username is provided +our $smtp_authpwd = ''; # This specifies the mail 'from' name which is shown to recipients of vacation replies. # If you leave it empty, the vacation mail will contain: @@ -275,6 +264,7 @@ if($test_mode == 1) { $appender->layout($log_layout); $logger->add_appender($appender); $logger->debug('Test mode enabled'); + } else { $logger = get_logger(); if($log_to_file == 1) { @@ -563,20 +553,24 @@ sub send_vacation_email { my $from = $email; my $to = $orig_from; - my $transport = Email::Sender::Transport::SMTPS->new({ - host => $smtp_server, - ssl => $smtp_ssl, - ssl_options => $smtp_ssl_options, - timeout => $smtp_timeout, + my $smtp_params = { + host => $smtp_server, port => $smtp_server_port, - sasl_username => $smtp_authid, - sasl_password => $smtp_authpwd, - - localaddr => $smtp_client, - debug => 1, - }); + ssl => $smtp_ssl, + timeout => $smtp_timeout, + localaddr => $smtp_client, + debug => 0, + }; + + if($smtp_authid ne ''){ + $smtp_params->{sasl_username}=$smtp_authid; + $smtp_params->{sasl_password}=$smtp_authpwd; + $logger->info("Doing SASL Authentication with user $smtp_params->{sasl_username}\n"); + }; + + my $transport = Email::Sender::Transport::SMTP->new($smtp_params); - my $email = Email::Simple->create( + $email = Email::Simple->create( header => [ To => $to, From => $from, @@ -597,9 +591,9 @@ sub send_vacation_email { sendmail($email, { transport => $transport }); } finally { if (@_) { - $logger->error("Failed to send vacation response: @_"); + $logger->error("Failed to send vacation response to $to from $from subject $subject: @_"); } else { - $logger->debug("Vacation response sent to $to, from $from"); + $logger->debug("Vacation response sent to $to from $from subject $subject sent\n"); } } } @@ -681,6 +675,7 @@ $cc = ''; $replyto = ''; $logger->debug("Script argument SMTP recipient is : '$smtp_recipient' and smtp_sender : '$smtp_sender'"); + while () { last if (/^$/); if (/^\s+(.*)/ and $lastheader) { $$lastheader .= " $1"; next; } @@ -722,7 +717,7 @@ if(!$from || !$to || !$messageid || !$smtp_sender || !$smtp_recipient) { } $logger->debug("Email headers have to: '$to' and From: '$from'"); -if ($to =~ ~ /^.*($novacation_pattern).*/i) { +if ($to =~ /^.*($novacation_pattern).*/i) { $logger->debug("Will not send vacation reply for messages to $to"); exit(0); } From e5e9ce76745c72db0fd1d310eceb783c4aab23d1 Mon Sep 17 00:00:00 2001 From: tkempf Date: Tue, 18 Jul 2017 13:00:41 +0200 Subject: [PATCH 04/11] When using STARTTLS the SSL_verifycn_name must be set to prevent SSL Errors --- VIRTUAL_VACATION/vacation.pl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/VIRTUAL_VACATION/vacation.pl b/VIRTUAL_VACATION/vacation.pl index 4a984c56..43bea207 100644 --- a/VIRTUAL_VACATION/vacation.pl +++ b/VIRTUAL_VACATION/vacation.pl @@ -168,7 +168,12 @@ our $smtp_client = 'localhost'; # send mail encrypted or plaintext # if 'starttls', use STARTTLS; if 'ssl' (or 1), connect securely; otherwise, no security -our $smtp_ssl = ''; +our $smtp_ssl = 'starttls'; + +# passed to Net::SMTP constructor for 'ssl' connections or to starttls for 'starttls' connections; should contain extra options for IO::Socket::SSL +our $ssl_options = { + SSL_verifycn_name => $smtp_server +}; # maximum time in secs to wait for server; default is 120 our $smtp_timeout = '120'; @@ -556,6 +561,7 @@ sub send_vacation_email { my $smtp_params = { host => $smtp_server, port => $smtp_server_port, + ssl_options => $ssl_options, ssl => $smtp_ssl, timeout => $smtp_timeout, localaddr => $smtp_client, From cc3d5b13e8380955ecad4c6a6790d5ff12694817 Mon Sep 17 00:00:00 2001 From: tkempf Date: Tue, 18 Jul 2017 15:03:41 +0200 Subject: [PATCH 05/11] Add Example for $novacation_pattern --- VIRTUAL_VACATION/vacation.pl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/VIRTUAL_VACATION/vacation.pl b/VIRTUAL_VACATION/vacation.pl index 43bea207..8c996339 100644 --- a/VIRTUAL_VACATION/vacation.pl +++ b/VIRTUAL_VACATION/vacation.pl @@ -223,6 +223,8 @@ our $noreply_pattern = 'bounce|do-not-reply|facebook|linkedin|list-|myspace|twit # hence an email to the alias should not trigger vacation messages. # By default vacation email addresses will be sent for all recipients. # default = '' +# preventing vacation notifications for recipient info@example.org would look like this: +# our $novacation_pattern = 'info\@example\.org'; our $novacation_pattern = ''; From 79f8a63a462785f3c8d06c9cecb1026a1c76fb2c Mon Sep 17 00:00:00 2001 From: tkempf Date: Fri, 21 Jul 2017 08:53:09 +0200 Subject: [PATCH 06/11] Bugfix in Encoding of vacation mail. UTF-8 header was missing and the mailbody is already utf8, so no need to recode --- VIRTUAL_VACATION/vacation.pl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/VIRTUAL_VACATION/vacation.pl b/VIRTUAL_VACATION/vacation.pl index 8c996339..0fa9c218 100644 --- a/VIRTUAL_VACATION/vacation.pl +++ b/VIRTUAL_VACATION/vacation.pl @@ -582,11 +582,12 @@ sub send_vacation_email { header => [ To => $to, From => $from, - Subject => encode_mimewords($subject, 'Charset', 'UTF-8'), + Subject => $subject, Precedence => 'junk', + 'Content-Type' => "text/plain; charset=utf-8", 'X-Loop' => 'Postfix Admin Virtual Vacation', ], - body => encode("UTF-8", $body), + body => $body, ); if($test_mode == 1) { From c5dcbeb48d9675923718543c191f9df3eff22187 Mon Sep 17 00:00:00 2001 From: tkempf Date: Fri, 21 Jul 2017 09:20:51 +0200 Subject: [PATCH 07/11] Removed unused libraries MIME::Encwords and MIME::Base64 --- VIRTUAL_VACATION/vacation.pl | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/VIRTUAL_VACATION/vacation.pl b/VIRTUAL_VACATION/vacation.pl index 0fa9c218..72f80dc0 100644 --- a/VIRTUAL_VACATION/vacation.pl +++ b/VIRTUAL_VACATION/vacation.pl @@ -91,7 +91,7 @@ # Requirements - the following perl modules are required: # DBD::Pg or DBD::mysql -# EMail::Sender,Email::Simple,Email::Valid,Try::Tiny,MIME::Charset, Log::Log4perl, Log::Dispatch, MIME::EncWords and GetOpt::Std +# EMail::Sender,Email::Simple,Email::Valid,Try::Tiny,MIME::Charset, Log::Log4perl, Log::Dispatch, and GetOpt::Std # # You may install these via CPAN, or through your package tool. # CPAN: 'perl -MCPAN -e shell', then 'install Module::Whatever' @@ -107,7 +107,6 @@ # liblog-dispatch-perl # libgetopt-argvfile-perl # libmime-charset-perl -# libmime-encwords-perl # # Note: When you use this module, you may start seeing error messages # like "Cannot insert a duplicate key into unique index @@ -123,9 +122,7 @@ # use utf8; use DBI; -use MIME::Base64 qw(encode_base64); -use Encode qw(encode decode); -use MIME::EncWords qw(:all); +use Encode qw(decode); use Email::Valid; use strict; use Getopt::Std; From 4660d65679f4c5b073cf7babf4185e5903545d11 Mon Sep 17 00:00:00 2001 From: tkempf Date: Mon, 24 Jul 2017 08:04:28 +0200 Subject: [PATCH 08/11] Renamed $novacation_pattern to $no_vacation_pattern + codestyle changes --- VIRTUAL_VACATION/vacation.pl | 52 ++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/VIRTUAL_VACATION/vacation.pl b/VIRTUAL_VACATION/vacation.pl index 72f80dc0..944d3fbb 100644 --- a/VIRTUAL_VACATION/vacation.pl +++ b/VIRTUAL_VACATION/vacation.pl @@ -83,9 +83,9 @@ # Also corrected log entry about "Already informed ..." to show the $orig_from, not $email # # 2017-07-14 Thomas Kempf -# Replacing deprecated Mail::Sender by Email::Sender -# Add configuration parameter $novacation_pattern in order to exlude specific alias-recipients from -# sending vacation mails, even if one or multiple of the recipients the alias points to has vacation +# Replacing deprecated Mail::Sender by Email::Sender +# Add configuration parameter $no_vacation_pattern in order to exlude specific alias-recipients from +# sending vacation mails, even if one or multiple of the recipients the alias points to has vacation # currently active. # @@ -100,7 +100,7 @@ # libemail-sender-perl # libemail-simple-perl # libemail-valid-perl -# libtry-tiny-perl +# libtry-tiny-perl # libdbd-pg-perl # libmime-perl # liblog-log4perl-perl @@ -169,7 +169,7 @@ our $smtp_ssl = 'starttls'; # passed to Net::SMTP constructor for 'ssl' connections or to starttls for 'starttls' connections; should contain extra options for IO::Socket::SSL our $ssl_options = { - SSL_verifycn_name => $smtp_server + SSL_verifycn_name => $smtp_server }; # maximum time in secs to wait for server; default is 120 @@ -221,8 +221,8 @@ our $noreply_pattern = 'bounce|do-not-reply|facebook|linkedin|list-|myspace|twit # By default vacation email addresses will be sent for all recipients. # default = '' # preventing vacation notifications for recipient info@example.org would look like this: -# our $novacation_pattern = 'info\@example\.org'; -our $novacation_pattern = ''; +# our $no_vacation_pattern = 'info\@example\.org'; +our $no_vacation_pattern = ''; # instead of changing this script, you can put your settings to /etc/mail/postfixadmin/vacation.conf @@ -557,25 +557,25 @@ sub send_vacation_email { my $from = $email; my $to = $orig_from; - my $smtp_params = { - host => $smtp_server, + my $smtp_params = { + host => $smtp_server, port => $smtp_server_port, ssl_options => $ssl_options, - ssl => $smtp_ssl, - timeout => $smtp_timeout, - localaddr => $smtp_client, + ssl => $smtp_ssl, + timeout => $smtp_timeout, + localaddr => $smtp_client, debug => 0, - }; + }; - if($smtp_authid ne ''){ - $smtp_params->{sasl_username}=$smtp_authid; - $smtp_params->{sasl_password}=$smtp_authpwd; + if($smtp_authid ne ''){ + $smtp_params->{sasl_username}=$smtp_authid; + $smtp_params->{sasl_password}=$smtp_authpwd; $logger->info("Doing SASL Authentication with user $smtp_params->{sasl_username}\n"); - }; - + }; + my $transport = Email::Sender::Transport::SMTP->new($smtp_params); - - $email = Email::Simple->create( + + $email = Email::Simple->create( header => [ To => $to, From => $from, @@ -586,7 +586,7 @@ sub send_vacation_email { ], body => $body, ); - + if($test_mode == 1) { $logger->info("** TEST MODE ** : Vacation response sent to $to from $from subject $subject (not) sent\n"); $logger->info($email); @@ -599,10 +599,10 @@ sub send_vacation_email { if (@_) { $logger->error("Failed to send vacation response to $to from $from subject $subject: @_"); } else { - $logger->debug("Vacation response sent to $to from $from subject $subject sent\n"); - } - } - } + $logger->debug("Vacation response sent to $to from $from subject $subject sent\n"); + } + } + } } # Convert a (list of) email address(es) from RFC 822 style addressing to @@ -723,7 +723,7 @@ if(!$from || !$to || !$messageid || !$smtp_sender || !$smtp_recipient) { } $logger->debug("Email headers have to: '$to' and From: '$from'"); -if ($to =~ /^.*($novacation_pattern).*/i) { +if ($to =~ /^.*($no_vacation_pattern).*/i) { $logger->debug("Will not send vacation reply for messages to $to"); exit(0); } From 34474a20e581f8bc926e3debdacafbb25c9dedfb Mon Sep 17 00:00:00 2001 From: tkempf Date: Mon, 24 Jul 2017 08:06:10 +0200 Subject: [PATCH 09/11] set default value for $no_vacation_pattern --- VIRTUAL_VACATION/vacation.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VIRTUAL_VACATION/vacation.pl b/VIRTUAL_VACATION/vacation.pl index 944d3fbb..b215930b 100644 --- a/VIRTUAL_VACATION/vacation.pl +++ b/VIRTUAL_VACATION/vacation.pl @@ -222,7 +222,7 @@ our $noreply_pattern = 'bounce|do-not-reply|facebook|linkedin|list-|myspace|twit # default = '' # preventing vacation notifications for recipient info@example.org would look like this: # our $no_vacation_pattern = 'info\@example\.org'; -our $no_vacation_pattern = ''; +our $no_vacation_pattern = 'info\@example\.org'; # instead of changing this script, you can put your settings to /etc/mail/postfixadmin/vacation.conf From f2d4e6dbcce4af30abca7c093c545999eef06bf4 Mon Sep 17 00:00:00 2001 From: tkempf Date: Mon, 24 Jul 2017 08:27:14 +0200 Subject: [PATCH 10/11] Subject with non ASCII-chars still needs to be encoded --- VIRTUAL_VACATION/vacation.pl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/VIRTUAL_VACATION/vacation.pl b/VIRTUAL_VACATION/vacation.pl index b215930b..de270fa2 100644 --- a/VIRTUAL_VACATION/vacation.pl +++ b/VIRTUAL_VACATION/vacation.pl @@ -91,7 +91,7 @@ # Requirements - the following perl modules are required: # DBD::Pg or DBD::mysql -# EMail::Sender,Email::Simple,Email::Valid,Try::Tiny,MIME::Charset, Log::Log4perl, Log::Dispatch, and GetOpt::Std +# EMail::Sender,Email::Simple,Email::Valid,Try::Tiny,MIME::Charset, MIME::EncWords, Log::Log4perl, Log::Dispatch, and GetOpt::Std # # You may install these via CPAN, or through your package tool. # CPAN: 'perl -MCPAN -e shell', then 'install Module::Whatever' @@ -107,6 +107,7 @@ # liblog-dispatch-perl # libgetopt-argvfile-perl # libmime-charset-perl +# libmime-encwords-perl # # Note: When you use this module, you may start seeing error messages # like "Cannot insert a duplicate key into unique index @@ -579,7 +580,7 @@ sub send_vacation_email { header => [ To => $to, From => $from, - Subject => $subject, + Subject => encode_mimewords($subject, 'Charset', 'UTF-8'), Precedence => 'junk', 'Content-Type' => "text/plain; charset=utf-8", 'X-Loop' => 'Postfix Admin Virtual Vacation', From 066a22cb4216ee1cef612c4fbd0a67b7b116b30d Mon Sep 17 00:00:00 2001 From: tkempf Date: Mon, 24 Jul 2017 10:55:47 +0200 Subject: [PATCH 11/11] Added forgotten use Statement for MIME:EncWords --- VIRTUAL_VACATION/vacation.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/VIRTUAL_VACATION/vacation.pl b/VIRTUAL_VACATION/vacation.pl index de270fa2..fb084e1d 100644 --- a/VIRTUAL_VACATION/vacation.pl +++ b/VIRTUAL_VACATION/vacation.pl @@ -124,6 +124,7 @@ use utf8; use DBI; use Encode qw(decode); +use MIME::EncWords qw(:all); use Email::Valid; use strict; use Getopt::Std;