diff options
author | Florian Pritz <bluewind@xinu.at> | 2018-07-19 17:25:00 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2018-07-19 17:25:00 +0200 |
commit | 13cad1519b679526b2b8f5f38dd388d0ed3a4dcd (patch) | |
tree | 755a323754e9d0d630f0fa595bf9a9c3f8e1dcd6 | |
parent | f4acd5a69e71fce176e6bb0cb57bd3d8b5717af8 (diff) | |
download | App-ImapNotify-13cad1519b679526b2b8f5f38dd388d0ed3a4dcd.tar.gz App-ImapNotify-13cad1519b679526b2b8f5f38dd388d0ed3a4dcd.tar.xz |
Decode MIME-Header encoded headers
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r-- | lib/App/ImapNotify.pm | 3 | ||||
-rw-r--r-- | t/07_unicode.t | 58 |
2 files changed, 60 insertions, 1 deletions
diff --git a/lib/App/ImapNotify.pm b/lib/App/ImapNotify.pm index b7b1cf7..cd81538 100644 --- a/lib/App/ImapNotify.pm +++ b/lib/App/ImapNotify.pm @@ -9,6 +9,7 @@ use App::ImapNotify::ImapClient; use App::ImapNotify::Notifier; use Carp; +use Encode qw(encode decode); use Function::Parameters; use Log::Any qw($log); use Syntax::Keyword::Try; @@ -138,7 +139,7 @@ method _notify($message) { for my $line ($message->@*) { if ($line =~ m/^(?<label>[^\s:]+): (?<value>.*)\r\n$/) { $current_field = lc($+{label}); - $fields->{$current_field} = $+{value}; + $fields->{$current_field} = decode('MIME-Header', $+{value}); next; } diff --git a/t/07_unicode.t b/t/07_unicode.t new file mode 100644 index 0000000..57601d9 --- /dev/null +++ b/t/07_unicode.t @@ -0,0 +1,58 @@ +use strict; +use warnings; +use Test::Differences; +use Test::More; +use Test::MockObject; + +use Log::Any::Adapter ('Stderr', log_level => "warn"); + +use App::ImapNotify; +use App::ImapNotify::ImapClient; + + +my $notifier = Test::MockObject->new(); +$notifier->set_true("notify"); + +my $socket = Test::MockObject->new(); +$socket->set_series('readline', + "* OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE LITERAL+ AUTH=PLAIN AUTH=LOGIN] Fake server ready.\r\n", + "CMD-0 OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE SNIPPET=FUZZY LITERAL+ NOTIFY SPECIAL-USE COMPRESS=DEFLATE] Logged in\r\n", + "CMD-1 OK [READ-WRITE] Select completed (0.001 + 0.000 secs).\r\n", + "CMD-2 OK NOTIFY completed (0.001 + 0.000 secs).\r\n", + # this stuff should be ignored + "* 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", + "From: <test\@localhost.localdomain>\r\n", + "To: <bluewind\@xinu.at>\r\n", + "Subject: =?UTF-8?B?U29tZSDwn5KpIFTDg8K2c3Qgc3ViamVjdA==?=\r\n", + "\r\n", + ")\r\n", +); + +$socket->set_true(qw(writeline reconnect)); + +my $config = { + log_id => 'test-id1', + host => 'localhost.localdomain', + port => 993, + username => 'tester1', + password => 'secretPW42', + mailboxes => [qw(INBOX INBOX.test)], + keepalive_timeout => 300, +}; + +my $imap_client = App::ImapNotify::ImapClient->new_no_defaults($config, {sock => $socket}); + +my $app = App::ImapNotify->new_no_defaults($config, {imap_client => $imap_client, notifier => $notifier}); + +$app->loop(); + +is($socket->readline(), undef, "readline queue is read fully"); + +eq_or_diff($notifier->_calls(), [ + ['notify', [$notifier, 'From: <test@localhost.localdomain>', "Subject: Some \x{1F4A9} Töst subject"]] + ], "notifier is called correctly"); + +done_testing; |