summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Flatz2016-02-03 18:00:43 +0100
committerDavid Flatz2016-02-03 18:00:43 +0100
commiteb55ac5cea8ad3720505645600e6d854d737603a (patch)
tree1959078c4af862f91da902f5ec65bb52f98ea998
parentd384e10b385431fe647ce481c7f57ce76e43c6c7 (diff)
downloaditools-eb55ac5cea8ad3720505645600e6d854d737603a.tar.gz
itools-eb55ac5cea8ad3720505645600e6d854d737603a.tar.bz2
itools-eb55ac5cea8ad3720505645600e6d854d737603a.zip
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
-rw-r--r--it_mail.class15
-rwxr-xr-xtests/it_mail.t14
2 files changed, 20 insertions, 9 deletions
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];
diff --git a/tests/it_mail.t b/tests/it_mail.t
index 1762788..44ed30d 100755
--- a/tests/it_mail.t
+++ b/tests/it_mail.t
@@ -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_=C3=8Blse?= <sömeone@example.com>',
"Don't escape email addresses but escape realnames",
);
@@ -45,27 +45,27 @@ is(
$mail = new it_mail(
'From' => 'Someone Ïmportant <ïmportant@search.ch>',
- 'To' => 'éxample@example.com, example@example.com, Sömeone Ëlse <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>',
- 'Cc' => 'éxample@example.com, example@example.com, Sömeone Ëlse <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>',
- 'Bcc' => 'éxample@example.com, example@example.com, Sömeone Ëlse <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>',
+ 'To' => 'éxample@example.com, example@example.com, Sömeone Ëlse <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>, "Schmitt, Sören" <schmitt@example.com>',
+ 'Cc' => 'éxample@example.com, example@example.com, Sömeone Ëlse <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>, "Schmitt, Sören" <schmitt@example.com>',
+ 'Bcc' => 'éxample@example.com, example@example.com, Sömeone Ëlse <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>, "Schmitt, Sören" <schmitt@example.com>',
'Subject' => "§önÐë®z€ı¢ħèṇ",
);
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>',
+ 'é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>',
'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>',
+ 'é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>',
'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>',
+ 'é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>',
'Escape Bcc: field as addrlist',
);