On the past few days Ive been working on a PHP spamd client, and I think it is somewhat usable for now since it already implements all of the protocol commands. This is release 0.1.0, so you might expect some API changes for the next versions. Feedback is always welcome. I tried to make this the most straight-forward as possible, abstracting some nasty things that happens under the hood, so you can do things like:
require('Spamassassin/Client.php');
require('Spamassassin/Client/Result.php');
$params = array "hostname" => "localhost", "port" => "783", "user" => "ppadron", ;
$sa = new SpamassassinClient($params); $message = file_get_contents'/path/to/message/file';var_dump$sa->isSpam$message;
$result = $sa->getSpamReport($message);echo "Message: ".$result->message . "n"; echo "<br><br>Your Spam Score: ".$result->score;
Methods available
- ping()
- Pings the server to test the connection
- getSpamReport($message)
- Returns a detailed report if the message is spam or null if its ham
- headers($message)
- Processes the message and returns its headers (like X-Spam-Flag and X-Spam-Status)
- check($message)
- Checks if a message is spam with the CHECK protocol command
- isSpam($message)
- Shortcut to check() method that returns a boolean
- process($message)
- Processes the message, checks it for spam and returning its modified version
- symbols($message)
- Returns all rules matched by the message
- learn($message, $learnType)
- Uses SpamAssassin learning feature with TELL. Must be enabled on the server.
- report($message)
- Report message as spam, both local and remote
- revoke($message)
- Revokes a message previously reported as spam
Im still working on providing some good usage examples, but Ive put (temporarily) In the meantime, you can browse the tests directory and learn some basic stuff. If you want to use this library to implement a spam filter for your mail server, maybe you should consider using the spamc command line utility or the Perl librarythat already comes with SpamAssassin (which was my main source of inspiration). This library is most useful when you already have stuff written in PHP and you need to do something with SpamAssassin. If you have a webmail written in PHP and would like to interact with a remote SpamAssassin server to report spam, for example. The project is hosted @ Github, so you can:
- clone the repository:
- https://github.com/templateria/php-spamassassin
https://github.com/templateria/php-spamassassin.git