Changeset 5228a55 in github


Ignore:
Timestamp:
Mar 11, 2011 3:55:20 AM (2 years ago)
Author:
alecpl <alec@…>
Children:
382b8b1
Parents:
2430846
Message:
  • Applied fixes from trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    r2430846 r5228a55  
    22=========================== 
    33 
     4- PEAR::Net_SMTP 1.5.1 
     5- Force names of unique constraints in PostgreSQL DDL 
     6- Add code for prevention from IMAP connection hangs when server closes socket unexpectedly 
     7- Remove redundant DELETE query (for old session deletion) on login 
     8- Get around unreliable rand() and mt_rand() in session ID generation (#1486281) 
    49- Fix some emails are not shown using Cyrus IMAP (#1487820) 
    510- Fix handling of mime-encoded words with non-integral number of octets in a word (#1487801) 
  • SQL/postgres.initial.sql

    r6f09681 r5228a55  
    2626    "language" varchar(5), 
    2727    preferences text DEFAULT ''::text NOT NULL, 
    28     UNIQUE (username, mail_host) 
     28    CONSTRAINT users_username_key UNIQUE (username, mail_host) 
    2929); 
    3030 
     
    218218    headers text NOT NULL, 
    219219    structure text, 
    220     UNIQUE (user_id, cache_key, uid) 
     220    CONSTRAINT messages_user_id_key UNIQUE (user_id, cache_key, uid) 
    221221); 
    222222 
  • SQL/postgres.update.sql

    r98cb0f1 r5228a55  
    8686 
    8787DROP INDEX users_username_id_idx; 
    88 ALTER TABLE users ADD UNIQUE (username, mail_host); 
     88ALTER TABLE users ADD CONSTRAINT users_username_key UNIQUE (username, mail_host); 
    8989ALTER TABLE contacts ALTER email TYPE varchar(255); 
    9090 
  • index.php

    rb46e5b74 r5228a55  
    9696  else if ($auth['valid'] && !$auth['abort'] && 
    9797        !empty($auth['host']) && !empty($auth['user']) && 
    98         $RCMAIL->login($auth['user'], $auth['pass'], $auth['host'])) { 
    99     // create new session ID 
     98        $RCMAIL->login($auth['user'], $auth['pass'], $auth['host']) 
     99  ) { 
     100    // create new session ID, don't destroy the current session 
     101    // it was destroyed already by $RCMAIL->kill_session() above 
    100102    $RCMAIL->session->remove('temp'); 
    101     $RCMAIL->session->regenerate_id(); 
     103    $RCMAIL->session->regenerate_id(false); 
    102104 
    103105    // send auth cookie if necessary 
     
    111113    if ($url = get_input_value('_url', RCUBE_INPUT_POST)) { 
    112114      parse_str($url, $query); 
    113        
     115 
    114116      // prevent endless looping on login page 
    115117      if ($query['_task'] == 'login') 
  • program/include/rcube_imap_generic.php

    r2430846 r5228a55  
    214214        $line = ''; 
    215215 
    216         if (!$this->fp) { 
    217             return NULL; 
    218         } 
    219  
    220216        if (!$size) { 
    221217            $size = 1024; 
     
    223219 
    224220        do { 
    225             if (feof($this->fp)) { 
     221            if ($this->eof()) { 
    226222                return $line ? $line : NULL; 
    227223            } 
     
    230226 
    231227            if ($buffer === false) { 
    232                 @fclose($this->fp); 
    233                 $this->fp = null; 
     228                $this->closeSocket(); 
    234229                break; 
    235230            } 
     
    238233            } 
    239234            $line .= $buffer; 
    240         } while ($buffer[strlen($buffer)-1] != "\n"); 
     235        } while (substr($buffer, -1) != "\n"); 
    241236 
    242237        return $line; 
     
    268263        $data = ''; 
    269264        $len  = 0; 
    270         while ($len < $bytes && !feof($this->fp)) 
     265        while ($len < $bytes && !$this->eof()) 
    271266        { 
    272267            $d = fread($this->fp, $bytes-$len); 
     
    313308                $this->errornum = self::ERROR_BAD; 
    314309            } else if ($res == 'BYE') { 
    315                 @fclose($this->fp); 
    316                 $this->fp = null; 
     310                $this->closeSocket(); 
    317311                $this->errornum = self::ERROR_BYE; 
    318312            } 
     
    340334    } 
    341335 
     336    private function eof() 
     337    { 
     338        if (!is_resource($this->fp)) { 
     339            return true; 
     340        } 
     341 
     342        // If a connection opened by fsockopen() wasn't closed 
     343        // by the server, feof() will hang. 
     344        $start = microtime(true); 
     345 
     346        if (feof($this->fp) ||  
     347            ($this->prefs['timeout'] && (microtime(true) - $start > $this->prefs['timeout'])) 
     348        ) { 
     349            $this->closeSocket(); 
     350            return true; 
     351        } 
     352 
     353        return false; 
     354    } 
     355 
     356    private function closeSocket() 
     357    { 
     358        @fclose($this->fp); 
     359        $this->fp = null; 
     360    } 
     361 
    342362    function setError($code, $msg='') 
    343363    { 
     
    361381        if ($error && preg_match('/^\* (BYE|BAD) /i', $string, $m)) { 
    362382            if (strtoupper($m[1]) == 'BYE') { 
    363                 @fclose($this->fp); 
    364                 $this->fp = null; 
     383                $this->closeSocket(); 
    365384            } 
    366385            return true; 
     
    702721        } 
    703722 
     723        if ($this->prefs['timeout'] <= 0) { 
     724            $this->prefs['timeout'] = ini_get('default_socket_timeout'); 
     725        } 
     726 
    704727        // Connect 
    705         if ($this->prefs['timeout'] > 0) 
    706             $this->fp = @fsockopen($host, $this->prefs['port'], $errno, $errstr, $this->prefs['timeout']); 
    707         else 
    708             $this->fp = @fsockopen($host, $this->prefs['port'], $errno, $errstr); 
     728        $this->fp = @fsockopen($host, $this->prefs['port'], $errno, $errstr, $this->prefs['timeout']); 
    709729 
    710730        if (!$this->fp) { 
     
    856876        } 
    857877 
    858         @fclose($this->fp); 
    859         $this->fp = false; 
     878        $this->closeSocket(); 
    860879    } 
    861880 
  • program/include/rcube_session.php

    rb46e5b74 r5228a55  
    184184 
    185185 
    186   public function regenerate_id() 
    187   { 
    188     $randval = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; 
    189  
    190     for ($random = '', $i=1; $i <= 32; $i++) { 
    191       $random .= substr($randval, mt_rand(0,(strlen($randval) - 1)), 1); 
    192     } 
    193  
    194     // use md5 value for id or remove capitals from string $randval 
    195     $random = md5($random); 
    196  
    197     // delete old session record 
    198     $this->destroy(session_id()); 
    199  
    200     session_id($random); 
    201  
    202     $cookie   = session_get_cookie_params(); 
    203     $lifetime = $cookie['lifetime'] ? time() + $cookie['lifetime'] : 0; 
    204  
    205     rcmail::setcookie(session_name(), $random, $lifetime); 
    206  
     186  public function regenerate_id($destroy=true) 
     187  { 
     188    session_regenerate_id($destroy); 
     189 
     190    $this->vars = false; 
     191    $this->key  = session_id(); 
    207192    return true; 
    208193  } 
  • program/lib/Net/SMTP.php

    r14015da r5228a55  
    107107 
    108108    /** 
     109     * The socket I/O timeout value in seconds. 
     110     * @var int 
     111     * @access private 
     112     */ 
     113    var $_timeout = 0; 
     114 
     115    /** 
    109116     * The most recent server response code. 
    110117     * @var int 
     
    149156     * @param string  $localhost  The value to give when sending EHLO or HELO. 
    150157     * @param boolean $pipeling   Use SMTP command pipelining 
     158     * @param integer $timeout    Socket I/O timeout in seconds. 
    151159     * 
    152160     * @access  public 
    153161     * @since   1.0 
    154162     */ 
    155     function Net_SMTP($host = null, $port = null, $localhost = null, $pipelining = false) 
     163    function Net_SMTP($host = null, $port = null, $localhost = null, 
     164        $pipelining = false, $timeout = 0) 
    156165    { 
    157166        if (isset($host)) { 
     
    167176 
    168177        $this->_socket = new Net_Socket(); 
     178        $this->_timeout = $timeout; 
    169179 
    170180        /* Include the Auth_SASL package.  If the package is not 
     
    180190 
    181191    /** 
     192     * Set the socket I/O timeout value in seconds plus microseconds. 
     193     * 
     194     * @param   integer $seconds        Timeout value in seconds. 
     195     * @param   integer $microseconds   Additional value in microseconds. 
     196     * 
     197     * @access  public 
     198     * @since   1.5.0 
     199     */ 
     200    function setTimeout($seconds, $microseconds = 0) { 
     201        return $this->_socket->setTimeout($seconds, $microseconds); 
     202    } 
     203 
     204    /** 
    182205     * Set the value of the debugging flag. 
    183206     * 
     
    370393     * 
    371394     * @param   int     $timeout    The timeout value (in seconds) for the 
    372      *                              socket connection. 
     395     *                              socket connection attempt. 
    373396     * @param   bool    $persistent Should a persistent socket connection 
    374397     *                              be used? 
     
    387410            return PEAR::raiseError('Failed to connect socket: ' . 
    388411                                    $result->getMessage()); 
     412        } 
     413 
     414        /* 
     415         * Now that we're connected, reset the socket's timeout value for  
     416         * future I/O operations.  This allows us to have different socket  
     417         * timeout values for the initial connection (our $timeout parameter)  
     418         * and all other socket operations. 
     419         */ 
     420        if (PEAR::isError($error = $this->setTimeout($this->_timeout))) { 
     421            return $error; 
    389422        } 
    390423 
     
    618651        $digest = &Auth_SASL::factory('digestmd5'); 
    619652        $auth_str = base64_encode($digest->getResponse($uid, $pwd, $challenge, 
    620                                                        $this->host, "smtp", $authz)); 
     653                                                       $this->host, "smtp", 
     654                                                       $authz)); 
    621655 
    622656        if (PEAR::isError($error = $this->_put($auth_str))) { 
     
    831865                $args .= ' XVERP=' . $params['verp']; 
    832866            } 
    833         } elseif (is_string($params)) { 
     867        } elseif (is_string($params) && !empty($params)) { 
    834868            $args .= ' ' . $params; 
    835869        } 
     
    920954        } 
    921955 
    922         /* RFC 1870, section 3, subsection 3 states "a value of zero 
    923          * indicates that no fixed maximum message size is in force". 
    924          * Furthermore, it says that if "the parameter is omitted no 
    925          * information is conveyed about the server's fixed maximum 
    926          * message size". */ 
    927         if (isset($this->_esmtp['SIZE']) && ($this->_esmtp['SIZE'] > 0)) { 
    928             /* Start by considering the size of the optional headers string.   
    929              * We also account for the addition 4 character "\r\n\r\n" 
    930              * separator sequence. */ 
    931             $size = (is_null($headers)) ? 0 : strlen($headers) + 4; 
    932  
    933             if (is_resource($data)) { 
    934                 $stat = fstat($data); 
    935                 if ($stat === false) { 
    936                     return PEAR::raiseError('Failed to get file size'); 
    937                 } 
    938                 $size += $stat['size']; 
    939             } else { 
    940                 $size += strlen($data); 
    941             } 
    942  
    943             if ($size >= $this->_esmtp['SIZE']) { 
    944                 $this->disconnect(); 
    945                 return PEAR::raiseError('Message size exceeds server limit'); 
    946             } 
     956        /* Start by considering the size of the optional headers string.  We 
     957         * also account for the addition 4 character "\r\n\r\n" separator 
     958         * sequence. */ 
     959        $size = (is_null($headers)) ? 0 : strlen($headers) + 4; 
     960 
     961        if (is_resource($data)) { 
     962            $stat = fstat($data); 
     963            if ($stat === false) { 
     964                return PEAR::raiseError('Failed to get file size'); 
     965            } 
     966            $size += $stat['size']; 
     967        } else { 
     968            $size += strlen($data); 
     969        } 
     970 
     971        /* RFC 1870, section 3, subsection 3 states "a value of zero indicates 
     972         * that no fixed maximum message size is in force".  Furthermore, it 
     973         * says that if "the parameter is omitted no information is conveyed 
     974         * about the server's fixed maximum message size". */ 
     975        $limit = (isset($this->_esmtp['SIZE'])) ? $this->_esmtp['SIZE'] : 0; 
     976        if ($limit > 0 && $size >= $limit) { 
     977            $this->disconnect(); 
     978            return PEAR::raiseError('Message size exceeds server limit'); 
    947979        } 
    948980 
     
    9751007            } 
    9761008        } else { 
    977             if (!isset($size)) 
    978                 $size = strlen($data); 
    9791009            /* 
    9801010             * Break up the data by sending one chunk (up to 512k) at a time.   
Note: See TracChangeset for help on using the changeset viewer.