Skip to content

Commit cb6c79e

Browse files
authored
Integrate markasjunk2 features into markasjunk - marking as non-junk + learning engine (#6504)
1 parent 70657e3 commit cb6c79e

24 files changed

+1650
-70
lines changed

plugins/markasjunk/README.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
Roundcube Webmail MarkAsJunk Plugin
2+
===================================
3+
This plugin adds "mark as spam" or "mark as not spam" button to the message
4+
menu.
5+
6+
When not in the Junk mailbox:
7+
Messages are moved into the Junk mailbox and marked as read
8+
9+
When in the Junk mailbox:
10+
The buttons are changed to "mark as not spam" or "this message is not spam"
11+
and the message is moved to the Inbox
12+
13+
14+
License
15+
-------
16+
17+
This plugin is released under the [GNU General Public License Version 3+][gpl].
18+
19+
Even if skins might contain some programming work, they are not considered
20+
as a linked part of the plugin and therefore skins DO NOT fall under the
21+
provisions of the GPL license. See the README file located in the core skins
22+
folder for details on the skin license.
23+
24+
25+
Configuration
26+
-------------
27+
28+
The default config file is plugins/markasjunk/config.inc.php.dist
29+
Rename this to plugins/markasjunk/config.inc.php
30+
31+
All config parameters are optional.
32+
33+
34+
The Learning Driver
35+
-------------------
36+
37+
The learning driver allows you to perform additional processing on each message
38+
marked as spam/ham. A driver must contain a class named markasjunk_{driver
39+
file name}. The class must contain 3 functions:
40+
41+
**spam:** This function should take 2 arguments: an array of UIDs of message(s)
42+
being marked as spam, the name of the mailbox containing those messages
43+
44+
**ham:** This function should take 2 arguments: an array of UIDs of message(s)
45+
being marked as ham, the name of the mailbox containing those messages
46+
47+
**init:** Optional, this function should take 0 arguments. eg: allows drivers
48+
to add JS to the page to control which of the spam/ham options are displayed.
49+
The `jsevents` driver is available to show how to use the JS events.
50+
51+
Several drivers are provided by default they are:
52+
53+
**cmd_learn:** This driver calls an external command (for example salearn) to
54+
process the message
55+
56+
**dir_learn:** This driver places a copy of the message in a predefined folder,
57+
for example to allow for processing later
58+
59+
**email_learn:** This driver emails the message either as an attachment or
60+
directly to a set address. This driver requires Roundcube 1.4 or above.
61+
62+
**sa_blacklist:** This driver adds the sender address of a spam message to the
63+
users blacklist (or whitelist of ham messages) Requires SAUserPrefs plugin
64+
65+
**amavis_blacklist:** This driver adds the sender address of a spam message to
66+
the users blacklist (or whitelist of ham messages) Requires Amacube plugin.
67+
Driver by Der-Jan
68+
69+
**sa_detach:** If the message is a Spamassassin spam report with the original
70+
email attached then this is detached and saved in the Inbox, the spam report is
71+
deleted
72+
73+
**edit_headers:** Edit the message headers. Headers are edited using
74+
preg_replace.
75+
76+
**WARNING:** Be sure to match the entire header line, including the name of the
77+
header, and include the ^ and $ and test carefully before use on real messages.
78+
This driver alters the message source
79+
80+
81+
Running multiple drivers
82+
------------------------
83+
84+
**WARNING:** This is very dangerous please always test carefully. Run multiple
85+
drivers at your own risk! It may be safer to create one driver that does
86+
everything you want.
87+
88+
It is possible to run multiple drivers when marking a message as spam/ham. For
89+
example running sa_blacklist followed by cmd_learn or edit_headers and
90+
cmd_learn. An [example multi-driver][multidriver] is available. This is a
91+
starting point only, it requires modification for individual cases.
92+
93+
94+
Spam learning commands
95+
----------------------
96+
97+
Spamassassin:
98+
99+
```sa-learn --spam --username=%u %f``` or
100+
```sa-learn --spam --prefs-file=/var/mail/%d/%l/.spamassassin/user_prefs %f```
101+
102+
103+
Ham learning commands
104+
---------------------
105+
106+
Spamassassin:
107+
108+
```sa-learn --ham --username=%u %f``` or
109+
```sa-learn --ham --prefs-file=/var/mail/%d/%l/.spamassassin/user_prefs %f```
110+
111+
112+
edit_headers example config
113+
---------------------------
114+
115+
**WARNING:** These are simple examples of how to configure the driver options,
116+
use at your own risk
117+
118+
```php
119+
$config['markasjunk_spam_patterns'] = array(
120+
'patterns' => array('/^(Subject:\s*)(.*)$/m'),
121+
'replacements' => array('$1[SPAM] $2')
122+
);
123+
```
124+
125+
```php
126+
$config['markasjunk_ham_patterns'] = array(
127+
'patterns' => array('/^(Subject:\s*)\[SPAM\](.*)$/m'),
128+
'replacements' => array('$1$2')
129+
);
130+
```
131+
132+
[gpl]: https://www.gnu.org/licenses/gpl.html
133+
[multidriver]: https://gist.github.com/johndoh/8173505

plugins/markasjunk/composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
{
22
"name": "roundcube/markasjunk",
33
"type": "roundcube-plugin",
4-
"description": "Adds a new button to the mailbox toolbar to mark the selected messages as Junk and move them to the configured Junk folder.",
4+
"description": "Adds buttons to mark messages as Junk/Non-Junk with moving to the Junk folder and Spam/Ham learning.",
55
"license": "GPLv3+",
6-
"version": "1.2",
6+
"version": "2.0",
77
"authors": [
88
{
99
"name": "Thomas Bruederli",
1010
"email": "[email protected]",
1111
"role": "Lead"
12+
},
13+
{
14+
"name": "Philip Weir",
15+
"email": "[email protected]",
16+
"role": "Developer"
1217
}
1318
],
1419
"repositories": [
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
<?php
2+
3+
// Learning driver
4+
// Use an external process such as sa-learn to learn from spam/ham messages. Default: null.
5+
// Please see the README for more information
6+
$config['markasjunk_learning_driver'] = null;
7+
8+
// Ham mailbox
9+
// Mailbox messages should be moved to when they are marked as ham. null = INBOX
10+
// set to FALSE to disable message moving
11+
$config['markasjunk_ham_mbox'] = null;
12+
13+
// Spam mailbox
14+
// Mailbox messages should be moved to when they are marked as spam.
15+
// null = the mailbox assigned as the spam folder in Roundcube settings
16+
// set to FALSE to disable message moving
17+
$config['markasjunk_spam_mbox'] = null;
18+
19+
// Mark messages as read when reporting them as spam
20+
$config['markasjunk_read_spam'] = false;
21+
22+
// Mark messages as unread when reporting them as ham
23+
$config['markasjunk_unread_ham'] = false;
24+
25+
// Add flag to messages marked as spam (flag will be removed when marking as ham)
26+
// If you do not want to use message flags set this to false
27+
$config['markasjunk_spam_flag'] = 'Junk';
28+
29+
// Add flag to messages marked as ham (flag will be removed when marking as spam)
30+
// If you do not want to use message flags set this to false
31+
$config['markasjunk_ham_flag'] = 'NonJunk';
32+
33+
// Write output from spam/ham commands to the log for debug
34+
$config['markasjunk_debug'] = false;
35+
36+
// The mark as spam/ham icon can either be displayed on the toolbar or as part of the mark messages menu.
37+
// Set to False to use Mark menu instead of the toolbar. Default: true.
38+
$config['markasjunk_toolbar'] = true;
39+
40+
// Learn any message moved to the spam mailbox as spam (not just when the button is pressed)
41+
$config['markasjunk_move_spam'] = false;
42+
43+
// Learn any message moved from the spam mailbox to the ham mailbox as ham (not just when the button is pressed)
44+
$config['markasjunk_move_ham'] = false;
45+
46+
// Some drivers create new copies of the target message(s), in this case the original message(s) will be deleted
47+
// Rather than deleting the message(s) (moving to Trash) setting this option true will cause the original message(s) to be permanently removed
48+
$config['markasjunk_permanently_remove'] = false;
49+
50+
// Display only a mark as spam button
51+
$config['markasjunk_spam_only'] = false;
52+
53+
// Activate markasjunk for selected mail hosts only. If this is not set all mail hosts are allowed.
54+
// Example: $config['markasjunk_allowed_hosts'] = array('mail1.domain.tld', 'mail2.domain.tld');
55+
$config['markasjunk_allowed_hosts'] = null;
56+
57+
// Load specific config for different mail hosts
58+
// Example: $config['markasjunk_host_config'] = array(
59+
// 'mail1.domain.tld' => 'mail1_config.inc.php',
60+
// 'mail2.domain.tld' => 'mail2_config.inc.php',
61+
// );
62+
$config['markasjunk_host_config'] = null;
63+
64+
// cmd_learn Driver options
65+
// ------------------------
66+
// The command used to learn that a message is spam
67+
// The command can contain the following macros that will be expanded as follows:
68+
// %u is replaced with the username (from the session info)
69+
// %l is replaced with the local part of the username (if the username is an email address)
70+
// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not)
71+
// %i is replaced with the email address from the user's default identity
72+
// %s is replaced with the email address the message is from
73+
// %f is replaced with the path to the message file
74+
// %h:<header name> is replaced with the content of that header from the message (lower case) eg: %h:x-dspam-signature
75+
// If you do not want to run the command set this to null
76+
$config['markasjunk_spam_cmd'] = null;
77+
78+
// The command used to learn that a message is ham
79+
// The command can contain the following macros that will be expanded as follows:
80+
// %u is replaced with the username (from the session info)
81+
// %l is replaced with the local part of the username (if the username is an email address)
82+
// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not)
83+
// %i is replaced with the email address from the user's default identity
84+
// %s is replaced with the email address the message is from
85+
// %f is replaced with the path to the message file
86+
// %h:<header name> is replaced with the content of that header from the message (lower case) eg: %h:x-dspam-signature
87+
// If you do not want to run the command set this to null
88+
$config['markasjunk_ham_cmd'] = null;
89+
90+
// dir_learn Driver options
91+
// ------------------------
92+
// The full path of the directory used to store spam (must be writable by webserver)
93+
$config['markasjunk_spam_dir'] = null;
94+
95+
// The full path of the directory used to store ham (must be writable by webserver)
96+
$config['markasjunk_ham_dir'] = null;
97+
98+
// The filename prefix
99+
// The filename can contain the following macros that will be expanded as follows:
100+
// %u is replaced with the username (from the session info)
101+
// %l is replaced with the local part of the username (if the username is an email address)
102+
// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not)
103+
// %t is replaced with the type of message (spam/ham)
104+
$config['markasjunk_filename'] = null;
105+
106+
// email_learn Driver options
107+
// --------------------------
108+
// The email address that spam messages will be sent to
109+
// The address can contain the following macros that will be expanded as follows:
110+
// %u is replaced with the username (from the session info)
111+
// %l is replaced with the local part of the username (if the username is an email address)
112+
// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not)
113+
// %i is replaced with the email address from the user's default identity
114+
// If you do not want to send an email set this to null
115+
$config['markasjunk_email_spam'] = null;
116+
117+
// The email address that ham messages will be sent to
118+
// The address can contain the following macros that will be expanded as follows:
119+
// %u is replaced with the username (from the session info)
120+
// %l is replaced with the local part of the username (if the username is an email address)
121+
// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not)
122+
// %i is replaced with the email address from the user's default identity
123+
// If you do not want to send an email set this to null
124+
$config['markasjunk_email_ham'] = null;
125+
126+
// Should the spam/ham message be sent as an attachment
127+
$config['markasjunk_email_attach'] = true;
128+
129+
// The email subject (when sending as attachment)
130+
// The subject can contain the following macros that will be expanded as follows:
131+
// %u is replaced with the username (from the session info)
132+
// %l is replaced with the local part of the username (if the username is an email address)
133+
// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not)
134+
// %t is replaced with the type of message (spam/ham)
135+
$config['markasjunk_email_subject'] = 'learn this message as %t';
136+
137+
// sa_blacklist Driver options
138+
// ---------------------------
139+
// Path to SAUserPrefs config file
140+
$config['markasjunk_sauserprefs_config'] = '../sauserprefs/config.inc.php';
141+
142+
// amavis_blacklist Driver options
143+
// ---------------------------
144+
// Path to amacube config file
145+
$config['markasjunk_amacube_config'] = '../amacube/config.inc.php';
146+
147+
// edit_headers Driver options
148+
// ---------------------------
149+
// Patterns to match and replace headers for spam messages
150+
// Replacement method uses preg_replace - http://www.php.net/manual/function.preg-replace.php
151+
// WARNING: Be sure to match the entire header line, including the name of the header, also use ^ and $ and the 'm' flag
152+
// see the README for an example
153+
// TEST CAREFULLY BEFORE USE ON REAL MESSAGES
154+
$config['markasjunk_spam_patterns'] = array(
155+
'patterns' => array(),
156+
'replacements' => array()
157+
);
158+
159+
// Patterns to match and replace headers for spam messages
160+
// Replacement method uses preg_replace - http://www.php.net/manual/function.preg-replace.php
161+
// WARNING: Be sure to match the entire header line, including the name of the header, also use ^ and $ and the 'm' flag
162+
// see the README for an example
163+
// TEST CAREFULLY BEFORE USE ON REAL MESSAGES
164+
$config['markasjunk_ham_patterns'] = array(
165+
'patterns' => array(),
166+
'replacements' => array()
167+
);

0 commit comments

Comments
 (0)