| | |
| | | Function containing "_C_" in name require connection handler to be |
| | | passed as one of the parameters. To obtain connection handler, use |
| | | iil_Connect() |
| | | VERSION: |
| | | IlohaMail-0.9-20050415 |
| | | CHANGES: |
| | | File altered by Thomas Bruederli <roundcube@gmail.com> |
| | | to fit enhanced equirements by the RoundCube Webmail: |
| | | - Added list of server capabilites and check these before invoking commands |
| | | - Added junk flag to iilBasicHeader |
| | | - Enhanced error reporting on fsockopen() |
| | | - Additional parameter for SORT command |
| | | - Removed Call-time pass-by-reference because deprecated |
| | | - Parse charset from content-type in iil_C_FetchHeaders() |
| | | - Enhanced heaer sorting |
| | | - Pass message as reference in iil_C_Append (to save memory) |
| | | - 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 |
| | | - Added function iil_C_ID2UID() |
| | | - Casting date parts in iil_StrToTime() to avoid mktime() warnings |
| | | - 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 ...) |
| | | |
| | | ********************************************************/ |
| | | |
| | | |
| | | // changed path to work within roundcube webmail |
| | | include_once("lib/icl_commons.inc"); |
| | |
| | | var $recent; |
| | | var $rootdir; |
| | | var $delimiter; |
| | | var $capability = array(); |
| | | } |
| | | |
| | | class iilBasicHeader{ |
| | |
| | | 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"); |
| | | } |
| | |
| | | $conn->errorNum = 0; |
| | | return $conn->fp; |
| | | }else{ |
| | | $conn->error .= 'Authentication failed (AUTH): <br>"'.htmlspecialchars($line)."\""; |
| | | $conn->error .= 'Authentication for '.$user.' failed (AUTH): "'.htmlspecialchars($line)."\""; |
| | | $conn->errorNum = -2; |
| | | return false; |
| | | } |
| | |
| | | |
| | | 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; |
| | |
| | | }else{ |
| | | $result=false; |
| | | fclose($conn->fp); |
| | | $conn->error .= 'Authentication failed (LOGIN):<br>"'.htmlspecialchars($line)."\""; |
| | | $conn->error .= 'Authentication for '.$user.' failed (LOGIN): "'.htmlspecialchars($line)."\""; |
| | | $conn->errorNum = -2; |
| | | } |
| | | return $result; |
| | |
| | | |
| | | function iil_C_NameSpace(&$conn){ |
| | | global $my_prefs; |
| | | |
| | | if (!in_array('NAMESPACE', $conn->capability)) |
| | | return false; |
| | | |
| | | if ($my_prefs["rootdir"]) return true; |
| | | |
| | |
| | | $iil_errornum = 0; |
| | | |
| | | //strip slashes |
| | | $user = stripslashes($user); |
| | | $password = stripslashes($password); |
| | | // $user = stripslashes($user); |
| | | // $password = stripslashes($password); |
| | | |
| | | //set auth method |
| | | $auth_method = "plain"; |
| | |
| | | //echo '<!-- conn sort_field: '.$my_prefs['sort_field'].' //-->'; |
| | | |
| | | //check input |
| | | if (empty($host)) $iil_error .= "Invalid host<br>\n"; |
| | | if (empty($user)) $iil_error .= "Invalid user<br>\n"; |
| | | if (empty($password)) $iil_error .= "Invalid password<br>\n"; |
| | | if (empty($host)) $iil_error .= "Invalid host\n"; |
| | | if (empty($user)) $iil_error .= "Invalid user\n"; |
| | | if (empty($password)) $iil_error .= "Invalid password\n"; |
| | | if (!empty($iil_error)) return false; |
| | | if (!$ICL_PORT) $ICL_PORT = 143; |
| | | |
| | |
| | | |
| | | $iil_error.="Socket connection established\r\n"; |
| | | $line=iil_ReadLine($conn->fp, 300); |
| | | |
| | | |
| | | if (strcasecmp($auth_method, "check")==0){ |
| | | //check for supported auth methods |
| | | |
| | |
| | | $a = explode(" ", $line); |
| | | if ($line[0]=="*"){ |
| | | while ( list($k, $w) = each($a) ){ |
| | | if ($w!='*' && $w!='CAPABILITY') |
| | | $conn->capability[] = $w; |
| | | if ((strcasecmp($w, "AUTH=CRAM_MD5")==0)|| |
| | | (strcasecmp($w, "AUTH=CRAM-MD5")==0)){ |
| | | $auth_method = "auth"; |
| | |
| | | //$month_a=array("Jan"=>1,"Feb"=>2,"Mar"=>3,"Apr"=>4,"May"=>5,"Jun"=>6,"Jul"=>7,"Aug"=>8,"Sep"=>9,"Oct"=>10,"Nov"=>11,"Dec"=>12); |
| | | $month_str=$a[1]; |
| | | $month=$IMAP_MONTHS[$month_str]; |
| | | $day=$a[0]; |
| | | $year=$a[2]; |
| | | $day=(int)$a[0]; |
| | | $year=(int)$a[2]; |
| | | $time=$a[3]; |
| | | $tz_str = $a[4]; |
| | | $tz = substr($tz_str, 0, 3); |
| | | $ta=explode(":",$time); |
| | | $ta = explode(":",$time); |
| | | $hour=(int)$ta[0]-(int)$tz; |
| | | $minute=$ta[1]; |
| | | $second=$ta[2]; |
| | | $minute=(int)$ta[1]; |
| | | $second=(int)$ta[2]; |
| | | |
| | | //make UNIX timestamp |
| | | $time2 = mktime($hour, $minute, $second, $month, $day, $year); |
| | |
| | | return $time2; |
| | | } |
| | | |
| | | function iil_C_Sort(&$conn, $mailbox, $field){ |
| | | function iil_C_Sort(&$conn, $mailbox, $field, $add='', $is_uid=FALSE, $encoding='US-ASCII'){ |
| | | /* Do "SELECT" command */ |
| | | if (!iil_C_Select($conn, $mailbox)) return false; |
| | | |
| | |
| | | if ($field=='INTERNALDATE') $field='ARRIVAL'; |
| | | $fields = array('ARRIVAL'=>1,'CC'=>1,'DATE'=>1,'FROM'=>1,'SIZE'=>1,'SUBJECT'=>1,'TO'=>1); |
| | | |
| | | if (!$fields[$field]) return false; |
| | | if (!$fields[$field]) |
| | | return false; |
| | | |
| | | $is_uid = $is_uid ? 'UID ' : ''; |
| | | |
| | | if (!empty($add)) |
| | | $add = " $add"; |
| | | |
| | | $fp = $conn->fp; |
| | | $command = 's SORT ('.$field.') US-ASCII ALL'."\r\n"; |
| | | $command = 's '. $is_uid .'SORT ('.$field.') '.$encoding.' ALL'."$add\r\n"; |
| | | $line = $data = ''; |
| | | |
| | | if (!fputs($fp, $command)) return false; |
| | |
| | | return $out; |
| | | } |
| | | |
| | | function iil_C_FetchHeaderIndex(&$conn, $mailbox, $message_set, $index_field,$normalize=true){ |
| | | function iil_C_FetchHeaderIndex(&$conn, $mailbox, $message_set, $index_field, $normalize=true){ |
| | | global $IMAP_USE_INTERNAL_DATE; |
| | | |
| | | $c=0; |
| | |
| | | if (empty($index_field)) $index_field="DATE"; |
| | | $index_field = strtoupper($index_field); |
| | | |
| | | if (empty($message_set)) return array(); |
| | | list($from_idx, $to_idx) = explode(':', $message_set); |
| | | if (empty($message_set) || (isset($to_idx) && (int)$from_idx > (int)$to_idx)) |
| | | return false; |
| | | |
| | | //$fields_a["DATE"] = ($IMAP_USE_INTERNAL_DATE?6:1); |
| | | $fields_a['DATE'] = 1; |
| | |
| | | global $clock; |
| | | global $index_a; |
| | | |
| | | if (empty($message_set)) return false; |
| | | list($from_idx, $to_idx) = explode(':', $message_set); |
| | | if (empty($message_set) || (isset($to_idx) && (int)$from_idx > (int)$to_idx)) |
| | | return false; |
| | | |
| | | $result = array(); |
| | | $uids = iil_C_FetchUIDs($conn, $mailbox); |
| | |
| | | function iil_C_BuildThreads2(&$conn, $mailbox, $message_set, &$clock){ |
| | | global $index_a; |
| | | |
| | | if (empty($message_set)) return false; |
| | | list($from_idx, $to_idx) = explode(':', $message_set); |
| | | if (empty($message_set) || (isset($to_idx) && (int)$from_idx > (int)$to_idx)) |
| | | return false; |
| | | |
| | | $result=array(); |
| | | $roots=array(); |
| | |
| | | return $t_index; |
| | | } |
| | | |
| | | function iil_C_FetchHeaders(&$conn, $mailbox, $message_set){ |
| | | function iil_C_FetchHeaders(&$conn, $mailbox, $message_set, $uidfetch=false){ |
| | | global $IMAP_USE_INTERNAL_DATE; |
| | | |
| | | $c=0; |
| | | $result=array(); |
| | | $fp = $conn->fp; |
| | | |
| | | if (empty($message_set)) return array(); |
| | | |
| | | list($from_idx, $to_idx) = explode(':', $message_set); |
| | | if (empty($message_set) || (isset($to_idx) && (int)$from_idx > (int)$to_idx)) |
| | | return false; |
| | | |
| | | /* Do "SELECT" command */ |
| | | if (!iil_C_Select($conn, $mailbox)){ |
| | | $conn->error = "Couldn't select $mailbox"; |
| | |
| | | |
| | | /* FETCH date,from,subject headers */ |
| | | $key="fh".($c++); |
| | | $request=$key." FETCH $message_set (BODY.PEEK[HEADER.FIELDS (DATE FROM TO SUBJECT REPLY-TO IN-REPLY-TO CC CONTENT-TRANSFER-ENCODING CONTENT-TYPE MESSAGE-ID)])\r\n"; |
| | | |
| | | // echo "// $request\n\n"; |
| | | $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 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]!=")"); |
| | | /* |
| | | 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))) |
| | | { |
| | | //process header, fill iilBasicHeader obj. |
| | | // initialize |
| | | if (is_array($headers)){ |
| | |
| | | } |
| | | |
| | | // 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]->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']); |
| | | |
| | | 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) $messageID = substr(substr($messageID, 1), 0, strlen($messageID)-2); |
| | | else $messageID = "mid:".$id; |
| | | $result[$id]->messageID = $messageID; |
| | | } |
| | | else { |
| | | $a=explode(" ", $line); |
| | | } |
| | | |
| | | } |
| | | }while(strcmp($a[0], $key)!=0); |
| | |
| | | Sample reply line: "* 3 FETCH (UID 2417 RFC822.SIZE 2730 FLAGS (\Seen \Deleted))" |
| | | */ |
| | | $command_key="fh".($c++); |
| | | $request= $command_key." FETCH $message_set (UID RFC822.SIZE FLAGS INTERNALDATE)\r\n"; |
| | | $request= $command_key.$prefix." FETCH $message_set (UID RFC822.SIZE FLAGS INTERNALDATE)\r\n"; |
| | | if (!fputs($fp, $request)) return false; |
| | | do{ |
| | | $line=chop(iil_ReadLine($fp, 200)); |
| | |
| | | $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... |
| | |
| | | } |
| | | |
| | | |
| | | function iil_C_FetchHeader(&$conn, $mailbox, $id){ |
| | | function iil_C_FetchHeader(&$conn, $mailbox, $id, $uidfetch=false){ |
| | | $fp = $conn->fp; |
| | | $a=iil_C_FetchHeaders($conn, $mailbox, $id); |
| | | if (is_array($a)) return $a[$id]; |
| | | $a=iil_C_FetchHeaders($conn, $mailbox, $id, $uidfetch); |
| | | if (is_array($a)) return array_shift($a); |
| | | else return false; |
| | | } |
| | | |
| | |
| | | if ($field=="date"||$field=='internaldate') $field="timestamp"; |
| | | if (empty($flag)) $flag="ASC"; |
| | | $flag=strtoupper($flag); |
| | | |
| | | $stripArr = ($field=='subject') ? array('Re: ','Fwd: ','Fw: ',"\"") : array("\""); |
| | | |
| | | $c=count($a); |
| | | if ($c>0){ |
| | | /* |
| | |
| | | and use that to sort the main array. |
| | | */ |
| | | |
| | | // create "index" array |
| | | // create "index" array |
| | | $index=array(); |
| | | reset($a); |
| | | while (list($key, $val)=each($a)){ |
| | | $data=$a[$key]->$field; |
| | | if (is_string($data)) $data=strtoupper(str_replace("\"", "", $data)); |
| | | |
| | | if ($field=="timestamp"){ |
| | | $data = @strtotime($val->date); |
| | | if ($data == false) |
| | | $data = $val->timestamp; |
| | | } |
| | | else { |
| | | $data = $val->$field; |
| | | if (is_string($data)) |
| | | $data=strtoupper(str_replace($stripArr, "", $data)); |
| | | } |
| | | |
| | | $index[$key]=$data; |
| | | } |
| | | |
| | |
| | | |
| | | $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)){ |
| | |
| | | return false; |
| | | } |
| | | |
| | | function iil_C_ID2UID(&$conn, $folder, $id){ |
| | | $fp = $conn->fp; |
| | | $result=-1; |
| | | if ($id > 0) { |
| | | if (iil_C_Select($conn, $folder)){ |
| | | $key = "FUID"; |
| | | if (fputs($fp, "$key FETCH $id (UID)\r\n")){ |
| | | do{ |
| | | $line=chop(iil_ReadLine($fp, 1024)); |
| | | if (eregi("^\* $id FETCH \(UID (.*)\)", $line, $r)){ |
| | | $result = $r[1]; |
| | | } |
| | | } while (!preg_match("/^$key/", $line)); |
| | | } |
| | | } |
| | | } |
| | | return $result; |
| | | } |
| | | |
| | | function iil_C_Search(&$conn, $folder, $criteria){ |
| | | $fp = $conn->fp; |
| | | if (iil_C_Select($conn, $folder)){ |
| | |
| | | $result_code=iil_ParseResult($line); |
| | | if ($result_code==0) return $messages; |
| | | else{ |
| | | $conn->error = "iil_C_Search: ".$line."<br>\n"; |
| | | $conn->error = "iil_C_Search: ".$line."\n"; |
| | | return false; |
| | | } |
| | | |
| | | }else{ |
| | | $conn->error = "iil_C_Search: Couldn't select \"$folder\" <br>\n"; |
| | | $conn->error = "iil_C_Search: Couldn't select \"$folder\"\n"; |
| | | return false; |
| | | } |
| | | } |
| | |
| | | $line=iil_ReadLine($fp, 500); |
| | | $line=iil_MultLine($fp, $line); |
| | | $a = explode(" ", $line); |
| | | if (($line[0]=="*") && ($a[1]=="LSUB")){ |
| | | if (($line[0]=="*") && ($a[1]=="LSUB" || $a[1]=="LIST")){ |
| | | $line = rtrim($line); |
| | | // split one line |
| | | $a=iil_ExplodeQuotedString(" ", $line); |
| | |
| | | $remaining = $bytes - $received; |
| | | $line = iil_ReadLine($fp, 1024); |
| | | $len = strlen($line); |
| | | if ($len > $remaining) substr($line, 0, $remaining); |
| | | if ($len > $remaining) $line = substr($line, 0, $remaining); |
| | | $received += strlen($line); |
| | | if ($mode==1) $result .= chop($line)."\n"; |
| | | else if ($mode==2){ echo chop($line)."\n"; flush(); } |
| | |
| | | } |
| | | } |
| | | |
| | | function iil_C_Append(&$conn, $folder, $message){ |
| | | function iil_C_Append(&$conn, $folder, &$message){ |
| | | if (!$folder) return false; |
| | | $fp = $conn->fp; |
| | | |
| | |
| | | if (!$len) return false; |
| | | |
| | | $request="A APPEND \"".$folder."\" (\\Seen) {".$len."}\r\n"; |
| | | // echo $request.'<br>'; |
| | | if (fputs($fp, $request)){ |
| | | $line=iil_ReadLine($fp, 100); |
| | | // echo $line.'<br>'; |
| | | |
| | | $line=iil_ReadLine($fp, 100); |
| | | $sent = fwrite($fp, $message."\r\n"); |
| | | flush(); |
| | | do{ |
| | | $line=iil_ReadLine($fp, 1000); |
| | | //echo $line.'<br>'; |
| | | }while($line[0]!="A"); |
| | | |
| | | $result = (iil_ParseResult($line)==0); |
| | | if (!$result) $conn->error .= $line."<br>\n"; |
| | | if (!$result) $conn->error .= $line."\n"; |
| | | return $result; |
| | | |
| | | }else{ |
| | | $conn->error .= "Couldn't send command \"$request\"<br>\n"; |
| | | $conn->error .= "Couldn't send command \"$request\"\n"; |
| | | return false; |
| | | } |
| | | } |
| | |
| | | $in_fp = false; |
| | | if (file_exists(realpath($path))) $in_fp = fopen($path, "r"); |
| | | if (!$in_fp){ |
| | | $conn->error .= "Couldn't open $path for reading<br>\n"; |
| | | $conn->error .= "Couldn't open $path for reading\n"; |
| | | return false; |
| | | } |
| | | |
| | |
| | | //read response |
| | | do{ |
| | | $line=iil_ReadLine($fp, 1000); |
| | | //echo $line.'<br>'; |
| | | }while($line[0]!="A"); |
| | | |
| | | $result = (iil_ParseResult($line)==0); |
| | | if (!$result) $conn->error .= $line."<br>\n"; |
| | | if (!$result) $conn->error .= $line."\n"; |
| | | return $result; |
| | | |
| | | }else{ |
| | | $conn->error .= "Couldn't send command \"$request\"<br>\n"; |
| | | $conn->error .= "Couldn't send command \"$request\"\n"; |
| | | return false; |
| | | } |
| | | } |
| | |
| | | return (iil_C_Expunge($conn, $folder) >= 0); |
| | | } |
| | | |
| | | ?> |
| | | ?> |