Changeset 11ef977 in github


Ignore:
Timestamp:
Sep 2, 2008 8:29:31 AM (5 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
76265ef
Parents:
ade8e11
Message:
  • fixed and re-enabled (RFC3501 [7.1]) CAPABILITY optional response use
Location:
program
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • program/include/rcube_imap.php

    r95987c3 r11ef977  
    6060  var $uid_id_map = array(); 
    6161  var $msg_headers = array(); 
    62   var $capabilities = array(); 
    6362  var $skip_deleted = FALSE; 
    6463  var $search_set = NULL; 
     
    132131    if ($this->conn) 
    133132      { 
    134       $this->_parse_capability($this->conn->capability); 
    135        
    136133      if (!empty($this->conn->delimiter)) 
    137134        $this->delimiter = $this->conn->delimiter; 
     
    330327  function get_capability($cap) 
    331328    { 
    332     $cap = strtoupper($cap); 
    333     return $this->capabilities[$cap]; 
     329    return iil_C_GetCapability($this->conn, strtoupper($cap)); 
    334330    } 
    335331 
     
    25792575     
    25802576    return $uid; 
    2581     } 
    2582  
    2583  
    2584   /** 
    2585    * Parse string or array of server capabilities and put them in internal array 
    2586    * @access private 
    2587    */ 
    2588   function _parse_capability($caps) 
    2589     { 
    2590     if (!is_array($caps)) 
    2591       $cap_arr = explode(' ', $caps); 
    2592     else 
    2593       $cap_arr = $caps; 
    2594      
    2595     foreach ($cap_arr as $cap) 
    2596       { 
    2597       if ($cap=='CAPABILITY') 
    2598         continue; 
    2599  
    2600       if (strpos($cap, '=')>0) 
    2601         { 
    2602         list($key, $value) = explode('=', $cap); 
    2603         if (!is_array($this->capabilities[$key])) 
    2604           $this->capabilities[$key] = array(); 
    2605            
    2606         $this->capabilities[$key][] = $value; 
    2607         } 
    2608       else 
    2609         $this->capabilities[$cap] = TRUE; 
    2610       } 
    26112577    } 
    26122578 
  • program/lib/imap.inc

    r876b15d r11ef977  
    5353                - Removed some debuggers (echo ...) 
    5454                File altered by Aleksander Machniak <alec@alec.pl> 
    55                 - RFC3501 [7.1] don't call CAPABILITY if was returned in server  
    56                   optional resposne in iil_Connect() 
    5755                - trim(chop()) replaced by trim() 
    5856                - added iil_Escape() with support for " and \ in folder names 
     
    6563                - removed flush() calls in iil_C_HandlePartBody() to prevent from memory leak (#1485187) 
    6664                - don't return "??" from iil_C_GetQuota() 
     65                - RFC3501 [7.1] don't call CAPABILITY if was returned in server  
     66                  optional resposne in iil_Connect(), added iil_C_GetCapability() 
    6767 
    6868********************************************************/ 
     
    127127        var $capability = array(); 
    128128        var $permanentflags = array(); 
     129        var $capability_readed = false; 
    129130} 
    130131 
     
    295296} 
    296297 
     298function iil_C_GetCapability(&$conn, $name) 
     299{ 
     300        if (in_array($name, $conn->capability)) { 
     301                return $conn->capability[$name]; 
     302        } 
     303        else if ($conn->capability_readed) { 
     304                return false; 
     305        } 
     306 
     307        // get capabilities (only once) because initial  
     308        // optional CAPABILITY response may differ 
     309        $conn->capability = array(); 
     310 
     311        iil_PutLine($conn->fp, "cp01 CAPABILITY"); 
     312        do { 
     313                $line = trim(iil_ReadLine($conn->fp, 1024)); 
     314                $a = explode(' ', $line); 
     315                if ($line[0] == '*') { 
     316                        while (list($k, $w) = each($a)) { 
     317                                if ($w != '*' && $w != 'CAPABILITY') 
     318                                        $conn->capability[] = strtoupper($w); 
     319                        } 
     320                } 
     321        } while ($a[0] != 'cp01'); 
     322         
     323        $conn->capability_readed = true; 
     324 
     325        if (in_array($name, $conn->capability)) { 
     326                return $conn->capability[$name]; 
     327        } 
     328 
     329        return false; 
     330} 
     331 
    297332function iil_C_Authenticate(&$conn, $user, $pass, $encChallenge) { 
    298333     
     
    399434        global $my_prefs; 
    400435         
    401         if (!in_array('NAMESPACE', $conn->capability)) { 
     436        if (!iil_C_GetCapability($conn, 'NAMESPACE')) { 
    402437            return false; 
    403438        } 
     
    517552 
    518553        // RFC3501 [7.1] optional CAPABILITY response 
    519         // commented out, because it's not working always as should 
    520 //      if (preg_match('/\[CAPABILITY ([^]]+)\]/i', $line, $matches)) { 
    521 //              $conn->capability = explode(' ', $matches[1]); 
    522 //      } else { 
    523                 iil_PutLine($conn->fp, "cp01 CAPABILITY"); 
    524                 do { 
    525                         $line = trim(iil_ReadLine($conn->fp, 1024)); 
    526  
    527                         $conn->message .= "$line\n"; 
    528  
    529                         $a = explode(' ', $line); 
    530                         if ($line[0] == '*') { 
    531                                 while (list($k, $w) = each($a)) { 
    532                                         if ($w != '*' && $w != 'CAPABILITY') 
    533                                         $conn->capability[] = $w; 
    534                                 } 
    535                         } 
    536                 } while ($a[0] != 'cp01'); 
    537 //      } 
     554        if (preg_match('/\[CAPABILITY ([^]]+)\]/i', $line, $matches)) { 
     555                $conn->capability = explode(' ', strtoupper($matches[1])); 
     556        } 
    538557 
    539558        if (strcasecmp($auth_method, "check") == 0) { 
    540559                //check for supported auth methods 
    541                  
    542                 //default to plain text auth 
    543                 $auth_method = 'plain'; 
    544                          
    545                 //check for CRAM-MD5 
    546                 foreach ($conn->capability as $c) 
    547                         if (strcasecmp($c, 'AUTH=CRAM_MD5') == 0 || 
    548                                 strcasecmp($c, 'AUTH=CRAM-MD5') == 0) { 
    549                                 $auth_method = 'auth'; 
    550                                 break; 
    551                         } 
     560                if (iil_C_GetCapability($conn, 'AUTH=CRAM-MD5') || iil_C_GetCapability($conn, 'AUTH=CRAM_MD5')) { 
     561                        $auth_method = 'auth'; 
     562                } 
     563                else { 
     564                        //default to plain text auth 
     565                        $auth_method = 'plain'; 
     566                } 
    552567        } 
    553568 
Note: See TracChangeset for help on using the changeset viewer.