Ticket #1484762 (new Feature Requests)
set to later: some coding on learning messages as spam/ham
| Reported by: | seansan | Owned by: | |
|---|---|---|---|
| Priority: | 5 | Milestone: | later |
| Component: | Client Scripts | Version: | 0.1-rc2 |
| Severity: | normal | Keywords: | spam filter spamassassin move_del |
| Cc: | sean116@… |
Description
Some code on adding spamassassin support - maybe as plugin in the future. Want to log the code for future reference - who knows, maybe a future release?
problem at this stage was that running sa-learn from the current user (that RC is run with) is probably not allowed to set spam filters. User server config issue. For the rest is seems to work fine.
// INSERTION STARTS HERE @ move_del.inc line 31
// For testing purposes
$CONFIG['learn_spam'] = TRUE;
// ok: ['learn_spam'] is new config variable
// ok: For testing purposes add it to your main config file as
// $rcmail_config['learn_spam'] = TRUE;
if (!empty($CONFIG['junk_mbox']) && !empty($CONFIG['junk_mbox']) &&
isset($CONFIG['learn_spam']) && ($CONFIG['learn_spam']==TRUE))
{
// todo: Do I need to check other vars like SESSION to confirm current mbox?
// seems ok
$source = get_input_value('_mbox', RCUBE_INPUT_POST);
// todo: Do I need to take _mbox and $target (already fetched in move_del) through checks?
// todo: Do I need to take _mbox and $target and formaat otherwise so they are comparable with config?
$s_type = NULL;
if ($target == $CONFIG['junk_mbox'])
$s_type = 'spam';
else if ($source == $CONFIG['junk_mbox'])
$s_type = 'ham';
if (!is_null($s_type))
{
$ret = system("which sa-learn", $retval);
// todo: Anymore checks to add?
if ($retval == 0 && file_exists($ret) && is_executable($ret))
{
// convert the list of uids to array
$a_uids = is_string($uids) ? explode(',', $uids) : (is_array($uids) ? $uids : NULL);
foreach ($a_uids as $uid)
{
// todo: Does this get the full e-mail, inlcuding headers?
// todo: The IMAP function is referenced, how to call correctly?
$src = $IMAP->get_raw_body($uid);
// create tmpfile to feed to sa-learn
$temp_dir = unslashify($CONFIG['temp_dir']);
$tmpfname = $INSTALL_PATH . tempnam($temp_dir, 'SAL');
if ($fp = @fopen($tmpfname, 'a'))
{
fwrite($fp, $src);
fwrite($fp, "TEST");
fclose($fp);
// todo: Can we fork this process? (Seeing we are looping)
// todo: How safe is this command and do we need to use escapeshellarg
// todo: Is this the way to feed the full message source to sa-learn?
$ret = system(escapeshellcmd(sprintf("sa-learn --no-sync --%s -f %s", $s_type, $tmpfname)), $retval);
raise_error(array('code' => 701,'type' => 'server','file' => 'move_del.inc', 'line' => __LINE__,
'message' => $ret), true, false);
unlink($tmpfname);
} else {
raise_error(array('code' => 701,'type' => 'server','file' => move_del.inc, 'line' => __LINE__,
'message' => "Cannot create temporary file, exiting loop:". $tmpfname), true, false);
// Stop the loop
break;
}
// sync sa-learn
$ret = system(escapeshellcmd('sa-learn --sync'), $retval);
}
} else {
raise_error(array('code' => 701,'type' => 'server','file' => move_del.inc, 'line' => __LINE__,
'message' => "sa-learn not found, verify or turn config variable learn_spam to FALSE"), true, false);
}
} else {
raise_error(array('code' => 701,'type' => 'server','file' => move_del.inc, 'line' => __LINE__,
'message' => "Source and target both not spam directory"), true, false);
}
} else {
raise_error(array('code' => 701,'type' => 'server','file' => move_del.inc, 'line' => __LINE__,
'message' => "Config variables not set, skipping sa-learn plugin"), true, false);
}
// INSERTION ENDS HERE
Change History
Note: See
TracTickets for help on using
tickets.