| | |
| | | - RFC3501 [7.1] don't call CAPABILITY if was returned in server |
| | | optional resposne in iil_Connect() |
| | | - trim(chop()) replaced by trim() |
| | | - added iil_Escape() with support for " and \ in folder names |
| | | |
| | | |
| | | ********************************************************/ |
| | |
| | | } |
| | | |
| | | |
| | | function iil_Escape($string) |
| | | { |
| | | return strtr($string, array('"'=>'\\"', '\\' => '\\\\')); |
| | | } |
| | | |
| | | function iil_C_Authenticate(&$conn, $user, $pass, $encChallenge) { |
| | | |
| | | $ipad = ''; |
| | |
| | | |
| | | function iil_C_Login(&$conn, $user, $password) { |
| | | |
| | | $password = strtr($password, array('"'=>'\\"', '\\' => '\\\\')); |
| | | $password = iil_Escape($password); |
| | | fputs($conn->fp, "a001 LOGIN $user \"$password\"\r\n"); |
| | | |
| | | do { |
| | |
| | | $conn = iil_Connect($host, $user, $password, 'plain'); |
| | | $fp = $conn->fp; |
| | | if ($fp) { |
| | | fputs($fp, "a002 EXAMINE \"$mailbox\"\r\n"); |
| | | fputs($fp, "a002 EXAMINE \"".iil_Escape($mailbox)."\"\r\n"); |
| | | do { |
| | | $line=chop(iil_ReadLine($fp, 300)); |
| | | $a=explode(' ', $line); |
| | |
| | | |
| | | iil_C_LoadCache($conn, $mailbox); |
| | | |
| | | if (fputs($fp, "sel1 SELECT \"$mailbox\"\r\n")) { |
| | | if (fputs($fp, "sel1 SELECT \"".iil_Escape($mailbox)."\"\r\n")) { |
| | | do { |
| | | $line=chop(iil_ReadLine($fp, 300)); |
| | | $a=explode(' ', $line); |
| | |
| | | return iil_C_ModFlag($conn, $mailbox, $messages, 'DELETED', '-'); |
| | | } |
| | | |
| | | |
| | | function iil_C_Unseen(&$conn, $mailbox, $messages) { |
| | | return iil_C_ModFlag($conn, $mailbox, $messages, 'SEEN', '-'); |
| | | } |
| | |
| | | if (iil_C_Select($conn, $from)) { |
| | | $c=0; |
| | | |
| | | fputs($fp, "cpy1 COPY $messages \"$to\"\r\n"); |
| | | fputs($fp, "cpy1 COPY $messages \"".iil_Escape($to)."\"\r\n"); |
| | | $line=iil_ReadReply($fp); |
| | | return iil_ParseResult($line); |
| | | } else { |
| | |
| | | $ignore = $IGNORE_FOLDERS[strtolower($conn->host)]; |
| | | |
| | | $fp = $conn->fp; |
| | | |
| | | if (empty($mailbox)) { |
| | | $mailbox = '*'; |
| | | } |
| | | |
| | | if (empty($ref) && $conn->rootdir) { |
| | | $ref = $conn->rootdir; |
| | | } |
| | | |
| | | // send command |
| | | if (!fputs($fp, "lmb LIST \"".$ref."\" \"$mailbox\"\r\n")) { |
| | | if (!fputs($fp, "lmb LIST \"".$ref."\" \"".iil_Escape($mailbox)."\"\r\n")) { |
| | | return false; |
| | | } |
| | | |
| | |
| | | $line = rtrim($line); |
| | | // split one line |
| | | $a = iil_ExplodeQuotedString(' ', $line); |
| | | |
| | | // last string is folder name |
| | | $folder = str_replace('"', '', $a[count($a)-1]); |
| | | $folder = trim($a[count($a)-1], '"'); |
| | | |
| | | if (empty($ignore) || (!empty($ignore) |
| | | && !eregi($ignore, $folder))) { |
| | |
| | | } |
| | | |
| | | // second from last is delimiter |
| | | $delim = str_replace('"', '', $a[count($a)-2]); |
| | | $delim = trim($a[count($a)-2], '"'); |
| | | // is it a container? |
| | | $i++; |
| | | } |
| | |
| | | if (!empty($ref)) { |
| | | // if rootdir was specified, make sure it's the first element |
| | | // some IMAP servers (i.e. Courier) won't return it |
| | | if ($ref[strlen($ref)-1]==$delim) $ref = substr($ref, 0, strlen($ref)-1); |
| | | if ($folders[0]!=$ref) array_unshift($folders, $ref); |
| | | if ($ref[strlen($ref)-1]==$delim) |
| | | $ref = substr($ref, 0, strlen($ref)-1); |
| | | if ($folders[0]!=$ref) |
| | | array_unshift($folders, $ref); |
| | | } |
| | | return $folders; |
| | | }else if (iil_ParseResult($line) == 0) { |
| | |
| | | $folders = array(); |
| | | |
| | | // send command |
| | | if (!fputs($fp, 'lsb LSUB "' . $ref . '" "' . $mailbox.'"' . "\r\n")) { |
| | | if (!fputs($fp, 'lsb LSUB "' . $ref . '" "' . iil_Escape($mailbox).'"' . "\r\n")) { |
| | | $conn->error = "Couldn't send LSUB command\n"; |
| | | return false; |
| | | } |
| | |
| | | |
| | | // last string is folder name |
| | | //$folder = UTF7DecodeString(str_replace('"', '', $a[count($a)-1])); |
| | | $folder = str_replace('"', '', $a[count($a)-1]); |
| | | $folder = trim($a[count($a)-1], '"'); |
| | | |
| | | if ((!in_array($folder, $folders)) && (empty($ignore) |
| | | || (!empty($ignore) && !eregi($ignore, $folder)))) { |
| | |
| | | } |
| | | |
| | | // second from last is delimiter |
| | | $delim = str_replace('"', '', $a[count($a)-2]); |
| | | $delim = trim($a[count($a)-2], '"'); |
| | | |
| | | // is it a container? |
| | | $i++; |
| | |
| | | function iil_C_Subscribe(&$conn, $folder) { |
| | | $fp = $conn->fp; |
| | | |
| | | $query = 'sub1 SUBSCRIBE "' . $folder. '"' . "\r\n"; |
| | | $query = 'sub1 SUBSCRIBE "' . iil_Escape($folder). '"' . "\r\n"; |
| | | fputs($fp, $query); |
| | | |
| | | $line = trim(iil_ReadLine($fp, 10000)); |
| | |
| | | function iil_C_UnSubscribe(&$conn, $folder) { |
| | | $fp = $conn->fp; |
| | | |
| | | $query = 'usub1 UNSUBSCRIBE "' . $folder . '"' . "\r\n"; |
| | | $query = 'usub1 UNSUBSCRIBE "' . iil_Escape($folder) . '"' . "\r\n"; |
| | | fputs($fp, $query); |
| | | |
| | | $line = trim(iil_ReadLine($fp, 10000)); |
| | |
| | | |
| | | function iil_C_CreateFolder(&$conn, $folder) { |
| | | $fp = $conn->fp; |
| | | if (fputs($fp, 'c CREATE "' . $folder . '"' . "\r\n")) { |
| | | if (fputs($fp, 'c CREATE "' . iil_Escape($folder) . '"' . "\r\n")) { |
| | | do { |
| | | $line=iil_ReadLine($fp, 300); |
| | | } while ($line[0] != 'c'); |
| | |
| | | |
| | | function iil_C_RenameFolder(&$conn, $from, $to) { |
| | | $fp = $conn->fp; |
| | | if (fputs($fp, 'r RENAME "' . $from . '" "' . $to . '"' . "\r\n")) { |
| | | if (fputs($fp, 'r RENAME "' . iil_Escape($from) . '" "' . iil_Escape($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 "' . iil_Escape($folder). '"' . "\r\n")) { |
| | | do { |
| | | $line=iil_ReadLine($fp, 300); |
| | | } while ($line[0] != 'd'); |
| | |
| | | if (!$len) { |
| | | return false; |
| | | } |
| | | $request = 'A APPEND "' . $folder .'" (\\Seen) {' . $len . "}\r\n"; |
| | | $request = 'A APPEND "' . iil_Escape($folder) .'" (\\Seen) {' . $len . "}\r\n"; |
| | | |
| | | if (fputs($fp, $request)) { |
| | | $line=iil_ReadLine($fp, 100); |
| | |
| | | } |
| | | |
| | | //send APPEND command |
| | | $request = 'A APPEND "' . $folder . '" (\\Seen) {' . $len . "}\r\n"; |
| | | $request = 'A APPEND "' . iil_Escape($folder) . '" (\\Seen) {' . $len . "}\r\n"; |
| | | $bytes_sent = 0; |
| | | if (fputs($fp, $request)) { |
| | | $line = iil_ReadLine($fp, 100); |
| | |
| | | } |
| | | return (iil_C_Expunge($conn, $folder) >= 0); |
| | | } |
| | | |
| | | ?> |