#765455 libmime-lite-perl: utf-8 encoded subject gains a space character on header line wrap

#765455#5
Date:
2014-10-15 09:22:34 UTC
From:
To:
Hi,
i am seeing an interesting issue where a long utf-8 subject gains a
space at the wrap point - See the attached testcase:

Cluster: Gütersloh Route: Brockweg -> Heidewaldstadion changed
Cluster: Gütersloh Route:  Bielefelder Straße - Rheda -> Bertelsmann Hauptverwaltung changed
                          ^

This space gets added - Here are the resulting Header lines from libmime-lite-perl:

Subject: Cluster:=?UTF-8?B?IEfDvHRlcnNsb2ggUm91dGU=?=: Brockweg ->
   Heidewaldstadion changed

Subject: Cluster:=?UTF-8?B?IEfDvHRlcnNsb2ggUm91dGU=?=:
  =?UTF-8?B?IEJpZWxlZmVsZGVyIFN0cmHDn2UgLSBSaGVkYSAt?=>
   Bertelsmann Hauptverwaltung changed

The display of the additional space is consistent in mutt and icedove so i expect
it to be standard conform interpretation of the mime headers.

It seems when the line ends with a non encoded word (:) and starts with
an encoded word we take all except the very first space. RFC2047 has an
example of this only using a single space in front of the encoded word
(Page 10, Examples). Duplicate space suppression does only happen
between encoded words, not between unencoded and encoded words.

Flo

#!/usr/bin/perl -w

use strict;
use utf8;
use MIME::Lite;
use Encode;

my @subjects=(
	'Cluster: Gütersloh Route: Brockweg -> Heidewaldstadion changed',
	'Cluster: Gütersloh Route: Bielefelder Straße - Rheda -> Bertelsmann Hauptverwaltung changed'
	);

foreach my $subject ( @subjects ) {

	my $msg = MIME::Lite->new(
		From    => 'testcase@zz.de',
		To      => 'flo',
		Subject => encode('MIME-Header', $subject),
		Type    => 'multipart/mixed',
	);

	$msg->attach(
		Type     => "text/plain; charset=UTF-8",
		Data     => "Testcase",
	);

	$msg->send;

}