Changeset 992 in subversion


Ignore:
Timestamp:
Feb 2, 2008 9:03:38 AM (5 years ago)
Author:
till
Message:
  • replace more double with single-quotes
  • some cs
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/lib/imap.inc

    r991 r992  
    5858 * @todo Split this file into smaller files. 
    5959 * @todo Refactor code. 
     60 * @todo Replace echo-debugging (make it adhere to config setting and log) 
    6061 */ 
    6162 
     
    563564 
    564565function iil_C_LoadCache(&$conn, $folder) { 
    565         if (!$conn->do_cache) return false; 
    566          
    567         $key = $folder.".imap"; 
     566        if (!$conn->do_cache) { 
     567            return false; 
     568        } 
     569     
     570        $key = $folder.'.imap'; 
    568571        if (!is_array($conn->cache[$folder])) { 
    569                 $conn->cache[$folder] = cache_read($conn->user, $conn->host, $key); 
     572                $conn->cache[$folder]       = cache_read($conn->user, $conn->host, $key); 
    570573                $conn->cache_dirty[$folder] = false; 
    571574        } 
     
    574577function iil_C_ExpireCachedItems(&$conn, $folder, $message_set) { 
    575578         
    576         if (!$conn->do_cache) return;   //caching disabled 
    577         if (!is_array($conn->cache[$folder])) return;   //cache not initialized|empty 
    578         if (count($conn->cache[$folder]) == 0) return;  //cache not initialized|empty 
    579                  
    580         $uids = iil_C_FetchHeaderIndex($conn, $folder, $message_set, "UID"); 
     579        if (!$conn->do_cache) { 
     580            return;     //caching disabled 
     581        } 
     582    if (!is_array($conn->cache[$folder])) { 
     583        return; //cache not initialized|empty 
     584        } 
     585    if (count($conn->cache[$folder]) == 0) { 
     586        return; //cache not initialized|empty 
     587    } 
     588     
     589        $uids = iil_C_FetchHeaderIndex($conn, $folder, $message_set, 'UID'); 
    581590        $num_removed = 0; 
    582591        if (is_array($uids)) { 
     
    609618 
    610619function iil_ExplodeQuotedString($delimiter, $string) { 
    611         $quotes=explode("\"", $string); 
    612         while ( list($key, $val) = each($quotes)) 
    613                 if (($key % 2) == 1)  
     620        $quotes=explode('"', $string); 
     621        while ( list($key, $val) = each($quotes)) { 
     622                if (($key % 2) == 1) { 
    614623                        $quotes[$key] = str_replace($delimiter, "_!@!_", $quotes[$key]); 
    615         $string=implode("\"", $quotes); 
     624        } 
     625    } 
     626        $string=implode('"', $quotes); 
    616627         
    617628        $result=explode($delimiter, $string); 
    618         while ( list($key, $val) = each($result) ) 
    619                 $result[$key] = str_replace("_!@!_", $delimiter, $result[$key]); 
    620          
     629        while ( list($key, $val) = each($result) ) { 
     630                $result[$key] = str_replace('_!@!_', $delimiter, $result[$key]); 
     631        } 
     632     
    621633        return $result; 
    622634} 
     
    634646                        $line=chop(iil_ReadLine($fp, 300)); 
    635647                        $a=explode(' ', $line); 
    636                         if (($a[0] == '*') && (strcasecmp($a[2], "RECENT") == 0)) { 
     648                        if (($a[0] == '*') && (strcasecmp($a[2], 'RECENT') == 0)) { 
    637649                            $result = (int) $a[1]; 
    638650            } 
    639                 } while (!iil_StartsWith($a[0],"a002")); 
     651                } while (!iil_StartsWith($a[0], 'a002')); 
    640652 
    641653                fputs($fp, "a003 LOGOUT\r\n"); 
     
    665677                        $a=explode(' ', $line); 
    666678                        if (count($a) == 3) { 
    667                                 if (strcasecmp($a[2], "EXISTS") == 0) $conn->exists=(int)$a[1]; 
    668                                 if (strcasecmp($a[2], "RECENT") == 0) $conn->recent=(int)$a[1]; 
     679                                if (strcasecmp($a[2], 'EXISTS') == 0) { 
     680                                    $conn->exists = (int) $a[1]; 
     681                                } 
     682                if (strcasecmp($a[2], 'RECENT') == 0) { 
     683                    $conn->recent = (int) $a[1]; 
     684                } 
    669685                        } 
    670                 } while (!iil_StartsWith($line, "sel1")); 
     686                } while (!iil_StartsWith($line, 'sel1')); 
    671687 
    672688                $a=explode(' ', $line); 
    673689 
    674                 if (strcasecmp($a[1],"OK") == 0) { 
     690                if (strcasecmp($a[1], 'OK') == 0) { 
    675691                        $conn->selected = $mailbox; 
    676692                        return true; 
     
    727743        //replace double spaces with single space 
    728744        $str = trim($str); 
    729         $str = str_replace("  ", " ", $str); 
     745        $str = str_replace('  ', ' ', $str); 
    730746         
    731747        //strip off day of week 
    732         $pos=strpos($str, " "); 
     748        $pos=strpos($str, ' '); 
    733749        if (!is_numeric(substr($str, 0, $pos))) { 
    734750            $str = substr($str, $pos+1); 
     
    744760        $tz_str    = $a[4]; 
    745761        $tz        = substr($tz_str, 0, 3); 
    746         $ta        = explode(":",$time); 
     762        $ta        = explode(':', $time); 
    747763        $hour      = (int)$ta[0]-(int)$tz; 
    748764        $minute    = (int)$ta[1]; 
     
    756772 
    757773function iil_C_Sort(&$conn, $mailbox, $field, $add='', $is_uid=FALSE, 
    758     $encoding='US-ASCII') { 
     774    $encoding = 'US-ASCII') { 
    759775        /*  Do "SELECT" command */ 
    760776        if (!iil_C_Select($conn, $mailbox)) { 
     
    787803        do { 
    788804                $line = chop(iil_ReadLine($fp, 1024)); 
    789                 if (iil_StartsWith($line, '* SORT')) $data.=($data?' ':'').substr($line,7); 
     805                if (iil_StartsWith($line, '* SORT')) { 
     806                    $data .= ($data?' ':'') . substr($line, 7); 
     807        } 
    790808        } while ($line[0]!='s'); 
    791809         
     
    915933                do { 
    916934                        $line=chop(iil_ReadLine($fp, 200)); 
    917                         if ($line[0]=="*") { 
    918                                 //original: "* 10 FETCH (INTERNALDATE "31-Jul-2002 09:18:02 -0500")" 
    919                                 $paren_pos = strpos($line, "("); 
    920                                 $foo = substr($line, 0, $paren_pos); 
    921                                 $a = explode(' ', $foo); 
    922                                 $id = $a[1]; 
     935                        if ($line[0] == '*') { 
     936                                /* 
     937                                 * original: 
     938                                 * "* 10 FETCH (INTERNALDATE "31-Jul-2002 09:18:02 -0500")" 
     939                                 */ 
     940                                $paren_pos = strpos($line, '('); 
     941                                $foo       = substr($line, 0, $paren_pos); 
     942                                $a         = explode(' ', $foo); 
     943                                $id        = $a[1]; 
    923944                                 
    924                                 $open_pos = strpos($line, "\"") + 1; 
    925                                 $close_pos = strrpos($line, "\""); 
     945                                $open_pos  = strpos($line, '"') + 1; 
     946                                $close_pos = strrpos($line, '"'); 
    926947                                if ($open_pos && $close_pos) { 
    927                                         $len = $close_pos - $open_pos; 
    928                                         $time_str = substr($line, $open_pos, $len); 
     948                                        $len         = $close_pos - $open_pos; 
     949                                        $time_str    = substr($line, $open_pos, $len); 
    929950                                        $result[$id] = strtotime($time_str); 
    930951                                } 
     
    10201041                $incr = $id - $prev; 
    10211042                if ($incr>1) {                  //found a gap 
    1022                         if ($start==$prev) $result[] = $prev;   //push single id 
    1023                         else $result[] = $start.':'.$prev;              //push sequence as start_id:end_id 
    1024                         $start = $id;                                                   //start of new sequence 
     1043                        if ($start==$prev) { 
     1044                            $result[] = $prev;  //push single id 
     1045                        } else { 
     1046                            $result[] = $start.':'.$prev;               //push sequence as start_id:end_id 
     1047                        } 
     1048            $start = $id;                                                       //start of new sequence 
    10251049                } 
    10261050                $prev = $id; 
     
    10591083            return array(); 
    10601084    } 
    1061         $message_set = '1'.($num>1?':'.$num:''); 
     1085        $message_set = '1' . ($num>1?':' . $num:''); 
    10621086         
    10631087        //if cache not enabled, just call iil_C_FetchHeaderIndex on 'UID' field 
     
    10751099     
    10761100        //was anything cached at all? 
    1077         if ($data===false) { 
     1101        if ($data === false) { 
    10781102            $cache_good = -1; 
    10791103        } 
     
    10991123 
    11001124        //otherwise, we need to fetch it 
    1101         $data      = array('n'=>$num,'d'=>array()); 
     1125        $data      = array('n' => $num, 'd' => array()); 
    11021126        $data['d'] = iil_C_FetchHeaderIndex($conn, $mailbox, $message_set, 'UID'); 
    11031127     
     
    21002124            $i++; 
    21012125                } 
    2102         } while (!iil_StartsWith($line, "lmb")); 
     2126        } while (!iil_StartsWith($line, 'lmb')); 
    21032127 
    21042128        if (is_array($folders)) { 
     
    21682192            $i++; 
    21692193                } 
    2170         } while (!iil_StartsWith($line, "lsb")); 
     2194        } while (!iil_StartsWith($line, 'lsb')); 
    21712195 
    21722196        if (is_array($folders)) { 
     
    22672291            $line = chop(iil_ReadLine($fp, 1000)); 
    22682292            $a    = explode(' ', $line); 
    2269         } while ($a[2]!="FETCH"); 
     2293        } while ($a[2] != 'FETCH'); 
    22702294        $len = strlen($line); 
    22712295        if ($line[$len-1] == ')') { 
     
    23182342        return false; 
    23192343        } else { 
    2320                 echo "Select failed."; 
     2344                echo 'Select failed.'; 
    23212345        } 
    23222346     
     
    23412365function iil_C_CreateFolder(&$conn, $folder) { 
    23422366        $fp = $conn->fp; 
    2343         if (fputs($fp, "c CREATE \"".$folder."\"\r\n")) { 
     2367        if (fputs($fp, 'c CREATE "' . $folder . '"' . "\r\n")) { 
    23442368                do { 
    23452369                        $line=iil_ReadLine($fp, 300); 
    2346                 } while ($line[0]!="c"); 
     2370                } while ($line[0] != 'c'); 
    23472371        $conn->error = $line; 
    23482372                return (iil_ParseResult($line) == 0); 
     
    23532377function iil_C_RenameFolder(&$conn, $from, $to) { 
    23542378        $fp = $conn->fp; 
    2355         if (fputs($fp, "r RENAME \"".$from."\" \"".$to."\"\r\n")) { 
     2379        if (fputs($fp, 'r RENAME "' . $from . '" "' . $to . '"' . "\r\n")) { 
    23562380                do { 
    23572381                        $line=iil_ReadLine($fp, 300); 
     
    23642388function iil_C_DeleteFolder(&$conn, $folder) { 
    23652389        $fp = $conn->fp; 
    2366         if (fputs($fp, "d DELETE \"".$folder."\"\r\n")) { 
     2390        if (fputs($fp, 'd DELETE "' . $folder. '"' . "\r\n")) { 
    23672391                do { 
    23682392                        $line=iil_ReadLine($fp, 300); 
     
    23962420                $result = (iil_ParseResult($line) == 0); 
    23972421                if (!$result) { 
    2398                     $conn->error .= $line."\n"; 
     2422                    $conn->error .= $line . "\n"; 
    23992423        } 
    24002424                return $result; 
     
    24142438        $in_fp = false;                          
    24152439        if (file_exists(realpath($path))) { 
    2416             $in_fp = fopen($path, "r"); 
     2440            $in_fp = fopen($path, 'r'); 
    24172441    } 
    24182442        if (!$in_fp) {  
     
    24502474                $result = (iil_ParseResult($line) == 0); 
    24512475                if (!$result) { 
    2452                     $conn->error .= $line."\n"; 
     2476                    $conn->error .= $line . "\n"; 
    24532477                } 
    24542478        return $result; 
     
    25142538         
    25152539        //get line containing quota info 
    2516         if (fputs($fp, "QUOT1 GETQUOTAROOT \"INBOX\"\r\n")) { 
     2540        if (fputs($fp, 'QUOT1 GETQUOTAROOT "INBOX"' . "\r\n")) { 
    25172541                do { 
    25182542                        $line=chop(iil_ReadLine($fp, 5000)); 
    2519                         if (iil_StartsWith($line, "* QUOTA ")) { 
     2543                        if (iil_StartsWith($line, '* QUOTA ')) { 
    25202544                            $quota_line = $line; 
    25212545            } 
    2522                 } while (!iil_StartsWith($line, "QUOT1")); 
     2546                } while (!iil_StartsWith($line, 'QUOT1')); 
    25232547        } 
    25242548         
    25252549        //return false if not found, parse if found 
    25262550        if (!empty($quota_line)) { 
    2527                 $quota_line = eregi_replace("[()]", '', $quota_line); 
     2551                $quota_line = eregi_replace('[()]', '', $quota_line); 
    25282552                $parts = explode(' ', $quota_line); 
    2529                 $storage_part = array_search("STORAGE", $parts); 
     2553                $storage_part = array_search('STORAGE', $parts); 
    25302554                if ($storage_part>0) { 
    25312555                        $result = array(); 
Note: See TracChangeset for help on using the changeset viewer.