]>
Commit | Line | Data |
---|---|---|
33b8a89c JR |
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 { | |
6 | int extra_env_num; | |
7 | } crm; | |
8 | struct { | |
9 | - const char *spam_arg; | |
10 | - const char *ham_arg; | |
11 | + char **spam_args; | |
12 | + int spam_args_num; | |
13 | + char **ham_args; | |
14 | + int ham_args_num; | |
15 | const char *pipe_binary;// = "/usr/sbin/sendmail"; | |
16 | const char *tmpdir;// = "/tmp"; | |
17 | char **extra_args; | |
18 | @@ -260,7 +262,7 @@ o_stream_create_from_fd(int fd, pool_t pool ATTR_UNUSED) | |
19 | { | |
20 | return o_stream_create_fd(fd, 0, TRUE); | |
21 | } | |
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) | |
32 | ||
33 | asbox->save_hack = FALSE; | |
34 | asbox->movetype = MMT_APPEND; | |
35 | - asbox->cfg = asuser->cfg; | |
36 | + asbox->cfg = asuser->cfg; | |
37 | ||
38 | v->free = antispam_mailbox_free; | |
39 | ||
40 | diff --git a/antispam.7 b/antispam.7 | |
41 | index 5e33e4c..5d077f0 100644 | |
42 | --- a/antispam.7 | |
43 | +++ b/antispam.7 | |
44 | @@ -1,4 +1,4 @@ | |
45 | -.TH ANTISPAM 7 "15 October 2007" "" "" | |
46 | +.TH ANTISPAM 7 "24 March 2012" "" "" | |
47 | .SH NAME | |
48 | antispam \- The dovecot antispam plugin. | |
49 | ||
50 | @@ -206,6 +206,11 @@ plugin { | |
51 | # semicolon-separated list of blacklisted results, case insensitive | |
52 | # antispam_dspam_result_blacklist = Virus | |
53 | ||
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 | |
58 | + | |
59 | #===================== | |
60 | # pipe plugin | |
61 | # | |
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. | |
66 | + # | |
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 | |
74 | ||
75 | # temporary directory | |
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 | |
80 | ||
81 | - # semicolon-separated list of extra arguments to dspam | |
82 | + # semicolon-separated list of extra arguments to crm114 | |
83 | # (default unset i.e. none) | |
84 | # antispam_crm_args = | |
85 | # antispam_crm_args = --config=/path/to/config | |
86 | @@ -257,11 +270,6 @@ plugin { | |
87 | # antispam_crm_env = | |
88 | # antispam_crm_env = HOME=%h;USER=%u | |
89 | ||
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 | |
94 | - | |
95 | # NOTE: you need to set the signature for this backend | |
96 | antispam_signature = X-CRM114-CacheID | |
97 | ||
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) | |
103 | ||
104 | maj = strtol(v, &e, 10); | |
105 | if (v == e) | |
106 | - return 1; | |
107 | + return 2; | |
108 | ||
109 | v = e + 1; | |
110 | ||
111 | min = strtol(v, &e, 10); | |
112 | if (v == e) | |
113 | - return 1; | |
114 | + return 3; | |
115 | ||
116 | /* not end of string yet? */ | |
117 | if (*e) { | |
118 | v = e + 1; | |
119 | ||
120 | - patch = strtol(v, &e, 10); | |
121 | - if (v == e) | |
122 | - return 1; | |
123 | + if (isdigit(*v)) { | |
124 | + patch = strtol(v, &e, 10); | |
125 | + if (v == e) | |
126 | + return 4; | |
127 | + } else | |
128 | + patch = 255; | |
129 | } | |
130 | ||
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"); | |
136 | + | |
137 | + /* Use the antispam-storage-2.0.c for dovecot 2.1 as well */ | |
138 | + if (maj == 2 && min == 1) | |
139 | + min = 0; | |
140 | + | |
141 | printf("#define ANTISPAM_STORAGE " | |
142 | "\"antispam-storage-%d.%d.c\"\n", maj, min); | |
143 | ||
144 | diff --git a/pipe.c b/pipe.c | |
145 | index 18c2233..a20b4aa 100644 | |
146 | --- a/pipe.c | |
147 | +++ b/pipe.c | |
148 | @@ -34,16 +34,19 @@ | |
149 | static int run_pipe(const struct antispam_config *cfg, | |
150 | int mailfd, enum classification wanted) | |
151 | { | |
152 | - const char *dest; | |
153 | + char **dest; | |
154 | + int dest_num; | |
155 | pid_t pid; | |
156 | int status; | |
157 | ||
158 | switch (wanted) { | |
159 | case CLASS_SPAM: | |
160 | - dest = cfg->pipe.spam_arg; | |
161 | + dest = cfg->pipe.spam_args; | |
162 | + dest_num = cfg->pipe.spam_args_num; | |
163 | break; | |
164 | case CLASS_NOTSPAM: | |
165 | - dest = cfg->pipe.ham_arg; | |
166 | + dest = cfg->pipe.ham_args; | |
167 | + dest_num = cfg->pipe.spam_args_num; | |
168 | break; | |
169 | } | |
170 | ||
171 | @@ -65,18 +68,23 @@ static int run_pipe(const struct antispam_config *cfg, | |
172 | return WEXITSTATUS(status); | |
173 | } else { | |
174 | char **argv; | |
175 | - int sz = sizeof(char *) * (2 + cfg->pipe.extra_args_num + 1); | |
176 | - int i, fd; | |
177 | + int sz = sizeof(char *) * (2 + cfg->pipe.extra_args_num + dest_num + 1); | |
178 | + int i, j, fd; | |
179 | ||
180 | argv = i_malloc(sz); | |
181 | memset(argv, 0, sz); | |
182 | ||
183 | argv[0] = (char *) cfg->pipe.pipe_binary; | |
184 | ||
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]); | |
189 | + } | |
190 | ||
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]); | |
195 | + } | |
196 | ||
197 | dup2(mailfd, 0); | |
198 | fd = open("/dev/null", O_WRONLY); | |
199 | @@ -228,7 +236,7 @@ static int backend_handle_mail(const struct antispam_config *cfg, | |
200 | return -1; | |
201 | } | |
202 | ||
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, | |
206 | ME(NOTPOSSIBLE) | |
207 | "antispam plugin not configured"); | |
208 | @@ -316,20 +324,50 @@ static void backend_init(struct antispam_config *cfg, | |
209 | const char *tmp; | |
210 | int i; | |
211 | ||
212 | - tmp = getenv("PIPE_PROGRAM_SPAM_ARG", getenv_data); | |
213 | - if (!tmp) | |
214 | - tmp = getenv("MAIL_SPAM", getenv_data); | |
215 | + tmp = getenv("PIPE_PROGRAM_SPAM_ARGS", getenv_data); | |
216 | if (tmp) { | |
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]); | |
225 | + } else { | |
226 | + tmp = getenv("PIPE_PROGRAM_SPAM_ARG", getenv_data); | |
227 | + if (!tmp) | |
228 | + tmp = getenv("MAIL_SPAM", getenv_data); | |
229 | + if (tmp) { | |
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); | |
236 | + tmp = NULL; | |
237 | + } | |
238 | } | |
239 | ||
240 | - tmp = getenv("PIPE_PROGRAM_NOTSPAM_ARG", getenv_data); | |
241 | - if (!tmp) | |
242 | - tmp = getenv("MAIL_NOTSPAM", getenv_data); | |
243 | + tmp = getenv("PIPE_PROGRAM_NOTSPAM_ARGS", getenv_data); | |
244 | if (tmp) { | |
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]); | |
253 | + } else { | |
254 | + tmp = getenv("PIPE_PROGRAM_NOTSPAM_ARG", getenv_data); | |
255 | + if (!tmp) | |
256 | + tmp = getenv("MAIL_NOTSPAM", getenv_data); | |
257 | + if (tmp) { | |
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); | |
264 | + tmp = NULL; | |
265 | + } | |
266 | } | |
267 | ||
268 | tmp = getenv("PIPE_PROGRAM", getenv_data); |