aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Berg <johannes@sipsolutions.net>2008-02-02 18:53:03 +0100
committerJohannes Berg <johannes@sipsolutions.net>2008-02-02 18:53:03 +0100
commit537bf130b486f97e29e0be1ce4b2927f902e7a44 (patch)
tree054cbdac002264fa4a10d994970d8a10a0622f35
parent7902510dd21e1628a6d7dfa0f73fab51b197b70f (diff)
downloaddovecot-antispam-537bf130b486f97e29e0be1ce4b2927f902e7a44.tar.gz
dovecot-antispam-537bf130b486f97e29e0be1ce4b2927f902e7a44.tar.xz
dovecot-antispam-537bf130b486f97e29e0be1ce4b2927f902e7a44.zip
allow arbitrary command line arguments for mailtrain backend
-rw-r--r--antispam.71
-rw-r--r--mailtrain.c47
2 files changed, 39 insertions, 9 deletions
diff --git a/antispam.7 b/antispam.7
index 4a36529..84234b4 100644
--- a/antispam.7
+++ b/antispam.7
@@ -142,6 +142,7 @@ plugin {
# sendmail binary
antispam_mail_sendmail = /usr/sbin/sendmail
+ #antispam_mail_sendmail_args = -f;%u@example.com # % expansion done by dovecot
#===================
# crm114-exec plugin
diff --git a/mailtrain.c b/mailtrain.c
index d734e20..cb571db 100644
--- a/mailtrain.c
+++ b/mailtrain.c
@@ -34,6 +34,8 @@ static const char *spamaddr = NULL;
static const char *hamaddr = NULL;
static const char *sendmail_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)
{
@@ -55,21 +57,37 @@ static int run_sendmail(int mailfd, enum classification wanted)
pid = fork();
- switch (pid) {
- case -1:
+ if (pid == -1)
return -1;
- case 0:
- dup2(mailfd, 0);
- close(1);
- close(2);
- execl(sendmail_binary, sendmail_binary, dest, NULL);
- _exit(1);
- default:
+
+ if (pid) {
if (waitpid(pid, &status, 0) == -1)
return -1;
if (!WIFEXITED(status))
return -1;
return WEXITSTATUS(status);
+ } else {
+ char **argv;
+ int sz = sizeof(char *) * (2 + extra_args_num + 1);
+ int i;
+
+ argv = i_malloc(sz);
+ memset(argv, 0, sz);
+
+ argv[0] = (char *) sendmail_binary;
+
+ for (i = 0; i < extra_args_num; i++)
+ argv[i + 1] = (char *) extra_args[i];
+
+ argv[i + 1] = (char *) dest;
+
+ dup2(mailfd, 0);
+ close(1);
+ close(2);
+ execv(sendmail_binary, argv);
+ _exit(1);
+ /* not reached */
+ return -1;
}
}
@@ -274,6 +292,7 @@ int backend_handle_mail(struct mailbox_transaction_context *t,
void backend_init(pool_t pool __attr_unused__)
{
const char *tmp;
+ int i;
tmp = get_setting("MAIL_SPAM");
if (tmp) {
@@ -293,6 +312,16 @@ void backend_init(pool_t pool __attr_unused__)
debug("mail backend sendmail %s\n", 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]);
+ }
+
tmp = get_setting("MAIL_TMPDIR");
if (tmp)
tmpdir = tmp;