aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Berg <johannes@sipsolutions.net>2011-02-27 11:35:01 +0100
committerJohannes Berg <johannes@sipsolutions.net>2011-02-27 11:42:45 +0100
commitd52daf7e31928c1b52bef6e57ec316f5f057d85a (patch)
treee69b6fc65e9f80054f8f8ea79a044d9c7c76cc2c
parent8ed65ea1566b8479536181c2520f8309ba14364e (diff)
downloaddovecot-antispam-d52daf7e31928c1b52bef6e57ec316f5f057d85a.tar.gz
dovecot-antispam-d52daf7e31928c1b52bef6e57ec316f5f057d85a.tar.xz
dovecot-antispam-d52daf7e31928c1b52bef6e57ec316f5f057d85a.zip
rename mailtrain to pipe
-rw-r--r--Makefile4
-rw-r--r--NOTES2
-rw-r--r--antispam.741
-rw-r--r--pipe.c (renamed from mailtrain.c)60
4 files changed, 62 insertions, 45 deletions
diff --git a/Makefile b/Makefile
index b7e446a..0516a6f 100644
--- a/Makefile
+++ b/Makefile
@@ -41,7 +41,7 @@ ifeq ("$(DEBUG_VERBOSE)", "1")
LOCALCFLAGS += -DCONFIG_DEBUG_VERBOSE
endif
-BACKENDS = dspam-exec.so signature-log.so crm114-exec.so mailtrain.so spool2dir.so
+BACKENDS = dspam-exec.so signature-log.so crm114-exec.so pipe.so spool2dir.so
# main make rules
LOCALCFLAGS += -fPIC -shared -Wall -Wextra -DPLUGINNAME=$(PLUGINNAME)
@@ -71,7 +71,7 @@ antispam-version.h: version.sh
dspam-exec.so: dspam-exec.o signature.o
signature-log.so: signature-log.o signature.o
crm114-exec.so: crm114-exec.o signature.o
-mailtrain.so: mailtrain.o
+pipe.so: pipe.o
spool2dir.so: spool2dir.o
$(BACKENDS):
diff --git a/NOTES b/NOTES
index 0eaf63c..70c4fb5 100644
--- a/NOTES
+++ b/NOTES
@@ -7,4 +7,4 @@ Full-message availability
Pristine retraining or SpamAssassin retraining might need the full message
available. This can easily be implemented since the backend is passed each
-struct mail *mail that is moved. For an example see the mailtrain backend.
+struct mail *mail that is moved. For an example see the pipe backend.
diff --git a/antispam.7 b/antispam.7
index 141ef5c..5544ca3 100644
--- a/antispam.7
+++ b/antispam.7
@@ -189,31 +189,38 @@ plugin {
# antispam_dspam_result_blacklist = Virus
#=====================
- # mail sending plugin
+ # pipe plugin
+ #
+ # This plug can be used to train via an arbitrary program that
+ # receives the message on standard input. Since sendmail can be
+ # such a program, it can be used to send the message to another
+ # email address for training there.
#
- # Because of the way this plugin works, you can also use it
- # to train via an arbitrary program that receives the message
- # on standard input, in that case you can use the config
- # options antispam_mail_spam and antispam_mail_notspam for
- # the argument that distinguishes between ham and spam.
# For example:
- # antispam_mail_sendmail = /path/to/mailtrain
- # antispam_mail_sendmail_args = --for;%u
- # antispam_mail_spam = --spam
- # antispam_mail_notspam = --ham
+ # antispam_pipe_program = /path/to/mailtrain
+ # (defaults to /usr/sbin/sendmail)
+ # antispam_pipe_program_args = --for;%u
+ # antispam_pipe_program_spam_arg = --spam
+ # antispam_pipe_program_notspam_arg = --ham
+ # antispam_pipe_tmpdir = /tmp
# will call it, for example, like this:
# /path/to/mailtrain --for jberg --spam
+ #
+ # The old configuration options from when this plugin was called
+ # "mailtrain" are still valid, these are, in the same order as
+ # above: antispam_mail_sendmail, antispam_mail_sendmail_args,
+ # antispam_mail_spam, antispam_mail_notspam and antispam_mail_tmpdir.
# temporary directory
- antispam_mail_tmpdir = /tmp
+ antispam_pipe_tmpdir = /tmp
- # spam/not-spam addresses (default unset which will give errors)
- # antispam_mail_spam =
- # antispam_mail_notspam =
+ # spam/not-spam argument (default unset which will is not what you want)
+ # antispam_pipe_program_spam_arg =
+ # antispam_pipe_program_notspam_arg =
- # sendmail binary
- antispam_mail_sendmail = /usr/sbin/sendmail
- #antispam_mail_sendmail_args = -f;%u@example.com # % expansion done by dovecot
+ # binary to pipe mail to
+ antispam_pipe_program = /usr/sbin/sendmail
+ #antispam_pipe_program_args = -f;%u@example.com # % expansion done by dovecot
#===================
# crm114-exec plugin
diff --git a/mailtrain.c b/pipe.c
index e1c7bab..309f8d9 100644
--- a/mailtrain.c
+++ b/pipe.c
@@ -30,14 +30,14 @@
#include "antispam-plugin.h"
-static const char *spamaddr = NULL;
-static const char *hamaddr = NULL;
-static const char *sendmail_binary = "/usr/sbin/sendmail";
+static const char *spam_arg = NULL;
+static const char *ham_arg = NULL;
+static const char *pipe_binary = "/usr/sbin/sendmail";
static const char *tmpdir = "/tmp";
static char **extra_args = NULL;
static int extra_args_num = 0;
-static int run_sendmail(int mailfd, enum classification wanted)
+static int run_pipe(int mailfd, enum classification wanted)
{
const char *dest;
pid_t pid;
@@ -45,10 +45,10 @@ static int run_sendmail(int mailfd, enum classification wanted)
switch (wanted) {
case CLASS_SPAM:
- dest = spamaddr;
+ dest = spam_arg;
break;
case CLASS_NOTSPAM:
- dest = hamaddr;
+ dest = ham_arg;
break;
}
@@ -60,7 +60,7 @@ static int run_sendmail(int mailfd, enum classification wanted)
if (pid == -1)
return -1;
- debug("running mailtrain backend program %s", sendmail_binary);
+ debug("running mailtrain backend program %s", pipe_binary);
if (pid) {
if (waitpid(pid, &status, 0) == -1)
@@ -76,7 +76,7 @@ static int run_sendmail(int mailfd, enum classification wanted)
argv = i_malloc(sz);
memset(argv, 0, sz);
- argv[0] = (char *) sendmail_binary;
+ argv[0] = (char *) pipe_binary;
for (i = 0; i < extra_args_num; i++)
argv[i + 1] = (char *) extra_args[i];
@@ -88,7 +88,7 @@ static int run_sendmail(int mailfd, enum classification wanted)
dup2(fd, 1);
dup2(fd, 2);
close(fd);
- execv(sendmail_binary, argv);
+ execv(pipe_binary, argv);
_exit(1);
/* not reached */
return -1;
@@ -143,7 +143,7 @@ static int process_tmpdir(struct mailbox_transaction_context *ctx,
fd = open(buf, O_RDONLY);
read(fd, &wanted, sizeof(wanted));
- if ((rc = run_sendmail(fd, wanted))) {
+ if ((rc = run_pipe(fd, wanted))) {
mail_storage_set_error(ctx->box->storage,
ME(TEMP)
"failed to send mail");
@@ -228,7 +228,7 @@ static int backend_handle_mail(struct mailbox_transaction_context *t,
return -1;
}
- if (!hamaddr || !spamaddr) {
+ if (!ham_arg || !spam_arg) {
mail_storage_set_error(t->box->storage,
ME(NOTPOSSIBLE)
"antispam plugin not configured");
@@ -315,38 +315,48 @@ static void backend_init(pool_t pool __attr_unused__)
const char *tmp;
int i;
- tmp = get_setting("MAIL_SPAM");
+ tmp = get_setting("PIPE_PROGRAM_SPAM_ARG");
+ if (!tmp)
+ tmp = get_setting("MAIL_SPAM");
if (tmp) {
- spamaddr = tmp;
- debug("mail backend spam address %s\n", tmp);
+ spam_arg = tmp;
+ debug("pipe backend spam argument = %s\n", tmp);
}
- tmp = get_setting("MAIL_NOTSPAM");
+ tmp = get_setting("PIPE_PROGRAM_NOTSPAM_ARG");
+ if (!tmp)
+ tmp = get_setting("MAIL_NOTSPAM");
if (tmp) {
- hamaddr = tmp;
- debug("mail backend not-spam address %s\n", tmp);
+ ham_arg = tmp;
+ debug("pipe backend not-spam argument = %s\n", tmp);
}
- tmp = get_setting("MAIL_SENDMAIL");
+ tmp = get_setting("PIPE_PROGRAM");
+ if (!tmp)
+ tmp = get_setting("MAIL_SENDMAIL");
if (tmp) {
- sendmail_binary = tmp;
- debug("mail backend sendmail %s\n", tmp);
+ pipe_binary = tmp;
+ debug("pipe backend program = %s\n", tmp);
}
- tmp = get_setting("MAIL_SENDMAIL_ARGS");
+ tmp = get_setting("PIPE_PROGRAM_ARGS");
+ if (!tmp)
+ tmp = get_setting("MAIL_SENDMAIL_ARGS");
if (tmp) {
extra_args = p_strsplit(pool, tmp, ";");
extra_args_num = str_array_length(
(const char *const *)extra_args);
for (i = 0; i < extra_args_num; i++)
- debug("mail backend sendmail arg %s\n",
- extra_args[i]);
+ debug("pipe backend program arg[%d] = %s\n",
+ i, extra_args[i]);
}
- tmp = get_setting("MAIL_TMPDIR");
+ tmp = get_setting("PIPE_TMPDIR");
+ if (!tmp)
+ tmp = get_setting("MAIL_TMPDIR");
if (tmp)
tmpdir = tmp;
- debug("mail backend tmpdir %s\n", tmpdir);
+ debug("pipe backend tmpdir %s\n", tmpdir);
}
static void backend_exit(void)