예제 #1
0
    /**
     * Read a reply from the SMTP server.  The reply consists of a response
     * code and a response message.
     *
     * @param   mixed   $valid      The set of valid response codes.  These
     *                              may be specified as an array of integer
     *                              values or as a single integer value.
     *
     * @return  mixed   True if the server returned a valid response code or
     *                  a PEAR_Error object is an error condition is reached.
     *
     * @access  private
     * @since   1.1.0
     *
     * @see     getResponse
     */
    function _parseResponse($valid)
    {
        $this->_code = -1;
        $this->_arguments = array();

        while ($line = $this->_socket->readLine()) {
            if ($this->_debug) {
                echo "DEBUG: Recv: $line\n";
            }

            /* If we receive an empty line, the connection has been closed. */
            if (empty($line)) {
                $this->disconnect();
                return PEAR::raiseError('Connection was unexpectedly closed');
            }

            /* Read the code and store the rest in the arguments array. */
            $code = substr($line, 0, 3);
            $this->_arguments[] = trim(substr($line, 4));

            /* Check the syntax of the response code. */
            if (is_numeric($code)) {
                $this->_code = (int)$code;
            } else {
                $this->_code = -1;
                break;
            }

            /* If this is not a multiline response, we're done. */
            if (substr($line, 3, 1) != '-') {
                break;
            }
        }

        /* Compare the server's response code with the valid code. */
        if (is_int($valid) && ($this->_code === $valid)) {
            return true;
        }

        /* If we were given an array of valid response codes, check each one. */
        if (is_array($valid)) {
            foreach ($valid as $valid_code) {
                if ($this->_code === $valid_code) {
                    return true;
                }
            }
        }

        return PEAR::raiseError('Invalid response code received from server',
                                $this->_code);
    }
예제 #2
0
 /**
  * Read a response from the server and see if the response code
  * matches what we are expecting. Also save the rest of the
  * response in the array passed by reference as the second
  * argument.
  *
  * @param int The response code we are expecting.
  * @param array An array to dump the rest of the response into.
  *
  * @return boolean True if we get what we expect, false otherwise.
  * @access private
  */
 function validateAndParseResponse($code, &$arguments)
 {
     $arguments = array();
     while ($this->lastline = $this->socket->readLine()) {
         $reply_code = strtok($this->lastline, ' ');
         if (!strcmp($code, $reply_code)) {
             $arguments[] = substr($this->lastline, strlen($code) + 1, strlen($this->lastline) - strlen($code) - 1);
             $this->code = $reply_code;
             return true;
         } else {
             $reply_code = strtok($this->lastline, '-');
             if (strcmp($code, $reply_code)) {
                 $this->code = $reply_code;
                 return false;
             }
         }
         $arguments[] = substr($this->lastline, strlen($code) + 1, strlen($this->lastline) - strlen($code) - 1);
     }
     return false;
 }
예제 #3
0
파일: SMTP.php 프로젝트: alecpl/Net_SMTP
 /**
  * Read a reply from the SMTP server.  The reply consists of a response
  * code and a response message.
  *
  * @param mixed $valid The set of valid response codes.  These
  *                     may be specified as an array of integer
  *                     values or as a single integer value.
  * @param bool  $later Do not parse the response now, but wait
  *                     until the last command in the pipelined
  *                     command group
  *
  * @return mixed True if the server returned a valid response code or
  *               a PEAR_Error object is an error condition is reached.
  *
  * @since 1.1.0
  *
  * @see getResponse
  */
 protected function parseResponse($valid, $later = false)
 {
     $this->code = -1;
     $this->arguments = array();
     if ($later) {
         $this->pipelined_commands++;
         return true;
     }
     for ($i = 0; $i <= $this->pipelined_commands; $i++) {
         while ($line = $this->socket->readLine()) {
             $this->debug("Recv: {$line}");
             /* If we receive an empty line, the connection was closed. */
             if (empty($line)) {
                 $this->disconnect();
                 return PEAR::raiseError('Connection was closed');
             }
             /* Read the code and store the rest in the arguments array. */
             $code = substr($line, 0, 3);
             $this->arguments[] = trim(substr($line, 4));
             /* Check the syntax of the response code. */
             if (is_numeric($code)) {
                 $this->code = (int) $code;
             } else {
                 $this->code = -1;
                 break;
             }
             /* If this is not a multiline response, we're done. */
             if (substr($line, 3, 1) != '-') {
                 break;
             }
         }
     }
     $this->pipelined_commands = 0;
     /* Compare the server's response code with the valid code/codes. */
     if (is_int($valid) && $this->code === $valid) {
         return true;
     } elseif (is_array($valid) && in_array($this->code, $valid, true)) {
         return true;
     }
     return PEAR::raiseError('Invalid response code received from server', $this->code);
 }
