Aleksander Machniak
2015-01-28 78f948f7b9838de6d62c76f4daf6834244ae1348
program/lib/Roundcube/rcube_smtp.php
@@ -29,6 +29,7 @@
    private $conn = null;
    private $response;
    private $error;
    private $anonymize_log = 0;
    // define headers delimiter
    const SMTP_MIME_CRLF = "\r\n";
@@ -111,6 +112,7 @@
        if ($rcube->config->get('smtp_debug')) {
            $this->conn->setDebug(true, array($this, 'debug_handler'));
            $this->anonymize_log = 0;
        }
        // register authentication methods
@@ -241,8 +243,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;
        }
@@ -260,8 +263,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;
            }
@@ -284,7 +288,7 @@
        }
        // Send the message's headers and the body as SMTP data.
        if (PEAR::isError($result = $this->conn->data($data, $text_headers))) {
        if (PEAR::isError($this->conn->data($data, $text_headers))) {
            $err = $this->conn->getResponse();
            if (!in_array($err[0], array(354, 250, 221))) {
                $msg = sprintf('[%d] %s', $err[0], $err[1]);
@@ -294,7 +298,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;
        }
@@ -330,6 +334,15 @@
     */
    public function debug_handler(&$smtp, $message)
    {
        // catch AUTH commands and set anonymization flag for subsequent sends
        if (preg_match('/^Send: AUTH ([A-Z]+)/', $message, $m)) {
            $this->anonymize_log = $m[1] == 'LOGIN' ? 2 : 1;
        }
        // anonymize this log entry
        else if ($this->anonymize_log > 0 && strpos($message, 'Send:') === 0 && --$this->anonymize_log == 0) {
            $message = sprintf('Send: ****** [%d]', strlen($message) - 8);
        }
        if (($len = strlen($message)) > self::DEBUG_LINE_LENGTH) {
            $diff    = $len - self::DEBUG_LINE_LENGTH;
            $message = substr($message, 0, self::DEBUG_LINE_LENGTH)