1 diff --git a/antispam-plugin.h b/antispam-plugin.h
2 index 280bb12..72b906d 100644
3 --- a/antispam-plugin.h
4 +++ b/antispam-plugin.h
5 @@ -98,8 +98,10 @@ struct antispam_config {
9 - const char *spam_arg;
10 - const char *ham_arg;
15 const char *pipe_binary;// = "/usr/sbin/sendmail";
16 const char *tmpdir;// = "/tmp";
18 @@ -260,7 +262,7 @@ o_stream_create_from_fd(int fd, pool_t pool ATTR_UNUSED)
20 return o_stream_create_fd(fd, 0, TRUE);
22 -#elif DOVECOT_IS_EQ(2, 0)
23 +#elif DOVECOT_IS_EQ(2, 0) || DOVECOT_IS_EQ(2, 1)
24 #define mempool_unref pool_unref
25 #define module_arg struct module *
26 #define ME(err) MAIL_ERROR_ ##err,
27 diff --git a/antispam-storage-2.0.c b/antispam-storage-2.0.c
28 index 5a089bc..3e67553 100644
29 --- a/antispam-storage-2.0.c
30 +++ b/antispam-storage-2.0.c
31 @@ -472,7 +472,7 @@ static void antispam_mailbox_allocated(struct mailbox *box)
33 asbox->save_hack = FALSE;
34 asbox->movetype = MMT_APPEND;
35 - asbox->cfg = asuser->cfg;
36 + asbox->cfg = asuser->cfg;
38 v->free = antispam_mailbox_free;
40 diff --git a/antispam.7 b/antispam.7
41 index 5e33e4c..5d077f0 100644
45 -.TH ANTISPAM 7 "15 October 2007" "" ""
46 +.TH ANTISPAM 7 "24 March 2012" "" ""
48 antispam \- The dovecot antispam plugin.
50 @@ -206,6 +206,11 @@ plugin {
51 # semicolon-separated list of blacklisted results, case insensitive
52 # antispam_dspam_result_blacklist = Virus
54 + # semicolon-separated list of environment variables to set
55 + # (default unset i.e. none)
56 + # antispam_dspam_env =
57 + # antispam_dspam_env = HOME=%h;USER=%u
59 #=====================
62 @@ -228,6 +233,14 @@ plugin {
63 # "mailtrain" are still valid, these are, in the same order as
64 # above: antispam_mail_sendmail, antispam_mail_sendmail_args,
65 # antispam_mail_spam, antispam_mail_notspam and antispam_mail_tmpdir.
67 + # Alternatively, if you need to give multiple options, you can use
68 + # the spam_args/notspam_args parameters (which are used in preference
69 + # of the singular form):
70 + # antispam_pipe_program_spam_args = --spam;--my-other-param1
71 + # antispam_pipe_program_notspam_args = --ham;--my-other-param2
72 + # which will then call
73 + # /path/to/mailtrain --for jberg --spam --my-other-param1
76 antispam_pipe_tmpdir = /tmp
77 @@ -247,7 +260,7 @@ plugin {
78 antispam_crm_binary = /bin/false
79 # antispam_crm_binary = /usr/share/crm114/mailreaver.crm
81 - # semicolon-separated list of extra arguments to dspam
82 + # semicolon-separated list of extra arguments to crm114
83 # (default unset i.e. none)
85 # antispam_crm_args = --config=/path/to/config
86 @@ -257,11 +270,6 @@ plugin {
88 # antispam_crm_env = HOME=%h;USER=%u
90 - # semicolon-separated list of environment variables to set
91 - # (default unset i.e. none)
92 - # antispam_dspam_env =
93 - # antispam_dspam_env = HOME=%h;USER=%u
95 # NOTE: you need to set the signature for this backend
96 antispam_signature = X-CRM114-CacheID
98 diff --git a/dovecot-version.c b/dovecot-version.c
99 index cbcb35b..0026fbf 100644
100 --- a/dovecot-version.c
101 +++ b/dovecot-version.c
102 @@ -17,21 +17,24 @@ int main(int argc, char **argv)
104 maj = strtol(v, &e, 10);
111 min = strtol(v, &e, 10);
116 /* not end of string yet? */
120 - patch = strtol(v, &e, 10);
124 + patch = strtol(v, &e, 10);
131 printf("/* Auto-generated file, do not edit */\n\n");
132 @@ -50,6 +53,11 @@ int main(int argc, char **argv)
133 "DOVECOT_VCODE < DOVECOT_VERSION_CODE(maj, min, 0)\n");
134 printf("#define DOVECOT_IS_LE(maj, min) "
135 "DOVECOT_VCODE <= DOVECOT_VERSION_CODE(maj, min, 0)\n");
137 + /* Use the antispam-storage-2.0.c for dovecot 2.1 as well */
138 + if (maj == 2 && min == 1)
141 printf("#define ANTISPAM_STORAGE "
142 "\"antispam-storage-%d.%d.c\"\n", maj, min);
144 diff --git a/pipe.c b/pipe.c
145 index 18c2233..a20b4aa 100644
149 static int run_pipe(const struct antispam_config *cfg,
150 int mailfd, enum classification wanted)
160 - dest = cfg->pipe.spam_arg;
161 + dest = cfg->pipe.spam_args;
162 + dest_num = cfg->pipe.spam_args_num;
165 - dest = cfg->pipe.ham_arg;
166 + dest = cfg->pipe.ham_args;
167 + dest_num = cfg->pipe.spam_args_num;
171 @@ -65,18 +68,23 @@ static int run_pipe(const struct antispam_config *cfg,
172 return WEXITSTATUS(status);
175 - int sz = sizeof(char *) * (2 + cfg->pipe.extra_args_num + 1);
177 + int sz = sizeof(char *) * (2 + cfg->pipe.extra_args_num + dest_num + 1);
183 argv[0] = (char *) cfg->pipe.pipe_binary;
185 - for (i = 0; i < cfg->pipe.extra_args_num; i++)
186 + for (i = 0; i < cfg->pipe.extra_args_num; i++) {
187 argv[i + 1] = (char *) cfg->pipe.extra_args[i];
188 + debug(&cfg->dbgcfg, "running mailtrain backend program parameter %d %s", i + 1, argv[i + 1]);
191 - argv[i + 1] = (char *) dest;
192 + for (j = 0; j < dest_num; j++) {
193 + argv[i + 1 + j] = (char *) dest[j];
194 + debug(&cfg->dbgcfg, "running mailtrain backend program parameter %d %s", i + 1 + j, argv[i + 1 + j]);
198 fd = open("/dev/null", O_WRONLY);
199 @@ -228,7 +236,7 @@ static int backend_handle_mail(const struct antispam_config *cfg,
203 - if (!cfg->pipe.ham_arg || !cfg->pipe.spam_arg) {
204 + if (!cfg->pipe.ham_args || !cfg->pipe.spam_args) {
205 mail_storage_set_error(t->box->storage,
207 "antispam plugin not configured");
208 @@ -316,20 +324,50 @@ static void backend_init(struct antispam_config *cfg,
212 - tmp = getenv("PIPE_PROGRAM_SPAM_ARG", getenv_data);
214 - tmp = getenv("MAIL_SPAM", getenv_data);
215 + tmp = getenv("PIPE_PROGRAM_SPAM_ARGS", getenv_data);
217 - cfg->pipe.spam_arg = tmp;
218 - debug(&cfg->dbgcfg, "pipe backend spam argument = %s\n", tmp);
219 + cfg->pipe.spam_args = p_strsplit(cfg->mem_pool, tmp, ";");
220 + cfg->pipe.spam_args_num = str_array_length(
221 + (const char *const *)cfg->pipe.spam_args);
222 + for (i = 0; i < cfg->pipe.spam_args_num; i++)
223 + debug(&cfg->dbgcfg, "pipe backend spam arg[%d] = %s\n",
224 + i, cfg->pipe.spam_args[i]);
226 + tmp = getenv("PIPE_PROGRAM_SPAM_ARG", getenv_data);
228 + tmp = getenv("MAIL_SPAM", getenv_data);
230 + /* bit of a hack */
231 + cfg->pipe.spam_args =
232 + p_strsplit(cfg->mem_pool, tmp, "\x01");
233 + cfg->pipe.spam_args_num = 1;
234 + debug(&cfg->dbgcfg,
235 + "pipe backend spam argument = %s\n", tmp);
240 - tmp = getenv("PIPE_PROGRAM_NOTSPAM_ARG", getenv_data);
242 - tmp = getenv("MAIL_NOTSPAM", getenv_data);
243 + tmp = getenv("PIPE_PROGRAM_NOTSPAM_ARGS", getenv_data);
245 - cfg->pipe.ham_arg = tmp;
246 - debug(&cfg->dbgcfg, "pipe backend not-spam argument = %s\n", tmp);
247 + cfg->pipe.ham_args = p_strsplit(cfg->mem_pool, tmp, ";");
248 + cfg->pipe.ham_args_num = str_array_length(
249 + (const char *const *)cfg->pipe.ham_args);
250 + for (i = 0; i < cfg->pipe.ham_args_num; i++)
251 + debug(&cfg->dbgcfg, "pipe backend ham arg[%d] = %s\n",
252 + i, cfg->pipe.ham_args[i]);
254 + tmp = getenv("PIPE_PROGRAM_NOTSPAM_ARG", getenv_data);
256 + tmp = getenv("MAIL_NOTSPAM", getenv_data);
258 + /* bit of a hack */
259 + cfg->pipe.ham_args =
260 + p_strsplit(cfg->mem_pool, tmp, "\x01");
261 + cfg->pipe.ham_args_num = 1;
262 + debug(&cfg->dbgcfg,
263 + "pipe backend not-spam argument = %s\n", tmp);
268 tmp = getenv("PIPE_PROGRAM", getenv_data);