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() |