[PHP] E-Mail Filter/Parser

2006-01-25 Thread Sascha Braun - immosky AG
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 -

Re: [PHP] E-Mail Filter/Parser

2006-01-25 Thread Sascha Braun - immosky AG
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']);