Newbie asking for help - Reading a text file of qurantined emails and parsing contents.

This is a discussion on Newbie asking for help - Reading a text file of qurantined emails and parsing contents. within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Greetings. Please excuse this post if it is about something that is very simple or have been discussed before, as ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-26-2004
Adam
 
Posts: n/a
Default Newbie asking for help - Reading a text file of qurantined emails and parsing contents.

Greetings.

Please excuse this post if it is about something that is very simple or
have been discussed before, as I am newbie in PHP, and failed so far to
see an answer.

I am trying to write a small script that reads a text file that is
holding spam suspected email and then release any emails that are caught
like that but are not a spam.

The anti-spam software dumps any suspected email not in the white list
to a single text file, so the messages are like this.


From Verna.Tillman@telus.net Fri Apr 23 17:32:33 2004
Return-Path: <Verna.Tillman@telus.net>
Received: from user-bad833.user.msu.edu (user-bad833.user.msu.edu
[35.11.130.226])
by xxxxxxx (8.11.6/8.11.6) with SMTP id i3NLW0B15450
for <postmaster@xxxx >; Fri, 23 Apr 2004 17:32:00 -0400
[some more headers]
[One blank line]
[Message body]

[One or more blank lines]

From Verna.Tillman@telus.net Fri Apr 23 17:32:33 2004
Return-Path: <Verna.Tillman@telus.net>
Received: from user-bad833.user.msu.edu (user-bad833.user.msu.edu
[35.11.130.226])
by xxxxxxx (8.11.6/8.11.6) with SMTP id i3NLW0B15450
for <postmaster@xxxx >; Fri, 23 Apr 2004 17:32:00 -0400
[some more headers]
[One blank line]
[Message body]

And so on.


I am trying to write a PHP script from the scratch to read that file,
and then list the email messages in a web email style, with the ability
of clicking on the message subject line to read it if needed, and next
to each message in the list a button that releases the message to be
delivered to the mail box selected from a list of users (it is a small
server for few people), another button that other deletes it, ...etc.

Please note that the file is not an email box, otherwise this would have
been very easy as POP3 and IMAP classes and the PHP manual are very
clear on that.

Searching through the web I came across this function.

http://www.faqts.com/knowledge_base/...d/3590/fid/933
How can I parse a text file delimited with a string of characters.

Here is a simple function to do what you need. It both reads a file and
returns an array of deliminated strings.

This will work with both local files as well as files through HTTP (on
another server). And for good measure, we'll create a global $splitfile
array that contains information about errors.

<?php

function splitFile ($filename,$seperator)
{
global $splitfile;

if (!isset($splitfile)) $splitfile = array();

if (!is_readable($filename)) {
$splitfile['errors'][] = "File ($filename) is not readable";
return false;
}

$fp = fopen($filename, 'r');

$contents = implode('', file($filename));

if (!stristr($contents, $seperator)) {
$splitfile['errors'][] = "Seperator ($seperator) not found
in file ($filename)";
return false;
}

return explode($seperator, $contents);
}

?>

Now my question here is, how do I decide what is the seperator between
the email messages in that file?

Clearly relying on the empty line that separates messages is wrong.

I was thinking about relying on a regular expression of the envelope
from header.

Something like

From+one space +email address(or could be mailer-daemon)+one space+ date
What do you suggest?
Any pointers, recommendations will be greatly appreciated.

Thank you for your help.

Adam.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:39 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0