From 8dc756f319858bf8a6bbe228b8e7ef62d5d77aac Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 01 Feb 2016 08:25:00 -0500
Subject: [PATCH] Fix bug in long recipients list parsing for cases where recipient name contained @-char (#1490653)

---
 program/lib/Roundcube/rcube_smtp.php |   10 +++++++---
 CHANGELOG                            |    1 +
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index efdc168..3f3c87e 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -18,6 +18,7 @@
 - Fix missing language name in "Add to Dictionary" request in HTML mode (#1490634)
 - Fix (again) security issue in DBMail driver of password plugin [CVE-2015-2181] (#1490643)
 - Fix bug where Archive/Junk buttons were not active after page jump with select=all mode (#1490647)
+- Fix bug in long recipients list parsing for cases where recipient name contained @-char (#1490653)
 
 RELEASE 1.2-beta
 ----------------
diff --git a/program/lib/Roundcube/rcube_smtp.php b/program/lib/Roundcube/rcube_smtp.php
index fc3f28c..4f5dd0f 100644
--- a/program/lib/Roundcube/rcube_smtp.php
+++ b/program/lib/Roundcube/rcube_smtp.php
@@ -459,15 +459,19 @@
         }
 
         $addresses  = array();
+        $recipients = preg_replace('/[\s\t]*\r?\n/', '', $recipients);
         $recipients = rcube_utils::explode_quoted_string(',', $recipients);
 
         reset($recipients);
         foreach ($recipients as $recipient) {
             $a = rcube_utils::explode_quoted_string(' ', $recipient);
             foreach ($a as $word) {
-                if (strpos($word, "@") > 0 && $word[strlen($word)-1] != '"') {
-                    $word = preg_replace('/^<|>$/', '', trim($word));
-                    if (in_array($word, $addresses) === false) {
+                $word = trim($word);
+                $len  = strlen($word);
+
+                if ($len && strpos($word, "@") > 0 && $word[$len-1] != '"') {
+                    $word = preg_replace('/^<|>$/', '', $word);
+                    if (!in_array($word, $addresses)) {
                         array_push($addresses, $word);
                     }
                 }

--
Gitblit v1.9.1