[thelist] Reading emails on the fly.........
Gijs van Tulder
evolt at gmx.net
Tue May 21 15:17:00 CDT 2002
Chris,
I recently wrote something like you want. Here's the code, take a look at.
Perhaps it's useful.
#!/usr/local/bin/php -q
<?php
// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
// handle email
$lines = explode("\n", $email);
// empty vars
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;
for ($i=0; $i<count($lines); $i++) {
if ($splittingheaders) {
// this is a header
$headers .= $lines[$i]."\n";
// look out for special headers
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
$subject = $matches[1];
}
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}
} else {
// not a header, but message
$message .= $lines[$i]."\n";
}
if (trim($regels[$i])=="") {
// empty line, header section has ended
$splittingheaders = false;
}
}
// put info in database
?>
More information about the thelist
mailing list