diff options
Diffstat (limited to 'it_mail.class')
-rw-r--r-- | it_mail.class | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/it_mail.class b/it_mail.class index f24a603..46095bf 100644 --- a/it_mail.class +++ b/it_mail.class @@ -304,20 +304,30 @@ function send($p = array()) */ function header_escape($string, $emailmode = false) { - # If in emailmode (From, To, Cc, Bcc) then exclude <email@domain.com> - # from being encoded as e.g. GMail has problems with that - # Otherwise encode whole string at once, i.e. do not split - $emailpattern = $emailmode ? '/(\s*<[^>]+@[^>]+>[,\s]*)/' : '/DO_NOT_SLPIT{64738}/'; - - foreach (preg_split($emailpattern, $string, -1, PREG_SPLIT_DELIM_CAPTURE) as $part) + $escape = function ($part) { - # Encode if not email address and contains special chars - $result .= !preg_match($emailpattern, $part) && preg_match('/[\x00-\x1f\x7f-\xff]/', $part) + return preg_match('/[\x00-\x1f\x7f-\xff]/', $part) ? ("=?{$this->charset}?Q?" . str_replace(" ", "_", preg_replace_callback('/[\x00-\x1f=\x7f-\xff]/', function($m) { return sprintf('=%02X', ord($m[0])); }, trim($part, '"'))) . "?=") : $part; - } + }; - return $result; + if ($emailmode) + { + # If in emailmode (From, To, Cc, Bcc) then exclude e-mail addresses + # from being encoded as e.g. GMail or Exchange have problems with that + $emailpattern = '/^(.*)(\s+?<[^>]+@[^>]+>\s*)$/'; + foreach (explode(',', $string) as $mailbox) + { + if (preg_match($emailpattern, $mailbox, $matches)) + $result[] = $escape($matches[1]) . $matches[2]; + else + $result[] = $mailbox; + } + + return implode(',', $result); + } + else + return $escape($string); } |