From 678f8e443fddcbf2a15495643e11147428d350a1 Mon Sep 17 00:00:00 2001 From: "v.kaukin" Date: Wed, 12 May 2021 14:38:42 +0500 Subject: [PATCH] fix MailMessage.subject --- README.rst | 3 ++- docs/release_notes.rst | 4 ++++ imap_tools/__init__.py | 2 +- imap_tools/message.py | 4 ++-- tests/messages_data/attachment_7bit.py | 2 +- .../plain_emails/raw_email_with_partially_quoted_subject.py | 2 +- tests/messages_data/rfc2822/example14.py | 2 +- 7 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 3eb35f1..a980e63 100644 --- a/README.rst +++ b/README.rst @@ -346,7 +346,8 @@ Big thanks to people who helped develop this library: `daniel55411 `_, `rcarmo `_, `bhernacki `_, -`ilep `_ +`ilep `_, +`ThKue `_ Donate ------ diff --git a/docs/release_notes.rst b/docs/release_notes.rst index 34ae411..3b5cee9 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -1,3 +1,7 @@ +0.41.0 +====== +* Fixed multiple encodings case bug at MailMessage.subject + 0.40.0 ====== * Fixed MailMessage.from_bytes - MailMessage.uid/flags parse errors diff --git a/imap_tools/__init__.py b/imap_tools/__init__.py index 55ffe4b..84bbf46 100644 --- a/imap_tools/__init__.py +++ b/imap_tools/__init__.py @@ -4,4 +4,4 @@ from .folder import MailBoxFolderManager, MailBoxFolderStatusOptions from .errors import * -__version__ = '0.40.0' +__version__ = '0.41.0' diff --git a/imap_tools/message.py b/imap_tools/message.py index 4021a53..8ac6028 100644 --- a/imap_tools/message.py +++ b/imap_tools/message.py @@ -102,8 +102,8 @@ def flags(self) -> (str,): def subject(self) -> str: """Message subject""" if 'subject' in self.obj: - msg_subject = decode_header(self.obj['subject']) - return decode_value(msg_subject[0][0], msg_subject[0][1]) + raw = self.obj['subject'] + return ''.join(decode_value(*head_part) for head_part in decode_header(raw)) return '' @property diff --git a/tests/messages_data/attachment_7bit.py b/tests/messages_data/attachment_7bit.py index 4a7f083..5be4e87 100644 --- a/tests/messages_data/attachment_7bit.py +++ b/tests/messages_data/attachment_7bit.py @@ -1,7 +1,7 @@ import datetime DATA = dict( - subject='статус', + subject='статус ', from_='i.kor@company.ru', to=('jessica.schmidt@uni.de', 'я你Rabea.Bartölke@uni.de'), cc=(), diff --git a/tests/messages_data/plain_emails/raw_email_with_partially_quoted_subject.py b/tests/messages_data/plain_emails/raw_email_with_partially_quoted_subject.py index 141eb9d..56ef6eb 100644 --- a/tests/messages_data/plain_emails/raw_email_with_partially_quoted_subject.py +++ b/tests/messages_data/plain_emails/raw_email_with_partially_quoted_subject.py @@ -1,7 +1,7 @@ import datetime DATA = dict( - subject='Re: Test: ', + subject='Re: Test: "漢字" mid "漢字" tail', from_='jamis@37signals.com', to=('jamis@37signals.com',), cc=(), diff --git a/tests/messages_data/rfc2822/example14.py b/tests/messages_data/rfc2822/example14.py index 2d76fb2..331d20e 100644 --- a/tests/messages_data/rfc2822/example14.py +++ b/tests/messages_data/rfc2822/example14.py @@ -1,7 +1,7 @@ import datetime DATA = dict( - subject='Re: TEST', + subject='Re: TESTテストテスト', from_='atsushi@example.com', to=('rudeboyjet@gmail.com',), cc=(),