| | |
| | | - Added BCC and REFERENCE to the list of headers to fetch in iil_C_FetchHeaders() |
| | | - Leave messageID unchanged in iil_C_FetchHeaders() |
| | | - Avoid stripslahes in iil_Connect() |
| | | - Escape quotes and backslashes in iil_C_Login() |
| | | - Added patch to iil_SortHeaders() by Richard Green |
| | | - Removed <br> from error messages (better for logging) |
| | | - Added patch to iil_C_Sort() enabling UID SORT commands |
| | |
| | | - Also acceppt LIST responses in iil_C_ListSubscribed() |
| | | - Sanity check of $message_set in iil_C_FetchHeaders(), iil_C_FetchHeaderIndex(), iil_C_FetchThreadHeaders() |
| | | - Implemented UID FETCH in iil_C_FetchHeaders() |
| | | - Abort do-loop on socket errors (fgets returns false) |
| | | - Removed some debuggers (echo ...) |
| | | |
| | | ********************************************************/ |
| | |
| | | var $messageID; |
| | | var $size; |
| | | var $encoding; |
| | | var $charset; |
| | | var $ctype; |
| | | var $flags; |
| | | var $timestamp; |
| | | var $f; |
| | | var $seen; |
| | | var $deleted; |
| | | var $recent; |
| | | var $answered; |
| | | var $junk; |
| | | var $internaldate; |
| | | var $is_reply; |
| | | var $references; |
| | | var $mdn_to; |
| | | var $mdn_sent = false; |
| | | var $is_reply = false; |
| | | var $seen = false; |
| | | var $deleted = false; |
| | | var $recent = false; |
| | | var $answered = false; |
| | | var $junk = false; |
| | | } |
| | | |
| | | |
| | |
| | | if ($fp){ |
| | | do{ |
| | | $buffer = fgets($fp, 2048); |
| | | if ($buffer === false) |
| | | break; |
| | | $line.=$buffer; |
| | | }while($buffer[strlen($buffer)-1]!="\n"); |
| | | } |
| | |
| | | |
| | | function iil_C_Login(&$conn, $user, $password){ |
| | | |
| | | $password = strtr($password, array('"'=>'\\"', '\\' => '\\\\')); |
| | | fputs($conn->fp, "a001 LOGIN $user \"$password\"\r\n"); |
| | | |
| | | do{ |
| | | $line = iil_ReadReply($conn->fp); |
| | | }while(!iil_StartsWith($line, "a001 ")); |
| | | |
| | | do{ |
| | | $line = iil_ReadReply($conn->fp); |
| | | if ($line === false) |
| | | break; |
| | | }while(!iil_StartsWith($line, "a001 ")); |
| | | $a=explode(" ", $line); |
| | | if (strcmp($a[1],"OK")==0){ |
| | | $result=$conn->fp; |
| | |
| | | /* FETCH date,from,subject headers */ |
| | | $key="fh".($c++); |
| | | $prefix=$uidfetch?" UID":""; |
| | | $request=$key.$prefix." FETCH $message_set (BODY.PEEK[HEADER.FIELDS (DATE FROM TO SUBJECT REPLY-TO IN-REPLY-TO CC BCC CONTENT-TRANSFER-ENCODING CONTENT-TYPE MESSAGE-ID REFERENCE)])\r\n"; |
| | | $request=$key.$prefix." FETCH $message_set (BODY.PEEK[HEADER.FIELDS (DATE FROM TO SUBJECT REPLY-TO IN-REPLY-TO CC BCC CONTENT-TRANSFER-ENCODING CONTENT-TYPE MESSAGE-ID REFERENCES DISPOSITION-NOTIFICATION-TO)])\r\n"; |
| | | |
| | | if (!fputs($fp, $request)) return false; |
| | | do{ |
| | |
| | | $result[$id]=new iilBasicHeader; |
| | | $result[$id]->id = $id; |
| | | $result[$id]->subject = ""; |
| | | $result[$id]->messageID = "mid:".$id; |
| | | /* |
| | | Start parsing headers. The problem is, some header "lines" take up multiple lines. |
| | | So, we'll read ahead, and if the one we're reading now is a valid header, we'll |
| | |
| | | $i++; |
| | | $lines[$i] = trim(chop($line)); |
| | | } |
| | | }while($line[0]!=")" && strncmp($line, $key, strlen($key))); // patch from "Maksim Rubis" <siburny@hotmail.com> |
| | | /* |
| | | The preg_match below works around communigate imap, which outputs " UID <number>)". |
| | | Without this, the while statement continues on and gets the "fh0 OK completed" message. |
| | | If this loop gets the ending message, then the outer loop does not receive it from radline on line 1249. |
| | | This in causes the if statement on line 1278 to never be true, which causes the headers to end up missing |
| | | If the if statement was changed to pick up the fh0 from this loop, then it causes the outer loop to spin |
| | | An alternative might be: |
| | | if (!preg_match("/:/",$line) && preg_match("/\)$/",$line)) break; |
| | | however, unsure how well this would work with all imap clients. |
| | | */ |
| | | if (preg_match("/^\s*UID [0-9]+\)$/",$line)) break; |
| | | }while(trim($line[0])!=")" && strncmp($line, $key, strlen($key))); // patch from "Maksim Rubis" <siburny@hotmail.com> |
| | | |
| | | if(strncmp($line, $key, strlen($key))) |
| | | { |
| | |
| | | } |
| | | |
| | | // create array with header field:data |
| | | $headers = array(); |
| | | while ( list($lines_key, $str) = each($lines) ){ |
| | | list($field, $string) = iil_SplitHeaderLine($str); |
| | | $field = strtolower($field); |
| | | $headers[$field] = $string; |
| | | |
| | | switch ($field){ |
| | | case 'date'; |
| | | $result[$id]->date = $string; |
| | | $result[$id]->timestamp = iil_StrToTime($string); |
| | | break; |
| | | case 'from': |
| | | $result[$id]->from = $string; |
| | | break; |
| | | case 'to': |
| | | $result[$id]->to = str_replace("\n", " ", $string); |
| | | break; |
| | | case 'subject': |
| | | $result[$id]->subject = str_replace("\n", "", $string); |
| | | break; |
| | | case 'reply-to': |
| | | $result[$id]->replyto = str_replace("\n", " ", $string); |
| | | break; |
| | | case 'cc': |
| | | $result[$id]->cc = str_replace("\n", " ", $string); |
| | | break; |
| | | case 'bcc': |
| | | $result[$id]->bcc = str_replace("\n", " ", $string); |
| | | break; |
| | | case 'content-transfer-encoding': |
| | | $result[$id]->encoding = str_replace("\n", " ", $string); |
| | | break; |
| | | case 'content-type': |
| | | $ctype_parts = explode(";", $string); |
| | | $result[$id]->ctype = array_shift($ctype_parts); |
| | | foreach ($ctype_parts as $ctype_add) |
| | | if (preg_match('/charset="?([a-z0-9\-]+)"?/i', $ctype_add, $regs)) |
| | | $result[$id]->charset = $regs[1]; |
| | | break; |
| | | case 'in-reply-to': |
| | | $result[$id]->in_reply_to = ereg_replace("[\n<>]", '', $string); |
| | | break; |
| | | case 'references': |
| | | $result[$id]->references = $string; |
| | | break; |
| | | case 'return-receipt-to': |
| | | case 'disposition-notification-to': |
| | | case 'x-confirm-reading-to': |
| | | $result[$id]->mdn_to = str_replace("\n", " ", $string); |
| | | break; |
| | | case 'message-id': |
| | | $result[$id]->messageID = $string; |
| | | break; |
| | | } |
| | | } |
| | | $result[$id]->date = $headers["date"]; |
| | | $result[$id]->timestamp = iil_StrToTime($headers["date"]); |
| | | $result[$id]->from = $headers["from"]; |
| | | $result[$id]->to = str_replace("\n", " ", $headers["to"]); |
| | | $result[$id]->subject = str_replace("\n", "", $headers["subject"]); |
| | | $result[$id]->replyto = str_replace("\n", " ", $headers["reply-to"]); |
| | | $result[$id]->cc = str_replace("\n", " ", $headers["cc"]); |
| | | $result[$id]->bcc = str_replace("\n", " ", $headers["bcc"]); |
| | | $result[$id]->encoding = str_replace("\n", " ", $headers["content-transfer-encoding"]); |
| | | $result[$id]->ctype = str_replace("\n", " ", $headers["content-type"]); |
| | | $result[$id]->in_reply_to = ereg_replace("[\n<>]",'', $headers['in-reply-to']); |
| | | $result[$id]->reference = $headers["reference"]; |
| | | |
| | | list($result[$id]->ctype, $ctype_add) = explode(";", $headers["content-type"]); |
| | | |
| | | if (preg_match('/charset="?([a-z0-9\-]+)"?/i', $ctype_add, $regs)) |
| | | $result[$id]->charset = $regs[1]; |
| | | |
| | | $messageID = $headers["message-id"]; |
| | | if (!$messageID) "mid:".$id; |
| | | $result[$id]->messageID = $messageID; |
| | | } |
| | | else { |
| | | $a=explode(" ", $line); |
| | | } |
| | | } |
| | | else { |
| | | $a=explode(" ", $line); |
| | | } |
| | | |
| | | } |
| | | }while(strcmp($a[0], $key)!=0); |
| | |
| | | $flags_a = explode(" ", $flags_str); |
| | | //echo "<!-- ID: $id FLAGS: ".implode(",", $flags_a)." //-->\n"; |
| | | |
| | | $result[$id]->seen = false; |
| | | $result[$id]->recent = false; |
| | | $result[$id]->deleted = false; |
| | | $result[$id]->answered = false; |
| | | if (is_array($flags_a)){ |
| | | reset($flags_a); |
| | | while (list($key,$val)=each($flags_a)){ |
| | |
| | | else if (strcasecmp($val, "Deleted")==0) $result[$id]->deleted=true; |
| | | else if (strcasecmp($val, "Recent")==0) $result[$id]->recent = true; |
| | | else if (strcasecmp($val, "Answered")==0) $result[$id]->answered = true; |
| | | else if (strcasecmp($val, "\$MDNSent")==0) $result[$id]->mdn_sent = true; |
| | | } |
| | | $result[$id]->flags=$flags_str; |
| | | $result[$id]->flags = $flags_a; |
| | | } |
| | | |
| | | // if time is gmt... |
| | |
| | | |
| | | $fp = $conn->fp; |
| | | $flags=array( |
| | | "SEEN"=>"\\Seen", |
| | | "DELETED"=>"\\Deleted", |
| | | "RECENT"=>"\\Recent", |
| | | "ANSWERED"=>"\\Answered", |
| | | "DRAFT"=>"\\Draft", |
| | | "FLAGGED"=>"\\Flagged" |
| | | ); |
| | | "SEEN"=>"\\Seen", |
| | | "DELETED"=>"\\Deleted", |
| | | "RECENT"=>"\\Recent", |
| | | "ANSWERED"=>"\\Answered", |
| | | "DRAFT"=>"\\Draft", |
| | | "FLAGGED"=>"\\Flagged", |
| | | "MDNSENT"=>"\$MDNSent" |
| | | ); |
| | | $flag=strtoupper($flag); |
| | | $flag=$flags[$flag]; |
| | | if (iil_C_Select($conn, $mailbox)){ |