Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- import email
- """
- SOURCE: https://spapas.github.io/2014/10/23/retrieve-gmail-blocked-attachments/
- 1. In gmail, find the email that has the blocked attachments you want to download.
- 2. Click the dropdown arrow located top-right of that email.
- Click "Show original"
- 3. Click "Download Original".
- 4. Copy the file to this folder.
- 5. Open command prompt to this folder
- Run this: $ python get_attachments.py original_msg.txt
- """
- def ensure_nested_dir(nested_dir):
- this_py_file = os.path.realpath(__file__)
- directory = os.path.join(os.getcwd(), nested_dir)
- if not os.path.exists(directory):
- os.makedirs(directory)
- if __name__=='__main__':
- if len(sys.argv)<2:
- print("Please enter a file to extract attachments from")
- sys.exit(1)
- original_msg_dir = os.getcwd()
- nested_dir = "Extracted Email Attachments"
- ensure_nested_dir(nested_dir)
- os.chdir(nested_dir)
- msg = email.message_from_file(open(os.path.join(original_msg_dir, sys.argv[1])))
- for pl in msg.get_payload():
- if pl.get_filename(): # if it is an attachment
- open(pl.get_filename(), 'wb').write(pl.get_payload(decode=True))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement