Ajout : dovecot-antispam + amavis + crm114.
[lhc/ateliers.git] / etc / dovecot / dovecot-antispam-call-backend-pipe-unlearn.patch
1 diff -u b/dovecot-antispam-2.0+20120225/antispam-plugin.h c/dovecot-antispam-2.0+20120225/antispam-plugin.h
2 --- b/dovecot-antispam-2.0+20120225/antispam-plugin.h 2013-07-30 05:22:21.248730740 +0200
3 +++ c/dovecot-antispam-2.0+20120225/antispam-plugin.h 2013-08-05 05:50:13.430597556 +0200
4 @@ -30,6 +30,8 @@
5 CLASS_UNSURE,
6 CLASS_NOTSPAM,
7 CLASS_SPAM,
8 + CLASS_UNSPAM,
9 + CLASS_UNNOTSPAM,
10 };
11
12 enum antispam_debug_target {
13 @@ -104,6 +106,10 @@
14 int spam_args_num;
15 char **ham_args;
16 int ham_args_num;
17 + char **unlearn_spam_args;
18 + int unlearn_spam_args_num;
19 + char **unlearn_ham_args;
20 + int unlearn_ham_args_num;
21 const char *pipe_binary;// = "/usr/sbin/sendmail";
22 const char *tmpdir;// = "/tmp";
23 char **extra_args;
24 diff -u b/dovecot-antispam-2.0+20120225/antispam-storage-2.0.c c/dovecot-antispam-2.0+20120225/antispam-storage-2.0.c
25 --- b/dovecot-antispam-2.0+20120225/antispam-storage-2.0.c 2013-07-31 14:52:43.277922438 +0200
26 +++ c/dovecot-antispam-2.0+20120225/antispam-storage-2.0.c 2013-08-05 07:51:45.235555750 +0200
27 @@ -327,7 +327,11 @@
28 }
29 }
30
31 - debug(&amail->cfg->dbgcfg, "keyword list:\n");
32 + debug(&amail->cfg->dbgcfg, "keyword list: modify_type=%s\n"
33 + , modify_type == MODIFY_ADD ? "MODIFY_ADD"
34 + : modify_type == MODIFY_REPLACE ? "MODIFY_REPLACE"
35 + : modify_type == MODIFY_REMOVE ? "MODIFY_REMOVE"
36 + : "ERROR");
37
38 for (i = 0; i < keywords->count; i++) {
39 unsigned int idx = keywords->idx[i];
40 @@ -346,28 +350,34 @@
41 break;
42 case MODIFY_REMOVE:
43 if (keyword_is_spam(amail->cfg, keyword_names[idx]))
44 - spam_class = CLASS_NOTSPAM;
45 + spam_class = previous_spam_keyword ? CLASS_UNSPAM : CLASS_UNSURE;
46 if (keyword_is_ham(amail->cfg, keyword_names[idx]))
47 - spam_class = CLASS_SPAM;
48 + spam_class = previous_ham_keyword ? CLASS_UNNOTSPAM : CLASS_UNSURE;
49 break;
50 default:
51 i_assert(0);
52 }
53 }
54
55 - debug(&amail->cfg->dbgcfg, "spam_class=%d previous_spam_keyword=%d previous_ham_keyword=%d\n",
56 - spam_class, previous_spam_keyword, previous_ham_keyword);
57 + debug(&amail->cfg->dbgcfg, "spam_class=%s previous_spam_keyword=%d previous_ham_keyword=%d\n"
58 + , spam_class == CLASS_UNSURE ? "CLASS_UNSURE"
59 + : spam_class == CLASS_SPAM ? "CLASS_SPAM"
60 + : spam_class == CLASS_NOTSPAM ? "CLASS_NOTSPAM"
61 + : spam_class == CLASS_UNSPAM ? "CLASS_UNSPAM"
62 + : spam_class == CLASS_UNNOTSPAM ? "CLASS_UNNOTSPAM"
63 + : "ERROR"
64 + , previous_spam_keyword, previous_ham_keyword);
65
66 amail->module_ctx.super.update_keywords(mail, modify_type, keywords);
67
68 - if (previous_spam_keyword && previous_ham_keyword) {
69 - /* NOTE: avoid to call the backend two times for the same change
70 - * once when adding one spam or ham keyword
71 - * and once when removing the other.
72 - */
73 - debug(&amail->cfg->dbgcfg, "does not run backend a second time\n");
74 - return;
75 - }
76 + //if (previous_spam_keyword && previous_ham_keyword) {
77 + // /* NOTE: avoid to call the backend two times for the same change
78 + // * once when adding one spam or ham keyword
79 + // * and once when removing the other.
80 + // */
81 + // debug(&amail->cfg->dbgcfg, "does not run backend a second time\n");
82 + // return;
83 + // }
84
85 if (spam_class != CLASS_UNSURE) {
86 /* NOTE: on error, backend uses mail_storage_set_error()
87 Les sous-répertoires b/dovecot-antispam-2.0+20120225/debian et c/dovecot-antispam-2.0+20120225/debian sont identiques
88 Les sous-répertoires b/dovecot-antispam-2.0+20120225/.pc et c/dovecot-antispam-2.0+20120225/.pc sont identiques
89 diff -u b/dovecot-antispam-2.0+20120225/pipe.c c/dovecot-antispam-2.0+20120225/pipe.c
90 --- b/dovecot-antispam-2.0+20120225/pipe.c 2013-07-31 14:16:12.164255967 +0200
91 +++ c/dovecot-antispam-2.0+20120225/pipe.c 2013-08-05 06:12:36.137800536 +0200
92 @@ -46,7 +46,15 @@
93 break;
94 case CLASS_NOTSPAM:
95 dest = cfg->pipe.ham_args;
96 - dest_num = cfg->pipe.spam_args_num;
97 + dest_num = cfg->pipe.ham_args_num;
98 + break;
99 + case CLASS_UNSPAM:
100 + dest = cfg->pipe.unlearn_spam_args;
101 + dest_num = cfg->pipe.unlearn_spam_args_num;
102 + break;
103 + case CLASS_UNNOTSPAM:
104 + dest = cfg->pipe.unlearn_ham_args;
105 + dest_num = cfg->pipe.unlearn_ham_args_num;
106 break;
107 default:
108 i_assert(0);
109 @@ -55,13 +63,13 @@
110 if (!dest)
111 return -1;
112
113 + debug(&cfg->dbgcfg, "running mailtrain backend program %s", cfg->pipe.pipe_binary);
114 +
115 pid = fork();
116
117 if (pid == -1)
118 return -1;
119
120 - debug(&cfg->dbgcfg, "running mailtrain backend program %s", cfg->pipe.pipe_binary);
121 -
122 if (pid) {
123 if (waitpid(pid, &status, 0) == -1)
124 return -1;
125 @@ -238,7 +246,7 @@
126 return -1;
127 }
128
129 - if (!cfg->pipe.ham_args || !cfg->pipe.spam_args) {
130 + if (!cfg->pipe.ham_args || !cfg->pipe.spam_args || !cfg->pipe.unlearn_ham_args || !cfg->pipe.unlearn_spam_args) {
131 mail_storage_set_error(t->box->storage,
132 ME(NOTPOSSIBLE)
133 "antispam plugin not configured");
134 @@ -371,6 +379,52 @@
135 tmp = NULL;
136 }
137 }
138 +
139 + tmp = getenv("PIPE_PROGRAM_UNLEARN_SPAM_ARGS", getenv_data);
140 + if (tmp) {
141 + cfg->pipe.unlearn_spam_args = p_strsplit(cfg->mem_pool, tmp, ";");
142 + cfg->pipe.unlearn_spam_args_num = str_array_length(
143 + (const char *const *)cfg->pipe.unlearn_spam_args);
144 + for (i = 0; i < cfg->pipe.unlearn_spam_args_num; i++)
145 + debug(&cfg->dbgcfg, "pipe backend unlearn spam arg[%d] = %s\n",
146 + i, cfg->pipe.unlearn_spam_args[i]);
147 + } else {
148 + tmp = getenv("PIPE_PROGRAM_UNLEARN_SPAM_ARG", getenv_data);
149 + if (!tmp)
150 + tmp = getenv("MAIL_UNLEARN_SPAM", getenv_data);
151 + if (tmp) {
152 + /* bit of a hack */
153 + cfg->pipe.unlearn_spam_args =
154 + p_strsplit(cfg->mem_pool, tmp, "\x01");
155 + cfg->pipe.unlearn_spam_args_num = 1;
156 + debug(&cfg->dbgcfg,
157 + "pipe backend unlearn spam argument = %s\n", tmp);
158 + tmp = NULL;
159 + }
160 + }
161 +
162 + tmp = getenv("PIPE_PROGRAM_UNLEARN_NOTSPAM_ARGS", getenv_data);
163 + if (tmp) {
164 + cfg->pipe.unlearn_ham_args = p_strsplit(cfg->mem_pool, tmp, ";");
165 + cfg->pipe.unlearn_ham_args_num = str_array_length(
166 + (const char *const *)cfg->pipe.unlearn_ham_args);
167 + for (i = 0; i < cfg->pipe.unlearn_ham_args_num; i++)
168 + debug(&cfg->dbgcfg, "pipe backend unlearn not-spam arg[%d] = %s\n",
169 + i, cfg->pipe.unlearn_ham_args[i]);
170 + } else {
171 + tmp = getenv("PIPE_PROGRAM_UNLEARN_NOTSPAM_ARG", getenv_data);
172 + if (!tmp)
173 + tmp = getenv("MAIL_UNLEARN_NOTSPAM", getenv_data);
174 + if (tmp) {
175 + /* bit of a hack */
176 + cfg->pipe.unlearn_ham_args =
177 + p_strsplit(cfg->mem_pool, tmp, "\x01");
178 + cfg->pipe.unlearn_ham_args_num = 1;
179 + debug(&cfg->dbgcfg,
180 + "pipe backend unlearn not-spam argument = %s\n", tmp);
181 + tmp = NULL;
182 + }
183 + }
184
185 tmp = getenv("PIPE_PROGRAM", getenv_data);
186 if (!tmp)