Aleksander Machniak
2016-02-01 3e12784cc27d7b130308901cd6f13568d9797122
program/lib/Roundcube/rcube_smtp.php
@@ -127,9 +127,10 @@
        $result = $this->conn->connect($CONFIG['smtp_timeout']);
        if (PEAR::isError($result)) {
            $this->response[] = "Connection failed: ".$result->getMessage();
            $this->error = array('label' => 'smtpconnerror', 'vars' => array('code' => $this->conn->_code));
            list($code,) = $this->conn->getResponse();
            $this->error = array('label' => 'smtpconnerror', 'vars' => array('code' => $code));
            $this->conn  = null;
            return false;
        }
@@ -160,10 +161,14 @@
            $result = $this->conn->auth($smtp_user, $smtp_pass, $smtp_auth_type, $use_tls, $smtp_authz);
            if (PEAR::isError($result)) {
                $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;
            }
        }
@@ -243,8 +248,9 @@
        if (PEAR::isError($this->conn->mailFrom($from, $from_params))) {
            $err = $this->conn->getResponse();
            $this->error = array('label' => 'smtpfromerror', 'vars' => array(
                'from' => $from, 'code' => $this->conn->_code, 'msg' => $err[1]));
            $this->response[] = "Failed to set sender '$from'";
                'from' => $from, 'code' => $err[0], 'msg' => $err[1]));
            $this->response[] = "Failed to set sender '$from'. "
                . $err[1] . ' (Code: ' . $err[0] . ')';
            $this->reset();
            return false;
        }
@@ -262,8 +268,9 @@
            if (PEAR::isError($this->conn->rcptTo($recipient, $recipient_params))) {
                $err = $this->conn->getResponse();
                $this->error = array('label' => 'smtptoerror', 'vars' => array(
                    'to' => $recipient, 'code' => $this->conn->_code, 'msg' => $err[1]));
                $this->response[] = "Failed to add recipient '$recipient'";
                    'to' => $recipient, 'code' => $err[0], 'msg' => $err[1]));
                $this->response[] = "Failed to add recipient '$recipient'. "
                    . $err[1] . ' (Code: ' . $err[0] . ')';
                $this->reset();
                return false;
            }
@@ -286,7 +293,8 @@
        }
        // Send the message's headers and the body as SMTP data.
        if (PEAR::isError($result = $this->conn->data($data, $text_headers))) {
        $result = $this->conn->data($data, $text_headers);
        if (PEAR::isError($result)) {
            $err = $this->conn->getResponse();
            if (!in_array($err[0], array(354, 250, 221))) {
                $msg = sprintf('[%d] %s', $err[0], $err[1]);
@@ -296,7 +304,7 @@
            }
            $this->error = array('label' => 'smtperror', 'vars' => array('msg' => $msg));
            $this->response[] = "Failed to send data";
            $this->response[] = "Failed to send data. " . $msg;
            $this->reset();
            return false;
        }
@@ -450,15 +458,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);
                    }
                }