diff options
-rw-r--r-- | it_mail.class | 7 | ||||
-rwxr-xr-x | tests/it_mail.t | 6 |
2 files changed, 12 insertions, 1 deletions
diff --git a/it_mail.class b/it_mail.class index aa242c5..6c4398f 100644 --- a/it_mail.class +++ b/it_mail.class @@ -305,7 +305,12 @@ function send($p = array()) function header_escape($string) { return preg_match('/[\x00-\x1f\x7f-\xff]/', $string) - ? ltrim(iconv_mime_encode('', $string, array('scheme' => 'Q', 'input-charset' => $this->charset, 'output-charset' => $this->charset)), ' :') + ? ltrim( + ($encoded = @iconv_mime_encode('', $string, array('scheme' => 'Q', 'input-charset' => $this->charset, 'output-charset' => $this->charset))) !== false + ? $encoded + : iconv_mime_encode('', $string, array('scheme' => 'B', 'input-charset' => $this->charset, 'output-charset' => $this->charset)), + ' :' + ) : $string; } diff --git a/tests/it_mail.t b/tests/it_mail.t index 41ca3d1..486dee8 100755 --- a/tests/it_mail.t +++ b/tests/it_mail.t @@ -19,6 +19,12 @@ is( ); is( + $mail->header_escape('search.ch e-mail code d\'accès'), + '=?utf-8?B?c2VhcmNoLmNoIGUtbWFpbCBjb2RlIGQnYWNjw6hz?=', + "Use base64 encoding when php iconv fails with quoted-printable (workaround for php bug #53891)" +); + +is( $mail->addrlist_escape('Èxample User <èxample@example.com>', true), '=?utf-8?Q?=C3=88xample=20User?= <èxample@example.com>', "Escape name but not email in email headers" |