diff options
-rw-r--r-- | it_mail.class | 8 | ||||
-rwxr-xr-x | tests/it_mail.t | 17 |
2 files changed, 15 insertions, 10 deletions
diff --git a/it_mail.class b/it_mail.class index 73b0bd7..aa242c5 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, ' "'))) . "?=") + ? ltrim(iconv_mime_encode('', $string, array('scheme' => 'Q', 'input-charset' => $this->charset, 'output-charset' => $this->charset)), ' :') : $string; } @@ -332,12 +332,12 @@ function addrlist_escape($string) 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); } diff --git a/tests/it_mail.t b/tests/it_mail.t index 687480c..41ca3d1 100755 --- a/tests/it_mail.t +++ b/tests/it_mail.t @@ -20,7 +20,7 @@ is( is( $mail->addrlist_escape('Èxample User <èxample@example.com>', true), - '=?utf-8?Q?=C3=88xample_User?= <èxample@example.com>', + '=?utf-8?Q?=C3=88xample=20User?= <èxample@example.com>', "Escape name but not email in email headers" ); @@ -32,7 +32,7 @@ is( is( $mail->addrlist_escape('example@example.com, éxample@example.com, Sömeone Ëlse <sömeone@example.com>', true), - 'example@example.com, éxample@example.com,=?utf-8?Q?S=C3=B6meone_=C3=8Blse?= <sömeone@example.com>', + 'example@example.com, éxample@example.com, =?utf-8?Q?S=C3=B6meone=20=C3=8Blse?= <sömeone@example.com>', "Don't escape email addresses but escape realnames" ); @@ -42,6 +42,11 @@ is( "Don't remove quoting characters from realname" ); +is( + $mail->addrlist_escape('"Schmitt, Sören" <schmitt@example.com>', true), + '=?utf-8?Q?"Schmitt,=20S=C3=B6ren"?= <schmitt@example.com>', + "Don't remove quoting characters from realname when it contains a quotable character" +); $mail = new it_mail(array( 'From' => 'Someone Ïmportant <ïmportant@search.ch>', @@ -53,25 +58,25 @@ $mail = new it_mail(array( is( $mail->to[0], - 'éxample@example.com, example@example.com,=?utf-8?Q?S=C3=B6meone_=C3=8Blse?= <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>,=?utf-8?Q?Schmitt,_S=C3=B6ren?= <schmitt@example.com>', + 'éxample@example.com, example@example.com, =?utf-8?Q?S=C3=B6meone=20=C3=8Blse?= <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>, =?utf-8?Q?"Schmitt,=20S=C3=B6ren"?= <schmitt@example.com>', 'Escape To: field as addrlist' ); is( $mail->cc[0], - 'éxample@example.com, example@example.com,=?utf-8?Q?S=C3=B6meone_=C3=8Blse?= <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>,=?utf-8?Q?Schmitt,_S=C3=B6ren?= <schmitt@example.com>', + 'éxample@example.com, example@example.com, =?utf-8?Q?S=C3=B6meone=20=C3=8Blse?= <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>, =?utf-8?Q?"Schmitt,=20S=C3=B6ren"?= <schmitt@example.com>', 'Escape Cc: field as addrlist' ); is( $mail->bcc[0], - 'éxample@example.com, example@example.com,=?utf-8?Q?S=C3=B6meone_=C3=8Blse?= <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>,=?utf-8?Q?Schmitt,_S=C3=B6ren?= <schmitt@example.com>', + 'éxample@example.com, example@example.com, =?utf-8?Q?S=C3=B6meone=20=C3=8Blse?= <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>, =?utf-8?Q?"Schmitt,=20S=C3=B6ren"?= <schmitt@example.com>', 'Escape Bcc: field as addrlist' ); is( $mail->header_values[0], - '=?utf-8?Q?Someone_=C3=8Fmportant?= <ïmportant@search.ch>', + '=?utf-8?Q?Someone=20=C3=8Fmportant?= <ïmportant@search.ch>', 'Escape From: field as addrlist' ); |