Commit 42838314 42838314448528fd390d93a0b07a0d3d2d9d312f by Sergey Poznyakoff

Various fixes

* libmu_sieve/extensions/vacation.c (build_mime): Remove superfluous seek.
(test_and_update_prop): days==0 means "forever", i.e. send a replay to
each user only once.
(vacation_reply): If :file tag is given, treat the argument as the
name of a file containing the reply message.
(vacation_tags): Add "sender" and "file" tags.

* libmu_sieve/extensions/moderator.c: Always unref transport stream
after passing it to mu_stream_to_message.
* maidag/lmtp.c: Likewise.
* mh/mh_stream.c: Likewise.
* mh/prompter.c: Likewise.
* mh/burst.c (flush_stream): Remove extra unnref.
* sieve/sieve.c: Likewise.
* testsuite/smtpsend.c: Likewise.
1 parent 2a6014f9
...@@ -239,6 +239,7 @@ moderator_message_get_part (mu_sieve_machine_t mach, ...@@ -239,6 +239,7 @@ moderator_message_get_part (mu_sieve_machine_t mach,
239 mu_body_get_streamref (body, &str); 239 mu_body_get_streamref (body, &str);
240 240
241 rc = mu_stream_to_message (str, pmsg); 241 rc = mu_stream_to_message (str, pmsg);
242 mu_stream_destroy (&str);
242 if (rc) 243 if (rc)
243 { 244 {
244 mu_sieve_error (mach, 245 mu_sieve_error (mach,
...@@ -246,7 +247,6 @@ moderator_message_get_part (mu_sieve_machine_t mach, ...@@ -246,7 +247,6 @@ moderator_message_get_part (mu_sieve_machine_t mach,
246 mu_strerror (rc)); 247 mu_strerror (rc));
247 return 1; 248 return 1;
248 } 249 }
249 mu_stream_destroy (&str);
250 } 250 }
251 else if (value) 251 else if (value)
252 { 252 {
......
...@@ -97,7 +97,6 @@ build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime, ...@@ -97,7 +97,6 @@ build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime,
97 return 1; 97 return 1;
98 } 98 }
99 99
100 mu_stream_seek (input, 0, MU_SEEK_SET, NULL);
101 rc = mu_stream_copy (stream, input, 0, NULL); 100 rc = mu_stream_copy (stream, input, 0, NULL);
102 if (rc) 101 if (rc)
103 { 102 {
...@@ -263,7 +262,6 @@ bulk_precedence_p (mu_header_t hdr) ...@@ -263,7 +262,6 @@ bulk_precedence_p (mu_header_t hdr)
263 return rc; 262 return rc;
264 } 263 }
265 264
266 #define DAYS_MIN 1
267 #define DAYS_DEFAULT 7 265 #define DAYS_DEFAULT 7
268 #define DAYS_MAX 60 266 #define DAYS_MAX 60
269 267
...@@ -283,6 +281,8 @@ test_and_update_prop (mu_property_t prop, const char *from, ...@@ -283,6 +281,8 @@ test_and_update_prop (mu_property_t prop, const char *from,
283 break; 281 break;
284 282
285 case 0: 283 case 0:
284 if (days == 0)
285 return 1;
286 last = (time_t) strtoul (result, NULL, 0); 286 last = (time_t) strtoul (result, NULL, 0);
287 if (last + (24 * 60 * 60 * days) > now) 287 if (last + (24 * 60 * 60 * days) > now)
288 return 1; 288 return 1;
...@@ -342,10 +342,7 @@ check_db (mu_sieve_machine_t mach, mu_list_t tags, char *from) ...@@ -342,10 +342,7 @@ check_db (mu_sieve_machine_t mach, mu_list_t tags, char *from)
342 342
343 if (mu_sieve_tag_lookup (tags, "days", &arg)) 343 if (mu_sieve_tag_lookup (tags, "days", &arg))
344 { 344 {
345 days = arg->v.number; 345 if (days > DAYS_MAX)
346 if (days < DAYS_MIN)
347 days = DAYS_MIN;
348 else if (days > DAYS_MAX)
349 days = DAYS_MAX; 346 days = DAYS_MAX;
350 } 347 }
351 else 348 else
...@@ -533,11 +530,40 @@ vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, mu_message_t msg, ...@@ -533,11 +530,40 @@ vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, mu_message_t msg,
533 char *value; 530 char *value;
534 mu_mailer_t mailer; 531 mu_mailer_t mailer;
535 int rc; 532 int rc;
536 533
537 if (build_mime (mach, tags, &mime, msg, text)) 534 if (mu_sieve_tag_lookup (tags, "file", NULL))
538 return -1; 535 {
539 mu_mime_get_message (mime, &newmsg); 536 mu_stream_t instr;
540 mu_message_get_header (newmsg, &newhdr); 537
538 rc = mu_mapfile_stream_create (&instr, text, MU_STREAM_READ);
539 if (rc)
540 {
541 mu_sieve_error (mach,
542 _("%lu: cannot open message file %s: %s"),
543 (unsigned long) mu_sieve_get_message_num (mach),
544 text,
545 mu_strerror (rc));
546 return -1;
547 }
548 rc = mu_stream_to_message (instr, &newmsg);
549 mu_stream_unref (instr);
550 if (rc)
551 {
552 mu_sieve_error (mach,
553 _("%lu: cannot read message from file %s: %s"),
554 (unsigned long) mu_sieve_get_message_num (mach),
555 text,
556 mu_strerror (rc));
557 return -1;
558 }
559 }
560 else
561 {
562 if (build_mime (mach, tags, &mime, msg, text))
563 return -1;
564 mu_mime_get_message (mime, &newmsg);
565 mu_message_get_header (newmsg, &newhdr);
566 }
541 567
542 rc = mu_address_create (&to_addr, to); 568 rc = mu_address_create (&to_addr, to);
543 if (rc) 569 if (rc)
...@@ -654,7 +680,9 @@ static mu_sieve_tag_def_t vacation_tags[] = { ...@@ -654,7 +680,9 @@ static mu_sieve_tag_def_t vacation_tags[] = {
654 {"addresses", SVT_STRING_LIST}, 680 {"addresses", SVT_STRING_LIST},
655 {"reply_regex", SVT_STRING}, 681 {"reply_regex", SVT_STRING},
656 {"reply_prefix", SVT_STRING}, 682 {"reply_prefix", SVT_STRING},
683 {"sender", SVT_STRING},
657 {"mime", SVT_VOID}, 684 {"mime", SVT_VOID},
685 {"file", SVT_VOID},
658 {NULL} 686 {NULL}
659 }; 687 };
660 688
......
...@@ -416,6 +416,7 @@ cfun_data (mu_stream_t iostr, char *arg) ...@@ -416,6 +416,7 @@ cfun_data (mu_stream_t iostr, char *arg)
416 } 416 }
417 417
418 rc = mu_stream_to_message (tempstr, &mesg); 418 rc = mu_stream_to_message (tempstr, &mesg);
419 mu_stream_unref (tempstr);
419 if (rc) 420 if (rc)
420 { 421 {
421 maidag_error (_("error creating temporary message: %s"), 422 maidag_error (_("error creating temporary message: %s"),
...@@ -425,7 +426,6 @@ cfun_data (mu_stream_t iostr, char *arg) ...@@ -425,7 +426,6 @@ cfun_data (mu_stream_t iostr, char *arg)
425 426
426 rc = mu_list_do (rcpt_list, dot_deliver, iostr); 427 rc = mu_list_do (rcpt_list, dot_deliver, iostr);
427 428
428 mu_stream_destroy (&tempstr);
429 mu_message_destroy (&mesg, mu_message_get_owner (mesg)); 429 mu_message_destroy (&mesg, mu_message_get_owner (mesg));
430 if (rc) 430 if (rc)
431 mu_list_do (rcpt_list, dot_temp_fail, iostr); 431 mu_list_do (rcpt_list, dot_temp_fail, iostr);
......
...@@ -379,7 +379,6 @@ finish_stream (struct burst_stream *bs) ...@@ -379,7 +379,6 @@ finish_stream (struct burst_stream *bs)
379 mu_mailbox_uidnext (tmpbox, &map.first); 379 mu_mailbox_uidnext (tmpbox, &map.first);
380 burst_or_copy (msg, recursive, 1); 380 burst_or_copy (msg, recursive, 1);
381 mu_message_destroy (&msg, mu_message_get_owner (msg)); 381 mu_message_destroy (&msg, mu_message_get_owner (msg));
382 mu_stream_unref (bs->stream);
383 bs->stream = 0; 382 bs->stream = 0;
384 383
385 bs->partno++; 384 bs->partno++;
......
...@@ -30,6 +30,7 @@ mh_stream_to_message (mu_stream_t instream) ...@@ -30,6 +30,7 @@ mh_stream_to_message (mu_stream_t instream)
30 mu_message_t msg; 30 mu_message_t msg;
31 31
32 rc = mu_stream_to_message (instream, &msg); 32 rc = mu_stream_to_message (instream, &msg);
33 mu_stream_unref (instream);
33 if (rc) 34 if (rc)
34 { 35 {
35 mu_error (_("cannot open draft message stream: %s"), 36 mu_error (_("cannot open draft message stream: %s"),
......
...@@ -186,6 +186,7 @@ main (int argc, char **argv) ...@@ -186,6 +186,7 @@ main (int argc, char **argv)
186 return 1; 186 return 1;
187 } 187 }
188 rc = mu_stream_to_message (in, &msg); 188 rc = mu_stream_to_message (in, &msg);
189 mu_stream_unref (in);
189 if (rc) 190 if (rc)
190 { 191 {
191 mu_error (_("input stream %s is not a message (%s)"), 192 mu_error (_("input stream %s is not a message (%s)"),
......
...@@ -355,6 +355,7 @@ sieve_message (mu_sieve_machine_t mach) ...@@ -355,6 +355,7 @@ sieve_message (mu_sieve_machine_t mach)
355 return EX_SOFTWARE; 355 return EX_SOFTWARE;
356 } 356 }
357 rc = mu_stream_to_message (instr, &msg); 357 rc = mu_stream_to_message (instr, &msg);
358 mu_stream_unref (instr);
358 if (rc) 359 if (rc)
359 { 360 {
360 mu_error (_("cannot create message from stream: %s"), 361 mu_error (_("cannot create message from stream: %s"),
......
...@@ -268,6 +268,7 @@ main (int argc, char **argv) ...@@ -268,6 +268,7 @@ main (int argc, char **argv)
268 mu_list_set_comparator (skiphdr_list, headercmp); 268 mu_list_set_comparator (skiphdr_list, headercmp);
269 269
270 MU_ASSERT (mu_stream_to_message (instr, &msg)); 270 MU_ASSERT (mu_stream_to_message (instr, &msg));
271 mu_stream_unref (instr);
271 MU_ASSERT (mu_smtp_data (smtp, &ostr)); 272 MU_ASSERT (mu_smtp_data (smtp, &ostr));
272 MU_ASSERT (mu_message_get_header (msg, &hdr)); 273 MU_ASSERT (mu_message_get_header (msg, &hdr));
273 MU_ASSERT (mu_header_get_iterator (hdr, &itr)); 274 MU_ASSERT (mu_header_get_iterator (hdr, &itr));
......