예제 #4
0
파일: SMTP.php 프로젝트: kidaa30/yes
 /**
  * Read a reply from the SMTP server.  The reply consists of a response
  * code and a response message.
  *
  * @param   mixed   $valid      The set of valid response codes.  These
  *                              may be specified as an array of integer
  *                              values or as a single integer value.
  * @param   bool    $later      Do not parse the response now, but wait
  *                              until the last command in the pipelined
  *                              command group
  *
  * @return  mixed   True if the server returned a valid response code or
  *                  a PEAR_Error object is an error condition is reached.
  *
  * @access  private
  * @since   1.1.0
  *
  * @see     getResponse
  */
 function _parseResponse($valid, $later = false)
 {
     $this->_code = -1;
     $this->_arguments = array();
     if ($later) {
         $this->_pipelined_commands++;
         return true;
     }
     for ($i = 0; $i <= $this->_pipelined_commands; $i++) {
         while ($line = $this->_socket->readLine()) {
             $this->_debug("Recv: {$line}");
             /* If we receive an empty line, the connection was closed. */
             if (empty($line)) {
                 $this->disconnect();
                 return PEAR::raiseError('Connection was closed', null, PEAR_ERROR_RETURN);
             }
             /* Read the code and store the rest in the arguments array. */
             $code = substr($line, 0, 3);
             $this->_arguments[] = trim(substr($line, 4));
             /* Check the syntax of the response code. */
             if (is_numeric($code)) {
                 $this->_code = (int) $code;
             } else {
                 $this->_code = -1;
                 break;
             }
             /* If this is not a multiline response, we're done. */
             if (substr($line, 3, 1) != '-') {
                 break;
             }
         }
     }
     $this->_pipelined_commands = 0;
     /* Compare the server's response code with the valid code/codes. */
     if (is_int($valid) && $this->_code === $valid) {
         return true;
     } elseif (is_array($valid) && in_array($this->_code, $valid, true)) {
         return true;
     }
     // CRM-8744
     $errorMessage = 'Invalid response code received from SMTP server while sending email.  This is often caused by a misconfiguration in Outbound Email settings. Please verify the settings at Administer CiviCRM >> Global Settings >> Outbound Email (SMTP).';
     return PEAR::raiseError($errorMessage, $this->_code, PEAR_ERROR_RETURN);
 }
예제 #5
0
 /**
  * Read a reply from the SMTP server.  The reply consists of a response
  * code and a response message.
  *
  * @param   mixed   $valid      The set of valid response codes.  These
  *                              may be specified as an array of integer
  *                              values or as a single integer value.
  * @param   bool    $later      Do not parse the response now, but wait
  *                              until the last command in the pipelined
  *                              command group
  *
  * @return  mixed   True if the server returned a valid response code or
  *                  a PEAR_Error object is an error condition is reached.
  *
  * @access  private
  * @since   1.1.0
  *
  * @see     getResponse
  */
 function _parseResponse($valid, $later = false)
 {
     $this->_code = -1;
     $this->_arguments = array();
     if ($later) {
         $this->_pipelined_commands++;
         return true;
     }
     for ($i = 0; $i <= $this->_pipelined_commands; $i++) {
         while ($line = $this->_socket->readLine()) {
             $this->_debug("Recv: {$line}");
             /* If we receive an empty line, the connection has been closed. */
             if (empty($line)) {
                 $this->disconnect();
                 return PEAR::raiseError('Connection was unexpectedly closed');
             }
             /* Read the code and store the rest in the arguments array. */
             $code = substr($line, 0, 3);
             $this->_arguments[] = trim(substr($line, 4));
             /* Check the syntax of the response code. */
             if (is_numeric($code)) {
                 $this->_code = (int) $code;
             } else {
                 $this->_code = -1;
                 break;
             }
             /* If this is not a multiline response, we're done. */
             if (substr($line, 3, 1) != '-') {
                 break;
             }
         }
     }
     $this->_pipelined_commands = 0;
     /* Server response code 553 => Requested action not taken-Mailbox name invalid.
      * Server response code 503 => Bad sequence of commands.
      */
     if ($this->_code == 553 || $this->_code == 503 || $this->_code == 501) {
         return PEAR::raiseError('recipient is not recognized');
     }
     /* Compare the server's response code with the valid code/codes. */
     if (is_int($valid) && $this->_code === $valid) {
         return true;
     } elseif (is_array($valid) && in_array($this->_code, $valid, true)) {
         return true;
     }
     /* 535: Authentication failed */
     if ($this->_code == 535) {
         $this->disconnect();
         return PEAR::raiseError('Authentication failed.');
     }
     $errorMessage = 'Invalid response code received from SMTP (outbound mail) server while attempting to send email.  This is often caused by a misconfiguration in the CiviCRM Outbound Email settings. Please verify the settings at Administer CiviCRM >> Global Settings >> Outbound Email (SMTP).';
     return PEAR::raiseError($errorMessage);
 }