Parsing a Text File

I have a mail rule script that uploads new individual blogs to my web server whenever i send email to a certain address.

the script saves each email as a text file in a certain folder on my local machine. once its saved, a folder action script uploads it to the correct place.

i want to be able to email photos to my blog, but the sprint moblog service only sends a html formatted email with the photo, and not the photo itself.

i need help parsing the text file, because my mail script saves the source of the message.

here is the middle of the message.

 <td>&&&&&</td>
        <td><p><img src="http://pictures.sprintpcs.com//shareImage/16536694146_235.jpg?border=1,255,255,255,1,0,0,0&invite=HERJzGPuh58n0h97UoUx" border="0" /></p>
</td><td>&&&&&</td>

is there a way to tell apple script to delete everything before “&&&&&” and then, everything after “&&&&&”

this will make the file look like this…

</td>
        <td><p><img src="http://pictures.sprintpcs.com//shareImage/16536694146_235.jpg?border=1,255,255,255,1,0,0,0&invite=HERJzGPuh58n0h97UoUx" border="0" /></p>
</td><td>

now, i would need to delete everything up to the paragraph tag, and everything after the paragraph tag.

anyone know how to do that?

set AppleScript’s text item delimiters to “&&&&&”
then you can get text item 2 of your text variable. That will be the text in-between.

Do a search here for regex or regular expressions if you need fancier capabilities.

Here’s one way…

(* The path to the file to read *)
set theRawData to (read file ("Macintosh HD:Users:jed:Desktop:page.html"))

(* Use perl to get only the image url *)
set thePerlScript to ("$theRawData='" & theRawData & "';
($junk,$theSun,$junk)=split(/&&&&&/, $theRawData);
($theMoon,$junk)=split(/\?/, $theSun);
($junk,$theOutput)=split(/<img src=\"/, $theMoon);
print $theOutput;")

(* The variable 'perlOutput' contains the URL *)
(* For example: "http://pictures.sprintpcs.com//shareImage/16536694146_235.jpg" *)
set perlOutput to do shell script ("perl  -e " & quoted form of thePerlScript)

return perlOutput

j