Aleksander Machniak
2016-02-01 3e55a2d9cb476c536ac132b16fb688ff031e3425
program/lib/Roundcube/rcube_smtp.php
@@ -127,9 +127,12 @@
        $result = $this->conn->connect($CONFIG['smtp_timeout']);
        if (is_a($result, 'PEAR_Error')) {
            $this->response[] = "Connection failed: ".$result->getMessage();
            $this->error = array('label' => 'smtpconnerror', 'vars' => array('code' => $this->conn->_code));
            $this->response[] = "Connection failed: " . $result->getMessage();
            list($code,) = $this->conn->getResponse();
            $this->error = array('label' => 'smtpconnerror', 'vars' => array('code' => $code));
            $this->conn  = null;
            return false;
        }
@@ -160,10 +163,14 @@
            $result = $this->conn->auth($smtp_user, $smtp_pass, $smtp_auth_type, $use_tls, $smtp_authz);
            if (is_a($result, 'PEAR_Error')) {
                $this->error = array('label' => 'smtpautherror', 'vars' => array('code' => $this->conn->_code));
                $this->response[] .= 'Authentication failure: ' . $result->getMessage() . ' (Code: ' . $result->getCode() . ')';
                list($code,) = $this->conn->getResponse();
                $this->error = array('label' => 'smtpautherror', 'vars' => array('code' => $code));
                $this->response[] = 'Authentication failure: ' . $result->getMessage()
                    . ' (Code: ' . $result->getCode() . ')';
                $this->reset();
                $this->disconnect();
                return false;
            }
        }
@@ -207,11 +214,6 @@
        }
        else if (is_string($headers)) {
            $text_headers = $headers;
        }
        else {
            $this->reset();
            $this->response[] = "Invalid message headers";
            return false;
        }
        // exit if no from address is given
@@ -275,8 +277,11 @@
        if (is_resource($body)) {
            // file handle
            $data         = $body;
            $text_headers = preg_replace('/[\r\n]+$/', '', $text_headers);
            $data = $body;
            if ($text_headers) {
                $text_headers = preg_replace('/[\r\n]+$/', '', $text_headers);
            }
        }
        else {
            // Concatenate headers and body so it can be passed by reference to SMTP_CONN->data
@@ -455,15 +460,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);
                    }
                }