Changeset 3d695da in github


Ignore:
Timestamp:
Feb 12, 2008 7:48:39 PM (5 years ago)
Author:
till <till@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
2f93b03
Parents:
8b661f6
Message:
  • cs fixes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/lib/imap.inc

    ra9a8ef2 r3d695da  
    5757/** 
    5858 * @todo Possibly clean up more CS. 
     59 * @todo Try to replace most double-quotes with single-quotes. 
    5960 * @todo Split this file into smaller files. 
    6061 * @todo Refactor code. 
     
    6364 
    6465// changed path to work within roundcube webmail 
    65 include_once("lib/icl_commons.inc"); 
     66include_once 'lib/icl_commons.inc'; 
    6667 
    6768 
     
    254255    // initialize ipad, opad 
    255256    for ($i=0;$i<64;$i++) { 
    256         $ipad .=chr(0x36); 
    257         $opad .=chr(0x5C); 
     257        $ipad .= chr(0x36); 
     258        $opad .= chr(0x5C); 
    258259    } 
    259260    // pad $pass so it's 64 bytes 
     
    265266    // generate hash 
    266267    $hash  = iil_xor($pass,$opad); 
    267     $hash .= pack("H*",md5(iil_xor($pass, $ipad) . base64_decode($encChallenge))); 
     268    $hash .= pack("H*", md5(iil_xor($pass, $ipad) . base64_decode($encChallenge))); 
    268269    $hash  = md5($hash); 
    269270     
     
    457458        //check for SSL 
    458459        if ($ICL_SSL) { 
    459                 $host = $ICL_SSL."://".$host; 
     460                $host = $ICL_SSL . '://' . $host; 
    460461        } 
    461462         
     
    475476                 
    476477                //default to plain text auth 
    477                 $auth_method = "plain"; 
     478                $auth_method = 'plain'; 
    478479                         
    479480                //check for CRAM-MD5 
     
    481482                do { 
    482483                    $line = trim(chop(iil_ReadLine($conn->fp, 100))); 
    483                     $conn->message.="$line\n"; 
     484 
     485                    $conn->message .= "$line\n"; 
     486 
    484487                        $a = explode(' ', $line); 
    485                         if ($line[0]=="*") { 
    486                                 while ( list($k, $w) = each($a) ) { 
    487                                     if ($w!='*' && $w!='CAPABILITY') { 
     488                        if ($line[0] == '*') { 
     489                                while (list($k, $w) = each($a)) { 
     490                                    if ($w != '*' && $w != 'CAPABILITY') { 
    488491                                        $conn->capability[] = $w; 
    489492                    } 
     
    494497                                } 
    495498                        } 
    496                 } while ($a[0]!="cp01"); 
    497         } 
    498  
    499         if (strcasecmp($auth_method, "auth") == 0) { 
     499                } while ($a[0] != 'cp01'); 
     500        } 
     501 
     502        if (strcasecmp($auth_method, 'auth') == 0) { 
    500503                $conn->message .= "Trying CRAM-MD5\n"; 
     504 
    501505                //do CRAM-MD5 authentication 
    502506                fputs($conn->fp, "a000 AUTHENTICATE CRAM-MD5\r\n"); 
    503507                $line = trim(chop(iil_ReadLine($conn->fp, 1024))); 
    504508         
    505                 $conn->message.="$line\n"; 
     509                $conn->message .= "$line\n"; 
    506510         
    507                 if ($line[0] == "+") { 
    508                         $conn->message .= 'Got challenge: ' . htmlspecialchars($line)."\n"; 
     511                if ($line[0] == '+') { 
     512                        $conn->message .= 'Got challenge: ' . htmlspecialchars($line) . "\n"; 
    509513 
    510514                        //got a challenge string, try CRAM-5 
     
    761765    } 
    762766        //explode, take good parts 
    763         $a=explode(' ',$str); 
     767        $a = explode(' ', $str); 
    764768 
    765769        $month_str = $a[1]; 
     
    791795            $field = 'ARRIVAL'; 
    792796    } 
    793         $fields = array('ARRIVAL'=>1,'CC'=>1,'DATE'=>1,'FROM'=>1,'SIZE'=>1, 
    794  'SUBJECT'=>1,'TO'=>1); 
     797        $fields = array('ARRIVAL' => 1,'CC' => 1,'DATE' => 1, 
     798        'FROM' => 1, 'SIZE' => 1, 'SUBJECT' => 1, 'TO' => 1); 
    795799         
    796800        if (!$fields[$field]) { 
     
    804808    } 
    805809 
    806         $fp      = $conn->fp; 
    807         $command = 's '. $is_uid .'SORT ('.$field.') '.$encoding.' ALL'."$add\r\n"; 
    808         $line    = $data = ''; 
     810        $fp       = $conn->fp; 
     811        $command  = 's ' . $is_uid . 'SORT (' . $field . ') '; 
     812    $command .= $encoding . ' ALL' . "$add\r\n"; 
     813        $line     = $data = ''; 
    809814         
    810815        if (!fputs($fp, $command)) { 
     
    943948 
    944949                $key     = 'fhi' . ($c++); 
    945                 $request = $key." FETCH $message_set (INTERNALDATE)\r\n"; 
     950                $request = $key . " FETCH $message_set (INTERNALDATE)\r\n"; 
    946951                if (!fputs($fp, $request)) { 
    947952                    return false; 
     
    10151020 
    10161021        //check number of elements... 
    1017         list($start_mid,$end_mid) = explode(':', $message_set); 
     1022        list($start_mid, $end_mid) = explode(':', $message_set); 
    10181023        if (is_numeric($start_mid) && is_numeric($end_mid)) { 
    10191024                //count how many we should have 
     
    10211026                 
    10221027                //if we have less, try and fill in the "gaps" 
    1023                 if (count($result)<$should_have) { 
    1024                         for ($i=$start_mid;$i<=$end_mid;$i++) { 
     1028                if (count($result) < $should_have) { 
     1029                        for ($i=$start_mid; $i<=$end_mid; $i++) { 
    10251030                            if (!isset($result[$i])) { 
    10261031                                $result[$i] = ''; 
     
    10291034                } 
    10301035        } 
    1031          
    10321036        return $result;  
    1033  
    10341037} 
    10351038 
     
    10491052     
    10501053        //separate, then sort 
    1051         $ids = explode(',',$message_set); 
     1054        $ids = explode(',', $message_set); 
    10521055        sort($ids); 
    10531056         
    10541057        $result = array(); 
    1055         $start = $prev = $ids[0]; 
     1058        $start  = $prev = $ids[0]; 
     1059 
    10561060        foreach ($ids as $id) { 
    10571061                $incr = $id - $prev; 
    1058                 if ($incr>1) {                  //found a gap 
    1059                         if ($start==$prev) { 
     1062                if ($incr > 1) {                        //found a gap 
     1063                        if ($start == $prev) { 
    10601064                            $result[] = $prev;  //push single id 
    10611065                        } else { 
    1062                             $result[] = $start.':'.$prev;               //push sequence as start_id:end_id 
     1066                            $result[] = $start . ':' . $prev;   //push sequence as start_id:end_id 
    10631067                        } 
    10641068            $start = $id;                                                       //start of new sequence 
     
    10811085            return array(); 
    10821086    } 
    1083         return iil_C_Search($conn, $mailbox, "UID ".implode(",", $uids)); 
     1087        return iil_C_Search($conn, $mailbox, 'UID ' . implode(',', $uids)); 
    10841088} 
    10851089 
    10861090function iil_C_UIDToMID(&$conn, $mailbox, $uid) { 
    10871091        $result = iil_C_UIDsToMIDs($conn, $mailbox, array($uid)); 
    1088         if (count($result)==1) { 
     1092        if (count($result) == 1) { 
    10891093            return $result[0]; 
    10901094        } 
     
    11201124     
    11211125        //make sure number of messages were the same 
    1122         if ($cache_good>0 && $data['n']!=$num) { 
     1126        if ($cache_good > 0 && $data['n'] != $num) { 
    11231127            $cache_good = -2; 
    11241128        } 
    11251129     
    11261130        //if everything's okay so far... 
    1127         if ($cache_good>0) { 
     1131        if ($cache_good > 0) { 
    11281132                //check UIDs of highest mid with current and cached 
    11291133                $temp = iil_C_Search($conn, $mailbox, 'UID ' . $data['d'][$num]); 
     
    11341138 
    11351139        //if cached data's good, return it 
    1136         if ($cache_good>0) { 
     1140        if ($cache_good > 0) { 
    11371141                return $data['d']; 
    11381142        } 
     
    12191223                                $new_thhd->id = $a[1]; 
    12201224                                do { 
    1221                                         $line=chop(iil_ReadLine($fp, 1024),"\r\n"); 
     1225                                        $line = chop(iil_ReadLine($fp, 1024), "\r\n"); 
    12221226                                        if (iil_StartsWithI($line, 'Message-ID:') 
    12231227                        || (iil_StartsWithI($line,'In-Reply-To:')) 
    12241228                        || (iil_StartsWithI($line,'SUBJECT:'))) { 
    1225                                                 $pos = strpos($line, ":"); 
     1229 
     1230                                                $pos        = strpos($line, ':'); 
    12261231                                                $field_name = substr($line, 0, $pos); 
    1227                                                 $field_val = substr($line, $pos+1); 
     1232                                                $field_val  = substr($line, $pos+1); 
     1233 
    12281234                                                $new[strtoupper($field_name)] = trim($field_val); 
     1235 
    12291236                                        } else if (ereg('^[[:space:]]', $line)) { 
    1230                                                 $new[strtoupper($field_name)].= trim($line); 
     1237                                                $new[strtoupper($field_name)] .= trim($line); 
    12311238                                        } 
    12321239                                } while ($line[0] != ')'); 
     
    13021309                //                      'IN-REPLY-TO'=>$header['r'], 'SUBJECT'=>$header['s']); 
    13031310                $id  = $header->id; 
    1304                 $new = array('id'=>$id, 'MESSAGE-ID'=>$header->mid,  
    1305             'IN-REPLY-TO'=>$header->irt, 'SUBJECT'=>$header->sbj); 
     1311                $new = array('id' => $id, 'MESSAGE-ID' => $header->mid,  
     1312            'IN-REPLY-TO' => $header->irt, 'SUBJECT' => $header->sbj); 
    13061313 
    13071314                /* add to message-id -> mid lookup table */ 
     
    13441351            $sub_mids[$new['MESSAGE-ID']] = $root_id; 
    13451352                        $result[$root_id][]           = $id; 
    1346                 }else if (!isset($roots[$sbj])||(!$has_re&&$root_in_root[$root_id])) { 
     1353                }else if (!isset($roots[$sbj]) || (!$has_re && $root_in_root[$root_id])) { 
    13471354                        /* try to use In-Reply-To header to find root  
    13481355                                unless subject contains 'Re:' */ 
     
    13871394        //now that we've gone through all the messages, 
    13881395        //go back and try and link up the stray threads 
    1389         if (count($strays)>0) { 
     1396        if (count($strays) > 0) { 
    13901397                foreach ($strays as $id=>$irt) { 
    13911398                        $root_id = $sub_mids[$irt]; 
     
    14531460        //sort by key, this basically sorts all threads 
    14541461        ksort($itree); 
    1455         $i=0; 
    1456         $out=array(); 
     1462        $i   = 0; 
     1463        $out = array(); 
    14571464        foreach ($itree as $k=>$node) { 
    14581465                $out[$i] = $itree[$k]; 
     
    16591666        */ 
    16601667        $command_key = 'fh' . ($c++); 
    1661         $request  = $command_key . $prefix; 
    1662         $request .= " FETCH $message_set (UID RFC822.SIZE FLAGS INTERNALDATE)\r\n"; 
     1668        $request     = $command_key . $prefix; 
     1669        $request    .= " FETCH $message_set (UID RFC822.SIZE FLAGS INTERNALDATE)\r\n"; 
    16631670         
    16641671        if (!fputs($fp, $request)) { 
     
    17001707                                        // process flags 
    17011708                                        $flags_str = eregi_replace('[\\\"]', '', $flags_str); 
    1702                                         $flags_a = explode(' ', $flags_str); 
    1703                                         //echo "<!-- ID: $id FLAGS: ".implode(",", $flags_a)." //-->\n"; 
     1709                                        $flags_a   = explode(' ', $flags_str); 
     1710 
     1711                    /* 
     1712                    trigger_error("<!-- ID: $id FLAGS: ".implode(",", $flags_a)." //-->\n", 
     1713                        E_USER_WARNING); 
     1714                    */ 
    17041715                                         
    17051716                                        if (is_array($flags_a)) { 
     
    17891800 
    17901801        $c=count($a); 
    1791         if ($c>0) { 
     1802        if ($c > 0) { 
    17921803                /* 
    17931804                        Strategy: 
     
    18391850        $fp = $conn->fp; 
    18401851        if (iil_C_Select($conn, $mailbox)) { 
    1841                 $c=0; 
     1852                $c = 0; 
    18421853                fputs($fp, "exp1 EXPUNGE\r\n"); 
    18431854                do { 
     
    18781889     
    18791890        if (iil_C_Select($conn, $mailbox)) { 
    1880                 $c=0; 
     1891                $c = 0; 
    18811892                fputs($fp, "flg STORE $messages " . $mod . "FLAGS (" . $flag . ")\r\n"); 
    18821893                do { 
     
    19932004        $fp = $conn->fp; 
    19942005        if (iil_C_Select($conn, $folder)) { 
    1995                 $c=0; 
     2006                $c = 0; 
    19962007                 
    19972008                $query = 'srch1 SEARCH ' . chop($criteria) . "\r\n"; 
     
    20032014                                $messages = explode(' ', $str); 
    20042015                        } 
    2005                 } while (!iil_StartsWith($line, "srch1")); 
     2016                } while (!iil_StartsWith($line, 'srch1')); 
    20062017                 
    2007                 $result_code=iil_ParseResult($line); 
    2008                 if ($result_code==0) { 
     2018                $result_code = iil_ParseResult($line); 
     2019                if ($result_code == 0) { 
    20092020                    return $messages; 
    20102021                } 
     
    20242035        } 
    20252036     
    2026         $r=iil_C_Copy($conn, $messages, $from,$to); 
     2037        $r = iil_C_Copy($conn, $messages, $from,$to); 
    20272038        if ($r==0) { 
    20282039                return iil_C_Delete($conn, $from, $messages); 
     
    22382249        $query = 'sub1 SUBSCRIBE "' . $folder. '"' . "\r\n"; 
    22392250        fputs($fp, $query); 
     2251 
    22402252        $line = trim(chop(iil_ReadLine($fp, 10000))); 
    22412253        return iil_ParseResult($line); 
     
    22682280                if (!fputs($fp, $request)) return false; 
    22692281                do { 
    2270                         $line=chop(iil_ReadLine($fp, 200)); 
    2271                         $a=explode(' ', $line); 
     2282                        $line = chop(iil_ReadLine($fp, 200)); 
     2283                        $a    = explode(' ', $line); 
    22722284                        if (($line[0] == '*') && ($a[2] == 'FETCH') 
    22732285                && ($line[strlen($line)-1] != ')')) { 
    22742286                                $line=iil_ReadLine($fp, 300); 
    2275                                 while (chop($line)!=")") { 
    2276                                         $result.=$line; 
     2287                                while (chop($line) != ')') { 
     2288                                        $result .= $line; 
    22772289                                        $line=iil_ReadLine($fp, 300); 
    22782290                                } 
    22792291                        } 
    2280                 } while (strcmp($a[0], $key)!=0); 
     2292                } while (strcmp($a[0], $key) != 0); 
    22812293        } 
    22822294         
     
    22932305        $fp     = $conn->fp; 
    22942306        $result = false; 
    2295         if (($part==0) || (empty($part))) { 
     2307        if (($part == 0) || empty($part)) { 
    22962308            $part = 'TEXT'; 
    22972309        } 
    22982310     
    22992311        if (iil_C_Select($conn, $mailbox)) { 
    2300         $reply_key='* ' . $id; 
     2312        $reply_key = '* ' . $id; 
    23012313         
    23022314        // format request 
     
    23432355                } 
    23442356                $received += strlen($line); 
    2345                 if ($mode==1) { 
    2346                     $result .= chop($line)."\n"; 
    2347                 } else if ($mode==2) { 
    2348                     echo chop($line)."\n"; flush(); 
    2349                 } else if ($mode==3) { 
     2357                if ($mode == 1) { 
     2358                    $result .= chop($line) . "\n"; 
     2359                } else if ($mode == 2) { 
     2360                    echo chop($line) . "\n"; flush(); 
     2361                } else if ($mode == 3) { 
    23502362                    echo base64_decode($line); flush(); 
    23512363                } 
     
    24002412        if (fputs($fp, 'r RENAME "' . $from . '" "' . $to . '"' . "\r\n")) { 
    24012413                do { 
    2402                         $line=iil_ReadLine($fp, 300); 
    2403                 } while ($line[0]!="r"); 
     2414                        $line = iil_ReadLine($fp, 300); 
     2415                } while ($line[0] != 'r'); 
    24042416                return (iil_ParseResult($line) == 0); 
    24052417        } 
    2406     return false;        
     2418    return false; 
    24072419} 
    24082420 
     
    24122424                do { 
    24132425                        $line=iil_ReadLine($fp, 300); 
    2414                 } while ($line[0]!="d"); 
     2426                } while ($line[0] != 'd'); 
    24152427                return (iil_ParseResult($line) == 0); 
    24162428        } 
     
    24202432 
    24212433function iil_C_Append(&$conn, $folder, &$message) { 
    2422         if (!$folder) return false; 
     2434        if (!$folder) { 
     2435        return false; 
     2436    } 
    24232437        $fp = $conn->fp; 
    24242438 
     
    24272441 
    24282442        $len = strlen($message); 
    2429         if (!$len) return false; 
    2430          
     2443        if (!$len) { 
     2444        return false; 
     2445        } 
    24312446        $request = 'A APPEND "' . $folder .'" (\\Seen) {' . $len . "}\r\n"; 
    24322447     
     
    24762491        $bytes_sent = 0; 
    24772492        if (fputs($fp, $request)) { 
    2478                 $line=iil_ReadLine($fp, 100); 
     2493                $line = iil_ReadLine($fp, 100); 
    24792494                                 
    24802495                //send file 
    24812496                while (!feof($in_fp)) { 
    2482                         $buffer = fgets($in_fp, 4096); 
     2497                        $buffer      = fgets($in_fp, 4096); 
    24832498                        $bytes_sent += strlen($buffer); 
    24842499                        fputs($fp, $buffer); 
     
    24902505                //read response 
    24912506                do { 
    2492                         $line=iil_ReadLine($fp, 1000); 
     2507                        $line = iil_ReadLine($fp, 1000); 
    24932508                } while ($line[0] != 'A'); 
    24942509                         
     
    25342549                                        $result = substr($post, 0, strlen($post)-1); 
    25352550                                } 
    2536                         } while (!preg_match("/^$key/",$line)); 
     2551                        } while (!preg_match("/^$key/", $line)); 
    25372552                } 
    25382553        } 
     
    25702585        //return false if not found, parse if found 
    25712586        if (!empty($quota_line)) { 
    2572                 $quota_line = eregi_replace('[()]', '', $quota_line); 
    2573                 $parts = explode(' ', $quota_line); 
     2587                $quota_line   = eregi_replace('[()]', '', $quota_line); 
     2588                $parts        = explode(' ', $quota_line); 
    25742589                $storage_part = array_search('STORAGE', $parts); 
    2575                 if ($storage_part>0) { 
     2590                if ($storage_part > 0) { 
    25762591                        $result = array(); 
    25772592                        $used   = $parts[$storage_part+1]; 
     
    25842599                } 
    25852600        } 
    2586          
    25872601        return $result; 
    25882602} 
     
    25962610        return (iil_C_Expunge($conn, $folder) >= 0); 
    25972611} 
    2598  
    25992612?> 
Note: See TracChangeset for help on using the changeset viewer.