From eb55ac5cea8ad3720505645600e6d854d737603a Mon Sep 17 00:00:00 2001 From: David Flatz Date: Wed, 3 Feb 2016 18:00:43 +0100 Subject: don't split addrlist at comma when the comma is inside a quoted string, this should fix mails to people with umlauts and comma in realname --- it_mail.class | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'it_mail.class') diff --git a/it_mail.class b/it_mail.class index 5746056..73b0bd7 100644 --- a/it_mail.class +++ b/it_mail.class @@ -305,7 +305,7 @@ function send($p = array()) function header_escape($string) { return preg_match('/[\x00-\x1f\x7f-\xff]/', $string) - ? ("=?{$this->charset}?Q?" . str_replace(" ", "_", preg_replace_callback('/[\x00-\x1f=\x7f-\xff]/', function($m) { return sprintf('=%02X', ord($m[0])); }, trim($string, '"'))) . "?=") + ? ("=?{$this->charset}?Q?" . str_replace(" ", "_", preg_replace_callback('/[\x00-\x1f=\x7f-\xff]/', function($m) { return sprintf('=%02X', ord($m[0])); }, trim($string, ' "'))) . "?=") : $string; } @@ -318,7 +318,18 @@ function addrlist_escape($string) { # Exclude e-mail addresses from being encoded as # e.g. GMail or Exchange have problems with that - foreach (explode(',', $string) as $mailbox) + foreach (str_split($string) as $char) + { + if ($char == '"') + $quoted = !$quoted; + + if ($char == ',' && !$quoted) + $n++; + else + $mailboxes[$n] .= $char; + } + + foreach ((array)$mailboxes as $mailbox) { if (preg_match('/^(.*)(\s+?<[^>]+@[^>]+>\s*)$/', $mailbox, $matches)) $result[] = $this->header_escape($matches[1]) . $matches[2]; -- cgit v1.2.3