> >I have a burning question that needs to be looked at, and see if
> someone can give me an idea of a
> >way to get the desired result.  Are you ready.
> >
> >Here is my problem, I need to strip out of an mbox file everything but
> the body of the email, now
> >to complicate matters this is an extremly large file, now seeing as it
> is a mbox file, and there
> >for has a set pattern of information display, I figure there must be
> some way of striping the
> >header information.

<?php
    $days = "Mon|Tue|Wed|Thu|Fri|Sat|Sun";
    $months = "Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec";
    $d = "[0-9]";
    # This probably needs the : escaped with \\ or \\\\ or something...
    # And you may need \r\n instead of just \n...
    $fromline = "^From $days $months $d$d $d$d:$d$d:$d$d $d$d$d$d\n\$";

    #Untested code:
    $mbox = fopen("/path/to/mbox", 'r') or die("Could not open mailbox.");
    $inheaders = TRUE;
    while (!feof($mbox)){
        # Skip headers:
        $line = "This is not a blank line.";
        # I'm not sure if it's \r\n or just \n, but this will work:
        while (!feof($mbox) && ($line != "\n") && $line != "\r\n"){
            $line = fgets($mbox, 1000000);
        }
        # Now you can parse the contents of the email...
        $contactus = fgets($mbox, 1000000);
        if ($contactus != "Contact Us\n"){
            # This is not a "Contact Us" email
            # Some goof sent real email here.  Do something with it.
        }
        else{
            $errors = 0;
            #Snag the subject:
            $subject = fgets($mbox, 1000000);
            $subject = explode(": ", $subject);
            if (count($subject) != 2){
                $errors++;
            }
            else{
                $subject = $subject[1];
            }

            #Snag their state:
            $state = fgets($mbox, 1000000);
            # Are there really two colons in there?...
            $state = explode(":: ", $state);
            if (count($state) != 2){
                $errors++;
            }
            else{
                $state = $state[1];
            }

            # I'm not typing the rest of the fields...
            # ...

            # Output the information you have parsed:
            if (!$errors){
                echo
"$subject\t$state\t$name\t$address\t$city\t$email\t$zip\t<BR>\n";
            }
            else{
                # This email was not processed properly.  Do something with
it.
            }

            # Skip to the next message:
            while (!feof($mbox) && !ereg($fromline, $line){
                $line = fgets($mbox, 1000000);
            }
        }
    }
?>

--
WARNING [EMAIL PROTECTED] address is an endangered species -- Use
[EMAIL PROTECTED]
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to