0

I have been working on getting SpamAssassin up and running for a while now and I am pretty close to being finished. However, I need some help with this. I'm storing the source emails in a database after I have fetching the emails from imap server. I'm running the cron job in every 24 hours to monitor for spam emails in the spam folder so the Bayes database can get update.

Here is what I am using right now to run on cron job:

/usr/local/cpanel/3rdparty/bin/sa-learn -p ~/.spamassassin/user_prefs --spam ~/mail/mydomain.com/myaccount/.spam/{cur,new

As I'm using to store the emails in a database, can I be able to run PHP script on cron job to get the Bayes database update if I create a txt file to get the sa-learn to scan my emails and learn from it?

Example:

/usr/local/cpanel/3rdparty/bin/sa-learn -p ~/.spamassassin/user_prefs --spam ~/public_html/username/myfolder/update_bayes.php

update_bayes.php:

<?php

ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);

require_once('../Spamassassin/Client.php');
require_once('../Spamassassin/Client/Exception.php');
require_once('../Spamassassin/Client/Result.php');

$spam_mailbox = $link->prepare("SELECT count(*) FROM `Spam` WHERE readtype = ?");
$spam_mailbox->execute([$unread]);
$row = spam_mailbox->fetch(PDO::FETCH_ASSOC);
$header = $row['header'];

$fp = fopen('/home/user/myfolder/spam.txt', 'w');
fwrite($fp, $header);
fclose($fp);
$message = @file_get_contents('spam.txt');
$params = array(
    "hostname" => "localhost",
    "port" => "783",
    "user" => "root");

$sa = new Spamassassin\Client($params);


if ($isSpam == 'Spam') {
    $sa->report($email_content);
}
else if ($isSpam == 'Not Spam') {
    $sa->revoke($email_content);
}
?>

Would it work to get the Bayes database update if I run PHP script on cron job so the sa-learn could scan my emails and learn from it??

I have been told that sa-learn don't have any way to scan the database, only mail directories or mbox files. I hope he is wrong.

chris oojer
  • 301
  • 1
  • 10

0 Answers0