| | |
| | | } |
| | | |
| | | function iil_PutLine($fp, $string, $endln=true) { |
| | | // console('C: '. rtrim($string)); |
| | | global $my_prefs; |
| | | |
| | | if(!empty($my_prefs['debug_mode'])) |
| | | write_log('imap', 'C: '. rtrim($string)); |
| | | |
| | | return fputs($fp, $string . ($endln ? "\r\n" : '')); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | function iil_ReadLine($fp, $size=1024) { |
| | | global $my_prefs; |
| | | |
| | | $line = ''; |
| | | |
| | | if (!$fp) { |
| | |
| | | if ($buffer === false) { |
| | | break; |
| | | } |
| | | // console('S: '. chop($buffer)); |
| | | if(!empty($my_prefs['debug_mode'])) |
| | | write_log('imap', 'S: '. chop($buffer)); |
| | | $line .= $buffer; |
| | | } while ($buffer[strlen($buffer)-1] != "\n"); |
| | | |
| | |
| | | } |
| | | |
| | | function iil_ReadBytes($fp, $bytes) { |
| | | global $my_prefs; |
| | | $data = ''; |
| | | $len = 0; |
| | | do { |
| | |
| | | if ($len == strlen($data)) { |
| | | break; //nothing was read -> exit to avoid apache lockups |
| | | } |
| | | // console('[...] '. $d); |
| | | if(!empty($my_prefs['debug_mode'])) |
| | | write_log('imap', 'S: '. $d); |
| | | $len = strlen($data); |
| | | } while ($len < $bytes); |
| | | |
| | |
| | | $my_prefs['rootdir'] = $optval; |
| | | } else if ($optkey == 'delimiter') { |
| | | $my_prefs['delimiter'] = $optval; |
| | | } else if ($optkey == 'debug_mode') { |
| | | $my_prefs['debug_mode'] = $optval; |
| | | } |
| | | } |
| | | } |
| | |
| | | return $result; |
| | | } |
| | | |
| | | function iil_C_FetchPartHeader(&$conn, $mailbox, $id, $part) { |
| | | function iil_C_FetchPartHeader(&$conn, $mailbox, $id, $is_uid=false, $part=NULL) { |
| | | |
| | | $part = empty($part) ? 'HEADER' : $part.'.MIME'; |
| | | |
| | | return iil_C_HandlePartBody($conn, $mailbox, $id, $part); |
| | | return iil_C_HandlePartBody($conn, $mailbox, $id, $is_uid, $part); |
| | | } |
| | | |
| | | function iil_C_HandlePartBody(&$conn, $mailbox, $id, $part='', $encoding=NULL, $print=NULL, $file=NULL) { |
| | | function iil_C_HandlePartBody(&$conn, $mailbox, $id, $is_uid=false, $part='', $encoding=NULL, $print=NULL, $file=NULL) { |
| | | |
| | | $fp = $conn->fp; |
| | | $result = false; |
| | |
| | | |
| | | // format request |
| | | $key = 'ftch0'; |
| | | $request = $key . " FETCH $id (BODY.PEEK[$part])"; |
| | | $request = $key . ($is_uid ? ' UID' : '') . " FETCH $id (BODY.PEEK[$part])"; |
| | | // send request |
| | | if (!iil_PutLine($fp, $request)) { |
| | | return false; |
| | |
| | | $len = $to - $from; |
| | | $result = substr($line, $from, $len); |
| | | } |
| | | |
| | | |
| | | if ($mode == 1) |
| | | $result = base64_decode($result); |
| | | else if ($mode == 2) |
| | |
| | | $sizeStr = substr($line, $from, $len); |
| | | $bytes = (int)$sizeStr; |
| | | $prev = ''; |
| | | |
| | | |
| | | while ($bytes > 0) { |
| | | $line = iil_ReadLine($fp, 1024); |
| | | $len = strlen($line); |
| | |
| | | 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; |
| | | } |
| | | |
| | | function iil_C_FetchPartBody(&$conn, $mailbox, $id, $part, $file=NULL) { |
| | | return iil_C_HandlePartBody($conn, $mailbox, $id, $part, NULL, NULL, $file); |
| | | } |
| | | |
| | | function iil_C_PrintPartBody(&$conn, $mailbox, $id, $part) { |
| | | iil_C_HandlePartBody($conn, $mailbox, $id, $part, NULL, true, NULL); |
| | | } |
| | | |
| | | function iil_C_CreateFolder(&$conn, $folder) { |
| | |
| | | return false; |
| | | } |
| | | |
| | | function iil_C_FetchStructureString(&$conn, $folder, $id) { |
| | | function iil_C_FetchStructureString(&$conn, $folder, $id, $is_uid=false) { |
| | | $fp = $conn->fp; |
| | | $result = false; |
| | | |
| | | if (iil_C_Select($conn, $folder)) { |
| | | $key = 'F1247'; |
| | | |
| | | if (iil_PutLine($fp, "$key FETCH $id (BODYSTRUCTURE)")) { |
| | | if (iil_PutLine($fp, $key . ($is_uid ? ' UID' : '') ." FETCH $id (BODYSTRUCTURE)")) { |
| | | 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; |