Changeset 4072 in subversion


Ignore:
Timestamp:
Oct 11, 2010 2:37:47 AM (3 years ago)
Author:
alec
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/lib/Net/SMTP.php

    r3339 r4072  
    505505     *               specified, the best supported method will be used. 
    506506     * @param bool   Flag indicating whether or not TLS should be attempted. 
     507     * @param string An optional authorization identifier.  If specified, this 
     508     *               identifier will be used as the authorization proxy. 
    507509     * 
    508510     * @return mixed Returns a PEAR_Error with an error message on any 
     
    511513     * @since  1.0 
    512514     */ 
    513     function auth($uid, $pwd , $method = '', $tls = true) 
     515    function auth($uid, $pwd , $method = '', $tls = true, $authz = '') 
    514516    { 
    515517        /* We can only attempt a TLS connection if one has been requested, 
     
    559561        switch ($method) { 
    560562        case 'DIGEST-MD5': 
    561             $result = $this->_authDigest_MD5($uid, $pwd); 
     563            $result = $this->_authDigest_MD5($uid, $pwd, $authz); 
    562564            break; 
    563565 
     
    571573 
    572574        case 'PLAIN': 
    573             $result = $this->_authPlain($uid, $pwd); 
     575            $result = $this->_authPlain($uid, $pwd, $authz); 
    574576            break; 
    575577 
     
    592594     * @param string The userid to authenticate as. 
    593595     * @param string The password to authenticate with. 
     596     * @param string The optional authorization proxy identifier. 
    594597     * 
    595598     * @return mixed Returns a PEAR_Error with an error message on any 
     
    598601     * @since  1.1.0 
    599602     */ 
    600     function _authDigest_MD5($uid, $pwd) 
     603    function _authDigest_MD5($uid, $pwd, $authz = '') 
    601604    { 
    602605        if (PEAR::isError($error = $this->_put('AUTH', 'DIGEST-MD5'))) { 
     
    615618        $digest = &Auth_SASL::factory('digestmd5'); 
    616619        $auth_str = base64_encode($digest->getResponse($uid, $pwd, $challenge, 
    617                                                        $this->host, "smtp")); 
     620                                                       $this->host, "smtp", $authz)); 
    618621 
    619622        if (PEAR::isError($error = $this->_put($auth_str))) { 
     
    726729     * @param string The userid to authenticate as. 
    727730     * @param string The password to authenticate with. 
     731     * @param string The optional authorization proxy identifier. 
    728732     * 
    729733     * @return mixed Returns a PEAR_Error with an error message on any 
     
    732736     * @since  1.1.0 
    733737     */ 
    734     function _authPlain($uid, $pwd) 
     738    function _authPlain($uid, $pwd, $authz = '') 
    735739    { 
    736740        if (PEAR::isError($error = $this->_put('AUTH', 'PLAIN'))) { 
     
    746750        } 
    747751 
    748         $auth_str = base64_encode(chr(0) . $uid . chr(0) . $pwd); 
     752        $auth_str = base64_encode($authz . chr(0) . $uid . chr(0) . $pwd); 
    749753 
    750754        if (PEAR::isError($error = $this->_put($auth_str))) { 
     
    970974                } 
    971975            } 
    972  
    973             /* Finally, send the DATA terminator sequence. */ 
    974             if (PEAR::isError($result = $this->_send("\r\n.\r\n"))) { 
    975                 return $result; 
    976             } 
    977976        } else { 
    978             /* Just send the entire quoted string followed by the DATA  
    979              * terminator. */ 
    980             $this->quotedata($data); 
    981             if (PEAR::isError($result = $this->_send($data . "\r\n.\r\n"))) { 
    982                 return $result; 
    983             } 
     977            /* 
     978             * Break up the data by sending one chunk (up to 512k) at a time.   
     979             * This approach reduces our peak memory usage. 
     980             */ 
     981            for ($offset = 0; $offset < $size;) { 
     982                $end = $offset + 512000; 
     983 
     984                /* 
     985                 * Ensure we don't read beyond our data size or span multiple  
     986                 * lines.  quotedata() can't properly handle character data  
     987                 * that's split across two line break boundaries. 
     988                 */ 
     989                if ($end >= $size) { 
     990                    $end = $size; 
     991                } else { 
     992                    for (; $end < $size; $end++) { 
     993                        if ($data[$end] != "\n") { 
     994                            break; 
     995                        } 
     996                    } 
     997                } 
     998 
     999                /* Extract our chunk and run it through the quoting routine. */ 
     1000                $chunk = substr($data, $offset, $end - $offset); 
     1001                $this->quotedata($chunk); 
     1002 
     1003                /* If we run into a problem along the way, abort. */ 
     1004                if (PEAR::isError($result = $this->_send($chunk))) { 
     1005                    return $result; 
     1006                } 
     1007 
     1008                /* Advance the offset to the end of this chunk. */ 
     1009                $offset = $end; 
     1010            } 
     1011        } 
     1012 
     1013        /* Finally, send the DATA terminator sequence. */ 
     1014        if (PEAR::isError($result = $this->_send("\r\n.\r\n"))) { 
     1015            return $result; 
    9841016        } 
    9851017 
Note: See TracChangeset for help on using the changeset viewer.