Skip to content

Integrate markasjunk2 features into markasjunk - marking as non-junk + learning engine #6504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions plugins/markasjunk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
Roundcube Webmail MarkAsJunk Plugin
===================================
This plugin adds "mark as spam" or "mark as not spam" button to the message
menu.

When not in the Junk mailbox:
Messages are moved into the Junk mailbox and marked as read

When in the Junk mailbox:
The buttons are changed to "mark as not spam" or "this message is not spam"
and the message is moved to the Inbox


License
-------

This plugin is released under the [GNU General Public License Version 3+][gpl].

Even if skins might contain some programming work, they are not considered
as a linked part of the plugin and therefore skins DO NOT fall under the
provisions of the GPL license. See the README file located in the core skins
folder for details on the skin license.


Configuration
-------------

The default config file is plugins/markasjunk/config.inc.php.dist
Rename this to plugins/markasjunk/config.inc.php

All config parameters are optional.


The Learning Driver
-------------------

The learning driver allows you to perform additional processing on each message
marked as spam/ham. A driver must contain a class named markasjunk_{driver
file name}. The class must contain 3 functions:

**spam:** This function should take 2 arguments: an array of UIDs of message(s)
being marked as spam, the name of the mailbox containing those messages

**ham:** This function should take 2 arguments: an array of UIDs of message(s)
being marked as ham, the name of the mailbox containing those messages

**init:** Optional, this function should take 0 arguments. eg: allows drivers
to add JS to the page to control which of the spam/ham options are displayed.
The `jsevents` driver is available to show how to use the JS events.

Several drivers are provided by default they are:

**cmd_learn:** This driver calls an external command (for example salearn) to
process the message

**dir_learn:** This driver places a copy of the message in a predefined folder,
for example to allow for processing later

**email_learn:** This driver emails the message either as an attachment or
directly to a set address. This driver requires Roundcube 1.4 or above.

**sa_blacklist:** This driver adds the sender address of a spam message to the
users blacklist (or whitelist of ham messages) Requires SAUserPrefs plugin

**amavis_blacklist:** This driver adds the sender address of a spam message to
the users blacklist (or whitelist of ham messages) Requires Amacube plugin.
Driver by Der-Jan

**sa_detach:** If the message is a Spamassassin spam report with the original
email attached then this is detached and saved in the Inbox, the spam report is
deleted

**edit_headers:** Edit the message headers. Headers are edited using
preg_replace.

**WARNING:** Be sure to match the entire header line, including the name of the
header, and include the ^ and $ and test carefully before use on real messages.
This driver alters the message source


Running multiple drivers
------------------------

**WARNING:** This is very dangerous please always test carefully. Run multiple
drivers at your own risk! It may be safer to create one driver that does
everything you want.

It is possible to run multiple drivers when marking a message as spam/ham. For
example running sa_blacklist followed by cmd_learn or edit_headers and
cmd_learn. An [example multi-driver][multidriver] is available. This is a
starting point only, it requires modification for individual cases.


Spam learning commands
----------------------

Spamassassin:

```sa-learn --spam --username=%u %f``` or
```sa-learn --spam --prefs-file=/var/mail/%d/%l/.spamassassin/user_prefs %f```


Ham learning commands
---------------------

Spamassassin:

```sa-learn --ham --username=%u %f``` or
```sa-learn --ham --prefs-file=/var/mail/%d/%l/.spamassassin/user_prefs %f```


edit_headers example config
---------------------------

**WARNING:** These are simple examples of how to configure the driver options,
use at your own risk

```php
$config['markasjunk_spam_patterns'] = array(
'patterns' => array('/^(Subject:\s*)(.*)$/m'),
'replacements' => array('$1[SPAM] $2')
);
```

```php
$config['markasjunk_ham_patterns'] = array(
'patterns' => array('/^(Subject:\s*)\[SPAM\](.*)$/m'),
'replacements' => array('$1$2')
);
```

