Commit 9a908ba5 9a908ba5a87216d24112e36f7f9c7ffbc6dd53a3 by Sergey Poznyakoff

Fixes in sieve vacation extension

* libmu_sieve/extensions/vacation.c (build_mime): Fix memory leak.
This also flushes the message body stream, so its content becomes
visible for the mailer.
(noreply_address_p): Rename "addresses" tag to "noreply".
(check_db): The "database" tag provides vacation database name.
(vacation_reply): Always set message headers.
(vacation_tags): Rename "addresses" tag to "noreply".
New tag: "database"

* sieve/tests/vacation.at: New file.
* sieve/tests/Makefile.am (TESTSUITE_AT): Add vacation.at.
* sieve/tests/testsuite.at: Include vacation.at.

* doc/texinfo/programs.texi: Minor change.
1 parent dcbf8f35
...@@ -1502,7 +1502,6 @@ requests during @var{time} seconds, the child process terminates. ...@@ -1502,7 +1502,6 @@ requests during @var{time} seconds, the child process terminates.
1502 1502
1503 @node Server Statement 1503 @node Server Statement
1504 @subsubsection Server Statement 1504 @subsubsection Server Statement
1505 @UNREVISED
1506 @cindex server statement 1505 @cindex server statement
1507 @kwindex server 1506 @kwindex server
1508 @* Syntax: 1507 @* Syntax:
...@@ -1614,6 +1613,7 @@ and is denied if any one of them denies it. ...@@ -1614,6 +1613,7 @@ and is denied if any one of them denies it.
1614 auth @{ 1613 auth @{
1615 # @r{Set a list of modules for authentication.} 1614 # @r{Set a list of modules for authentication.}
1616 authentication @var{module-list}; 1615 authentication @var{module-list};
1616
1617 # @r{Set a list of modules for authorization.} 1617 # @r{Set a list of modules for authorization.}
1618 authorization @var{module-list}; 1618 authorization @var{module-list};
1619 @} 1619 @}
......
...@@ -19,10 +19,14 @@ ...@@ -19,10 +19,14 @@
19 /* Syntax: vacation [:days <ndays: number>] 19 /* Syntax: vacation [:days <ndays: number>]
20 [:subject <subject: string>] 20 [:subject <subject: string>]
21 [:aliases <address-list: list>] 21 [:aliases <address-list: list>]
22 [:addresses <noreply-address-list: list>] 22 [:noreply <noreply-address-list: list>]
23 [:reply_regex <expr: string>] 23 [:reply_regex <expr: string>]
24 [:reply_prefix <prefix: string>] 24 [:reply_prefix <prefix: string>]
25 <reply text: string> 25 [:sender <email: string>]
26 [:database <path: string>]
27 [:file]
28 [:mime]
29 <reply: string>
26 */ 30 */
27 31
28 #ifdef HAVE_CONFIG_H 32 #ifdef HAVE_CONFIG_H
...@@ -98,6 +102,9 @@ build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime, ...@@ -98,6 +102,9 @@ build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime,
98 } 102 }
99 103
100 rc = mu_stream_copy (stream, input, 0, NULL); 104 rc = mu_stream_copy (stream, input, 0, NULL);
105 mu_stream_destroy (&input);
106 mu_stream_destroy (&stream);
107
101 if (rc) 108 if (rc)
102 { 109 {
103 mu_sieve_error (mach, 110 mu_sieve_error (mach,
...@@ -105,13 +112,9 @@ build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime, ...@@ -105,13 +112,9 @@ build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime,
105 mu_strerror (rc)); 112 mu_strerror (rc));
106 mu_mime_destroy (&mime); 113 mu_mime_destroy (&mime);
107 mu_message_destroy (&newmsg, NULL); 114 mu_message_destroy (&newmsg, NULL);
108 mu_stream_destroy (&input);
109 mu_stream_destroy (&stream);
110 return 1; 115 return 1;
111 } 116 }
112 117
113 mu_stream_destroy (&input);
114
115 mu_header_create (&hdr, header, strlen (header)); 118 mu_header_create (&hdr, header, strlen (header));
116 mu_message_set_header (newmsg, hdr, NULL); 119 mu_message_set_header (newmsg, hdr, NULL);
117 120
...@@ -157,7 +160,7 @@ _compare (void *item, void *data) ...@@ -157,7 +160,7 @@ _compare (void *item, void *data)
157 160
158 /* Check whether an alias from ADDRESSES is part of To: or Cc: headers 161 /* Check whether an alias from ADDRESSES is part of To: or Cc: headers
159 of the originating mail. Return non-zero if so and store a pointer 162 of the originating mail. Return non-zero if so and store a pointer
160 to the matching address to *MY_ADDRESS. */ 163 to the matching address in *MY_ADDRESS. */
161 static int 164 static int
162 match_addresses (mu_header_t hdr, mu_sieve_value_t *addresses, 165 match_addresses (mu_header_t hdr, mu_sieve_value_t *addresses,
163 char **my_address) 166 char **my_address)
...@@ -241,7 +244,7 @@ noreply_address_p (mu_sieve_machine_t mach, mu_list_t tags, char *email) ...@@ -241,7 +244,7 @@ noreply_address_p (mu_sieve_machine_t mach, mu_list_t tags, char *email)
241 for (i = 0; rc == 0 && noreply_sender[i]; i++) 244 for (i = 0; rc == 0 && noreply_sender[i]; i++)
242 rc = regex_comparator (noreply_sender[i], &rd); 245 rc = regex_comparator (noreply_sender[i], &rd);
243 246
244 if (!rc && mu_sieve_tag_lookup (tags, "addresses", &arg)) 247 if (!rc && mu_sieve_tag_lookup (tags, "noreply", &arg))
245 rc = mu_sieve_vlist_do (arg, regex_comparator, &rd); 248 rc = mu_sieve_vlist_do (arg, regex_comparator, &rd);
246 249
247 return rc; 250 return rc;
...@@ -338,6 +341,7 @@ check_db (mu_sieve_machine_t mach, mu_list_t tags, char *from) ...@@ -338,6 +341,7 @@ check_db (mu_sieve_machine_t mach, mu_list_t tags, char *from)
338 int rc; 341 int rc;
339 mu_stream_t str; 342 mu_stream_t str;
340 mu_locker_t locker; 343 mu_locker_t locker;
344 const char *dbfile = "~/.vacation";
341 345
342 if (mu_sieve_tag_lookup (tags, "days", &arg)) 346 if (mu_sieve_tag_lookup (tags, "days", &arg))
343 { 347 {
...@@ -348,7 +352,10 @@ check_db (mu_sieve_machine_t mach, mu_list_t tags, char *from) ...@@ -348,7 +352,10 @@ check_db (mu_sieve_machine_t mach, mu_list_t tags, char *from)
348 else 352 else
349 days = DAYS_DEFAULT; 353 days = DAYS_DEFAULT;
350 354
351 file = mu_tilde_expansion ("~/.vacation", MU_HIERARCHY_DELIMITER, NULL); 355 if (mu_sieve_tag_lookup (tags, "database", &arg))
356 dbfile = arg->v.string;
357
358 file = mu_tilde_expansion (dbfile, MU_HIERARCHY_DELIMITER, NULL);
352 if (!file) 359 if (!file)
353 { 360 {
354 mu_sieve_error (mach, _("%lu: cannot build db file name"), 361 mu_sieve_error (mach, _("%lu: cannot build db file name"),
...@@ -563,9 +570,10 @@ vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, mu_message_t msg, ...@@ -563,9 +570,10 @@ vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, mu_message_t msg,
563 return -1; 570 return -1;
564 mu_mime_get_message (mime, &newmsg); 571 mu_mime_get_message (mime, &newmsg);
565 mu_message_unref (newmsg); 572 mu_message_unref (newmsg);
566 mu_message_get_header (newmsg, &newhdr);
567 } 573 }
568 574
575 mu_message_get_header (newmsg, &newhdr);
576
569 rc = mu_address_create (&to_addr, to); 577 rc = mu_address_create (&to_addr, to);
570 if (rc) 578 if (rc)
571 { 579 {
...@@ -685,10 +693,11 @@ static mu_sieve_tag_def_t vacation_tags[] = { ...@@ -685,10 +693,11 @@ static mu_sieve_tag_def_t vacation_tags[] = {
685 {"days", SVT_NUMBER}, 693 {"days", SVT_NUMBER},
686 {"subject", SVT_STRING}, 694 {"subject", SVT_STRING},
687 {"aliases", SVT_STRING_LIST}, 695 {"aliases", SVT_STRING_LIST},
688 {"addresses", SVT_STRING_LIST}, 696 {"noreply", SVT_STRING_LIST},
689 {"reply_regex", SVT_STRING}, 697 {"reply_regex", SVT_STRING},
690 {"reply_prefix", SVT_STRING}, 698 {"reply_prefix", SVT_STRING},
691 {"sender", SVT_STRING}, 699 {"sender", SVT_STRING},
700 {"database", SVT_STRING},
692 {"mime", SVT_VOID}, 701 {"mime", SVT_VOID},
693 {"file", SVT_VOID}, 702 {"file", SVT_VOID},
694 {NULL} 703 {NULL}
......
...@@ -67,6 +67,7 @@ TESTSUITE_AT = \ ...@@ -67,6 +67,7 @@ TESTSUITE_AT = \
67 size.at\ 67 size.at\
68 true.at\ 68 true.at\
69 testsuite.at\ 69 testsuite.at\
70 vacation.at\
70 version.at 71 version.at
71 72
72 TESTSUITE = $(srcdir)/testsuite 73 TESTSUITE = $(srcdir)/testsuite
......
...@@ -146,5 +146,5 @@ m4_include([pipetest.at]) ...@@ -146,5 +146,5 @@ m4_include([pipetest.at])
146 m4_include([list.at]) 146 m4_include([list.at])
147 m4_include([addheader.at]) 147 m4_include([addheader.at])
148 m4_include([delheader.at]) 148 m4_include([delheader.at])
149 149 m4_include([vacation.at])
150 150
......
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2015 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_BANNER([vacation])
18 m4_pushdef([MUT_SIEVE_EXT_NAME],[vacation])
19
20 MUT_SIEVE_EXT_TEST([default],[vac00],
21 [require "vacation";
22
23 vacation :database "vacation.db" "I'm on vacation";
24 ],
25 [MUT_MBCOPY($abs_top_srcdir/testsuite/spool/sieve.mbox,mailbox)
26 MTA_DIAG=`pwd`/mta.diag
27 MTA_APPEND=1
28 export MTA_DIAG MTA_APPEND
29 sieve MUT_SIEVE_CMDLINE MUT_SIEVE_OPTIONS -f ./mailbox prog || exit 1
30 cat ./mta.diag
31 ],
32 [ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
33 ENVELOPE TO: <coyote@desert.example.org>
34 0: In-Reply-To: Your message of Sun May 6 22:16:47 2001
35 1: Subject: =?UTF-8?Q?Re:_I_have_a_present_for_you?=
36 2: To: coyote@desert.example.org
37 3: Content-Transfer-Encoding: 8bit
38 4: Content-Type: text/plain;charset=UTF-8
39 5: MIME-Version: 1.0
40 6:
41 7: I'm on vacation
42 END OF MESSAGE
43 ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
44 ENVELOPE TO: <b1ff@de.res.example.com>
45 0: In-Reply-To: Your message of TBD
46 1: Subject: =?UTF-8?Q?Re:_$$$_YOU,_TOO,_CAN_BE_A_MILLIONAIRE!_$$$?=
47 2: To: b1ff@de.res.example.com
48 3: Content-Transfer-Encoding: 8bit
49 4: Content-Type: text/plain;charset=UTF-8
50 5: MIME-Version: 1.0
51 6:
52 7: I'm on vacation
53 END OF MESSAGE
54 ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
55 ENVELOPE TO: <bar@dontmailme.org>
56 0: References: <200112232808.fERKR9N16790@dontmailme.org>
57 1: In-Reply-To: Your message of Fri, 28 Dec 2001 23:28:08 +0200
58 2: <200112232808.fERKR9N16790@dontmailme.org>
59 3: Subject: =?UTF-8?Q?Re:_Coffee?=
60 4: To: bar@dontmailme.org
61 5: Content-Transfer-Encoding: 8bit
62 6: Content-Type: text/plain;charset=UTF-8
63 7: MIME-Version: 1.0
64 8:
65 9: I'm on vacation
66 END OF MESSAGE
67 ],
68 [VACATION on msg uid 1
69 VACATION on msg uid 2
70 VACATION on msg uid 3
71 ])
72
73 MUT_SIEVE_EXT_TEST([database matching],[vac01],
74 [require "vacation";
75
76 vacation :database "vacation.db" "I'm on vacation";
77 ],
78 [MUT_MBCOPY($abs_top_srcdir/testsuite/spool/sieve.mbox,mailbox)
79 MTA_DIAG=`pwd`/mta.diag
80 MTA_APPEND=1
81 export MTA_DIAG MTA_APPEND
82 sieve MUT_SIEVE_CMDLINE MUT_SIEVE_OPTIONS -f ./mailbox prog || exit 1
83 sieve MUT_SIEVE_CMDLINE MUT_SIEVE_OPTIONS -f ./mailbox prog || exit 1
84 cat ./mta.diag
85 ],
86 [ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
87 ENVELOPE TO: <coyote@desert.example.org>
88 0: In-Reply-To: Your message of Sun May 6 22:16:47 2001
89 1: Subject: =?UTF-8?Q?Re:_I_have_a_present_for_you?=
90 2: To: coyote@desert.example.org
91 3: Content-Transfer-Encoding: 8bit
92 4: Content-Type: text/plain;charset=UTF-8
93 5: MIME-Version: 1.0
94 6:
95 7: I'm on vacation
96 END OF MESSAGE
97 ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
98 ENVELOPE TO: <b1ff@de.res.example.com>
99 0: In-Reply-To: Your message of TBD
100 1: Subject: =?UTF-8?Q?Re:_$$$_YOU,_TOO,_CAN_BE_A_MILLIONAIRE!_$$$?=
101 2: To: b1ff@de.res.example.com
102 3: Content-Transfer-Encoding: 8bit
103 4: Content-Type: text/plain;charset=UTF-8
104 5: MIME-Version: 1.0
105 6:
106 7: I'm on vacation
107 END OF MESSAGE
108 ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
109 ENVELOPE TO: <bar@dontmailme.org>
110 0: References: <200112232808.fERKR9N16790@dontmailme.org>
111 1: In-Reply-To: Your message of Fri, 28 Dec 2001 23:28:08 +0200
112 2: <200112232808.fERKR9N16790@dontmailme.org>
113 3: Subject: =?UTF-8?Q?Re:_Coffee?=
114 4: To: bar@dontmailme.org
115 5: Content-Transfer-Encoding: 8bit
116 6: Content-Type: text/plain;charset=UTF-8
117 7: MIME-Version: 1.0
118 8:
119 9: I'm on vacation
120 END OF MESSAGE
121 ],
122 [VACATION on msg uid 1
123 VACATION on msg uid 2
124 VACATION on msg uid 3
125 VACATION on msg uid 1
126 VACATION on msg uid 2
127 VACATION on msg uid 3
128 ])
129
130 MUT_SIEVE_EXT_TEST([mime],[vac02],
131 [require "vacation";
132
133 vacation :database "vacation.db" :mime "I'm on vacation.";
134 ],
135 [MUT_MBCOPY($abs_top_srcdir/testsuite/spool/sieve.mbox,mailbox)
136 MTA_DIAG=`pwd`/mta.diag
137 MTA_APPEND=1
138 export MTA_DIAG MTA_APPEND
139 sieve MUT_SIEVE_CMDLINE MUT_SIEVE_OPTIONS -f ./mailbox prog || exit 1
140 cat ./mta.diag
141 ],
142 [ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
143 ENVELOPE TO: <coyote@desert.example.org>
144 0: In-Reply-To: Your message of Sun May 6 22:16:47 2001
145 1: Subject: =?UTF-8?Q?Re:_I_have_a_present_for_you?=
146 2: To: coyote@desert.example.org
147 3: Content-Transfer-Encoding: base64
148 4: Content-Type: text/plain;charset=UTF-8
149 5: MIME-Version: 1.0
150 6:
151 7: SSdtIG9uIHZhY2F0aW9uLg==
152 END OF MESSAGE
153 ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
154 ENVELOPE TO: <b1ff@de.res.example.com>
155 0: In-Reply-To: Your message of TBD
156 1: Subject: =?UTF-8?Q?Re:_$$$_YOU,_TOO,_CAN_BE_A_MILLIONAIRE!_$$$?=
157 2: To: b1ff@de.res.example.com
158 3: Content-Transfer-Encoding: base64
159 4: Content-Type: text/plain;charset=UTF-8
160 5: MIME-Version: 1.0
161 6:
162 7: SSdtIG9uIHZhY2F0aW9uLg==
163 END OF MESSAGE
164 ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
165 ENVELOPE TO: <bar@dontmailme.org>
166 0: References: <200112232808.fERKR9N16790@dontmailme.org>
167 1: In-Reply-To: Your message of Fri, 28 Dec 2001 23:28:08 +0200
168 2: <200112232808.fERKR9N16790@dontmailme.org>
169 3: Subject: =?UTF-8?Q?Re:_Coffee?=
170 4: To: bar@dontmailme.org
171 5: Content-Transfer-Encoding: base64
172 6: Content-Type: text/plain;charset=UTF-8
173 7: MIME-Version: 1.0
174 8:
175 9: SSdtIG9uIHZhY2F0aW9uLg==
176 END OF MESSAGE
177 ],
178 [VACATION on msg uid 1
179 VACATION on msg uid 2
180 VACATION on msg uid 3
181 ])
182
183 MUT_SIEVE_EXT_TEST([reply from file],[vac03],
184 [require "vacation";
185
186 vacation :database "vacation.db" :file "reply";
187 ],
188 [AT_DATA([reply],[X-Mail-Processor: sieve
189
190 I'm on vacation right now.
191 I will attend to your message as soon as I'm back.
192
193 Best regards,
194 Ty Coon
195 ])
196 MUT_MBCOPY($abs_top_srcdir/testsuite/spool/sieve.mbox,mailbox)
197 MTA_DIAG=`pwd`/mta.diag
198 MTA_APPEND=1
199 export MTA_DIAG MTA_APPEND
200 sieve MUT_SIEVE_CMDLINE MUT_SIEVE_OPTIONS -f ./mailbox prog || exit 1
201 cat ./mta.diag
202 ],
203 [ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
204 ENVELOPE TO: <coyote@desert.example.org>
205 0: In-Reply-To: Your message of Sun May 6 22:16:47 2001
206 1: Subject: =?UTF-8?Q?Re:_I_have_a_present_for_you?=
207 2: To: coyote@desert.example.org
208 3: X-Mail-Processor: sieve
209 4:
210 5: I'm on vacation right now.
211 6: I will attend to your message as soon as I'm back.
212 7:
213 8: Best regards,
214 9: Ty Coon
215 END OF MESSAGE
216 ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
217 ENVELOPE TO: <b1ff@de.res.example.com>
218 0: In-Reply-To: Your message of TBD
219 1: Subject: =?UTF-8?Q?Re:_$$$_YOU,_TOO,_CAN_BE_A_MILLIONAIRE!_$$$?=
220 2: To: b1ff@de.res.example.com
221 3: X-Mail-Processor: sieve
222 4:
223 5: I'm on vacation right now.
224 6: I will attend to your message as soon as I'm back.
225 7:
226 8: Best regards,
227 9: Ty Coon
228 END OF MESSAGE
229 ENVELOPE FROM: MAILER-DAEMON@nonexistent.net
230 ENVELOPE TO: <bar@dontmailme.org>
231 0: References: <200112232808.fERKR9N16790@dontmailme.org>
232 1: In-Reply-To: Your message of Fri, 28 Dec 2001 23:28:08 +0200
233 2: <200112232808.fERKR9N16790@dontmailme.org>
234 3: Subject: =?UTF-8?Q?Re:_Coffee?=
235 4: To: bar@dontmailme.org
236 5: X-Mail-Processor: sieve
237 6:
238 7: I'm on vacation right now.
239 8: I will attend to your message as soon as I'm back.
240 9:
241 10: Best regards,
242 11: Ty Coon
243 END OF MESSAGE
244 ],
245 [VACATION on msg uid 1
246 VACATION on msg uid 2
247 VACATION on msg uid 3
248 ])
249
250 m4_popdef([MUT_SIEVE_EXT_NAME])
251