till
2008-02-12 3d695da299cf236864ee75c02969669831950676
* cs fixes



1 files modified
63 ■■■■■ changed files
program/lib/imap.inc 63 ●●●●● patch | view | raw | blame | history
program/lib/imap.inc
@@ -56,13 +56,14 @@
/**
 * @todo Possibly clean up more CS.
 * @todo Try to replace most double-quotes with single-quotes.
 * @todo Split this file into smaller files.
 * @todo Refactor code.
 * @todo Replace echo-debugging (make it adhere to config setting and log)
 */
// changed path to work within roundcube webmail
include_once("lib/icl_commons.inc");
include_once 'lib/icl_commons.inc';
if (!$IMAP_USE_HEADER_DATE) {
@@ -456,7 +457,7 @@
    
    //check for SSL
    if ($ICL_SSL) {
        $host = $ICL_SSL."://".$host;
        $host = $ICL_SSL . '://' . $host;
    }
    
    //open socket connection
@@ -474,15 +475,17 @@
        //check for supported auth methods
        
        //default to plain text auth
        $auth_method = "plain";
        $auth_method = 'plain';
            
        //check for CRAM-MD5
        fputs($conn->fp, "cp01 CAPABILITY\r\n");
        do {
            $line = trim(chop(iil_ReadLine($conn->fp, 100)));
            $conn->message.="$line\n";
            $a = explode(' ', $line);
            if ($line[0]=="*") {
            if ($line[0] == '*') {
                while ( list($k, $w) = each($a) ) {
                    if ($w!='*' && $w!='CAPABILITY') {
                        $conn->capability[] = $w;
@@ -493,18 +496,19 @@
                    }
                }
            }
        } while ($a[0]!="cp01");
        } while ($a[0] != 'cp01');
    }
    if (strcasecmp($auth_method, "auth") == 0) {
    if (strcasecmp($auth_method, 'auth') == 0) {
        $conn->message .= "Trying CRAM-MD5\n";
        //do CRAM-MD5 authentication
        fputs($conn->fp, "a000 AUTHENTICATE CRAM-MD5\r\n");
        $line = trim(chop(iil_ReadLine($conn->fp, 1024)));
        
        $conn->message.="$line\n";
        
        if ($line[0] == "+") {
        if ($line[0] == '+') {
            $conn->message .= 'Got challenge: ' . htmlspecialchars($line)."\n";
            //got a challenge string, try CRAM-5
@@ -790,8 +794,8 @@
    if ($field == 'INTERNALDATE') {
        $field = 'ARRIVAL';
    }
    $fields = array('ARRIVAL'=>1,'CC'=>1,'DATE'=>1,'FROM'=>1,'SIZE'=>1,
 'SUBJECT'=>1,'TO'=>1);
    $fields = array('ARRIVAL' => 1,'CC' => 1,'DATE' => 1,
        'FROM' => 1, 'SIZE' => 1, 'SUBJECT' => 1, 'TO' => 1);
    
    if (!$fields[$field]) {
        return false;
@@ -804,7 +808,8 @@
    }
    $fp      = $conn->fp;
    $command = 's '. $is_uid .'SORT ('.$field.') '.$encoding.' ALL'."$add\r\n";
    $command  = 's ' . $is_uid . 'SORT (' . $field . ') ';
    $command .= $encoding . ' ALL' . "$add\r\n";
    $line    = $data = '';
    
    if (!fputs($fp, $command)) {
@@ -1028,9 +1033,7 @@
            }
        }
    }
    return $result;    
}
function iil_CompressMessageSet($message_set) {
@@ -1053,6 +1056,7 @@
    
    $result = array();
    $start = $prev = $ids[0];
    foreach ($ids as $id) {
        $incr = $id - $prev;
        if ($incr>1) {            //found a gap
@@ -1080,7 +1084,7 @@
    if (!is_array($uids) || count($uids) == 0) {
        return array();
    }
    return iil_C_Search($conn, $mailbox, "UID ".implode(",", $uids));
    return iil_C_Search($conn, $mailbox, 'UID ' . implode(',', $uids));
}
function iil_C_UIDToMID(&$conn, $mailbox, $uid) {
@@ -1222,10 +1226,13 @@
                    if (iil_StartsWithI($line, 'Message-ID:')
                        || (iil_StartsWithI($line,'In-Reply-To:'))
                        || (iil_StartsWithI($line,'SUBJECT:'))) {
                        $pos = strpos($line, ":");
                        $pos        = strpos($line, ':');
                        $field_name = substr($line, 0, $pos);
                        $field_val = substr($line, $pos+1);
                        $new[strtoupper($field_name)] = trim($field_val);
                    } else if (ereg('^[[:space:]]', $line)) {
                        $new[strtoupper($field_name)].= trim($line);
                    }
@@ -1700,7 +1707,11 @@
                    // process flags
                    $flags_str = eregi_replace('[\\\"]', '', $flags_str);
                    $flags_a = explode(' ', $flags_str);
                    //echo "<!-- ID: $id FLAGS: ".implode(",", $flags_a)." //-->\n";
                    /*
                    trigger_error("<!-- ID: $id FLAGS: ".implode(",", $flags_a)." //-->\n",
                        E_USER_WARNING);
                    */
                    
                    if (is_array($flags_a)) {
                        reset($flags_a);
@@ -2002,7 +2013,7 @@
                $str = trim(substr($line, 8));
                $messages = explode(' ', $str);
            }
        } while (!iil_StartsWith($line, "srch1"));
        } while (!iil_StartsWith($line, 'srch1'));
        
        $result_code=iil_ParseResult($line);
        if ($result_code==0) {
@@ -2237,6 +2248,7 @@
    $query = 'sub1 SUBSCRIBE "' . $folder. '"' . "\r\n";
    fputs($fp, $query);
    $line = trim(chop(iil_ReadLine($fp, 10000)));
    return iil_ParseResult($line);
}
@@ -2272,7 +2284,7 @@
            if (($line[0] == '*') && ($a[2] == 'FETCH')
                && ($line[strlen($line)-1] != ')')) {
                $line=iil_ReadLine($fp, 300);
                while (chop($line)!=")") {
                while (chop($line) != ')') {
                    $result.=$line;
                    $line=iil_ReadLine($fp, 300);
                }
@@ -2292,7 +2304,7 @@
    */
    $fp     = $conn->fp;
    $result = false;
    if (($part==0) || (empty($part))) {
    if (($part == 0) || empty($part)) {
        $part = 'TEXT';
    }
    
@@ -2400,7 +2412,7 @@
    if (fputs($fp, 'r RENAME "' . $from . '" "' . $to . '"' . "\r\n")) {
        do {
            $line=iil_ReadLine($fp, 300);
        } while ($line[0]!="r");
        } while ($line[0] != 'r');
        return (iil_ParseResult($line) == 0);
    }
    return false;    
@@ -2411,7 +2423,7 @@
    if (fputs($fp, 'd DELETE "' . $folder. '"' . "\r\n")) {
        do {
            $line=iil_ReadLine($fp, 300);
        } while ($line[0]!="d");
        } while ($line[0] != 'd');
        return (iil_ParseResult($line) == 0);
    }
    $conn->error = "Couldn't send command\n";
@@ -2419,15 +2431,18 @@
}
function iil_C_Append(&$conn, $folder, &$message) {
    if (!$folder) return false;
    if (!$folder) {
        return false;
    }
    $fp = $conn->fp;
    $message = str_replace("\r", '', $message);
    $message = str_replace("\n", "\r\n", $message);        
    $len = strlen($message);
    if (!$len) return false;
    if (!$len) {
        return false;
    }
    $request = 'A APPEND "' . $folder .'" (\\Seen) {' . $len . "}\r\n";
    
    if (fputs($fp, $request)) {
@@ -2583,7 +2598,6 @@
            $result['free']    = 100 - $result['percent'];
        }
    }
    return $result;
}
@@ -2595,5 +2609,4 @@
    }
    return (iil_C_Expunge($conn, $folder) >= 0);
}
?>