Changeset 4367 in subversion


Ignore:
Timestamp:
Dec 23, 2010 1:25:18 PM (2 years ago)
Author:
alec
Message:
  • Add debug handler support in rcube_imap_generic
Location:
trunk/roundcubemail/program/include
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/rcmail.php

    r4363 r4367  
    504504      'auth_cid'    => $this->config->get('imap_auth_cid'), 
    505505      'auth_pw'     => $this->config->get('imap_auth_pw'), 
    506       'debug_mode'  => (bool) $this->config->get('imap_debug', 0), 
     506      'debug'       => (bool) $this->config->get('imap_debug', 0), 
    507507      'force_caps'  => (bool) $this->config->get('imap_force_caps'), 
    508508      'timeout'     => (int) $this->config->get('imap_timeout', 0), 
  • trunk/roundcubemail/program/include/rcube_imap.php

    r4344 r4367  
    149149        $this->options['port'] = $port; 
    150150 
     151        if ($this->options['debug']) 
     152            $this->conn->setDebug(true, array($this, 'debug_handler')); 
     153 
    151154        $attempt = 0; 
    152155        do { 
     
    224227    function get_error_code() 
    225228    { 
    226         return ($this->conn) ? $this->conn->errornum : 0; 
     229        return $this->conn->errornum; 
    227230    } 
    228231 
     
    235238    function get_error_str() 
    236239    { 
    237         return ($this->conn) ? $this->conn->error : null; 
     240        return $this->conn->error; 
    238241    } 
    239242 
     
    246249    function get_response_code() 
    247250    { 
    248         if (!$this->conn) 
    249             return self::UNKNOWN; 
    250  
    251251        switch ($this->conn->resultcode) { 
    252252            case 'NOPERM': 
     
    279279    function get_response_str() 
    280280    { 
    281         return ($this->conn) ? $this->conn->result : null; 
     281        return $this->conn->result; 
    282282    } 
    283283 
     
    547547        $imap_delimiter = $config->get('imap_delimiter'); 
    548548 
    549         if (!$this->conn) 
     549        if (!$this->conn->connected()) 
    550550            return; 
    551551 
     
    47414741    } 
    47424742 
     4743 
     4744    /** 
     4745     * This is our own debug handler for the IMAP connection 
     4746     * @access public 
     4747     */ 
     4748    public function debug_handler(&$imap, $message) 
     4749    { 
     4750        write_log('imap', $message); 
     4751    } 
     4752 
    47434753}  // end class rcube_imap 
    47444754 
  • trunk/roundcubemail/program/include/rcube_imap_generic.php

    r4360 r4367  
    110110    private $cmd_tag; 
    111111    private $cmd_num = 0; 
     112    private $_debug = false; 
     113    private $_debug_handler = false; 
    112114 
    113115    const ERROR_OK = 0; 
     
    143145            return false; 
    144146 
    145         if (!empty($this->prefs['debug_mode'])) { 
    146             write_log('imap', 'C: '. rtrim($string)); 
     147        if ($this->_debug) { 
     148            $this->debug('C: '. rtrim($string)); 
    147149        } 
    148150 
     
    232234                break; 
    233235            } 
    234             if (!empty($this->prefs['debug_mode'])) { 
    235                 write_log('imap', 'S: '. rtrim($buffer)); 
     236            if ($this->_debug) { 
     237                $this->debug('S: '. rtrim($buffer)); 
    236238            } 
    237239            $line .= $buffer; 
     
    269271        { 
    270272            $d = fread($this->fp, $bytes-$len); 
    271             if (!empty($this->prefs['debug_mode'])) { 
    272                 write_log('imap', 'S: '. $d); 
     273            if ($this->_debug) { 
     274                $this->debug('S: '. $d); 
    273275            } 
    274276            $data .= $d; 
     
    687689        $line = trim(fgets($this->fp, 8192)); 
    688690 
    689         if ($this->prefs['debug_mode'] && $line) { 
    690             write_log('imap', 'S: '. $line); 
     691        if ($this->_debug && $line) { 
     692            $this->debug('S: '. $line); 
    691693        } 
    692694 
     
    32393241    } 
    32403242 
     3243    /** 
     3244     * Set the value of the debugging flag. 
     3245     * 
     3246     * @param   boolean $debug      New value for the debugging flag. 
     3247     * 
     3248     * @access  public 
     3249     * @since   0.5-stable 
     3250     */ 
     3251    function setDebug($debug, $handler = null) 
     3252    { 
     3253        $this->_debug = $debug; 
     3254        $this->_debug_handler = $handler; 
     3255    } 
     3256 
     3257    /** 
     3258     * Write the given debug text to the current debug output handler. 
     3259     * 
     3260     * @param   string  $message    Debug mesage text. 
     3261     * 
     3262     * @access  private 
     3263     * @since   0.5-stable 
     3264     */ 
     3265    private function debug($message) 
     3266    { 
     3267        if ($this->_debug_handler) { 
     3268            call_user_func_array($this->_debug_handler, array(&$this, $message)); 
     3269        } else { 
     3270            echo "DEBUG: $message\n"; 
     3271        } 
     3272    } 
     3273 
    32413274} 
Note: See TracChangeset for help on using the changeset viewer.