echo "Extract and return as string\n"; $result = mailparse_msg_extract_part_file($mime, $fp, null); echo "-->\n"; echo $result; echo "\nExtract to open file\n"; $fpdest = tmpfile(); mailparse_msg_extract_part_file($mime, $fp, $fpdest); echo "\nrewinding\n"; rewind($fpdest); fpassthru($fpdest); echo "\nExtract via user function\n"; mailparse_msg_extract_part_file($mime, $fp); echo "\nExtract whole part to output\n"; mailparse_msg_extract_whole_part_file($mime, $fp); echo "\nExtract part from string to output\n"; mailparse_msg_extract_part($mime, $text); fclose($fpdest); fclose($fp); $output = ob_get_contents(); ob_end_clean(); VS($output, "Extract to output\n" . "hello, this is some text hello.\n" . "blah blah blah.\n" . "Extract and return as string\n" . "-->\n" . "hello, this is some text hello.\n" . "blah blah blah.\n" . "\n" . "Extract to open file\n" . "\n" . "rewinding\n" . "hello, this is some text hello.\n" . "blah blah blah.\n" . "\n" . "Extract via user function\n" . "hello, this is some text hello.\n" . "blah blah blah.\n" . "\n" . "Extract whole part to output\n" . "To: fred@bloggs.com\n" . "Mime-Version: 1.0\n" . "Content-Type: text/plain\n" . "Subject: A simple MIME message\n" . "\n" . "hello, this is some text hello.\n" . "blah blah blah.\n" . "\n" . "Extract part from string to output\n" . "hello, this is some text hello.\n" . "blah blah blah.\n"); ////////////////////////////////////////////////////////////////////// $msg = "Received: from mail pickup service by hotmail.com with Microsoft\n" . "SMTPSVC;\n" . "Sat, 18 Feb 2006 22:58:14 -0800\n" . "Received: from 66.178.40.49 by BAY116-DAV8.phx.gbl with DAV;\n" . "Sun, 19 Feb 2006 06:58:13 +0000\n" . "\n" . "test"; $mail = mailparse_msg_create(); mailparse_msg_parse($mail, $msg); $arr = mailparse_msg_get_structure($mail); foreach ($arr as $first => $second) { $section = mailparse_msg_get_part($mail, $second); $info = mailparse_msg_get_part_data($section); $received = array("from mail pickup service by hotmail.com with Microsoft", "from 66.178.40.49 by BAY116-DAV8.phx.gbl with DAV;"); VS($info, array("headers" => array("received" => $received), "starting-pos" => 0, "starting-pos-body" => 200, "ending-pos" => 200, "ending-pos-body" => 200, "line-count" => 6, "body-line-count" => 0, "charset" => "us-ascii", "transfer-encoding" => "8bit", "content-type" => "text/plain", "content-base" => "/"));
/** * @param string $msgBody * @param callable $callback * * @return void */ public function extractPart(string $msgBody, callable $callback) { mailparse_msg_extract_part($this->resource, $msgBody, $callback); }
if (strlen(trim($str)) > 0) { mail('*****@*****.**', 'Output from incomingmail.php', $str, 'From: TwitApps <*****@*****.**>', '*****@*****.**'); } } $data = file_get_contents('php://stdin'); $msg = mailparse_msg_create(); if (!mailparse_msg_parse($msg, $data)) { mail('*****@*****.**', 'TwitApps incoming mail: Parse failed', $data, 'From: TwitApps <*****@*****.**>', '*****@*****.**'); } else { $message = mailparse_msg_get_part($msg, 1); $info = mailparse_msg_get_part_data($message); if (!$message or !$info) { mail('*****@*****.**', 'TwitApps incoming mail: Failed to get message or info', $data, 'From: TwitApps <*****@*****.**>', '*****@*****.**'); } else { ob_start(); mailparse_msg_extract_part($message, $data); $body = ob_get_clean(); $body = urldecode($body); $body = iconv($info['charset'], 'UTF-8', $body); $body = html_entity_decode($body, ENT_NOQUOTES, 'UTF-8'); //mail('*****@*****.**', $info['headers']['subject'], $body."\n\n========================================\n\n".$data, 'From: TwitApps <*****@*****.**>', '*****@*****.**'); switch (@$info['headers']['x-twitterrecipientscreenname']) { case 'ta_follows': require dirname(__FILE__) . '/../follows/cli/incoming_mail.php'; break; case 'ta_replies': require dirname(__FILE__) . '/../replies/cli/incoming_mail.php'; break; // Unhandled, forward the email on so it doesn't get lost // Unhandled, forward the email on so it doesn't get lost default:
} foreach ($struct as $st) { $GLOBALS['email_out'] = ''; $section = mailparse_msg_get_part($mail, $st); $info = mailparse_msg_get_part_data($section); $header .= "\n\n Section:" . $st; foreach ($info as $infoname => $infovalue) { if (is_array($infovalue)) { foreach ($infovalue as $sectionheadername => $sectionheadervalue) { $header .= "\n " . $sectionheadername . ":" . $sectionheadervalue; } } else { $header .= "\n " . $infoname . " = " . $infovalue; } } mailparse_msg_extract_part($section, $content_Email, "get_content"); $section_content .= "\n--------------------------\n Section " . $st . ":\n" . $GLOBALS['email_out'] . "\n----------------------\n"; // only collect plain/html content for now if ($info['content-type'] == "text/plain") { $message_content[$st] = $GLOBALS['email_out']; } if ($info['content-type'] == "text/html") { $message_content_html[$st] = $GLOBALS['email_out']; } // Extracting the attachments if (trim($info['content-disposition']) == "attachment") { $attachment[]['filename'] = $info['disposition-filename']; $attachment[]['content'] = $GLOBAL['email_out']; } } $fp = fopen("/usr/local/sqlf/log/ofuz_catch.log", "a");