~ubuntu-branches/ubuntu/raring/roundcube-plugins-extra/raring

« back to all changes in this revision

Viewing changes to markasjunk2-1-2/drivers/cmd_learn.php

Tags: 0.5.4-20110919
* Bump version number for Roundcube to 0.5.4.
* Upgrade sieverules to version 1.11-20110813.
* Label jqueryui as version 1.8+dfsg instead of 1.8.12+dfsg.
* Upgrade sauserprefs to version 1.6-20110828.
* Upgrade markasjunk2 to version 1.3.
* Fix typo in debian/copyright.
* Use system-wide jQuery Mousewheel plugin in contextmenu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
/**
4
 
 * Command line learn driver
5
 
 * @version 1.1
6
 
 * @author Philip Weir
7
 
 * Patched by Julien Vehent to support DSPAM
8
 
 * Enhanced support for DSPAM by Stevan Bajic <stevan@bajic.ch>
9
 
 */
10
 
function learn_spam($uids)
11
 
{
12
 
        do_salearn($uids, true);
13
 
}
14
 
 
15
 
function learn_ham($uids)
16
 
{
17
 
        do_salearn($uids, false);
18
 
}
19
 
 
20
 
function do_salearn($uids, $spam)
21
 
{
22
 
        $rcmail = rcmail::get_instance();
23
 
        $temp_dir = realpath($rcmail->config->get('temp_dir'));
24
 
 
25
 
        if ($spam)
26
 
                $command = $rcmail->config->get('markasjunk2_spam_cmd');
27
 
        else
28
 
                $command = $rcmail->config->get('markasjunk2_ham_cmd');
29
 
 
30
 
        if (!$command)
31
 
                return;
32
 
 
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);
39
 
        }
40
 
 
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);
46
 
                        else
47
 
                                continue; // no DSPAM signature found in headers -> continue with next uid/message
48
 
                }
49
 
 
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);
54
 
                }
55
 
 
56
 
                exec($tmp_command, $output);
57
 
 
58
 
                if ($rcmail->config->get('markasjunk2_debug')) {
59
 
                        write_log('markasjunk2', $tmp_command);
60
 
                        write_log('markasjunk2', $output);
61
 
                }
62
 
 
63
 
                if (preg_match('/%f/', $command))
64
 
                        unlink($tmpfname);
65
 
 
66
 
                $output = '';
67
 
        }
68
 
}
69
 
 
70
 
?>
 
 
b'\\ No newline at end of file'