1 commit 98b5e06d18f6a95695833afaa4b9bc1f256648df
2 Author: Johannes Berg <johannes@sipsolutions.net>
3 Date: Mon Nov 7 11:00:25 2011 +0100
7 diff --git a/antispam-storage-2.0.c b/antispam-storage-2.0.c
8 index 5a089bc..3e67553 100644
9 --- a/antispam-storage-2.0.c
10 +++ b/antispam-storage-2.0.c
11 @@ -472,7 +472,7 @@ static void antispam_mailbox_allocated(struct mailbox *box)
13 asbox->save_hack = FALSE;
14 asbox->movetype = MMT_APPEND;
15 - asbox->cfg = asuser->cfg;
16 + asbox->cfg = asuser->cfg;
18 v->free = antispam_mailbox_free;
21 commit ecaa554d472002a001bc2b91526cecaf2f21a480
22 Author: Johannes Berg <johannes@sipsolutions.net>
23 Date: Fri Feb 24 20:22:48 2012 +0100
25 allow multiple spam/not_spam arguments
27 Some tools need multiple different arguments,
28 so introduce configuration for that.
30 diff --git a/antispam-plugin.h b/antispam-plugin.h
31 index 280bb12..5bd3f06 100644
32 --- a/antispam-plugin.h
33 +++ b/antispam-plugin.h
34 @@ -98,8 +98,10 @@ struct antispam_config {
38 - const char *spam_arg;
39 - const char *ham_arg;
44 const char *pipe_binary;// = "/usr/sbin/sendmail";
45 const char *tmpdir;// = "/tmp";
47 diff --git a/antispam.7 b/antispam.7
48 index 5e33e4c..d87db93 100644
51 @@ -228,6 +228,14 @@ plugin {
52 # "mailtrain" are still valid, these are, in the same order as
53 # above: antispam_mail_sendmail, antispam_mail_sendmail_args,
54 # antispam_mail_spam, antispam_mail_notspam and antispam_mail_tmpdir.
56 + # Alternatively, if you need to give multiple options, you can use
57 + # the spam_args/notspam_args parameters (which are used in preference
58 + # of the singular form):
59 + # antispam_pipe_program_spam_args = --spam;--my-other-param1
60 + # antispam_pipe_program_notspam_args = --ham;--my-other-param2
61 + # which will then call
62 + # /path/to/mailtrain --for jberg --spam --my-other-param1
65 antispam_pipe_tmpdir = /tmp
66 diff --git a/pipe.c b/pipe.c
67 index 18c2233..a20b4aa 100644
71 static int run_pipe(const struct antispam_config *cfg,
72 int mailfd, enum classification wanted)
82 - dest = cfg->pipe.spam_arg;
83 + dest = cfg->pipe.spam_args;
84 + dest_num = cfg->pipe.spam_args_num;
87 - dest = cfg->pipe.ham_arg;
88 + dest = cfg->pipe.ham_args;
89 + dest_num = cfg->pipe.spam_args_num;
93 @@ -65,18 +68,23 @@ static int run_pipe(const struct antispam_config *cfg,
94 return WEXITSTATUS(status);
97 - int sz = sizeof(char *) * (2 + cfg->pipe.extra_args_num + 1);
99 + int sz = sizeof(char *) * (2 + cfg->pipe.extra_args_num + dest_num + 1);
105 argv[0] = (char *) cfg->pipe.pipe_binary;
107 - for (i = 0; i < cfg->pipe.extra_args_num; i++)
108 + for (i = 0; i < cfg->pipe.extra_args_num; i++) {
109 argv[i + 1] = (char *) cfg->pipe.extra_args[i];
110 + debug(&cfg->dbgcfg, "running mailtrain backend program parameter %d %s", i + 1, argv[i + 1]);
113 - argv[i + 1] = (char *) dest;
114 + for (j = 0; j < dest_num; j++) {
115 + argv[i + 1 + j] = (char *) dest[j];
116 + debug(&cfg->dbgcfg, "running mailtrain backend program parameter %d %s", i + 1 + j, argv[i + 1 + j]);
120 fd = open("/dev/null", O_WRONLY);
121 @@ -228,7 +236,7 @@ static int backend_handle_mail(const struct antispam_config *cfg,
125 - if (!cfg->pipe.ham_arg || !cfg->pipe.spam_arg) {
126 + if (!cfg->pipe.ham_args || !cfg->pipe.spam_args) {
127 mail_storage_set_error(t->box->storage,
129 "antispam plugin not configured");
130 @@ -316,20 +324,50 @@ static void backend_init(struct antispam_config *cfg,
134 - tmp = getenv("PIPE_PROGRAM_SPAM_ARG", getenv_data);
136 - tmp = getenv("MAIL_SPAM", getenv_data);
137 + tmp = getenv("PIPE_PROGRAM_SPAM_ARGS", getenv_data);
139 - cfg->pipe.spam_arg = tmp;
140 - debug(&cfg->dbgcfg, "pipe backend spam argument = %s\n", tmp);
141 + cfg->pipe.spam_args = p_strsplit(cfg->mem_pool, tmp, ";");
142 + cfg->pipe.spam_args_num = str_array_length(
143 + (const char *const *)cfg->pipe.spam_args);
144 + for (i = 0; i < cfg->pipe.spam_args_num; i++)
145 + debug(&cfg->dbgcfg, "pipe backend spam arg[%d] = %s\n",
146 + i, cfg->pipe.spam_args[i]);
148 + tmp = getenv("PIPE_PROGRAM_SPAM_ARG", getenv_data);
150 + tmp = getenv("MAIL_SPAM", getenv_data);
152 + /* bit of a hack */
153 + cfg->pipe.spam_args =
154 + p_strsplit(cfg->mem_pool, tmp, "\x01");
155 + cfg->pipe.spam_args_num = 1;
156 + debug(&cfg->dbgcfg,
157 + "pipe backend spam argument = %s\n", tmp);
162 - tmp = getenv("PIPE_PROGRAM_NOTSPAM_ARG", getenv_data);
164 - tmp = getenv("MAIL_NOTSPAM", getenv_data);
165 + tmp = getenv("PIPE_PROGRAM_NOTSPAM_ARGS", getenv_data);
167 - cfg->pipe.ham_arg = tmp;
168 - debug(&cfg->dbgcfg, "pipe backend not-spam argument = %s\n", tmp);
169 + cfg->pipe.ham_args = p_strsplit(cfg->mem_pool, tmp, ";");
170 + cfg->pipe.ham_args_num = str_array_length(
171 + (const char *const *)cfg->pipe.ham_args);
172 + for (i = 0; i < cfg->pipe.ham_args_num; i++)
173 + debug(&cfg->dbgcfg, "pipe backend ham arg[%d] = %s\n",
174 + i, cfg->pipe.ham_args[i]);
176 + tmp = getenv("PIPE_PROGRAM_NOTSPAM_ARG", getenv_data);
178 + tmp = getenv("MAIL_NOTSPAM", getenv_data);
180 + /* bit of a hack */
181 + cfg->pipe.ham_args =
182 + p_strsplit(cfg->mem_pool, tmp, "\x01");
183 + cfg->pipe.ham_args_num = 1;
184 + debug(&cfg->dbgcfg,
185 + "pipe backend not-spam argument = %s\n", tmp);
190 tmp = getenv("PIPE_PROGRAM", getenv_data);
192 commit d5f9b770ecc6cd6226d8d4806844eb615307e00e
193 Author: Ron <ron@debian.org>
194 Date: Sat Mar 24 22:12:45 2012 +1030
196 Fix dspam config example in antispam.7
198 Move some dspam configuration out of the crm114 section.
199 Thanks to Benoît Knecht for catching this. Closes: #663721
201 diff --git a/antispam.7 b/antispam.7
202 index d87db93..5d077f0 100644
206 -.TH ANTISPAM 7 "15 October 2007" "" ""
207 +.TH ANTISPAM 7 "24 March 2012" "" ""
209 antispam \- The dovecot antispam plugin.
211 @@ -206,6 +206,11 @@ plugin {
212 # semicolon-separated list of blacklisted results, case insensitive
213 # antispam_dspam_result_blacklist = Virus
215 + # semicolon-separated list of environment variables to set
216 + # (default unset i.e. none)
217 + # antispam_dspam_env =
218 + # antispam_dspam_env = HOME=%h;USER=%u
220 #=====================
223 @@ -255,7 +260,7 @@ plugin {
224 antispam_crm_binary = /bin/false
225 # antispam_crm_binary = /usr/share/crm114/mailreaver.crm
227 - # semicolon-separated list of extra arguments to dspam
228 + # semicolon-separated list of extra arguments to crm114
229 # (default unset i.e. none)
230 # antispam_crm_args =
231 # antispam_crm_args = --config=/path/to/config
232 @@ -265,11 +270,6 @@ plugin {
234 # antispam_crm_env = HOME=%h;USER=%u
236 - # semicolon-separated list of environment variables to set
237 - # (default unset i.e. none)
238 - # antispam_dspam_env =
239 - # antispam_dspam_env = HOME=%h;USER=%u
241 # NOTE: you need to set the signature for this backend
242 antispam_signature = X-CRM114-CacheID
245 commit 83b0b4b8a5e85f70025fbb874c30d3e28ad01f56
246 Author: Ron <ron@debian.org>
247 Date: Thu Sep 27 11:27:20 2012 +0200
249 make it work for dovecot 2.1
251 This patch from me/Ron tweaks the code to use
252 the same backends for dovecot 2.1 as for 2.0.
254 diff --git a/antispam-plugin.h b/antispam-plugin.h
255 index 5bd3f06..72b906d 100644
256 --- a/antispam-plugin.h
257 +++ b/antispam-plugin.h
258 @@ -262,7 +262,7 @@ o_stream_create_from_fd(int fd, pool_t pool ATTR_UNUSED)
260 return o_stream_create_fd(fd, 0, TRUE);
262 -#elif DOVECOT_IS_EQ(2, 0)
263 +#elif DOVECOT_IS_EQ(2, 0) || DOVECOT_IS_EQ(2, 1)
264 #define mempool_unref pool_unref
265 #define module_arg struct module *
266 #define ME(err) MAIL_ERROR_ ##err,
267 diff --git a/dovecot-version.c b/dovecot-version.c
268 index cbcb35b..0026fbf 100644
269 --- a/dovecot-version.c
270 +++ b/dovecot-version.c
271 @@ -17,21 +17,24 @@ int main(int argc, char **argv)
273 maj = strtol(v, &e, 10);
280 min = strtol(v, &e, 10);
285 /* not end of string yet? */
289 - patch = strtol(v, &e, 10);
293 + patch = strtol(v, &e, 10);
300 printf("/* Auto-generated file, do not edit */\n\n");
301 @@ -50,6 +53,11 @@ int main(int argc, char **argv)
302 "DOVECOT_VCODE < DOVECOT_VERSION_CODE(maj, min, 0)\n");
303 printf("#define DOVECOT_IS_LE(maj, min) "
304 "DOVECOT_VCODE <= DOVECOT_VERSION_CODE(maj, min, 0)\n");
306 + /* Use the antispam-storage-2.0.c for dovecot 2.1 as well */
307 + if (maj == 2 && min == 1)
310 printf("#define ANTISPAM_STORAGE "
311 "\"antispam-storage-%d.%d.c\"\n", maj, min);
314 commit 8e2caa4c2ad42feb65a0693711f73f17f417fb87
315 Author: Johannes Berg <johannes@sipsolutions.net>
316 Date: Wed Aug 21 22:33:37 2013 +0200
318 remove unnecessary dict code
320 I long removed the signature-log backend, so the support code
321 for it to use dovecot's dict API across multiple version is
322 really no longer needed - kill it.
324 This was reported to me (indirectly) by Micah Anderson, thanks.
326 diff --git a/antispam-plugin.h b/antispam-plugin.h
327 index 72b906d..0c3f18e 100644
328 --- a/antispam-plugin.h
329 +++ b/antispam-plugin.h
335 #include "imap-search.h"
338 @@ -206,12 +205,6 @@ o_stream_create_from_fd(int fd, pool_t pool)
339 return o_stream_create_file(fd, pool, 0, TRUE);
342 -static inline struct dict *
343 -string_dict_init(const char *uri, const char *username)
345 - return dict_init(uri, username);
348 static inline int _mail_get_stream(struct mail *mail,
349 struct message_size *hdr_size,
350 struct message_size *body_size,
351 @@ -281,12 +274,6 @@ o_stream_create_from_fd(int fd, pool_t pool ATTR_UNUSED)
353 return o_stream_create_fd(fd, 0, TRUE);
356 -static inline struct dict *
357 -string_dict_init(const char *uri, const char *username)
359 - return dict_init(uri, DICT_DATA_TYPE_STRING, username, NULL);
362 #error "Building against this dovecot version is not supported"
365 commit c2d97b386177d945581574e74690d773a6231338
366 Author: Micah Anderson <micah@riseup.net>
367 Date: Wed Aug 21 21:25:41 2013 -0400
369 make things work for dovecot 2.2
371 diff --git a/antispam-plugin.h b/antispam-plugin.h
372 index 0c3f18e..a06f7be 100644
373 --- a/antispam-plugin.h
374 +++ b/antispam-plugin.h
375 @@ -255,7 +255,7 @@ o_stream_create_from_fd(int fd, pool_t pool ATTR_UNUSED)
377 return o_stream_create_fd(fd, 0, TRUE);
379 -#elif DOVECOT_IS_EQ(2, 0) || DOVECOT_IS_EQ(2, 1)
380 +#elif DOVECOT_IS_EQ(2, 0) || DOVECOT_IS_EQ(2, 1) || DOVECOT_IS_EQ(2, 2)
381 #define mempool_unref pool_unref
382 #define module_arg struct module *
383 #define ME(err) MAIL_ERROR_ ##err,
385 commit abdad24e671da556682fb1bca2a076bc8686025a
386 Author: Ron <ron@debian.org>
387 Date: Thu Sep 12 18:49:34 2013 +0930
389 More tweaks for dovecot 2.2
391 Use antispam-storage-2.0.c for 2.2 as well.
392 Dovecot 2.2 now checks for a real ABI version string rather than
393 just the release version.
395 diff --git a/antispam-plugin.c b/antispam-plugin.c
396 index 7756204..103b5fb 100644
397 --- a/antispam-plugin.c
398 +++ b/antispam-plugin.c
399 @@ -392,4 +392,8 @@ void PLUGIN_FUNCTION(deinit)(void)
402 /* put dovecot version we built against into plugin for checking */
403 +#if DOVECOT_IS_GE(2,2)
404 +const char *PLUGIN_FUNCTION(version) = DOVECOT_ABI_VERSION;
406 const char *PLUGIN_FUNCTION(version) = PACKAGE_VERSION;
408 diff --git a/dovecot-version.c b/dovecot-version.c
409 index 0026fbf..e7e7cf2 100644
410 --- a/dovecot-version.c
411 +++ b/dovecot-version.c
412 @@ -54,8 +54,8 @@ int main(int argc, char **argv)
413 printf("#define DOVECOT_IS_LE(maj, min) "
414 "DOVECOT_VCODE <= DOVECOT_VERSION_CODE(maj, min, 0)\n");
416 - /* Use the antispam-storage-2.0.c for dovecot 2.1 as well */
417 - if (maj == 2 && min == 1)
418 + /* Use the antispam-storage-2.0.c for dovecot 2.1 and 2.2 as well */
419 + if (maj == 2 && min < 3)
422 printf("#define ANTISPAM_STORAGE "
424 commit 446b62b634db89054073e0484626c5c4623d9903
425 Author: Johannes Berg <johannes@sipsolutions.net>
426 Date: Fri Oct 24 17:33:21 2014 +0200
428 add version check macros to check for dovecot patchlevel
430 Add a new set of version check macros that also take the patchlevel.
432 diff --git a/dovecot-version.c b/dovecot-version.c
433 index e7e7cf2..623461a 100644
434 --- a/dovecot-version.c
435 +++ b/dovecot-version.c
436 @@ -34,7 +34,7 @@ int main(int argc, char **argv)
444 printf("/* Auto-generated file, do not edit */\n\n");
445 @@ -43,6 +43,8 @@ int main(int argc, char **argv)
447 printf("#define DOVECOT_VCODE "
448 "0x%.2x%.2x%.2x\n", maj, min, 0);
449 + printf("#define DOVECOT_VCODE_PATCH "
450 + "0x%.2x%.2x%.2x\n", maj, min, patch);
451 printf("#define DOVECOT_IS_EQ(maj, min) "
452 "DOVECOT_VCODE == DOVECOT_VERSION_CODE(maj, min, 0)\n");
453 printf("#define DOVECOT_IS_GT(maj, min) "
454 @@ -54,6 +56,17 @@ int main(int argc, char **argv)
455 printf("#define DOVECOT_IS_LE(maj, min) "
456 "DOVECOT_VCODE <= DOVECOT_VERSION_CODE(maj, min, 0)\n");
458 + printf("#define DOVECOT_P_IS_EQ(maj, min, patch) "
459 + "DOVECOT_VCODE_PATCH == DOVECOT_VERSION_CODE(maj, min, patch)\n");
460 + printf("#define DOVECOT_P_IS_GT(maj, min, patch) "
461 + "DOVECOT_VCODE_PATCH > DOVECOT_VERSION_CODE(maj, min, patch)\n");
462 + printf("#define DOVECOT_P_IS_GE(maj, min, patch) "
463 + "DOVECOT_VCODE_PATCH >= DOVECOT_VERSION_CODE(maj, min, patch)\n");
464 + printf("#define DOVECOT_P_IS_LT(maj, min, patch) "
465 + "DOVECOT_VCODE_PATCH < DOVECOT_VERSION_CODE(maj, min, patch)\n");
466 + printf("#define DOVECOT_P_IS_LE(maj, min, patch) "
467 + "DOVECOT_VCODE_PATCH <= DOVECOT_VERSION_CODE(maj, min, patch)\n");
469 /* Use the antispam-storage-2.0.c for dovecot 2.1 and 2.2 as well */
470 if (maj == 2 && min < 3)
473 commit eba2805c61c37cc006b9a90b43ba61f3256ee190
474 Author: Ron <ron@debian.org>
475 Date: Sat Oct 25 00:47:21 2014 +1030
477 Add a compatibility macro for t_push()
479 This should fix things for the API change in dovecot 2.2.14 reported in:
480 https://bugs.debian.org/765943
482 diff --git a/antispam-plugin.h b/antispam-plugin.h
483 index a06f7be..245393b 100644
484 --- a/antispam-plugin.h
485 +++ b/antispam-plugin.h
486 @@ -260,6 +260,10 @@ o_stream_create_from_fd(int fd, pool_t pool ATTR_UNUSED)
487 #define module_arg struct module *
488 #define ME(err) MAIL_ERROR_ ##err,
490 +#if DOVECOT_P_IS_GE(2,2,14)
491 +#define t_push() t_push(__func__)
494 static inline const char *const *
495 get_mail_headers(struct mail *mail, const char *hdr)
498 commit 31c81ae3faa205c245b0245c027a9a4e2f72e504
499 Author: Timo Sirainen <tss@iki.fi>
500 Date: Mon Nov 10 11:57:28 2014 +0100
504 Johannes: Timo's patch, adjusted to fix compilation and carry
505 a backport for dovecot 1.0 in case somebody still
508 For the original (although modified by somebody else to compile):
509 Acked-by: Phil Carmody <phil@dovecot.fi>
511 diff --git a/antispam-plugin.c b/antispam-plugin.c
512 index 103b5fb..76ced7b 100644
513 --- a/antispam-plugin.c
514 +++ b/antispam-plugin.c
515 @@ -90,7 +90,7 @@ static bool mailbox_patternmatch(struct mailbox *box,
522 boxname = mailbox_get_name(box);
524 @@ -110,7 +110,7 @@ static bool mailbox_patternmatch(struct mailbox *box,
526 rc = memcmp(name, boxname, len) == 0;
533 @@ -257,7 +257,7 @@ static int parse_folder_setting(const struct antispam_config *cfg,
540 for (i = 0; i < NUM_MT; ++i) {
541 tmp = getenv(t_strconcat(setting, match_info[i].suffix, NULL),
542 @@ -286,7 +286,7 @@ static int parse_folder_setting(const struct antispam_config *cfg,
550 debug(&cfg->dbgcfg, "no %s folders\n", display_name);
551 diff --git a/antispam-plugin.h b/antispam-plugin.h
552 index 245393b..f813964 100644
553 --- a/antispam-plugin.h
554 +++ b/antispam-plugin.h
555 @@ -217,6 +217,11 @@ static inline int _mail_get_stream(struct mail *mail,
558 #define mail_get_stream _mail_get_stream
561 + STMT_START { t_push();
563 + t_pop(); } STMT_END
564 #elif DOVECOT_IS_EQ(1, 1)
565 #define mempool_unref pool_unref
566 #define module_arg void
567 @@ -260,10 +265,6 @@ o_stream_create_from_fd(int fd, pool_t pool ATTR_UNUSED)
568 #define module_arg struct module *
569 #define ME(err) MAIL_ERROR_ ##err,
571 -#if DOVECOT_P_IS_GE(2,2,14)
572 -#define t_push() t_push(__func__)
575 static inline const char *const *
576 get_mail_headers(struct mail *mail, const char *hdr)
578 diff --git a/antispam-storage-1.1.c b/antispam-storage-1.1.c
579 index f28a0cf..aab23d9 100644
580 --- a/antispam-storage-1.1.c
581 +++ b/antispam-storage-1.1.c
582 @@ -508,10 +508,10 @@ void antispam_mail_storage_created(struct mail_storage *storage)
584 static const char *_getenv(const char *env, void *data ATTR_UNUSED)
588 env = t_str_ucase(t_strconcat("antispam_", env, NULL));
595 diff --git a/antispam-storage-1.2.c b/antispam-storage-1.2.c
596 index 5e0cb97..269a373 100644
597 --- a/antispam-storage-1.2.c
598 +++ b/antispam-storage-1.2.c
599 @@ -498,10 +498,10 @@ void antispam_mail_storage_created(struct mail_storage *storage)
601 static const char *_getenv(const char *env, void *data ATTR_UNUSED)
605 env = t_str_ucase(t_strconcat("antispam_", env, NULL));
612 diff --git a/antispam-storage-2.0.c b/antispam-storage-2.0.c
613 index 3e67553..c3d6251 100644
614 --- a/antispam-storage-2.0.c
615 +++ b/antispam-storage-2.0.c
616 @@ -494,11 +494,11 @@ static const char *_getenv(const char *name, void *data)
617 struct mail_user *user = data;
622 env = t_strconcat("antispam_", t_str_lcase(name), NULL);
624 env = mail_user_plugin_getenv(user, env);
630 diff --git a/crm114-exec.c b/crm114-exec.c
631 index 5b39ca9..d786e04 100644
634 @@ -113,7 +113,7 @@ static int call_reaver(const struct antispam_config *cfg,
636 debugv(&cfg->dbgcfg, argv);
640 for (i = 0; i < cfg->crm.extra_env_num; i++) {
642 name = t_strdup_noconst(cfg->crm.extra_env[i]);
643 @@ -124,7 +124,7 @@ static int call_reaver(const struct antispam_config *cfg,
645 setenv(name, value, 1);
650 execv(cfg->crm.reaver_binary, argv);
651 /* fall through if reaver can't be found */
652 diff --git a/debug.c b/debug.c
653 index d2683fa..7a2353a 100644
656 @@ -14,7 +14,7 @@ static void _debug(const struct antispam_debug_config *cfg,
657 if (cfg->target == ADT_NONE)
663 fmt = t_strconcat("antispam: ", format, NULL);
665 @@ -30,7 +30,7 @@ static void _debug(const struct antispam_debug_config *cfg,
673 void debug(const struct antispam_debug_config *cfg, const char *fmt, ...)
674 @@ -48,7 +48,7 @@ void debugv(const struct antispam_debug_config *cfg, char **args)
680 buf = t_buffer_get(buflen);
683 @@ -72,7 +72,7 @@ void debugv(const struct antispam_debug_config *cfg, char **args)
686 debug(cfg, "%s", buf);
691 void debugv_not_stderr(const struct antispam_debug_config *cfg, char **args)
692 diff --git a/dspam-exec.c b/dspam-exec.c
693 index 2e353ce..856babb 100644
696 @@ -141,7 +141,7 @@ static int call_dspam(const struct antispam_config *cfg,
698 debugv_not_stderr(&cfg->dbgcfg, argv);
702 for (i = 0; i < cfg->dspam.extra_env_num; i++) {
704 name = t_strdup_noconst(cfg->dspam.extra_env[i]);
705 @@ -152,7 +152,7 @@ static int call_dspam(const struct antispam_config *cfg,
707 setenv(name, value, 1);
712 execv(cfg->dspam.binary, argv);
713 debug(&cfg->dbgcfg, "executing %s failed: %d (uid=%d, gid=%d)",
714 diff --git a/pipe.c b/pipe.c
715 index a20b4aa..1fc1904 100644
718 @@ -136,7 +136,7 @@ static int process_tmpdir(const struct antispam_config *cfg,
719 enum classification wanted;
725 buf = t_malloc(20 + ast->tmplen);
727 @@ -159,7 +159,7 @@ static int process_tmpdir(const struct antispam_config *cfg,
736 @@ -168,7 +168,7 @@ static void clear_tmpdir(struct antispam_transaction_context *ast)
743 buf = t_malloc(20 + ast->tmplen);
745 @@ -180,7 +180,7 @@ static void clear_tmpdir(struct antispam_transaction_context *ast)
753 static void backend_rollback(const struct antispam_config *cfg ATTR_UNUSED,
754 @@ -250,7 +250,7 @@ static int backend_handle_mail(const struct antispam_config *cfg,
761 buf = t_malloc(20 + ast->tmplen);
762 i_snprintf(buf, 20 + ast->tmplen - 1, "%s/%d", ast->tmpdir, ast->count);
763 @@ -311,8 +311,8 @@ static int backend_handle_mail(const struct antispam_config *cfg,
764 o_stream_destroy(&outstream);
774 diff --git a/spool2dir.c b/spool2dir.c
775 index cbd1909..d304716 100644
778 @@ -165,7 +165,7 @@ static int backend_handle_mail(const struct antispam_config *cfg,
785 /* atomically create a _new_ file */
786 while (ast->count <= 9999) {
787 @@ -174,9 +174,6 @@ static int backend_handle_mail(const struct antispam_config *cfg,
788 if (fd >= 0 || errno != EEXIST)
790 /* current filename in buf already exists, zap it */
793 - /* buf is invalid now! */
797 @@ -225,8 +222,8 @@ static int backend_handle_mail(const struct antispam_config *cfg,
809 commit 963c046c19b5d7019c607a8b648cae7b53d93ce2
810 Author: Ron <ron@debian.org>
811 Date: Sun Feb 22 08:58:23 2015 +1030
813 Use the correct argc for pipe.ham_args
815 This fixes a typo bug, where if the number of arguments set for
816 antispam_pipe_program_spam_arg is not the same as what was set
817 for antispam_pipe_program_notspam_arg, then we'll either scribble
818 past the end of the allocated argv array, or populate it with
819 pointers to whatever followed the real ham_args.
821 Thanks to Peter Colberg who reported this, including a correct
822 patch to fix it, to the security team. The security implications
823 of this seem somewhat limited, since you need to edit a config
824 file as root to create the bad situation, and there is no path
825 for remote injection of crafted data (whether it overflows or
826 underflows) if you do, the argv array will just get some 'random'
827 extra pointers to existing internal data.
829 However it does pose a potential problem for a legitimate user
830 who does legitimately need or want to pass a different number of
831 arguments for the spam and ham cases, since that could crash
832 dovecot, or confuse the hell out of their pipe program when it
833 gets some random extra arguments. It's probably gone unnoticed
834 for this long because most uses will pass the same number of
835 arguments for both of them, but that's not a necessary condition
838 diff --git a/pipe.c b/pipe.c
839 index 1fc1904..f9abef5 100644
842 @@ -46,7 +46,7 @@ static int run_pipe(const struct antispam_config *cfg,
845 dest = cfg->pipe.ham_args;
846 - dest_num = cfg->pipe.spam_args_num;
847 + dest_num = cfg->pipe.ham_args_num;
852 commit 1ad6a9cf0dbed6cd51d3435a39fc5bfbfa2c27fd
853 Author: Johannes Berg <johannes@sipsolutions.net>
854 Date: Mon Jan 2 11:51:56 2017 +0100
856 fix mail_get_headers() return value usage
858 Dovecot 2.2.27 changed the mail_get_headers() return value
859 to be positive (not zero) for success, breaking everything.
861 Timo suggested to check for < 0, so do that.
863 Reported-by: Tom Talpey <tom@talpey.com>
865 diff --git a/antispam-plugin.h b/antispam-plugin.h
866 index f813964..a3a5c8d 100644
867 --- a/antispam-plugin.h
868 +++ b/antispam-plugin.h
869 @@ -231,7 +231,7 @@ static inline const char *const *
870 get_mail_headers(struct mail *mail, const char *hdr)
872 const char *const *ret;
873 - if (mail_get_headers(mail, hdr, &ret))
874 + if (mail_get_headers(mail, hdr, &ret) < 0)
878 @@ -250,7 +250,7 @@ static inline const char *const *
879 get_mail_headers(struct mail *mail, const char *hdr)
881 const char *const *ret;
882 - if (mail_get_headers(mail, hdr, &ret))
883 + if (mail_get_headers(mail, hdr, &ret) < 0)
887 @@ -269,7 +269,7 @@ static inline const char *const *
888 get_mail_headers(struct mail *mail, const char *hdr)
890 const char *const *ret;
891 - if (mail_get_headers(mail, hdr, &ret))
892 + if (mail_get_headers(mail, hdr, &ret) < 0)
897 commit 6b9003cb3a1b8f133ca70408b181109a48b10c57
898 Author: Johannes Berg <johannes@sipsolutions.net>
899 Date: Mon Jan 9 11:55:27 2017 +0100
901 make debug prefix configurable
903 The default remains "antispam: ", but you can now configure it
904 to include, for example, the logged-in username.
906 diff --git a/antispam-plugin.h b/antispam-plugin.h
907 index a3a5c8d..62a3eb3 100644
908 --- a/antispam-plugin.h
909 +++ b/antispam-plugin.h
910 @@ -42,6 +42,7 @@ struct signature_config {
913 struct antispam_debug_config {
914 + const char *prefix;
915 enum antispam_debug_target target;
918 diff --git a/antispam.7 b/antispam.7
919 index 5d077f0..497da58 100644
922 @@ -120,6 +120,9 @@ plugin {
923 # antispam_debug_target = syslog
924 # antispam_debug_target = stderr
925 # antispam_verbose_debug = 1
927 + # This can be used to get a prefix, e.g. by specifying %u in it
928 + # antispam_debug_prefix = "antispam: "
930 # backend selection, MUST be configured first,
931 # there's no default so you need to set one of
932 diff --git a/debug.c b/debug.c
933 index 7a2353a..e1f45a8 100644
936 @@ -16,7 +16,7 @@ static void _debug(const struct antispam_debug_config *cfg,
940 - fmt = t_strconcat("antispam: ", format, NULL);
941 + fmt = t_strconcat(cfg->prefix, format, NULL);
943 switch (cfg->target) {
945 @@ -111,6 +111,10 @@ int debug_init(struct antispam_debug_config *cfg,
949 + cfg->prefix = getenv("DEBUG_PREFIX", getenv_data);
951 + cfg->prefix = "antispam: ";
953 debug(cfg, "plugin initialising (%s)\n", ANTISPAM_VERSION);
955 tmp = getenv("VERBOSE_DEBUG", getenv_data);
957 commit cf96d8d46fb98d81cc664e3dcee596af2b19628a
958 Author: Ron <ron@debian.org>
959 Date: Fri Jan 6 02:31:13 2017 +1030
961 Include ctype.h for isdigit
963 It's no longer pulled in implicitly with libc6 2.24 and gcc 6.3.
965 diff --git a/dovecot-version.c b/dovecot-version.c
966 index 623461a..fe9bc73 100644
967 --- a/dovecot-version.c
968 +++ b/dovecot-version.c
976 int main(int argc, char **argv)
978 commit 649963a047ebad59f62b7cd620d6fe4329f392b2
979 Author: Ron <ron@debian.org>
980 Date: Fri Jan 6 02:49:19 2017 +1030
982 Drop the #define _BSD_SOURCE
984 In theory, it is needed for vsyslog(3), but glibc 2.20 deprecated it in
985 favour of _DEFAULT_SOURCE, and features.h in 2.24 now barks about it
986 being defined without _DEFAULT_SOURCE.
988 In practice, we don't need it at all here, since we aren't invoking the
989 compiler in a way that disables the default modes, so the "BSD" guarded
990 functions are already available to us by default anyway, and defining
991 _DEFAULT_SOURCE would be a no-op.
993 diff --git a/debug.c b/debug.c
994 index e1f45a8..77f0167 100644
1003 commit 0cab392a87b1d097fbd7a6cfcdfa29ad99ab78c9
1004 Author: Johannes Berg <johannes.berg@intel.com>
1005 Date: Sun Dec 24 14:15:57 2017 +0100
1007 storage 2.0: abort COPY properly when errors happen
1009 diff --git a/antispam-storage-2.0.c b/antispam-storage-2.0.c
1010 index c3d6251..3298908 100644
1011 --- a/antispam-storage-2.0.c
1012 +++ b/antispam-storage-2.0.c
1013 @@ -108,6 +108,7 @@ antispam_copy(struct mail_save_context *ctx, struct mail *mail)
1014 if (mailbox_is_unsure(asbox->cfg, t->box)) {
1015 mail_storage_set_error(t->box->storage, MAIL_ERROR_NOTPOSSIBLE,
1016 "Cannot copy to unsure folder");
1017 + mailbox_save_cancel(&ctx);
1022 commit 713e9e9ffd4adfcc58c6e12470e87c9fd1b8af44
1023 Author: Johannes Berg <johannes@sipsolutions.net>
1024 Date: Thu Dec 28 18:51:12 2017 +0100
1028 Tested by Björn Franke.
1030 diff --git a/antispam-plugin.h b/antispam-plugin.h
1031 index 62a3eb3..c974129 100644
1032 --- a/antispam-plugin.h
1033 +++ b/antispam-plugin.h
1034 @@ -280,6 +280,27 @@ o_stream_create_from_fd(int fd, pool_t pool ATTR_UNUSED)
1036 return o_stream_create_fd(fd, 0, TRUE);
1038 +#elif DOVECOT_IS_EQ(2, 3)
1039 +#define mempool_unref pool_unref
1040 +#define module_arg struct module *
1041 +#define ME(err) MAIL_ERROR_ ##err,
1043 +static inline const char *const *
1044 +get_mail_headers(struct mail *mail, const char *hdr)
1046 + const char *const *ret;
1047 + if (mail_get_headers(mail, hdr, &ret) < 0)
1052 +static inline struct ostream *
1053 +o_stream_create_from_fd(int fd, pool_t pool ATTR_UNUSED)
1055 + return o_stream_create_fd_autoclose(&fd, 0);
1058 +#define t_malloc t_malloc0
1060 #error "Building against this dovecot version is not supported"
1062 diff --git a/antispam-storage-2.0.c b/antispam-storage-2.0.c
1063 index 3298908..ce522b1 100644
1064 --- a/antispam-storage-2.0.c
1065 +++ b/antispam-storage-2.0.c
1066 @@ -379,14 +379,22 @@ antispam_mail_update_keywords(struct mail *mail,
1068 static struct mailbox_transaction_context *
1069 antispam_mailbox_transaction_begin(struct mailbox *box,
1070 - enum mailbox_transaction_flags flags)
1071 + enum mailbox_transaction_flags flags
1072 +#if DOVECOT_IS_GE(2, 3)
1073 + , const char *reason
1077 struct antispam_mailbox *asbox = ANTISPAM_CONTEXT(box);
1078 struct mailbox_transaction_context *t;
1079 struct antispam_transaction_context *ast;
1080 struct antispam_internal_context *aic;
1082 - t = asbox->module_ctx.super.transaction_begin(box, flags);
1083 + t = asbox->module_ctx.super.transaction_begin(box, flags
1084 +#if DOVECOT_IS_GE(2, 3)
1088 aic = i_new(struct antispam_internal_context, 1);
1089 ast = antispam_transaction_begin(box);
1090 aic->backendctx = ast;
1091 diff --git a/dovecot-version.c b/dovecot-version.c
1092 index fe9bc73..d4744f0 100644
1093 --- a/dovecot-version.c
1094 +++ b/dovecot-version.c
1095 @@ -68,8 +68,8 @@ int main(int argc, char **argv)
1096 printf("#define DOVECOT_P_IS_LE(maj, min, patch) "
1097 "DOVECOT_VCODE_PATCH <= DOVECOT_VERSION_CODE(maj, min, patch)\n");
1099 - /* Use the antispam-storage-2.0.c for dovecot 2.1 and 2.2 as well */
1100 - if (maj == 2 && min < 3)
1101 + /* Use the antispam-storage-2.0.c for dovecot 2.1 - 2.3 as well */
1102 + if (maj == 2 && min < 4)
1105 printf("#define ANTISPAM_STORAGE "