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,
mu_body_get_streamref (body, &str);
rc = mu_stream_to_message (str, pmsg);
mu_stream_destroy (&str);
if (rc)
{
mu_sieve_error (mach,
......@@ -246,7 +247,6 @@ moderator_message_get_part (mu_sieve_machine_t mach,
mu_strerror (rc));
return 1;
}
mu_stream_destroy (&str);
}
else if (value)
{
......
......@@ -97,7 +97,6 @@ build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime,
return 1;
}
mu_stream_seek (input, 0, MU_SEEK_SET, NULL);
rc = mu_stream_copy (stream, input, 0, NULL);
if (rc)
{
......@@ -263,7 +262,6 @@ bulk_precedence_p (mu_header_t hdr)
return rc;
}
#define DAYS_MIN 1
#define DAYS_DEFAULT 7
#define DAYS_MAX 60
......@@ -283,6 +281,8 @@ test_and_update_prop (mu_property_t prop, const char *from,
break;
case 0:
if (days == 0)
return 1;
last = (time_t) strtoul (result, NULL, 0);
if (last + (24 * 60 * 60 * days) > now)
return 1;
......@@ -342,10 +342,7 @@ check_db (mu_sieve_machine_t mach, mu_list_t tags, char *from)
if (mu_sieve_tag_lookup (tags, "days", &arg))
{
days = arg->v.number;
if (days < DAYS_MIN)
days = DAYS_MIN;
else if (days > DAYS_MAX)
if (days > DAYS_MAX)
days = DAYS_MAX;
}
else
......@@ -533,11 +530,40 @@ vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, mu_message_t msg,
char *value;
mu_mailer_t mailer;
int rc;
if (build_mime (mach, tags, &mime, msg, text))
return -1;
mu_mime_get_message (mime, &newmsg);
mu_message_get_header (newmsg, &newhdr);
if (mu_sieve_tag_lookup (tags, "file", NULL))
{
mu_stream_t instr;
rc = mu_mapfile_stream_create (&instr, text, MU_STREAM_READ);
if (rc)
{
mu_sieve_error (mach,
_("%lu: cannot open message file %s: %s"),
(unsigned long) mu_sieve_get_message_num (mach),
text,
mu_strerror (rc));
return -1;
}
rc = mu_stream_to_message (instr, &newmsg);
mu_stream_unref (instr);
if (rc)
{
mu_sieve_error (mach,
_("%lu: cannot read message from file %s: %s"),
(unsigned long) mu_sieve_get_message_num (mach),
text,
mu_strerror (rc));
return -1;
}
}
else
{
if (build_mime (mach, tags, &mime, msg, text))
return -1;
mu_mime_get_message (mime, &newmsg);
mu_message_get_header (newmsg, &newhdr);
}
rc = mu_address_create (&to_addr, to);
if (rc)
......@@ -654,7 +680,9 @@ static mu_sieve_tag_def_t vacation_tags[] = {
{"addresses", SVT_STRING_LIST},
{"reply_regex", SVT_STRING},
{"reply_prefix", SVT_STRING},
{"sender", SVT_STRING},
{"mime", SVT_VOID},
{"file", SVT_VOID},
{NULL}
};
......
......@@ -416,6 +416,7 @@ cfun_data (mu_stream_t iostr, char *arg)
}
rc = mu_stream_to_message (tempstr, &mesg);
mu_stream_unref (tempstr);
if (rc)
{
maidag_error (_("error creating temporary message: %s"),
......@@ -425,7 +426,6 @@ cfun_data (mu_stream_t iostr, char *arg)
rc = mu_list_do (rcpt_list, dot_deliver, iostr);
mu_stream_destroy (&tempstr);
mu_message_destroy (&mesg, mu_message_get_owner (mesg));
if (rc)
mu_list_do (rcpt_list, dot_temp_fail, iostr);
......
......@@ -379,7 +379,6 @@ finish_stream (struct burst_stream *bs)
mu_mailbox_uidnext (tmpbox, &map.first);
burst_or_copy (msg, recursive, 1);
mu_message_destroy (&msg, mu_message_get_owner (msg));
mu_stream_unref (bs->stream);
bs->stream = 0;
bs->partno++;
......
......@@ -30,6 +30,7 @@ mh_stream_to_message (mu_stream_t instream)
mu_message_t msg;
rc = mu_stream_to_message (instream, &msg);
mu_stream_unref (instream);
if (rc)
{
mu_error (_("cannot open draft message stream: %s"),
......
......@@ -186,6 +186,7 @@ main (int argc, char **argv)
return 1;
}
rc = mu_stream_to_message (in, &msg);
mu_stream_unref (in);
if (rc)
{
mu_error (_("input stream %s is not a message (%s)"),
......
......@@ -355,6 +355,7 @@ sieve_message (mu_sieve_machine_t mach)
return EX_SOFTWARE;
}
rc = mu_stream_to_message (instr, &msg);
mu_stream_unref (instr);
if (rc)
{
mu_error (_("cannot create message from stream: %s"),
......
......@@ -268,6 +268,7 @@ main (int argc, char **argv)
mu_list_set_comparator (skiphdr_list, headercmp);
MU_ASSERT (mu_stream_to_message (instr, &msg));
mu_stream_unref (instr);
MU_ASSERT (mu_smtp_data (smtp, &ostr));
MU_ASSERT (mu_message_get_header (msg, &hdr));
MU_ASSERT (mu_header_get_iterator (hdr, &itr));
......