| | |
| | | } |
| | | |
| | | function iil_ReadLine($fp, $size) { |
| | | $line = ''; |
| | | if ($fp) { |
| | | do { |
| | | // FIXME: hardcode size? |
| | | $buffer = fgets($fp, 2048); |
| | | if ($buffer === false) { |
| | | break; |
| | | } |
| | | $line .= $buffer; |
| | | } while ($buffer[strlen($buffer)-1]!="\n"); |
| | | } |
| | | return $line; |
| | | $line = ''; |
| | | if (!$fp) { |
| | | return $line; |
| | | } |
| | | do { |
| | | // FIXME: hardcode size? |
| | | $buffer = fgets($fp, 2048); |
| | | if ($buffer === false) { |
| | | break; |
| | | } |
| | | $line .= $buffer; |
| | | } while ($buffer[strlen($buffer)-1] != "\n"); |
| | | return $line; |
| | | } |
| | | |
| | | function iil_MultLine($fp, $line) { |
| | |
| | | } |
| | | |
| | | function iil_ReadBytes($fp, $bytes) { |
| | | $data = ''; |
| | | $len = 0; |
| | | do { |
| | | $data.=fread($fp, $bytes-$len); |
| | | $len = strlen($data); |
| | | } while ($len<$bytes); |
| | | return $data; |
| | | $data = ''; |
| | | $len = 0; |
| | | do { |
| | | $data .= fread($fp, $bytes-$len); |
| | | if ($len == strlen($data)) { |
| | | break; //nothing was read -> exit to avoid apache lockups |
| | | } |
| | | $len = strlen($data); |
| | | } while ($len < $bytes); |
| | | return $data; |
| | | } |
| | | |
| | | function iil_ReadReply($fp) { |
| | |
| | | while ( list($lines_key, $str) = each($lines) ) { |
| | | list($field, $string) = iil_SplitHeaderLine($str); |
| | | |
| | | $field = strtolower($field); |
| | | $field = strtolower($field); |
| | | $string = ereg_replace("\n[[:space:]]*"," ",$string); |
| | | |
| | | switch ($field) { |
| | | case 'date'; |
| | |
| | | $result[$id]->from = $string; |
| | | break; |
| | | case 'to': |
| | | $result[$id]->to = str_replace("\n", " ", $string); |
| | | $result[$id]->to = $string; |
| | | break; |
| | | case 'subject': |
| | | $result[$id]->subject = str_replace("\n", '', $string); |
| | | $result[$id]->subject = $string; |
| | | break; |
| | | case 'reply-to': |
| | | $result[$id]->replyto = str_replace("\n", " ", $string); |
| | | $result[$id]->replyto = $string; |
| | | break; |
| | | case 'cc': |
| | | $result[$id]->cc = str_replace("\n", " ", $string); |
| | | $result[$id]->cc = $string; |
| | | break; |
| | | case 'bcc': |
| | | $result[$id]->bcc = str_replace("\n", " ", $string); |
| | | $result[$id]->bcc = $string; |
| | | break; |
| | | case 'content-transfer-encoding': |
| | | $result[$id]->encoding = str_replace("\n", " ", $string); |
| | | $result[$id]->encoding = $string; |
| | | break; |
| | | case 'content-type': |
| | | $ctype_parts = explode(";", $string); |
| | |
| | | case 'return-receipt-to': |
| | | case 'disposition-notification-to': |
| | | case 'x-confirm-reading-to': |
| | | $result[$id]->mdn_to = str_replace("\n", " ", $string); |
| | | $result[$id]->mdn_to = $string; |
| | | break; |
| | | case 'message-id': |
| | | $result[$id]->messageID = $string; |
| | |
| | | $len = strlen($line); |
| | | if ($line[$len-1] == ')') { |
| | | //one line response, get everything between first and last quotes |
| | | $from = strpos($line, '"') + 1; |
| | | $to = strrpos($line, '"'); |
| | | $len = $to - $from; |
| | | if ($mode == 1) { |
| | | $result = substr($line, $from, $len); |
| | | } else if ($mode == 2) { |
| | | echo substr($line, $from, $len); |
| | | if (substr($line, -4, 3) == 'NIL') { |
| | | // NIL response |
| | | $result = ''; |
| | | } else { |
| | | $from = strpos($line, '"') + 1; |
| | | $to = strrpos($line, '"'); |
| | | $len = $to - $from; |
| | | $result = substr($line, $from, $len); |
| | | } |
| | | |
| | | if ($mode == 2) { |
| | | echo $result; |
| | | } else if ($mode == 3) { |
| | | echo base64_decode(substr($line, $from, $len)); |
| | | echo base64_decode($result); |
| | | } |
| | | }else if ($line[$len-1] == '}') { |
| | | } else if ($line[$len-1] == '}') { |
| | | //multi-line request, find sizes of content and receive that many bytes |
| | | $from = strpos($line, '{') + 1; |
| | | $to = strrpos($line, '}'); |
| | |
| | | } |
| | | $received += strlen($line); |
| | | if ($mode == 1) { |
| | | $result .= chop($line) . "\n"; |
| | | $result .= rtrim($line, "\t\r\n\0\x0B") . "\n"; |
| | | } else if ($mode == 2) { |
| | | echo chop($line) . "\n"; flush(); |
| | | echo rtrim($line, "\t\r\n\0\x0B") . "\n"; flush(); |
| | | } else if ($mode == 3) { |
| | | echo base64_decode($line); flush(); |
| | | } |
| | |
| | | } while (!iil_StartsWith($line, $key)); |
| | | |
| | | if ($result) { |
| | | $result = chop($result); |
| | | $result = rtrim($result, "\t\r\n\0\x0B"); |
| | | return $result; // substr($result, 0, strlen($result)-1); |
| | | } |
| | | return false; |
| | |
| | | if (fputs($fp, $request)) { |
| | | $line=iil_ReadLine($fp, 100); |
| | | $sent = fwrite($fp, $message."\r\n"); |
| | | flush(); |
| | | do { |
| | | $line=iil_ReadLine($fp, 1000); |
| | | } while ($line[0] != 'A'); |