diff options
author | alecpl <alec@alec.pl> | 2010-10-20 08:58:21 +0000 |
---|---|---|
committer | alecpl <alec@alec.pl> | 2010-10-20 08:58:21 +0000 |
commit | 435c315223d65aeb28b50b2707bea0bdea6d3980 (patch) | |
tree | 769f6836d3b627217470a9784affd67ef3b13aa9 | |
parent | 13326b75403ec1d1f21254753d5a66f8bfaa5f5c (diff) |
- Fix decoding of e-mail address strings in message headers (#1487068)
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | program/include/rcube_imap.php | 51 |
2 files changed, 34 insertions, 18 deletions
@@ -35,6 +35,7 @@ CHANGELOG Roundcube Webmail - Add ACL extension support into IMAP classes (RFC4314) - Add ANNOTATEMORE extension support into IMAP classes (draft-daboo-imap-annotatemore) - Add METADATA extension support into IMAP classes (RFC5464) +- Fix decoding of e-mail address strings in message headers (#1487068) RELEASE 0.4.2 ------------- diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php index d94f4ae4b..5d90fe41f 100644 --- a/program/include/rcube_imap.php +++ b/program/include/rcube_imap.php @@ -4000,10 +4000,7 @@ class rcube_imap foreach ($a as $val) { $j++; $address = trim($val['address']); - $name = trim($val['name']); - - if ($name && preg_match('/^[\'"]/', $name) && preg_match('/[\'"]$/', $name)) - $name = trim($name, '\'"'); + $name = trim($val['name']); if ($name && $address && $name != $address) $string = sprintf('%s <%s>', preg_match("/$special_chars/", $name) ? '"'.addcslashes($name, '"').'"' : $name, $address); @@ -4419,22 +4416,40 @@ class rcube_imap $result = array(); foreach ($a as $key => $val) { - $val = preg_replace("/([\"\w])</", "$1 <", $val); - $sub_a = rcube_explode_quoted_string(' ', $decode ? $this->decode_header($val) : $val); - $result[$key]['name'] = ''; - - foreach ($sub_a as $k => $v) { - // use angle brackets in regexp to not handle names with @ sign - if (preg_match('/^<\S+@\S+>$/', $v)) - $result[$key]['address'] = trim($v, '<>'); - else - $result[$key]['name'] .= (empty($result[$key]['name'])?'':' ').str_replace("\"",'',stripslashes($v)); + $name = ''; + $address = ''; + $val = trim($val); + + if (preg_match('/(.*)<(\S+@\S+)>$/', $val, $m)) { + $address = $m[2]; + $name = trim($m[1]); + } + else if (preg_match('/^(\S+@\S+)$/', $val, $m)) { + $address = $m[1]; + $name = ''; + } + else { + $name = $val; } -// if (empty($result[$key]['name'])) -// $result[$key]['name'] = $result[$key]['address']; - if (empty($result[$key]['address'])) - $result[$key]['address'] = $result[$key]['name']; + // dequote and/or decode name + if ($name) { + if ($name[0] == '"') { + $name = substr($name, 1, -1); + $name = stripslashes($name); + } + else if ($decode) { + $name = $this->decode_header($name); + } + } + + if (!$address && $name) { + $address = $name; + } + + if ($address) { + $result[$key] = array('name' => $name, 'address' => $address); + } } return $result; |