| | |
| | | |
| | | /** |
| | | * @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) { |
| | |
| | | |
| | | //check for SSL |
| | | if ($ICL_SSL) { |
| | | $host = $ICL_SSL."://".$host; |
| | | $host = $ICL_SSL . '://' . $host; |
| | | } |
| | | |
| | | //open socket connection |
| | |
| | | //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; |
| | |
| | | } |
| | | } |
| | | } |
| | | } 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 |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | $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)) { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | return $result; |
| | | |
| | | } |
| | | |
| | | function iil_CompressMessageSet($message_set) { |
| | |
| | | |
| | | $result = array(); |
| | | $start = $prev = $ids[0]; |
| | | |
| | | foreach ($ids as $id) { |
| | | $incr = $id - $prev; |
| | | if ($incr>1) { //found a gap |
| | |
| | | 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) { |
| | |
| | | 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); |
| | | } |
| | |
| | | // 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); |
| | |
| | | $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) { |
| | |
| | | |
| | | $query = 'sub1 SUBSCRIBE "' . $folder. '"' . "\r\n"; |
| | | fputs($fp, $query); |
| | | |
| | | $line = trim(chop(iil_ReadLine($fp, 10000))); |
| | | return iil_ParseResult($line); |
| | | } |
| | |
| | | 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); |
| | | } |
| | |
| | | */ |
| | | $fp = $conn->fp; |
| | | $result = false; |
| | | if (($part==0) || (empty($part))) { |
| | | if (($part == 0) || empty($part)) { |
| | | $part = 'TEXT'; |
| | | } |
| | | |
| | |
| | | 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; |
| | |
| | | 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"; |
| | |
| | | } |
| | | |
| | | 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)) { |
| | |
| | | $result['free'] = 100 - $result['percent']; |
| | | } |
| | | } |
| | | |
| | | return $result; |
| | | } |
| | | |
| | |
| | | } |
| | | return (iil_C_Expunge($conn, $folder) >= 0); |
| | | } |
| | | |
| | | ?> |