From b5abb144d8a695c36267fe568fa142252168615d Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Mon, 6 Aug 2018 18:23:35 +0200 Subject: Decode multi word MIME headers Signed-off-by: Florian Pritz --- lib/App/ImapNotify.pm | 4 ++-- t/07_unicode.t | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/App/ImapNotify.pm b/lib/App/ImapNotify.pm index 675d695..cbdc4ac 100644 --- a/lib/App/ImapNotify.pm +++ b/lib/App/ImapNotify.pm @@ -146,8 +146,8 @@ method _notify($message) { next; } - if ($line =~ m/^\s+(.*)$/) { - $fields->{$current_field} .= $1; + if ($line =~ m/^\s+(.*)\r$/) { + $fields->{$current_field} .= decode('MIME-Header', $1); } } diff --git a/t/07_unicode.t b/t/07_unicode.t index 57601d9..46a7a8d 100644 --- a/t/07_unicode.t +++ b/t/07_unicode.t @@ -23,10 +23,13 @@ $socket->set_series('readline', "* 51 EXISTS\r\n", "* 1 RECENT\r\n", # this is a notification - "* 51 FETCH (UID 41023 BODY[HEADER.FIELDS (FROM TO SUBJECT)] {".(36+24+59+2)."}\r\n", + "* 51 FETCH (UID 41023 BODY[HEADER.FIELDS (FROM TO SUBJECT)] {".(36+24+60+56+27+51+2)."}\r\n", "From: \r\n", "To: \r\n", - "Subject: =?UTF-8?B?U29tZSDwn5KpIFTDg8K2c3Qgc3ViamVjdA==?=\r\n", + "Subject: =?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\r\n", + " =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=\r\n", + " =?US-ASCII?Q?.._cool! ?=\r\n", + " =?UTF-8?B?U29tZSDwn5KpIFTDg8K2c3Qgc3ViamVjdA==?=\r\n", "\r\n", ")\r\n", ); @@ -52,7 +55,7 @@ $app->loop(); is($socket->readline(), undef, "readline queue is read fully"); eq_or_diff($notifier->_calls(), [ - ['notify', [$notifier, 'From: ', "Subject: Some \x{1F4A9} Töst subject"]] + ['notify', [$notifier, 'From: ', "Subject: If you can read this you understand the example... cool! Some \x{1F4A9} Töst subject"]] ], "notifier is called correctly"); done_testing; -- cgit v1.2.3-24-g4f1b