- Fix decoding of e-mail address strings in message headers (#1487068)

release-0.6
alecpl 14 years ago
parent 13326b7540
commit 435c315223

@ -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
-------------

@ -4002,9 +4002,6 @@ class rcube_imap
$address = trim($val['address']);
$name = trim($val['name']);
if ($name && preg_match('/^[\'"]/', $name) && preg_match('/[\'"]$/', $name))
$name = trim($name, '\'"');
if ($name && $address && $name != $address)
$string = sprintf('%s <%s>', preg_match("/$special_chars/", $name) ? '"'.addcslashes($name, '"').'"' : $name, $address);
else if ($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;

Loading…
Cancel
Save