忍者ブログ

【Python】複数のMIMEファイルから添付ファイルを取得して保存

2020年10月04日 00時14分06秒
特定のフォルダに複数のMIMEファイルを保存。
そのフォルダ内にある全てのMIMEから添付ファイルだけ取得したかったので、Pythonでツールを作成。

import glob from email.parser import Parser # MIME一覧のパス、ファイル名を指定 files = glob.glob('パス/ファイル名') for file in files: with open(file, 'r', encoding='iso-8859-1') as f_mime: mime_str = f_mime.read() mime_obj = Parser().parsestr(mime_str) for part in mime_obj.walk(): filename = part.get_filename() if filename: content = part.get_payload(decode=True) with open('パス' + filename, 'wb') as fout: fout.write(content)

PR
Comment
No title
Chính vì yêu cầu đó nên bên trên thị ngôi trường
đã xuất hiện tại chủng loại Titan Gel Gold thường xuyên dành cho phái mạnh.
  Vodafone絵文字 i-mode絵文字 Ezweb絵文字