dovecot-1.2-sieve: Vacation extension: subject is now only MIME-...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Fri Jan 8 13:18:30 EET 2010
details: http://hg.rename-it.nl/dovecot-1.2-sieve/rev/219a6f0d6bf6
changeset: 1193:219a6f0d6bf6
user: Stephan Bosch <stephan at rename-it.nl>
date: Fri Jan 08 12:18:20 2010 +0100
description:
Vacation extension: subject is now only MIME-encoded when it contains 8bit characters.
diffstat:
Makefile.am | 1 +
src/lib-sieve/plugins/vacation/cmd-vacation.c | 45 +++++++++++++++-------
tests/extensions/vacation/utf-8.svtest | 56 +++++++++++++++++++++++++---
3 files changed, 82 insertions(+), 20 deletions(-)
diffs (185 lines):
diff -r e3ed9a03a28b -r 219a6f0d6bf6 Makefile.am
--- a/Makefile.am Thu Jan 07 02:58:08 2010 +0100
+++ b/Makefile.am Fri Jan 08 12:18:20 2010 +0100
@@ -105,6 +105,7 @@
tests/extensions/vacation/execute.svtest \
tests/extensions/vacation/message.svtest \
tests/extensions/vacation/smtp.svtest \
+ tests/extensions/vacation/utf-8.svtest \
tests/extensions/enotify/basic.svtest \
tests/extensions/enotify/encodeurl.svtest \
tests/extensions/enotify/valid_notify_method.svtest \
diff -r e3ed9a03a28b -r 219a6f0d6bf6 src/lib-sieve/plugins/vacation/cmd-vacation.c
--- a/src/lib-sieve/plugins/vacation/cmd-vacation.c Thu Jan 07 02:58:08 2010 +0100
+++ b/src/lib-sieve/plugins/vacation/cmd-vacation.c Fri Jan 08 12:18:20 2010 +0100
@@ -854,6 +854,17 @@
return result;
}
+static bool _contains_8bit(const char *text)
+{
+ const unsigned char *p = (const unsigned char *) text;
+
+ for (; *p != '\0'; p++) {
+ if ((*p & 0x80) != 0)
+ return TRUE;
+ }
+ return FALSE;
+}
+
static bool act_vacation_send
(const struct sieve_action_exec_env *aenv, struct act_vacation_context *ctx,
const char *sender, const char *recipient)
@@ -864,6 +875,7 @@
FILE *f;
const char *outmsgid;
const char *const *headers;
+ const char *subject;
int ret;
/* Check smpt functions just to be sure */
@@ -873,6 +885,21 @@
return TRUE;
}
+ /* Make sure we have a subject for our reply */
+
+ if ( ctx->subject == NULL || *(ctx->subject) == '\0' ) {
+ if ( mail_get_headers_utf8
+ (msgdata->mail, "subject", &headers) >= 0 && headers[0] != NULL ) {
+ subject = t_strconcat("Auto: ", headers[0], NULL);
+ } else {
+ subject = "Automated reply";
+ }
+ } else {
+ subject = ctx->subject;
+ }
+
+ subject = str_sanitize(subject, 256);
+
/* Open smtp session */
smtp_handle = senv->smtp_open(sender, NULL, &f);
@@ -896,8 +923,10 @@
*/
rfc2822_header_field_printf(f, "To", "<%s>", sender);
- rfc2822_header_field_utf8_printf(f, "Subject", "%s",
- str_sanitize(ctx->subject, 256));
+ if ( _contains_8bit(subject) )
+ rfc2822_header_field_utf8_printf(f, "Subject", "%s", subject);
+ else
+ rfc2822_header_field_printf(f, "Subject", "%s", subject);
/* Compose proper in-reply-to and references headers */
@@ -968,7 +997,6 @@
const char *const *headers;
const char *sender = sieve_message_get_sender(aenv->msgctx);
const char *recipient = sieve_message_get_recipient(aenv->msgctx);
- pool_t pool;
/* Is the recipient unset?
*/
@@ -1093,17 +1121,6 @@
recipient );
return TRUE;
}
-
- /* Make sure we have a subject for our reply */
- if ( ctx->subject == NULL || *(ctx->subject) == '\0' ) {
- if ( mail_get_headers_utf8
- (msgdata->mail, "subject", &headers) >= 0 && headers[0] != NULL ) {
- pool = sieve_result_pool(aenv->result);
- ctx->subject = p_strconcat(pool, "Auto: ", headers[0], NULL);
- } else {
- ctx->subject = "Automated reply";
- }
- }
/* Send the message */
diff -r e3ed9a03a28b -r 219a6f0d6bf6 tests/extensions/vacation/utf-8.svtest
--- a/tests/extensions/vacation/utf-8.svtest Thu Jan 07 02:58:08 2010 +0100
+++ b/tests/extensions/vacation/utf-8.svtest Fri Jan 08 12:18:20 2010 +0100
@@ -13,30 +13,74 @@
Frop
.
;
+
test "UTF-8 Subject" {
/* Trigger vacation response with rediculous Russian subject */
vacation :subject "Auto: Я Ð¼Ð¾Ð³Ñ ÐµÑÑÑ ÑÑекло, оно мне не вÑедиÑ."
"I am not in today";
/* Execute Sieve result (sending message to dummy SMTP) */
- if not test_result_execute {
- test_fail "execution of result failed";
- }
+ if not test_result_execute {
+ test_fail "execution of result failed";
+ }
/* Retrieve message from dummy SMTP and set it as the active message under
* test.
*/
- test_message :smtp 0;
+ test_message :smtp 0;
set "expected" "Auto: Я Ð¼Ð¾Ð³Ñ ÐµÑÑÑ ÑÑекло, оно мне не вÑедиÑ.";
if not header :is "subject" "${expected}" {
if header :matches "subject" "*" { set "subject" "${1}"; }
- test_fail text:
+ test_fail text:
subject header is not encoded/decoded properly:
expected: ${expected}
decoded: ${subject}
.
;
- }
+ }
}
+
+test_result_reset;
+
+test_set "message" text:
+From: stephan at rename-it.nl
+Subject: frop
+References: <1234 at local.machine.example> <3456 at example.net>
+ <435444 at ttms.com> <4223 at froop.nl> <m345444444 at message-id.exp>
+Message-ID: <432df324 at rename-it.nl>
+To: nico at vestingbar.nl
+
+Frop
+.
+;
+
+
+test "MIME Encoded Subject" {
+ /* Trigger vacation response with rediculous Russian subject */
+ vacation :subject "=?utf-8?b?w4TDlsOc?= sadasd"
+ "I am not in today";
+
+ /* Execute Sieve result (sending message to dummy SMTP) */
+ if not test_result_execute {
+ test_fail "execution of result failed";
+ }
+
+ /* Retrieve message from dummy SMTP and set it as the active message under
+ * test.
+ */
+ test_message :smtp 0;
+
+ set "expected" "ÃÃÃ sadasd";
+ if not header :is "subject" "${expected}" {
+ if header :matches "subject" "*" { set "subject" "${1}"; }
+
+ test_fail text:
+subject header is not encoded/decoded properly:
+expected: ${expected}
+decoded: ${subject}
+.
+;
+ }
+}
More information about the dovecot-cvs
mailing list