From cc2fc03953f42279e4593fdb407392fa72715c66 Mon Sep 17 00:00:00 2001 From: Tony McNulty Date: Thu, 6 Oct 2022 20:52:06 +0100 Subject: [PATCH] Only encode subject and recipients when necessary Spamassassin marks you down one point for unnecessarily encoding headers. When spam filters are set low, emails sent through this class will be higher rated as spam. The rule is: 1.05 FROM_EXCESS_BASE64_2 META: From: base64 encoded unnecessarily --- src/SimpleEmailServiceMessage.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/SimpleEmailServiceMessage.php b/src/SimpleEmailServiceMessage.php index ee951f0..9bb9e87 100644 --- a/src/SimpleEmailServiceMessage.php +++ b/src/SimpleEmailServiceMessage.php @@ -533,7 +533,11 @@ public function getRawMessage($encode = true) { } if ($this->subject != null && strlen($this->subject) > 0) { - $raw_message .= 'Subject: =?' . $this->subjectCharset . '?B?' . base64_encode($this->subject) . "?=\n"; + if (preg_match('/[^\x20-\x7f]/', $this->subject)) { + $raw_message .= 'Subject: =?' . $this->subjectCharset . '?B?' . base64_encode($this->subject) . "?=\n"; + } else { + $raw_message .= 'Subject: ' . $this->subject . "\n"; + } } $raw_message .= 'MIME-Version: 1.0' . "\n"; @@ -589,7 +593,9 @@ public function encodeRecipients($recipient) { } if (preg_match("/(.*)<(.*)>/", $recipient, $regs)) { - $recipient = '=?' . $this->recipientsCharset . '?B?' . base64_encode($regs[1]) . '?= <' . $regs[2] . '>'; + if (preg_match('/[^\x20-\x7f]/', $regs[1])) { + $recipient = '=?' . $this->recipientsCharset . '?B?' . base64_encode($regs[1]) . '?= <' . $regs[2] . '>'; + } } return $recipient;