Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.

Skip to content
Snippets Groups Projects
Commit f32da22a authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Vacation extension: subject is now only MIME-encoded when it contains 8bit characters.

parent fa3e26d0
No related branches found
No related tags found
No related merge requests found
...@@ -88,6 +88,7 @@ test_cases = \ ...@@ -88,6 +88,7 @@ test_cases = \
tests/extensions/vacation/execute.svtest \ tests/extensions/vacation/execute.svtest \
tests/extensions/vacation/message.svtest \ tests/extensions/vacation/message.svtest \
tests/extensions/vacation/smtp.svtest \ tests/extensions/vacation/smtp.svtest \
tests/extensions/vacation/utf-8.svtest \
tests/extensions/enotify/basic.svtest \ tests/extensions/enotify/basic.svtest \
tests/extensions/enotify/encodeurl.svtest \ tests/extensions/enotify/encodeurl.svtest \
tests/extensions/enotify/valid_notify_method.svtest \ tests/extensions/enotify/valid_notify_method.svtest \
......
...@@ -855,6 +855,17 @@ static inline bool _contains_my_address ...@@ -855,6 +855,17 @@ static inline bool _contains_my_address
return result; 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 static bool act_vacation_send
(const struct sieve_action_exec_env *aenv, struct act_vacation_context *ctx, (const struct sieve_action_exec_env *aenv, struct act_vacation_context *ctx,
const char *sender, const char *recipient) const char *sender, const char *recipient)
...@@ -865,6 +876,7 @@ static bool act_vacation_send ...@@ -865,6 +876,7 @@ static bool act_vacation_send
FILE *f; FILE *f;
const char *outmsgid; const char *outmsgid;
const char *const *headers; const char *const *headers;
const char *subject;
int ret; int ret;
/* Check smpt functions just to be sure */ /* Check smpt functions just to be sure */
...@@ -874,6 +886,21 @@ static bool act_vacation_send ...@@ -874,6 +886,21 @@ static bool act_vacation_send
return TRUE; 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 */ /* Open smtp session */
smtp_handle = sieve_smtp_open(senv, sender, NULL, &f); smtp_handle = sieve_smtp_open(senv, sender, NULL, &f);
...@@ -897,8 +924,10 @@ static bool act_vacation_send ...@@ -897,8 +924,10 @@ static bool act_vacation_send
*/ */
rfc2822_header_field_printf(f, "To", "<%s>", sender); rfc2822_header_field_printf(f, "To", "<%s>", sender);
rfc2822_header_field_utf8_printf(f, "Subject", "%s", if ( _contains_8bit(subject) )
str_sanitize(ctx->subject, 256)); 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 */ /* Compose proper in-reply-to and references headers */
...@@ -969,7 +998,6 @@ static bool act_vacation_commit ...@@ -969,7 +998,6 @@ static bool act_vacation_commit
const char *const *headers; const char *const *headers;
const char *sender = sieve_message_get_sender(aenv->msgctx); const char *sender = sieve_message_get_sender(aenv->msgctx);
const char *recipient = sieve_message_get_recipient(aenv->msgctx); const char *recipient = sieve_message_get_recipient(aenv->msgctx);
pool_t pool;
/* Is the recipient unset? /* Is the recipient unset?
*/ */
...@@ -1094,17 +1122,6 @@ static bool act_vacation_commit ...@@ -1094,17 +1122,6 @@ static bool act_vacation_commit
recipient ); recipient );
return TRUE; 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 */ /* Send the message */
......
...@@ -13,30 +13,74 @@ To: nico@vestingbar.nl ...@@ -13,30 +13,74 @@ To: nico@vestingbar.nl
Frop Frop
. .
; ;
test "UTF-8 Subject" { test "UTF-8 Subject" {
/* Trigger vacation response with rediculous Russian subject */ /* Trigger vacation response with rediculous Russian subject */
vacation :subject "Auto: Я могу есть стекло, оно мне не вредит." vacation :subject "Auto: Я могу есть стекло, оно мне не вредит."
"I am not in today"; "I am not in today";
/* Execute Sieve result (sending message to dummy SMTP) */ /* Execute Sieve result (sending message to dummy SMTP) */
if not test_result_execute { if not test_result_execute {
test_fail "execution of result failed"; test_fail "execution of result failed";
} }
/* Retrieve message from dummy SMTP and set it as the active message under /* Retrieve message from dummy SMTP and set it as the active message under
* test. * test.
*/ */
test_message :smtp 0; test_message :smtp 0;
set "expected" "Auto: Я могу есть стекло, оно мне не вредит."; set "expected" "Auto: Я могу есть стекло, оно мне не вредит.";
if not header :is "subject" "${expected}" { if not header :is "subject" "${expected}" {
if header :matches "subject" "*" { set "subject" "${1}"; } 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@rename-it.nl
Subject: frop
References: <1234@local.machine.example> <3456@example.net>
<435444@ttms.com> <4223@froop.nl> <m345444444@message-id.exp>
Message-ID: <432df324@rename-it.nl>
To: nico@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: subject header is not encoded/decoded properly:
expected: ${expected} expected: ${expected}
decoded: ${subject} decoded: ${subject}
. .
; ;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment