I have this code to parse raw email ... which is;
Code: Select all
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
$lines = explode("\n", $email);
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;
for ($i=0; $i<count($lines); $i++) {
if ($splittingheaders) {
$headers .= $lines[$i]."\n";
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
$subject = $matches[1];
}
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}
if (preg_match("/^MIME-Version: (.*)/", $lines[$i], $matches)) {
$headers = $matches[1];
}
if (preg_match("/^Content-type: (.*)/", $lines[$i], $matches)) {
$headers = $matches[1];
}
if (preg_match("/^X-Spam-Checker-Version: (.*)/", $lines[$i], $matches)) {
$headers = $matches[1];
}
if (preg_match("/^X-Spam-Level: (.*)/", $lines[$i], $matches)) {
$headers = $matches[1];
}
if (preg_match("/^X-Spam-Status: (.*)/", $lines[$i], $matches)) {
$headers = $matches[1];
}
} else {
$message .= $lines[$i]."\n";
}
if (trim($lines[$i])=="") {
$splittingheaders = false;
}
}It is recieved as this ....
"X-Message-Info: JGTYoYF78jEHjJx36Oi8+Q1OJDRSDidP
Received: from megs11.100mwh.com ([209.151.94.18]) by mc8-f36.law1.hotmail.com with Microsoft SMTPSVC(5.0.2195.5600);
Fri, 2 May 2003 15:31:21 -0700
Received: from mwood_2k by megs11.100mwh.com with local (Exim 3.36 #1)
id 19Bj1k-0001Db-00
for mwood_2k2@msn.com; Fri, 02 May 2003 16:29:12 -0600
To: mwood_2k2@msn.com
Subject: dssdsdfg
From: roleplay@barnsleyclub.co.uk
MIME-Version: 1.0
Content-type: text/html; charset=iso-8859-1
Message-Id: <E19Bj1k-0001Db-00@megs11.100mwh.com>
Date: Fri, 02 May 2003 16:29:12 -0600
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - megs11.100mwh.com
X-AntiAbuse: Original Domain - msn.com
X-AntiAbuse: Originator/Caller UID/GID - [32005 506] / [32005 506]
X-AntiAbuse: Sender Address Domain - megs11.100mwh.com
Return-Path: mwood_2k@megs11.100mwh.com
X-OriginalArrivalTime: 02 May 2003 22:31:21.0414 (UTC) FILETIME=[8E70EE60:01C310FA]
--0-1280163348-1051914679=:24744
Content-Type: text/plain; charset=us-ascii
dfdfrddg
---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
--0-1280163348-1051914679=:24744
Content-Type: text/html; charset=us-ascii"
The script treats everything up to a blank line as headers, then after it encounters a blank line assumes the rest is the message, but as you can see above, there are these two lines;
--0-1280163348-1051914679=:24744
Content-Type: text/plain; charset=us-ascii
Ok, so, yahoo! being a pain as usual sends these headers which includes a couple of blank lines then a further 2 lines of headers ... how can I get my script to get these as headers and not part of the message?
Additionally, I recieve
"--0-1280163348-1051914679=:24744-- "
after my message (must be a mime header?)
I really need to solve this, I just need the message to appear not all this crap around it ....
Can anyone help? Cheers in advance ...