def get_attachments(self) -> Generator:
"""
Attachments of the mail message (generator)
:return: generator of tuple(filename: str, payload: bytes)
"""
for part in self.obj.walk():
# multipart/* are just containers
if part.get_content_maintype() == 'multipart':
continue
if part.get('Content-Disposition') is None:
continue
filename = part.get_filename()
if not part.get_filename():
continue # this is what happens when Content-Disposition = inline
filename = self._decode_value(*decode_header(filename)[0])
payload = part.get_payload(decode=True)
if not payload:
continue
yield filename, payload
评论列表
文章目录