#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    cranbrook BC canada
    Posts
    12
    Rep Power
    0
    Just Beginning to get my feet wet with php, and i have been presented with a challenge (on a deadline even)

    We are sent a series of email bullitins daily, and they need to be parsed, and sent to a mySQL database (the database is already prepared to take the incoming messages)

    Heres what i've got:
    The Message will always begin with:
    Return-Path: <push_services@prnewswire.com>
    (or some other address)
    i would liek to send this to tblMail.MailAddy

    next come the junk:
    Received: from mail01-ewr.pilot.net (mail-ewr-1.pilot.net [206.98.230.18])
    by mail.cintek.com (8.9.3/8.9.3) with ESMTP id HAA29427
    for <webguy@cintek.com>; Thu, 13 Jul 2000 07:32:05 -0600
    From: push_services@prnewswire.com
    Received: from prnmail4 (prnmail4.prnewswire.com [199.230.26.98] (may be forged)) by mail01-ewr.pilot.net with ESMTP id JAA24918 for <webguy@cintek.com>; Thu, 13 Jul 2000 09:22:38 -0400 (EDT)
    Received: from hssmtp3 ([198.199.176.20] helo=hssmtp3.prnewswire.com)
    by prnmail4 with esmtp (Exim 3.02 #1)
    id 13Cj2D-0001Iz-00
    for webguy@cintek.com; Thu, 13 Jul 2000 09:28:13 -0400
    Received: from [199.230.20.132] (helo=hspdl001.prnewswire.com)
    by hssmtp3.prnewswire.com with smtp (Exim 2.05 #1)
    id 13Civu-0003sM-00
    for webguy@cintek.com; Thu, 13 Jul 2000 09:21:42 -0400
    Received: by hspdl001.prnewswire.com (SMI-8.6/SMI-SVR4)
    id JAA15992; Thu, 13 Jul 2000 09:21:25 -0400
    Date: Thu, 13 Jul 2000 09:21:25 -0400
    Message-Id: <200007131321.JAA15992@hspdl001.prnewswire.com>
    To: webguy@cintek.com

    (it will Always end with To: webguy@cintek.com)

    then the message Subject, and Body:
    Subject: Researchers Unveil Data on VIRAMUNE(R) (nevirapine) for Prevention of Mother-to-Child Transmission of HIV in Developing Countries
    Status:

    Researchers Unveil Data on VIRAMUNE(R) (nevirapine) for Prevention of
    Mother-to-Child Transmission of HIV in Developing Countries

    - More than 1,300 South African Women Participate in Landmark SAINT Trial -

    DURBAN, South Africa,
    Story Story Story etc.

    (What i would like to do is parse the Topic in to its own column, and the message body in to an other.)

    (The End of the message Always ends with the word SOURCE, and then a lot more of unneeded information. i would like to drop all of that.)

    Can this be done with PHP? Does Anyone have any suggestions on how i would execute it? Feedback would be bliss.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    30
    Rep Power
    15
    This can be done in PHP, I don't have time to write the code for you, but if you want to do it look into regular expressions to be able to evaluate each line by line and pick out what you want. Look around the forums as i'm sure somebody has done something like it.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    cranbrook BC canada
    Posts
    12
    Rep Power
    0
    what i have is this:
    <html>
    <?php
    $db = mysql_connect("localhost", "root");
    mysql_select_db("EatMail",$db);
    $result = mysql_query("SELECT * FROM tbRawMail",$db);
    if ($myrow = mysql_fetch_array($result))
    {
    do {

    ereg("Return-Path: <(.*)>",$myrow["FullMail"],$title );
    ereg("Subject .*)Status:",$myrow["FullMail"],$subject );
    ereg("Status .*)CO:",$myrow["FullMail"],$body );
    ereg($subject."(.*)CO:",$body,$body2 );

    print $title;
    print $subject;
    print $body2;
    } while ($myrow = mysql_fetch_array($result));
    } else {
    echo "Sorry, no records were found!";
    }
    ?>

    unbfortunately the only thing it brings up in after the query is:

    ArrayArray


    any ideas?


    [This message has been edited by rev (edited July 14, 2000).]

    [This message has been edited by rev (edited July 14, 2000).]
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    cranbrook BC canada
    Posts
    12
    Rep Power
    0
    sorry about the frownies
    each one is this:

    : (

  8. #5
  9. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    I would cut out all the junk first using something like....assuming $thismail contains the complete e-mail as a string.

    $thismail = ereg_replace("Received: (.*) To: webguy@cintek.com"," ", $thismail)

    this strips out everything between the 1st occurence of "Received:" and the LAST occurance of "To: webguy@cintek.com".

    you can do this to stip out any other unwanted info as long as you can guarrantee 'keywords/strings that you can use as an anchor for your regex.

    The dodgy bit looks like seperating the topic from the story, - could not work out if 'STATUS:' means the beginning of the topic body - if it was you could use....

    $grab = ereg("SUBJECT .*) "STATUS:, $thismail, $topic);

    The results of the above are stored in $topic[1] , for reasons I do not understand - but that is where they are!

    Variations on the above should get you the content you need pretty quickly.

    Note that if each email contained several topic / contents, you need to explode() them otherwise the $grab = ereg("SUBJECT .*) "STATUS:, $thismail, $topic); code will grab the first SUBJECT and the last STATUS.

    So -1)clear out the crap
    -2)explode() the remains.(using SUBJECT as the key?)
    -3)use the ereg functions to put the data into variables
    -4)Stickem' in MySQL
    -4a)Have a cuppa.

    Hope this helps,

    Simon.


    (GGRRRRR Smilies are making me frown ! - same as your post !)

    ------------------
    Simon Wheeler
    FirePages -DHTML/PHP/MySQL

    [This message has been edited by firepages (edited July 15, 2000).]
  10. #6
  11. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    doublr Grrrrr - this bit has to be right so here it is without the smileys.

    OOOOOpppps - it was wrong anyway! -try

    $grab = ereg("SUBJECT.*)STATUS:", $thismail, $topic);



    ------------------
    Simon Wheeler
    FirePages -DHTML/PHP/MySQL
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    cranbrook BC canada
    Posts
    12
    Rep Power
    0
    thanks so much.

    forced myself away from the comp for 48 hours to rejuvinate from the headache the prob was causing... gunna try it now.

    thanks again
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    cranbrook BC canada
    Posts
    12
    Rep Power
    0
    Ok Daily Status update.... in case anyone is wondering 'did that jerk figure it ou or not?'
    here is my 10 am caffine induced code.
    I've made it a bit fatter/uglier, because firepages replace command seems to be the only thing i can make work without it changing my parsed info into a string of numbers (??!??!)
    here it is
    -=-=-
    <html><head><title>PARSE ONE</title><body bgcolor="#D5D0C4"></head>
    <?php
    $db = mysql_connect("localhost", "root");
    mysql_select_db("EatMail",$db);
    $result = mysql_query("SELECT * FROM tbRawMail",$db);
    if ($thismail = mysql_fetch_array($result))

    {
    do {

    //removing the crap from the beginning and end of the mail file!
    $parseT = ereg_replace("Return-Path: (.*)To: "," ", $thismail["FullMail"]);
    $parseF = ereg_replace("CO: (.*)=========="," END ", $parseT);
    //extracting the topic!
    $grab1 = ereg_replace("webguy@cintek.com(.*)Subject: "," ", $parseT);
    $grab2 = ereg_replace("Status: (.*)====="," ", $grab1);
    //Should grab the body (it doesn't work though, dont know why)
    $grab = ereg("Status.*)CO: ", $parseT, $topic);
    //What i would LIKE here is for it to say "ok, grab from the topic, to the end of the message, but ti doesn't seem to work)
    //$body = ereg($grab."(.*)CO: ", $parseF, $message);

    echo $grab2;
    echo $grab;
    ?><br><br><?php
    echo $parseF;

    ?><br><br><br><?php
    } while ($myrow = mysql_fetch_array($result));
    } else {
    echo "Sorry, no records were found!";
    }
    ?>

    So as you can see, i'm getting Closer. Things i dont understand, is why my ereg command always returns a small string of numbers (like 112) instead of the text it Should be grabbing, and how i can ereg to grab from $grab to the text at the end of the file

    Also, its grabbing out of a table of 2 records, only one of them, twice. is that something i need to explode to fix? Any Idea?

    BTW, thanks to all that have helped (including the very helpful email i got this morning) The PHP devshed community is one of the most helpful i have met.
  16. #9
  17. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    Hi rev hope you are getting there -
    in:
    $grab = ereg("Status .*)CO: ", $parseT, $topic);

    $grab holds nothing useful/ the result of the regex is now contained in $parseT[1] - like I said before I am not sure why, it just does! I hate regex,

    See this for an example along similar lines
    http://www.firepages.com.au/news.htm

    Regards,

    ------------------
    Simon Wheeler
    FirePages -DHTML/PHP/MySQL
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    cranbrook BC canada
    Posts
    12
    Rep Power
    0
    ooo i think i dig what you mean now. i'm gunna spend a few hours implimenting it right now.
  20. #11
  21. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    cranbrook BC canada
    Posts
    12
    Rep Power
    0
    REGEX is WEIRD
    here is the format that finally works

    <html><head><title>PARSE ONE</title><body bgcolor="#D5D0C4"></head>
    <?php
    $db = mysql_connect("localhost", "root");
    mysql_select_db("EatMail",$db);
    $result = mysql_query("SELECT * FROM tbRawMail",$db);
    if ($thismail = mysql_fetch_array($result))
    {
    do {


    $parseT = ereg_replace("Return-Path: (.*)To: "," ", $thismail["FullMail"]);
    $parseF = ereg_replace("CO: (.*)=========="," END ", $parseT);
    $grab1 = ereg_replace("webguy@cintek.com(.*)Subject: "," ", $parseT);
    $grab2 = ereg_replace("Status: (.*)====="," ", $grab1);
    eregi("(Status)(.*)(CO: )", $thismail["FullMail"], $regs);
    $subject = $regs[2];

    echo $grab2;

    echo $subject;

    } while ($thismail = mysql_fetch_array($result));
    } else {
    echo "Sorry, no records were found!";
    }
    ?>


    Thanks Much for your info firepages, it helped a Lot.
  22. #12
  23. No Profile Picture
    ledjon
    Guest
    Devshed Newbie (0 - 499 posts)
    Since e-mails usually come in a standard format (all the headers) you should have just up it into an array (one line per element) and only used certian lines. Then you could have more easly parsed that information.

    But that's just a suggestion.
  24. #13
  25. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    cranbrook BC canada
    Posts
    12
    Rep Power
    0
    thanks, i'm working on it, seems when i put too much in to one string, it stops working.

    does anyone know if i can use a variable from earlier in a new ereg?

    eg:

    eregi("($grab2)(.*)(CO", $thismail["FullMail"], $fry);
    $legstest = $fry[2];
    echo $frytest;

    i know, thats pretty advanced scary stuff, but i'm sure Someone on here will know if it can be done.

Similar Threads

  1. loading variables from an external file
    By paulc218 in forum Flash Help
    Replies: 9
    Last Post: February 11th, 2004, 11:30 AM
  2. select file based on POST variables
    By nycteris in forum Perl Programming
    Replies: 15
    Last Post: February 11th, 2004, 10:37 AM
  3. PHP file upload script trouble
    By casbboy in forum PHP Development
    Replies: 9
    Last Post: February 5th, 2004, 08:42 PM
  4. How to parse a CSV .txt file and upload into MySQL?
    By JakeBones in forum PHP Development
    Replies: 1
    Last Post: February 5th, 2004, 12:32 PM
  5. send variables from html to external file
    By Alicia in forum Visual Basic Programming
    Replies: 6
    Last Post: February 1st, 2004, 12:12 PM

IMN logo majestic logo threadwatch logo seochat tools logo