Skip to content

Instantly share code, notes, and snippets.

@laserson
Created September 28, 2017 18:51
Show Gist options
  • Save laserson/4f4c61e45994d38277dd153d76c1e6de to your computer and use it in GitHub Desktop.
Save laserson/4f4c61e45994d38277dd153d76c1e6de to your computer and use it in GitHub Desktop.
Transfer mail from Outlook for Mac to Gmail

Drag and drop desired messages to directories (e.g., archived/).

Convert directory to mbox file

./eml2mbox.py archived archived.mbox

Follow directions here to upload via Gmail API

https://github.com/google/import-mailbox-to-gmail
#!/usr/bin/env python
""" Converts a directory full of .eml files to a single Unix "mbox" file.
Based on https://gist.github.com/kadin2048/c332a572a388acc22d56
"""
import os
import os.path as osp
import mailbox
from click import command, argument, Path
from tqdm import tqdm
@command()
@argument('input-dir', type=Path(exists=True, file_okay=False))
@argument('output-file', type=Path(exists=False))
def main(input_dir, output_file):
dest_mbox = mailbox.mbox(output_file, create=True)
dest_mbox.lock()
for filename in tqdm(os.listdir(input_dir)):
assert osp.splitext(filename)[1] == '.eml'
with open(osp.join(input_dir, filename), 'r') as ip:
dest_mbox.add(ip)
dest_mbox.close()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment