diff --git a/README.rst b/README.rst index 4559bc8..43f1bb3 100644 --- a/README.rst +++ b/README.rst @@ -333,6 +333,7 @@ Big thanks to people who helped develop this library: `nathan30 `_, `daniel55411 `_, `rcarmo `_, -`bhernacki `_ +`bhernacki `_, +`ilep `_ 💰 You may `donate `_, if this library helped you. diff --git a/docs/release_notes.rst b/docs/release_notes.rst index 5acac77..e1cb1ad 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -1,3 +1,7 @@ +0.39.0 +====== +* Fixed MailAttachment.attachments - message/rfc822 forwarded messages not missing now + 0.38.0 ====== * Fixed bug at utils.parse_email_addresses - quoted with newlines diff --git a/imap_tools/__init__.py b/imap_tools/__init__.py index eec7be1..b563d2b 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.38.1' +__version__ = '0.39.0' diff --git a/imap_tools/message.py b/imap_tools/message.py index 74603e3..0c314f6 100644 --- a/imap_tools/message.py +++ b/imap_tools/message.py @@ -227,7 +227,8 @@ def attachments(self) -> ['MailAttachment']: for part in self.obj.walk(): if part.get_content_maintype() == 'multipart': # multipart/* are containers continue - if part.get('Content-ID') is None and part.get_filename() is None: + if part.get('Content-ID') is None and part.get_filename() is None \ + and part.get_content_type() != 'message/rfc822': continue results.append(MailAttachment(part)) return results @@ -249,8 +250,8 @@ def filename(self) -> str: forwarded message (Content-Type = message/rfc822) :return: filename """ - filename = self.part.get_filename() or '' - return ''.join(decode_value(*head_part) for head_part in decode_header(filename)) + raw = self.part.get_filename() or '' + return ''.join(decode_value(*head_part) for head_part in decode_header(raw)) @property @lru_cache() diff --git a/tests/data.py b/tests/data.py index 900c671..0feedd1 100644 --- a/tests/data.py +++ b/tests/data.py @@ -611,9 +611,9 @@ def get_content_type(self): headers={'message-id': ('<5fa9c763>',), 'date': ('Mon, 01 Nov 2020 14:49:07 -0800 (PST)',), 'mime-version': ('1.0',), 'from': ('"Sender" ',), 'to': ('My Name , Other Name\r\n ',), 'cc': ( - 'Third Name , "Quoted Mailing List\r\n One" , "Quoted\r\n Mailing List Two" ',), + 'Third Name , "Quoted Mailing List\r\n One" , "Quoted\r\n Mailing List Two" ',), 'bcc': ( - 'My Name , Mailing List One - One Name\r\n , Mailing List Two - Second Name\r\n ',), + 'My Name , Mailing List One - One Name\r\n , Mailing List Two - Second Name\r\n ',), 'subject': ('Daily',), 'content-type': ('multipart/mixed; boundary=--boundary_20_d4727d16-8454-4fa4-9da0-950a95b2c962',)}, attachments=[ @@ -630,16 +630,52 @@ def get_content_type(self): {'email': 'other.name@domain.com', 'name': 'Other Name', 'full': 'Other Name '}), cc_values=( - {'email': 'third.name@domain.com', 'name': 'Third Name', 'full': 'Third Name '}, - {'email': 'quoted-mailing-list-one@domain.com', 'name': 'Quoted Mailing List One', - 'full': 'Quoted Mailing List One '}, - {'email': 'quoted-mailing-list-two@domain.com', 'name': 'Quoted Mailing List Two', - 'full': 'Quoted Mailing List Two '}), + {'email': 'third.name@domain.com', 'name': 'Third Name', 'full': 'Third Name '}, + {'email': 'quoted-mailing-list-one@domain.com', 'name': 'Quoted Mailing List One', + 'full': 'Quoted Mailing List One '}, + {'email': 'quoted-mailing-list-two@domain.com', 'name': 'Quoted Mailing List Two', + 'full': 'Quoted Mailing List Two '}), bcc_values=({'email': 'my.name@domain.com', 'name': 'My Name', 'full': 'My Name '}, {'email': 'list1-one-name@domain.com', 'name': 'Mailing List One - One Name', 'full': 'Mailing List One - One Name '}, {'email': 'list2-second-name@domain.com', 'name': 'Mailing List Two - Second Name', 'full': 'Mailing List Two - Second Name '}), reply_to_values=(), + ), + 'forwarded_message': dict( + subject='статус', + from_='i.kor@company.ru', + to=('jessica.schmidt@uni.de', 'я你Rabea.Bartölke@uni.de'), + cc=(), + bcc=(), + reply_to=(), + date=datetime.datetime(2017, 10, 12, 9, 41, 56, tzinfo=datetime.timezone(datetime.timedelta(0, 18000))), + date_str='Thu, 12 Oct 2017 09:41:56 +0500', + text='\r\n', + html='\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n Новый заказ №28922\r\n \r\n\r\n \r\n \r\n\r\n', + headers={'subject': ('=?UTF-8?B?0YHRgtCw0YLRg9GB?=',), 'to': ( + 'Jessica Schmidt ,\r\n\t=?iso-8859-1?Q?Rabea=2EBart=F6lke=40uni=2Ede?= <\udcd1\udc8f\udce4\udcbd\udca0Rabea.Bart\udcc3\udcb6lke@uni.de>',), + 'from': ('i.kor@company.ru',), 'message-id': ('<2405271c-86ac-0a65-e50c-d1ebccfcc644@company.ru>',), + 'date': ('Thu, 12 Oct 2017 09:41:56 +0500',), 'mime-version': ('1.0',), + 'in-reply-to': ('<20171011085432.15374.20485@web.hades.company>',), + 'content-type': ('multipart/mixed;\r\n boundary="------------BF90926EC9DF73443A6B8F28"',), + 'content-language': ('ru',)}, + attachments=[ + dict( + filename='', + content_id='', + content_disposition='attachment', + content_type='message/rfc822', + payload=b'Content-Type: multipart/alternative;\n boundary="===============3693132879591888836=="\nMIME-Version: 1.0\nSubject: =?UTF-8?B?0YHRgtCw0YLRg9GB?= \nFrom: group@company.ru\nTo: group@company.ru\nDate: Wed, 11 Oct 2017 08:54:32 -0000\nMessage-ID: <20171011085432.15374.20485@web.hades.company>\n\n--===============3693132879591888836==\nContent-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\n\n=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9 =D0=B7=D0=B0=D0=BA=D0=B0=D0=B7 =E2=84=9628=\n922 http://group.company.ru/ru/order/28922/process/\n=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BB:=20\n=D0=9A=D0=BB=D0=B8=D0=B5=D0=BD=D1=82 =D0=9A=D0=BE=D0=B2=D1=87=D0=B5=D0=B3=\n (=D0=93=D1=83=D1=81=D0=B5=D0=B2 =D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=\n)\n\n=D0=A1=D0=B5=D0=B3=D0=BC=D0=B5=D0=BD=D1=82=D1=8B:\n\n- =D0=9C=D0=BE=D1=81=D0=BA=D0=B2=D0=B0 - =D0=A2=D0=B5=D0=BB=D1=8C-=D0=90=D0=\n=B2=D0=B8=D0=B2, some-889, 15.03.2018, =D1=8D=D0=BA=D0=BE=D0=BD=D0=BE=D0=BC=\n: (15 =D0=B2=D0=B7=D1=80.)\n\n- =D0=A2=D0=B5=D0=BB=D1=8C-=D0=90=D0=B2=D0=B8=D0=B2 - =D0=9C=D0=BE=D1=81=D0=\n=BA=D0=B2=D0=B0, some-890, 22.03.2018, =D1=8D=D0=BA=D0=BE=D0=BD=D0=BE=D0=BC=\n: (15 =D0=B2=D0=B7=D1=80.)\n--===============3693132879591888836==\nContent-Type: text/html; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\n\n\n\n \n \n \n \n =20\n \n\n \n =20\n =20\n =20\n \n =20\n =D0=9D=D0=BE=D0=B2=D1=8B=D0=B9 =D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=\n =E2=84=9628922\n \n\n \n \n\n\n--===============3693132879591888836==--\n', + ), + ], + from_values={'email': 'i.kor@company.ru', 'name': '', 'full': 'i.kor@company.ru'}, + to_values=({'email': 'jessica.schmidt@uni.de', 'name': 'Jessica Schmidt', + 'full': 'Jessica Schmidt '}, + {'email': 'я你Rabea.Bartölke@uni.de', 'name': 'Rabea.Bartölke@uni.de', + 'full': 'Rabea.Bartölke@uni.de <я你Rabea.Bartölke@uni.de>'}), + cc_values=(), + bcc_values=(), + reply_to_values=(), ) } diff --git a/tests/messages/forwarded_message.eml b/tests/messages/forwarded_message.eml new file mode 100644 index 0000000..d574463 --- /dev/null +++ b/tests/messages/forwarded_message.eml @@ -0,0 +1,88 @@ +Subject: =?UTF-8?B?0YHRgtCw0YLRg9GB?= +To: Jessica Schmidt , + =?iso-8859-1?Q?Rabea=2EBart=F6lke=40uni=2Ede?= <я你Rabea.Bartölke@uni.de> +From: i.kor@company.ru +Message-ID: <2405271c-86ac-0a65-e50c-d1ebccfcc644@company.ru> +Date: Thu, 12 Oct 2017 09:41:56 +0500 +MIME-Version: 1.0 +In-Reply-To: <20171011085432.15374.20485@web.hades.company> +Content-Type: multipart/mixed; + boundary="------------BF90926EC9DF73443A6B8F28" +Content-Language: ru + +This is a multi-part message in MIME format. +--------------BF90926EC9DF73443A6B8F28 +Content-Type: text/plain; charset=utf-8; format=flowed +Content-Transfer-Encoding: 7bit + + + +--------------BF90926EC9DF73443A6B8F28 +Content-Type: message/rfc822; +Content-Transfer-Encoding: 7bit +Content-Disposition: attachment; + +Content-Type: multipart/alternative; + boundary="===============3693132879591888836==" +MIME-Version: 1.0 +Subject: =?UTF-8?B?0YHRgtCw0YLRg9GB?= +From: group@company.ru +To: group@company.ru +Date: Wed, 11 Oct 2017 08:54:32 -0000 +Message-ID: <20171011085432.15374.20485@web.hades.company> + +--===============3693132879591888836== +Content-Type: text/plain; charset="utf-8" +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable + +=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9 =D0=B7=D0=B0=D0=BA=D0=B0=D0=B7 =E2=84=9628= +922 http://group.company.ru/ru/order/28922/process/ +=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BB:=20 +=D0=9A=D0=BB=D0=B8=D0=B5=D0=BD=D1=82 =D0=9A=D0=BE=D0=B2=D1=87=D0=B5=D0=B3= + (=D0=93=D1=83=D1=81=D0=B5=D0=B2 =D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9= +) + +=D0=A1=D0=B5=D0=B3=D0=BC=D0=B5=D0=BD=D1=82=D1=8B: + +- =D0=9C=D0=BE=D1=81=D0=BA=D0=B2=D0=B0 - =D0=A2=D0=B5=D0=BB=D1=8C-=D0=90=D0= +=B2=D0=B8=D0=B2, some-889, 15.03.2018, =D1=8D=D0=BA=D0=BE=D0=BD=D0=BE=D0=BC= +: (15 =D0=B2=D0=B7=D1=80.) + +- =D0=A2=D0=B5=D0=BB=D1=8C-=D0=90=D0=B2=D0=B8=D0=B2 - =D0=9C=D0=BE=D1=81=D0= +=BA=D0=B2=D0=B0, some-890, 22.03.2018, =D1=8D=D0=BA=D0=BE=D0=BD=D0=BE=D0=BC= +: (15 =D0=B2=D0=B7=D1=80.) +--===============3693132879591888836== +Content-Type: text/html; charset="utf-8" +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable + + + + + + + + =20 + + + + =20 + =20 + =20 + + =20 + =D0=9D=D0=BE=D0=B2=D1=8B=D0=B9 =D0=B7=D0=B0=D0=BA=D0=B0=D0=B7= + =E2=84=9628922 + + + + + + +--===============3693132879591888836==-- + +--------------BF90926EC9DF73443A6B8F28--