[gpl]: https://www.gnu.org/licenses/gpl.html
[multidriver]: https://gist.github.com/johndoh/8173505
9 changes: 7 additions & 2 deletions plugins/markasjunk/composer.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
{
"name": "roundcube/markasjunk",
"type": "roundcube-plugin",
"description": "Adds a new button to the mailbox toolbar to mark the selected messages as Junk and move them to the configured Junk folder.",
"description": "Adds buttons to mark messages as Junk/Non-Junk with moving to the Junk folder and Spam/Ham learning.",
"license": "GPLv3+",
"version": "1.2",
"version": "2.0",
"authors": [
{
"name": "Thomas Bruederli",
"email": "[email protected]",
"role": "Lead"
},
{
"name": "Philip Weir",
"email": "[email protected]",
"role": "Developer"
}
],
"repositories": [
Expand Down
167 changes: 167 additions & 0 deletions plugins/markasjunk/config.inc.php.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?php

// Learning driver
// Use an external process such as sa-learn to learn from spam/ham messages. Default: null.
// Please see the README for more information
$config['markasjunk_learning_driver'] = null;

// Ham mailbox
// Mailbox messages should be moved to when they are marked as ham. null = INBOX
// set to FALSE to disable message moving
$config['markasjunk_ham_mbox'] = null;

// Spam mailbox
// Mailbox messages should be moved to when they are marked as spam.
// null = the mailbox assigned as the spam folder in Roundcube settings
// set to FALSE to disable message moving
$config['markasjunk_spam_mbox'] = null;

// Mark messages as read when reporting them as spam
$config['markasjunk_read_spam'] = false;

// Mark messages as unread when reporting them as ham
$config['markasjunk_unread_ham'] = false;

// Add flag to messages marked as spam (flag will be removed when marking as ham)
// If you do not want to use message flags set this to false
$config['markasjunk_spam_flag'] = 'Junk';

// Add flag to messages marked as ham (flag will be removed when marking as spam)
// If you do not want to use message flags set this to false
$config['markasjunk_ham_flag'] = 'NonJunk';

// Write output from spam/ham commands to the log for debug
$config['markasjunk_debug'] = false;

// The mark as spam/ham icon can either be displayed on the toolbar or as part of the mark messages menu.
// Set to False to use Mark menu instead of the toolbar. Default: true.
$config['markasjunk_toolbar'] = true;

// Learn any message moved to the spam mailbox as spam (not just when the button is pressed)
$config['markasjunk_move_spam'] = false;

// Learn any message moved from the spam mailbox to the ham mailbox as ham (not just when the button is pressed)
$config['markasjunk_move_ham'] = false;

// Some drivers create new copies of the target message(s), in this case the original message(s) will be deleted
// Rather than deleting the message(s) (moving to Trash) setting this option true will cause the original message(s) to be permanently removed
$config['markasjunk_permanently_remove'] = false;

// Display only a mark as spam button
$config['markasjunk_spam_only'] = false;

// Activate markasjunk for selected mail hosts only. If this is not set all mail hosts are allowed.
// Example: $config['markasjunk_allowed_hosts'] = array('mail1.domain.tld', 'mail2.domain.tld');
$config['markasjunk_allowed_hosts'] = null;

// Load specific config for different mail hosts
// Example: $config['markasjunk_host_config'] = array(
// 'mail1.domain.tld' => 'mail1_config.inc.php',
// 'mail2.domain.tld' => 'mail2_config.inc.php',
// );
$config['markasjunk_host_config'] = null;

// cmd_learn Driver options
// ------------------------
// The command used to learn that a message is spam
// The command can contain the following macros that will be expanded as follows:
// %u is replaced with the username (from the session info)
// %l is replaced with the local part of the username (if the username is an email address)
// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not)
// %i is replaced with the email address from the user's default identity
// %s is replaced with the email address the message is from
// %f is replaced with the path to the message file
// %h:<header name> is replaced with the content of that header from the message (lower case) eg: %h:x-dspam-signature
// If you do not want to run the command set this to null
$config['markasjunk_spam_cmd'] = null;

// The command used to learn that a message is ham
// The command can contain the following macros that will be expanded as follows:
// %u is replaced with the username (from the session info)
// %l is replaced with the local part of the username (if the username is an email address)
// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not)
// %i is replaced with the email address from the user's default identity
// %s is replaced with the email address the message is from
// %f is replaced with the path to the message file
// %h:<header name> is replaced with the content of that header from the message (lower case) eg: %h:x-dspam-signature
// If you do not want to run the command set this to null
$config['markasjunk_ham_cmd'] = null;

// dir_learn Driver options
// ------------------------
// The full path of the directory used to store spam (must be writable by webserver)
$config['markasjunk_spam_dir'] = null;

// The full path of the directory used to store ham (must be writable by webserver)
$config['markasjunk_ham_dir'] = null;

// The filename prefix
// The filename can contain the following macros that will be expanded as follows:
// %u is replaced with the username (from the session info)
// %l is replaced with the local part of the username (if the username is an email address)
// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not)
// %t is replaced with the type of message (spam/ham)
$config['markasjunk_filename'] = null;

// email_learn Driver options
// --------------------------
// The email address that spam messages will be sent to
// The address can contain the following macros that will be expanded as follows:
// %u is replaced with the username (from the session info)
// %l is replaced with the local part of the username (if the username is an email address)
// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not)
// %i is replaced with the email address from the user's default identity
// If you do not want to send an email set this to null
$config['markasjunk_email_spam'] = null;

// The email address that ham messages will be sent to
// The address can contain the following macros that will be expanded as follows:
// %u is replaced with the username (from the session info)
// %l is replaced with the local part of the username (if the username is an email address)
// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not)
// %i is replaced with the email address from the user's default identity
// If you do not want to send an email set this to null
$config['markasjunk_email_ham'] = null;

// Should the spam/ham message be sent as an attachment
$config['markasjunk_email_attach'] = true;

// The email subject (when sending as attachment)
// The subject can contain the following macros that will be expanded as follows:
// %u is replaced with the username (from the session info)
// %l is replaced with the local part of the username (if the username is an email address)
// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not)
// %t is replaced with the type of message (spam/ham)
$config['markasjunk_email_subject'] = 'learn this message as %t';

// sa_blacklist Driver options
// ---------------------------
// Path to SAUserPrefs config file
$config['markasjunk_sauserprefs_config'] = '../sauserprefs/config.inc.php';

// amavis_blacklist Driver options
// ---------------------------
// Path to amacube config file
$config['markasjunk_amacube_config'] = '../amacube/config.inc.php';

// edit_headers Driver options
// ---------------------------
// Patterns to match and replace headers for spam messages
// Replacement method uses preg_replace - http://www.php.net/manual/function.preg-replace.php
// WARNING: Be sure to match the entire header line, including the name of the header, also use ^ and $ and the 'm' flag
// see the README for an example
// TEST CAREFULLY BEFORE USE ON REAL MESSAGES
$config['markasjunk_spam_patterns'] = array(
'patterns' => array(),
'replacements' => array()
);

// Patterns to match and replace headers for spam messages
// Replacement method uses preg_replace - http://www.php.net/manual/function.preg-replace.php
// WARNING: Be sure to match the entire header line, including the name of the header, also use ^ and $ and the 'm' flag
// see the README for an example
// TEST CAREFULLY BEFORE USE ON REAL MESSAGES
$config['markasjunk_ham_patterns'] = array(
'patterns' => array(),
'replacements' => array()
);
Loading