diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-10-27 17:29:36 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-10-27 17:29:36 +0200 |
commit | cdb95d01e4ead871b5d10543a32dd28ea5740a0d (patch) | |
tree | 877424091045179ebd69c2eacbe1c060553869dc /libmu_sieve | |
parent | 42ca2c2ef8ed0987f302cc360359c5b2ce4427c8 (diff) | |
download | mailutils-cdb95d01e4ead871b5d10543a32dd28ea5740a0d.tar.gz mailutils-cdb95d01e4ead871b5d10543a32dd28ea5740a0d.tar.bz2 |
vacation: read message body from the file
* doc/texinfo/sieve.texi: Document recent changes to vacation.
* libmu_sieve/extensions/vacation.c (vacation_reply): Handle
the "rfc2822" tag: if set together with :file, treat the file
as the RFC2822 message. Otherwise, read message body from it.
* sieve/tests/vacation.at: Add test for :rfc2822
Diffstat (limited to 'libmu_sieve')
-rw-r--r-- | libmu_sieve/extensions/vacation.c | 77 |
1 files changed, 67 insertions, 10 deletions
diff --git a/libmu_sieve/extensions/vacation.c b/libmu_sieve/extensions/vacation.c index b0f75d2ee..cd95202a2 100644 --- a/libmu_sieve/extensions/vacation.c +++ b/libmu_sieve/extensions/vacation.c @@ -24,6 +24,7 @@ [:reply_prefix <prefix: string>] [:sender <email: string>] [:database <path: string>] + [:rfc2822] [:file] [:mime] [:always_reply] @@ -637,17 +638,72 @@ vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, mu_message_t msg, mu_strerror (rc)); return -1; } - rc = mu_stream_to_message (instr, &newmsg); - mu_stream_unref (instr); - if (rc) + + if (mu_sieve_tag_lookup (tags, "rfc2822", NULL)) { - 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; - } + 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 + { + mu_stream_t text_stream; + mu_transport_t trans[2]; + + rc = mu_memory_stream_create (&text_stream, MU_STREAM_RDWR); + if (rc) + { + mu_stream_unref (instr); + mu_sieve_error (mach, + _("%lu: cannot create memory stream: %s"), + (unsigned long) mu_sieve_get_message_num (mach), + mu_strerror (rc)); + return -1; + } + + rc = mu_stream_copy (text_stream, instr, 0, NULL); + mu_stream_unref (instr); + if (rc == 0) + rc = mu_stream_write (text_stream, "", 1, NULL); + if (rc) + { + mu_sieve_error (mach, + _("%lu: failed reading from %s: %s"), + (unsigned long) mu_sieve_get_message_num (mach), + text, + mu_strerror (rc)); + return -1; + } + + rc = mu_stream_ioctl (text_stream, MU_IOCTL_TRANSPORT, + MU_IOCTL_OP_GET, trans); + if (rc) + { + mu_stream_unref (text_stream); + mu_sieve_error (mach, + "%lu: mu_stream_ioctl: %s", + (unsigned long) mu_sieve_get_message_num (mach), + mu_strerror (rc)); + return -1; + } + + if (build_mime (mach, tags, &mime, msg, (char const *) trans[0])) + { + mu_stream_unref (text_stream); + return -1; + } + mu_mime_get_message (mime, &newmsg); + mu_message_unref (newmsg); + mu_stream_unref (text_stream); + } } else { @@ -814,6 +870,7 @@ static mu_sieve_tag_def_t vacation_tags[] = { {"always_reply", SVT_VOID}, {"return_address", SVT_STRING}, {"header", SVT_STRING_LIST}, + {"rfc2822", SVT_VOID}, {NULL} }; |