Commit d469cacc authored by Alex Vandiver's avatar Alex Vandiver
Browse files

Ensure that the Subject header is not double-encoded

In Encode 2.52 and below, `decode_utf8(...)` called on a string with the
internal utf8" flag (i.e. containing characters, not bytes) was a no-op.
Encode 2.53 changed this, for parity with `decode('utf8', ...)`

The contents of the 'Subject' header when sending mail were usually
bytes, as parsed by MIME-Tools.  As such, before adding the subject tag,
they were decoded into characters.  However, in the case where no
Subject was given by the template (for example, the "Transaction"
template), RT generated a (wide-character) string for the Subject based
on the ticket title, and inserted it into the MIME object.  Later,
before the subject tag was added decode_utf8() was called on this wide
string -- and prior to Encode 2.53, this was a no-op.

Ensure that the values placed in the MIME header are always bytes, and
not wide characters.  There are two changes to do this: first, ensure
that the automatically-generated subject is encoded before being used;
and second, that the string with the subject tag is re-encoded before
the header is set to it.
parent a87a48ac
......@@ -972,7 +972,7 @@ sub SetSubject {
$subject =~ s/(\r\n|\n|\s)/ /g;
$self->SetHeader( 'Subject', $subject );
$self->SetHeader( 'Subject', Encode::encode_utf8( $subject ) );
......@@ -986,11 +986,14 @@ sub SetSubjectToken {
my $self = shift;
my $head = $self->TemplateObj->MIMEObj->head;
Subject => RT::Interface::Email::AddSubjectTag(
Encode::decode_utf8( $head->get('Subject') ),
Subject =>
Encode::decode_utf8( $head->get('Subject') ),
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment