diff options
author | alecpl <alec@alec.pl> | 2009-02-13 10:44:49 +0000 |
---|---|---|
committer | alecpl <alec@alec.pl> | 2009-02-13 10:44:49 +0000 |
commit | 050410f56097bfb29bb8e5d99e792cc3a9165a55 (patch) | |
tree | 38949402fa7fa7d26b8f5f4a3adeb92cac65e0d7 /program/steps | |
parent | 33875df40b31d571597d92e9f1bd100fba10d10b (diff) |
- Fix multiple recipients input parsing (#1485733)
- added shared rcube_explode_quoted_string() function
Diffstat (limited to 'program/steps')
-rw-r--r-- | program/steps/mail/sendmail.inc | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc index 0a9c3681e..f73c44bac 100644 --- a/program/steps/mail/sendmail.inc +++ b/program/steps/mail/sendmail.inc @@ -143,33 +143,39 @@ function rcmail_mailto_format($mailto) $regexp = array('/[,;]\s*[\r\n]+/', '/[\r\n]+/', '/[,;]\s*$/m', '/;/', '/(\S{1})(<\S+@\S+>)/U'); $replace = array(', ', ', ', '', ',', '\\1 \\2'); - // replace new lines and strip ending ', ', make address strings more valid also + // replace new lines and strip ending ', ', make address input more valid $mailto = trim(preg_replace($regexp, $replace, $mailto)); - $result = $name = ''; - - // handle simple email (without <>) - if (preg_match('/^\S+@\S+$/', $mailto)) - $result = '<' . $mailto . '>'; - else - // quote unquoted names (#1485654) - foreach (explode(' ', $mailto) as $item) { - if (preg_match('/<\S+@\S+>,*/', $item)) { - if ($name && ($name[0] != '"' || $name[strlen($name)-1] != '"') + $result = array(); + $items = rcube_explode_quoted_string(',', $mailto); + + foreach($items as $item) { + $item = trim($item); + // address in brackets without name (do nothing) + if (preg_match('/^<\S+@\S+>$/', $item)) { + $result[] = $item; + // address without brackets and without name (add brackets) + } else if (preg_match('/^\S+@\S+$/', $item)) { + $result[] = '<'.$item.'>'; + // address with name (handle name) + } else if (preg_match('/\S+@\S+>*$/', $item, $matches)) { + $address = $matches[0]; + $name = str_replace($address, '', $item); + $name = trim($name); + if ($name && ($name[0] != '"' || $name[strlen($name)-1] != '"') && preg_match('/[\(\)\<\>\\\.\[\]@,;:"]/', $name)) { $name = '"'.addcslashes($name, '"').'"'; - } - if ($name) { - $result .= ' ' . $name; - $name = ''; - } - $result .= ' ' . $item; - } else { - $name .= ($name ? ' ' : '') . $item; } + if (!preg_match('/^<\S+@\S+>$/', $address)) + $address = '<'.$address.'>'; + + $result[] = $name.' '.$address; + } else if (trim($item)) { + // @TODO: handle errors } + } - return trim($result); + return implode(', ', $result); } /****** compose message ********/ |