diff options
Diffstat (limited to 'it_mail.class')
-rw-r--r-- | it_mail.class | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/it_mail.class b/it_mail.class index 5746056..503da08 100644 --- a/it_mail.class +++ b/it_mail.class @@ -305,7 +305,14 @@ 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, '"'))) . "?=") + ? ltrim( + ($encoded = @iconv_mime_encode('', $string, array('scheme' => 'Q', 'input-charset' => $this->charset, 'output-charset' => $this->charset))) !== false + ? $encoded + : ($encoded = @iconv_mime_encode('', $string, array('scheme' => 'B', 'input-charset' => $this->charset, 'output-charset' => $this->charset))) !== false + ? $encoded + : iconv_mime_encode('', $string, array('scheme', 'B', 'input-charset' => 'ISO-8859-1', 'output-charset' => $this->charset)), + ' :' + ) : $string; } @@ -318,15 +325,26 @@ 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]; + $result[] = $this->header_escape(trim($matches[1])) . $matches[2]; else - $result[] = $mailbox; + $result[] = trim($mailbox); } - return implode(',', $result); + return implode(', ', $result); } |