| | |
| | | * @todo Possibly clean up more CS. |
| | | * @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 |
| | |
| | | } |
| | | |
| | | function iil_C_LoadCache(&$conn, $folder) { |
| | | if (!$conn->do_cache) return false; |
| | | |
| | | $key = $folder.".imap"; |
| | | if (!$conn->do_cache) { |
| | | return false; |
| | | } |
| | | |
| | | $key = $folder.'.imap'; |
| | | if (!is_array($conn->cache[$folder])) { |
| | | $conn->cache[$folder] = cache_read($conn->user, $conn->host, $key); |
| | | $conn->cache[$folder] = cache_read($conn->user, $conn->host, $key); |
| | | $conn->cache_dirty[$folder] = false; |
| | | } |
| | | } |
| | | |
| | | function iil_C_ExpireCachedItems(&$conn, $folder, $message_set) { |
| | | |
| | | if (!$conn->do_cache) return; //caching disabled |
| | | if (!is_array($conn->cache[$folder])) return; //cache not initialized|empty |
| | | if (count($conn->cache[$folder]) == 0) return; //cache not initialized|empty |
| | | |
| | | $uids = iil_C_FetchHeaderIndex($conn, $folder, $message_set, "UID"); |
| | | if (!$conn->do_cache) { |
| | | return; //caching disabled |
| | | } |
| | | if (!is_array($conn->cache[$folder])) { |
| | | return; //cache not initialized|empty |
| | | } |
| | | if (count($conn->cache[$folder]) == 0) { |
| | | return; //cache not initialized|empty |
| | | } |
| | | |
| | | $uids = iil_C_FetchHeaderIndex($conn, $folder, $message_set, 'UID'); |
| | | $num_removed = 0; |
| | | if (is_array($uids)) { |
| | | //echo "<!-- unsetting: ".implode(",",$uids)." //-->\n"; |
| | |
| | | } |
| | | |
| | | function iil_ExplodeQuotedString($delimiter, $string) { |
| | | $quotes=explode("\"", $string); |
| | | while ( list($key, $val) = each($quotes)) |
| | | if (($key % 2) == 1) |
| | | $quotes=explode('"', $string); |
| | | while ( list($key, $val) = each($quotes)) { |
| | | if (($key % 2) == 1) { |
| | | $quotes[$key] = str_replace($delimiter, "_!@!_", $quotes[$key]); |
| | | $string=implode("\"", $quotes); |
| | | } |
| | | } |
| | | $string=implode('"', $quotes); |
| | | |
| | | $result=explode($delimiter, $string); |
| | | while ( list($key, $val) = each($result) ) |
| | | $result[$key] = str_replace("_!@!_", $delimiter, $result[$key]); |
| | | |
| | | while ( list($key, $val) = each($result) ) { |
| | | $result[$key] = str_replace('_!@!_', $delimiter, $result[$key]); |
| | | } |
| | | |
| | | return $result; |
| | | } |
| | | |
| | |
| | | do { |
| | | $line=chop(iil_ReadLine($fp, 300)); |
| | | $a=explode(' ', $line); |
| | | if (($a[0] == '*') && (strcasecmp($a[2], "RECENT") == 0)) { |
| | | if (($a[0] == '*') && (strcasecmp($a[2], 'RECENT') == 0)) { |
| | | $result = (int) $a[1]; |
| | | } |
| | | } while (!iil_StartsWith($a[0],"a002")); |
| | | } while (!iil_StartsWith($a[0], 'a002')); |
| | | |
| | | fputs($fp, "a003 LOGOUT\r\n"); |
| | | fclose($fp); |
| | |
| | | $line=chop(iil_ReadLine($fp, 300)); |
| | | $a=explode(' ', $line); |
| | | if (count($a) == 3) { |
| | | if (strcasecmp($a[2], "EXISTS") == 0) $conn->exists=(int)$a[1]; |
| | | if (strcasecmp($a[2], "RECENT") == 0) $conn->recent=(int)$a[1]; |
| | | if (strcasecmp($a[2], 'EXISTS') == 0) { |
| | | $conn->exists = (int) $a[1]; |
| | | } |
| | | if (strcasecmp($a[2], 'RECENT') == 0) { |
| | | $conn->recent = (int) $a[1]; |
| | | } |
| | | } |
| | | } while (!iil_StartsWith($line, "sel1")); |
| | | } while (!iil_StartsWith($line, 'sel1')); |
| | | |
| | | $a=explode(' ', $line); |
| | | |
| | | if (strcasecmp($a[1],"OK") == 0) { |
| | | if (strcasecmp($a[1], 'OK') == 0) { |
| | | $conn->selected = $mailbox; |
| | | return true; |
| | | } |
| | |
| | | |
| | | //replace double spaces with single space |
| | | $str = trim($str); |
| | | $str = str_replace(" ", " ", $str); |
| | | $str = str_replace(' ', ' ', $str); |
| | | |
| | | //strip off day of week |
| | | $pos=strpos($str, " "); |
| | | $pos=strpos($str, ' '); |
| | | if (!is_numeric(substr($str, 0, $pos))) { |
| | | $str = substr($str, $pos+1); |
| | | } |
| | |
| | | $time = $a[3]; |
| | | $tz_str = $a[4]; |
| | | $tz = substr($tz_str, 0, 3); |
| | | $ta = explode(":",$time); |
| | | $ta = explode(':', $time); |
| | | $hour = (int)$ta[0]-(int)$tz; |
| | | $minute = (int)$ta[1]; |
| | | $second = (int)$ta[2]; |
| | |
| | | } |
| | | |
| | | function iil_C_Sort(&$conn, $mailbox, $field, $add='', $is_uid=FALSE, |
| | | $encoding='US-ASCII') { |
| | | $encoding = 'US-ASCII') { |
| | | /* Do "SELECT" command */ |
| | | if (!iil_C_Select($conn, $mailbox)) { |
| | | return false; |
| | |
| | | } |
| | | do { |
| | | $line = chop(iil_ReadLine($fp, 1024)); |
| | | if (iil_StartsWith($line, '* SORT')) $data.=($data?' ':'').substr($line,7); |
| | | if (iil_StartsWith($line, '* SORT')) { |
| | | $data .= ($data?' ':'') . substr($line, 7); |
| | | } |
| | | } while ($line[0]!='s'); |
| | | |
| | | if (empty($data)) { |
| | |
| | | } |
| | | do { |
| | | $line=chop(iil_ReadLine($fp, 200)); |
| | | if ($line[0]=="*") { |
| | | //original: "* 10 FETCH (INTERNALDATE "31-Jul-2002 09:18:02 -0500")" |
| | | $paren_pos = strpos($line, "("); |
| | | $foo = substr($line, 0, $paren_pos); |
| | | $a = explode(' ', $foo); |
| | | $id = $a[1]; |
| | | if ($line[0] == '*') { |
| | | /* |
| | | * original: |
| | | * "* 10 FETCH (INTERNALDATE "31-Jul-2002 09:18:02 -0500")" |
| | | */ |
| | | $paren_pos = strpos($line, '('); |
| | | $foo = substr($line, 0, $paren_pos); |
| | | $a = explode(' ', $foo); |
| | | $id = $a[1]; |
| | | |
| | | $open_pos = strpos($line, "\"") + 1; |
| | | $close_pos = strrpos($line, "\""); |
| | | $open_pos = strpos($line, '"') + 1; |
| | | $close_pos = strrpos($line, '"'); |
| | | if ($open_pos && $close_pos) { |
| | | $len = $close_pos - $open_pos; |
| | | $time_str = substr($line, $open_pos, $len); |
| | | $len = $close_pos - $open_pos; |
| | | $time_str = substr($line, $open_pos, $len); |
| | | $result[$id] = strtotime($time_str); |
| | | } |
| | | } else { |
| | |
| | | foreach ($ids as $id) { |
| | | $incr = $id - $prev; |
| | | if ($incr>1) { //found a gap |
| | | if ($start==$prev) $result[] = $prev; //push single id |
| | | else $result[] = $start.':'.$prev; //push sequence as start_id:end_id |
| | | $start = $id; //start of new sequence |
| | | if ($start==$prev) { |
| | | $result[] = $prev; //push single id |
| | | } else { |
| | | $result[] = $start.':'.$prev; //push sequence as start_id:end_id |
| | | } |
| | | $start = $id; //start of new sequence |
| | | } |
| | | $prev = $id; |
| | | } |
| | |
| | | if ($num == 0) { |
| | | return array(); |
| | | } |
| | | $message_set = '1'.($num>1?':'.$num:''); |
| | | $message_set = '1' . ($num>1?':' . $num:''); |
| | | |
| | | //if cache not enabled, just call iil_C_FetchHeaderIndex on 'UID' field |
| | | if (!$conn->do_cache) |
| | |
| | | } |
| | | |
| | | //was anything cached at all? |
| | | if ($data===false) { |
| | | if ($data === false) { |
| | | $cache_good = -1; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | //otherwise, we need to fetch it |
| | | $data = array('n'=>$num,'d'=>array()); |
| | | $data = array('n' => $num, 'd' => array()); |
| | | $data['d'] = iil_C_FetchHeaderIndex($conn, $mailbox, $message_set, 'UID'); |
| | | |
| | | cache_write($conn->user, $conn->host, $key, $data); |
| | |
| | | // is it a container? |
| | | $i++; |
| | | } |
| | | } while (!iil_StartsWith($line, "lmb")); |
| | | } while (!iil_StartsWith($line, 'lmb')); |
| | | |
| | | if (is_array($folders)) { |
| | | if (!empty($ref)) { |
| | |
| | | // is it a container? |
| | | $i++; |
| | | } |
| | | } while (!iil_StartsWith($line, "lsb")); |
| | | } while (!iil_StartsWith($line, 'lsb')); |
| | | |
| | | if (is_array($folders)) { |
| | | if (!empty($ref)) { |
| | |
| | | do { |
| | | $line = chop(iil_ReadLine($fp, 1000)); |
| | | $a = explode(' ', $line); |
| | | } while ($a[2]!="FETCH"); |
| | | } while ($a[2] != 'FETCH'); |
| | | $len = strlen($line); |
| | | if ($line[$len-1] == ')') { |
| | | //one line response, get everything between first and last quotes |
| | |
| | | } |
| | | return false; |
| | | } else { |
| | | echo "Select failed."; |
| | | echo 'Select failed.'; |
| | | } |
| | | |
| | | if ($mode==1) { |
| | |
| | | |
| | | function iil_C_CreateFolder(&$conn, $folder) { |
| | | $fp = $conn->fp; |
| | | if (fputs($fp, "c CREATE \"".$folder."\"\r\n")) { |
| | | if (fputs($fp, 'c CREATE "' . $folder . '"' . "\r\n")) { |
| | | do { |
| | | $line=iil_ReadLine($fp, 300); |
| | | } while ($line[0]!="c"); |
| | | } while ($line[0] != 'c'); |
| | | $conn->error = $line; |
| | | return (iil_ParseResult($line) == 0); |
| | | } |
| | |
| | | |
| | | function iil_C_RenameFolder(&$conn, $from, $to) { |
| | | $fp = $conn->fp; |
| | | if (fputs($fp, "r RENAME \"".$from."\" \"".$to."\"\r\n")) { |
| | | if (fputs($fp, 'r RENAME "' . $from . '" "' . $to . '"' . "\r\n")) { |
| | | do { |
| | | $line=iil_ReadLine($fp, 300); |
| | | } while ($line[0]!="r"); |
| | |
| | | |
| | | function iil_C_DeleteFolder(&$conn, $folder) { |
| | | $fp = $conn->fp; |
| | | if (fputs($fp, "d DELETE \"".$folder."\"\r\n")) { |
| | | if (fputs($fp, 'd DELETE "' . $folder. '"' . "\r\n")) { |
| | | do { |
| | | $line=iil_ReadLine($fp, 300); |
| | | } while ($line[0]!="d"); |
| | |
| | | |
| | | $result = (iil_ParseResult($line) == 0); |
| | | if (!$result) { |
| | | $conn->error .= $line."\n"; |
| | | $conn->error .= $line . "\n"; |
| | | } |
| | | return $result; |
| | | |
| | |
| | | //open message file |
| | | $in_fp = false; |
| | | if (file_exists(realpath($path))) { |
| | | $in_fp = fopen($path, "r"); |
| | | $in_fp = fopen($path, 'r'); |
| | | } |
| | | if (!$in_fp) { |
| | | $conn->error .= "Couldn't open $path for reading\n"; |
| | |
| | | |
| | | $result = (iil_ParseResult($line) == 0); |
| | | if (!$result) { |
| | | $conn->error .= $line."\n"; |
| | | $conn->error .= $line . "\n"; |
| | | } |
| | | return $result; |
| | | |
| | |
| | | $quota_line = ''; |
| | | |
| | | //get line containing quota info |
| | | if (fputs($fp, "QUOT1 GETQUOTAROOT \"INBOX\"\r\n")) { |
| | | if (fputs($fp, 'QUOT1 GETQUOTAROOT "INBOX"' . "\r\n")) { |
| | | do { |
| | | $line=chop(iil_ReadLine($fp, 5000)); |
| | | if (iil_StartsWith($line, "* QUOTA ")) { |
| | | if (iil_StartsWith($line, '* QUOTA ')) { |
| | | $quota_line = $line; |
| | | } |
| | | } while (!iil_StartsWith($line, "QUOT1")); |
| | | } while (!iil_StartsWith($line, 'QUOT1')); |
| | | } |
| | | |
| | | //return false if not found, parse if found |
| | | if (!empty($quota_line)) { |
| | | $quota_line = eregi_replace("[()]", '', $quota_line); |
| | | $quota_line = eregi_replace('[()]', '', $quota_line); |
| | | $parts = explode(' ', $quota_line); |
| | | $storage_part = array_search("STORAGE", $parts); |
| | | $storage_part = array_search('STORAGE', $parts); |
| | | if ($storage_part>0) { |
| | | $result = array(); |
| | | $used = $parts[$storage_part+1]; |