running conditions while looping through arrays....

From: Date: Mon, 19 Jun 2006 16:05:09 +0000
Subject: running conditions while looping through arrays....
Groups: php.general 
Request: Send a blank email to php-general+get-238298@lists.php.net to get a copy of this message
I want to run filters on an pop3 inbox. I have the following arrays which I'll get from the database- $subject $email $body $subject_like $email_like $body_like I then go through each email in turn using this loop- $popy = "{".$pop3."/pop3:110}INBOX"; $mailbox = imap_open($popy, $un, $pw);
    $num_messages = imap_num_msg($mailbox);
if ($num_messages <= $no_srch) {$rrt = 0;} else {$rrt = $num_messages-$no_srch;}
for($i=$num_messages; $i>($rrt); $i--) { What I want to do is to check if the email address or subject or body of each email is exactly like any of the details stored in the arrays $subject, $email, $body and to check if the email address or subject or body contains a word or phrase from the arrays $subject_like, $email_like, $body_like. For example- $subject[0] = "SPAM"; $email[0]= ""; $body[0] = ""; $subject_like[0] = ""; $email_like[0] = ""; $body_like[0] = ""; // If the subject of the email = "spam" $subject[1] = ""; $email[1]= "spam@spammer.com"; $body[1] = ""; $subject_like[1] = ""; $email_like[1] = ""; $body_like[1] = ""; // if the email address of the email = "spam@spammer.com" $subject[2] = ""; $email[2]= ""; $body[2] = "spam body text"; $subject_like[2] = ""; $email_like[2] = ""; $body_like[2] = ""; // if the body of the email = "spam body text" $subject[3] = "SPAM"; $email[3]= "spam@spammer.com"; $body[3] = ""; $subject_like[3] = ""; $email_like[3] = ""; $body_like[3] = ""; // if the subject of the email = "SPAM" AND the email address = "spam@spammer.com" $subject[4] = "SPAM"; $email[4]= ""; $body[4] = ""; $subject_like[4] = ""; $email_like[4] = ""; $body_like[4] = "spam text"; // if the subject of the email = "SPAM" AND the body contains "spam text" If any of the above conditions are met then the email message is then stored in a database and deleted of the POP3 server. Is there a quick way of doing the above? The only way I can think of is by looping through each array for every email. This is really really slow. I'd be grateful for some help here.... Ian

« previous php.general (#238298) next »