Created
July 1, 2021 15:22
-
-
Save keiichiw/b323a8bcf725755f90ad38b117bd6b3c to your computer and use it in GitHub Desktop.
Split an mbox file into multiple .patch files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import mailbox | |
import sys | |
import os | |
def main(): | |
argv = sys.argv | |
if len(argv) != 2: | |
print(f'Usage: {argv[0]} <mbx file>') | |
exit(1) | |
fname = argv[1] | |
dirname = os.path.dirname(fname) | |
(root, ext) = os.path.splitext(os.path.basename(fname)) | |
if ext != ".mbx": | |
print(f'extension must be "mbx" but "{ext}"') | |
exit(1) | |
mbox = mailbox.mbox(fname) | |
count = 1 | |
for m in mbox: | |
with open(f'{dirname}/{count:04}-{root}.patch'.format(), 'w+') as f: | |
f.write(str(m)) | |
count += 1 | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment