From 5729e018e59e99b766d8773c819eea38e3acdc8a Mon Sep 17 00:00:00 2001 From: Daniel Lerch Date: Fri, 28 Aug 2020 18:04:30 +0200 Subject: [PATCH] Fix various mailing issues - Increase frequency of scheduler - Fix non-ASCII mail sender names - Avoid duplicate Reply-To headers --- install/default/docker/kool-scheduler | 2 +- mailing.php | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/install/default/docker/kool-scheduler b/install/default/docker/kool-scheduler index 7d30fd3..363707b 100644 --- a/install/default/docker/kool-scheduler +++ b/install/default/docker/kool-scheduler @@ -1 +1 @@ -*/5 * * * * www-data /usr/local/bin/php /var/www/html/scheduler.php +*/1 * * * * www-data /usr/local/bin/php /var/www/html/scheduler.php diff --git a/mailing.php b/mailing.php index 38e5a1b..baba969 100644 --- a/mailing.php +++ b/mailing.php @@ -1118,11 +1118,11 @@ function ko_mailing_store_moderation($imap, $mail, $login, $modifyRcpts = true, $header = preg_replace('/(\n|^)X-Spam-Report:(.*)(\n\s+(.*))*\n/i', '$1', $header); $header = preg_replace('/(\n|^)DKIM-Signature:(.*)(\n\s+(.*))*\n/i', '$1', $header); - $manualReplyTo = FALSE; - $replyTo = ''; + // Delete any existing Reply-To headers to avoid duplicates + $header = preg_replace('/(\n|^)Reply-To:(.*)(\n\s+(.*))*\n/i', '$1', $header); + + $replyTo = NULL; if($mail['_reply_to']) { - //Remove Reply-To - $header = preg_replace('/(\n|^)Reply-To:(.*)(\n\s+(.*))*\n/i', '$1', $header); //Set new Reply-To switch($mail['_reply_to']) { case 'list': @@ -1134,14 +1134,12 @@ function ko_mailing_store_moderation($imap, $mail, $login, $modifyRcpts = true, break; } $header = trim($header)."\nReply-To: ".$replyTo."\n"; - $manualReplyTo = TRUE; } - //Set from address to an spf save sender address $header = preg_replace('/(\n|^)From:(.*)(\n\s+(.*))*\n/i', '$1', $header); - if(!$manualReplyTo) { + if($replyTo === NULL) { $header = trim($header)."\nReply-To: ".$mail['from']."\n"; } @@ -1149,7 +1147,12 @@ function ko_mailing_store_moderation($imap, $mail, $login, $modifyRcpts = true, ko_mail_get_spf_from($mailFrom, $replyTo, $mailSender, $login['id']); $fromEmail = array_key_first($mailFrom); - $from = '"'.str_replace('"', '', $mailFrom[$fromEmail]).'" <'.$fromEmail.'>'; + if (empty($mailFrom[$fromEmail])) { + $from = $fromEmail; + } else { + // Computed From fields might contain no ASCII chars and have to be encoded first + $from = mb_encode_mimeheader($mailFrom[$fromEmail], 'UTF-8', 'Q').' <'.$fromEmail.'>'; + } $header = trim($header)."\nFrom: ".$from."\n"; if($mailSender) {