4
* Command line learn driver
7
* Patched by Julien Vehent to support DSPAM
8
* Enhanced support for DSPAM by Stevan Bajic <stevan@bajic.ch>
10
function learn_spam($uids)
12
do_salearn($uids, true);
15
function learn_ham($uids)
17
do_salearn($uids, false);
20
function do_salearn($uids, $spam)
22
$rcmail = rcmail::get_instance();
23
$temp_dir = realpath($rcmail->config->get('temp_dir'));
26
$command = $rcmail->config->get('markasjunk2_spam_cmd');
28
$command = $rcmail->config->get('markasjunk2_ham_cmd');
33
$command = str_replace('%u', $_SESSION['username'], $command);
34
$command = str_replace('%l', $rcmail->user->get_username('local'), $command);
35
$command = str_replace('%d', $rcmail->user->get_username('domain'), $command);
36
if (preg_match('/%i/', $command)) {
37
$identity_arr = $rcmail->user->get_identity();
38
$command = str_replace('%i', $identity_arr['email'], $command);
41
foreach (explode(",", $uids) as $uid) {
42
// get DSPAM signature from header (if %xds macro is used)
43
if (preg_match('/%xds/', $command)) {
44
if (preg_match('/^X\-DSPAM\-Signature:\s+((\d+,)?([a-f\d]+))\s*$/im', $rcmail->imap->get_raw_headers($uid), $dspam_signature))
45
$tmp_command = str_replace('%xds', $dspam_signature[1], $command);
47
continue; // no DSPAM signature found in headers -> continue with next uid/message
50
if (preg_match('/%f/', $command)) {
51
$tmpfname = tempnam($temp_dir, 'rcmSALearn');
52
file_put_contents($tmpfname, $rcmail->imap->get_raw_body($uid));
53
$tmp_command = str_replace('%f', $tmpfname, $command);
56
exec($tmp_command, $output);
58
if ($rcmail->config->get('markasjunk2_debug')) {
59
write_log('markasjunk2', $tmp_command);
60
write_log('markasjunk2', $output);
63
if (preg_match('/%f/', $command))
b'\\ No newline at end of file'