Re: E-Mail Filter/Parser
| From: | Sascha Braun - immosky AG | Date: | Wed, 25 Jan 2006 10:49:10 +0000 |
| Subject: | Re: E-Mail Filter/Parser | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-229218@lists.php.net to get a copy of this message | ||
But how can i get the next key in a foreach loop?
Can't see how i can use a continue statement in that circumstance?
Am Mittwoch, den 25.01.2006, 11:28 +0200 schrieb Geoff:
> Possibly the continue statement would help you?
>
> Geoff.
>
>
> On 25 Jan 2006 at 10:12, Sascha Braun - immosky AG wrote:
>
> > Hi,
> >
> > I started to write an E-Mail Parser so E-Mails from different Internet
> > Plattforms can be sorted automatically into an customer database.
> >
> > Everything is working pretty fine, but only if all expected fields
> > appear in the Mail from the sending plattform.
> >
> > But sometimes the Mails send out by a plattform doesnt contain all
> > fields the filter expects. And i dont know how to write the foreach
> > loop I am using to walk over the current field to check if the start
> > element of the next needed field occours so the parsing for the needed
> > element can stop somewhere and start reading the next field element.
> >
> > A Filter looks like that, at the moment:
> >
> > Array
> > (
> > [attribute] => Array
> > (
> > [plattform] => plattform.com
> > )
> >
> > [firstname] => Array
> > (
> > [attribute] => Array
> > (
> > [read_init] => Name:
> > [read_from] => Name:
> > [read_to] =>
> > )
> >
> > )
> >
> > [name] => Array
> > (
> > [attribute] => Array
> > (
> > [read_init] =>
> > [read_from] =>
> > [read_to] => Anschrift:
> > )
> >
> > )
> >
> > [adress] => Array
> > (
> > [attribute] => Array
> > (
> > [read_init] => Anschrift:
> > [read_from] => Anschrift:
> > [read_to] => ,
> > )
> >
> > )
> >
> > [plz] => Array
> > (
> > [attribute] => Array
> > (
> > [read_init] => ,
> > [read_from] => ,
> > [read_to] =>
> > )
> >
> > )
> >
> > [city] => Array
> > (
> > [attribute] => Array
> > (
> > [read_init] =>
> > [read_from] =>
> > [read_to] => E-Mail:
> > )
> >
> > )
> >
> > [email] => Array
> > (
> > [attribute] => Array
> > (
> > [read_init] => E-Mail:
> > [read_from] => E-Mail:
> > [read_to] => Telefon:
> > )
> >
> > )
> >
> > [phone] => Array
> > (
> > [attribute] => Array
> > (
> > [read_init] => Telefon:
> > [read_from] => Telefon:
> > [read_to] => Folgender
> > )
> >
> > )
> >
> > [comment1] => Array
> > (
> > [attribute] => Array
> > (
> > [read_init] => ussert:
> > [read_from] => ussert:
> > [read_to] => Kommentar:
> > )
> >
> > )
> >
> > [comment2] => Array
> > (
> > [attribute] => Array
> > (
> > [read_init] => Kommentar:
> > [read_from] => Kommentar:
> > [read_to] => ===
> > )
> >
> > )
> >
> > [headline] => Array
> > (
> > [attribute] => Array
> > (
> > [read_init] => berschrift:
> > [read_from] => berschrift:
> > [read_to] => Anzeige
> > )
> >
> > )
> >
> > [object] => Array
> > (
> > [attribute] => Array
> > (
> > [read_init] => Objekt Nr:
> > [read_from] => Objekt Nr:
> > [read_to] => )
> > )
> >
> > )
> >
> > )
> >
> > And the filter funltion looks like that, at the moment:
> >
> > private function filter_email($message)
> > // Filter upcomming email messages into the immetix database
> > {
> >
> > if (is_dir($this -> filter_folder)) {
> >
> > if ($filters = opendir($this -> filter_folder)) {
> >
> > while(($filter = readdir($filters)) !== false) {
> >
> > if ($filter != "." && $filter != "..") {
> >
> > $xml = new xml_mm($this -> filter_folder.$filter);
> >
> > if (!empty($xml -> email_filter['attribute']['plattform'])
> > &&
> > substr_count(strtolower($message), $xml ->
> > email_filter['attribute']['plattform'])) {
> >
> > unset($xml -> email_filter['attribute']);
> >
> > foreach($xml -> email_filter as $key => $value) {
> >
> > if ($pos = strpos($message, $xml ->
> > email_filter[$key]['attribute']['read_init'])) {
> >
> > $message = substr($message, $pos + strlen($xml ->
> > email_filter[$key]['attribute']['read_from']), strlen($message) -
> > $pos);
> > }
> >
> > $this -> element[$key] = trim(substr($message, 0,
> > strpos($message, $xml ->
> > email_filter[$key]['attribute']['read_to'])));
> > }
> > }
> > }
> > }
> > closedir($filters);
> > }
> > }
> > }
> >
> > It would be nice to know how i can iterate over the next elements of the
> > email filter array till a valid field part is found and the iteration
> > can start with the next element of the filter, from the last occourance
> > of a valid read_init string.
> >
> > Hope i described my problem well enough, otherwise please ask, because
> > this filter seems to be a pretty cool script, because there is not found
> > anything similar at google at this time :))
> >
> > Thanks for your help.
> >
> > Best Regards,
> >
> > Sascha Braun
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>
>