| | |
| | | function iil_PutLine($fp, $string, $endln=true) { |
| | | global $my_prefs; |
| | | |
| | | if(!empty($my_prefs['debug_mode'])) |
| | | if (!empty($my_prefs['debug_mode'])) |
| | | write_log('imap', 'C: '. rtrim($string)); |
| | | |
| | | return fputs($fp, $string . ($endln ? "\r\n" : '')); |
| | |
| | | if ($buffer === false) { |
| | | break; |
| | | } |
| | | if(!empty($my_prefs['debug_mode'])) |
| | | if (!empty($my_prefs['debug_mode'])) |
| | | write_log('imap', 'S: '. chop($buffer)); |
| | | $line .= $buffer; |
| | | } while ($buffer[strlen($buffer)-1] != "\n"); |
| | |
| | | $len = 0; |
| | | do { |
| | | $d = fread($fp, $bytes-$len); |
| | | if (!empty($my_prefs['debug_mode'])) |
| | | write_log('imap', 'S: '. $d); |
| | | $data .= $d; |
| | | if ($len == strlen($data)) { |
| | | $data_len = strlen($data); |
| | | if ($len == $data_len) { |
| | | break; //nothing was read -> exit to avoid apache lockups |
| | | } |
| | | if(!empty($my_prefs['debug_mode'])) |
| | | write_log('imap', 'S: '. $d); |
| | | $len = strlen($data); |
| | | $len = $data_len; |
| | | } while ($len < $bytes); |
| | | |
| | | return $data; |
| | |
| | | return false; |
| | | } |
| | | |
| | | function iil_StartsWithI($string, $match, $bye=false) { |
| | | function iil_StartsWithI($string, $match, $error=false) { |
| | | $len = strlen($match); |
| | | if ($len == 0) { |
| | | return false; |
| | |
| | | if (strncasecmp($string, $match, $len) == 0) { |
| | | return true; |
| | | } |
| | | if ($bye && strncmp($string, '* BYE ', 6) == 0) { |
| | | if ($error && preg_match('/^\* (BYE|BAD) /i', $string)) { |
| | | return true; |
| | | |
| | | } |
| | |
| | | if (strcasecmp($a[2], 'EXISTS') == 0) { |
| | | $conn->exists = (int) $a[1]; |
| | | } |
| | | if (strcasecmp($a[2], 'RECENT') == 0) { |
| | | else if (strcasecmp($a[2], 'RECENT') == 0) { |
| | | $conn->recent = (int) $a[1]; |
| | | } |
| | | } |
| | |
| | | $command = 's ' . $is_uid . 'SORT (' . $field . ') '; |
| | | $command .= $encoding . ' ALL' . $add; |
| | | $line = $data = ''; |
| | | |
| | | |
| | | if (!iil_PutLineC($conn->fp, $command)) { |
| | | return false; |
| | | } |
| | | do { |
| | | $line = chop(iil_ReadLine($conn->fp, 1024)); |
| | | $line = chop(iil_ReadLine($conn->fp)); |
| | | if (iil_StartsWith($line, '* SORT')) { |
| | | $data .= ($data ? ' ' : '') . substr($line, 7); |
| | | $data .= substr($line, 7); |
| | | } else if (preg_match('/^[0-9 ]+$/', $line)) { |
| | | $data .= $line; |
| | | } |
| | |
| | | return false; |
| | | } |
| | | |
| | | $out = explode(' ',$data); |
| | | return $out; |
| | | return preg_split('/\s+/', $data, -1, PREG_SPLIT_NO_EMPTY); |
| | | } |
| | | |
| | | function iil_C_FetchHeaderIndex(&$conn, $mailbox, $message_set, $index_field='', $skip_deleted=true) { |
| | |
| | | } |
| | | |
| | | function iil_C_CountUnseen(&$conn, $folder) { |
| | | $index = iil_C_Search($conn, $folder, 'ALL UNSEEN'); |
| | | if (is_array($index)) { |
| | | if (($cnt = count($index)) && $index[0] != '') { |
| | | return $cnt; |
| | | } |
| | | } |
| | | return false; |
| | | $index = iil_C_Search($conn, $folder, 'ALL UNSEEN'); |
| | | if (is_array($index)) |
| | | return count($index); |
| | | return false; |
| | | } |
| | | |
| | | function iil_C_UID2ID(&$conn, $folder, $uid) { |
| | |
| | | } |
| | | |
| | | function iil_C_ID2UID(&$conn, $folder, $id) { |
| | | $fp = $conn->fp; |
| | | |
| | | if ($id == 0) { |
| | | return -1; |
| | | } |
| | | $result = -1; |
| | | if (iil_C_Select($conn, $folder)) { |
| | | $key = 'FUID'; |
| | | if (iil_PutLine($fp, "$key FETCH $id (UID)")) { |
| | | $key = 'fuid'; |
| | | if (iil_PutLine($conn->fp, "$key FETCH $id (UID)")) { |
| | | do { |
| | | $line=chop(iil_ReadLine($fp, 1024)); |
| | | $line = chop(iil_ReadLine($conn->fp, 1024)); |
| | | if (preg_match("/^\* $id FETCH \(UID (.*)\)/i", $line, $r)) { |
| | | $result = $r[1]; |
| | | } |
| | | } while (!preg_match("/^$key/", $line)); |
| | | } while (!iil_StartsWith($line, $key, true)); |
| | | } |
| | | } |
| | | return $result; |
| | | } |
| | | |
| | | function iil_C_Search(&$conn, $folder, $criteria) { |
| | | $fp = $conn->fp; |
| | | |
| | | if (iil_C_Select($conn, $folder)) { |
| | | $c = 0; |
| | | $data = ''; |
| | | |
| | | $query = 'srch1 SEARCH ' . chop($criteria); |
| | | if (!iil_PutLineC($fp, $query)) { |
| | | if (!iil_PutLineC($conn->fp, $query)) { |
| | | return false; |
| | | } |
| | | do { |
| | | $line=trim(iil_ReadLine($fp, 10000)); |
| | | if (preg_match('/^\* SEARCH/i', $line)) { |
| | | $str = trim(substr($line, 8)); |
| | | $messages = explode(' ', $str); |
| | | $line = trim(iil_ReadLine($conn->fp)); |
| | | if (iil_StartsWith($line, '* SEARCH')) { |
| | | $data .= substr($line, 8); |
| | | } else if (preg_match('/^[0-9 ]+$/', $line)) { |
| | | $data .= $line; |
| | | } |
| | | } while (!iil_StartsWith($line, 'srch1', true)); |
| | | |
| | | $result_code = iil_ParseResult($line); |
| | | if ($result_code == 0) { |
| | | return $messages; |
| | | return preg_split('/\s+/', $data, -1, PREG_SPLIT_NO_EMPTY); |
| | | } |
| | | $conn->error = 'iil_C_Search: ' . $line . "\n"; |
| | | return false; |
| | |
| | | $len = $to - $from; |
| | | $result = substr($line, $from, $len); |
| | | } |
| | | |
| | | |
| | | if ($mode == 1) |
| | | $result = base64_decode($result); |
| | | else if ($mode == 2) |
| | |
| | | |
| | | if ($len > $bytes) { |
| | | $line = substr($line, 0, $bytes); |
| | | $len = strlen($line); |
| | | } |
| | | $bytes -= strlen($line); |
| | | $bytes -= $len; |
| | | |
| | | if ($mode == 1) { |
| | | $line = rtrim($line, "\t\r\n\0\x0B"); |
| | |
| | | do { |
| | | $line = iil_ReadLine($fp, 1024); |
| | | } while (!iil_StartsWith($line, $key, true)); |
| | | |
| | | |
| | | if ($result) { |
| | | $result = rtrim($result, "\t\r\n\0\x0B"); |
| | | if ($file) { |
| | |
| | | echo $result; |
| | | } else |
| | | return $result; // substr($result, 0, strlen($result)-1); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | return false; |
| | |
| | | do { |
| | | $line=iil_ReadLine($fp, 300); |
| | | } while ($line[0] != 'c'); |
| | | $conn->error = $line; |
| | | return (iil_ParseResult($line) == 0); |
| | | } |
| | | return false; |
| | |
| | | } while ($line[0] != 'd'); |
| | | return (iil_ParseResult($line) == 0); |
| | | } |
| | | $conn->error = "Couldn't send command\n"; |
| | | return false; |
| | | } |
| | | |
| | |
| | | do { |
| | | $line = iil_ReadLine($fp, 5000); |
| | | $line = iil_MultLine($fp, $line); |
| | | list(, $index, $cmd, $rest) = explode(' ', $line); |
| | | if ($cmd != 'FETCH' || $index == $id || preg_match("/^$key/", $line)) |
| | | if (!preg_match("/^$key/", $line)) |
| | | $result .= $line; |
| | | } while (!preg_match("/^$key/", $line)); |
| | | |
| | | $result = trim(substr($result, strpos($result, 'BODYSTRUCTURE')+13, -(strlen($result)-strrpos($result, $key)+1))); |
| | | $result = trim(substr($result, strpos($result, 'BODYSTRUCTURE')+13, -1)); |
| | | } |
| | | } |
| | | return $result; |