aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-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;