POP3 filter in PHP using Zend Framework

Install Zend Framework (Debian way)

$ apt-get install zendframework

pop3filter.php

$ su - john
$ mkdir -p bin/pop3filter
$ touch bin/pop3filter/pop3filter.php
<?php
require_once 'Zend/Mail/Storage/Pop3.php';

$spammers = array(
    "spamaddress1@example.com",
    "spamaddress2@example.com",
);

$mail = new Zend_Mail_Storage_Pop3(array('host' => 'pop3.example.com', 'user' => 'john.doe@example.com', 'password' => 'example', 'port' => 110));

echo $mail->countMessages() . " messages found\n";

foreach ($mail as $messageId => $message) {
  echo "{$messageId} : Mail from '{$message->from}': {$message->subject}\n";

  if(in_array(strtolower($message->from), $spammers, true)) {
    $mail->removeMessage($messageId);
    echo "Message removed\n";
  }
}

?>

Crontab

$ crontab -e
# m h  dom mon dow   command
*/10 * * * * /usr/bin/php /home/john/bin/pop3filter/pop3filter.php > /dev/null 2>&1