-
Notifications
You must be signed in to change notification settings - Fork 0
/
dumpmbox.py
40 lines (33 loc) · 1.19 KB
/
dumpmbox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#
# Version: 0.1.0 2/1/21
#
# License: CC BY-NC-SA 4.0, https://creativecommons.org/licenses/by-nc-sa/4.0/
#
# Graeme Williams
#
# See the README for instructions about how to use this command
#
import mailbox
import argparse
import sys
def dumpmsg(k, m, ofile):
print(10*'=', "Dumping message", k, len(m), type(m), 10*'=', file=ofile)
for p in m.walk():
print(">>>>> Walk: ", type(p), file=ofile)
for f,v in p.items():
print(f, '///', v[0:200], file=ofile)
if not p.is_multipart():
print("PAYLOAD:", p.get_payload()[0:50], file=ofile)
parser = argparse.ArgumentParser()
parser.add_argument("--input", "-i", help="Input filename")
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("--stop", "-s", type=int, help="Stop every n messages")
group.add_argument("--output", "-o", help="Output filename")
args = parser.parse_args()
mb = mailbox.mbox(args.input)
outputfile = open(args.output, 'w') if args.output else sys.stdout
for i, (k, msg) in enumerate(mb.iteritems()):
dumpmsg(k, msg, outputfile)
if args.stop and not ((i+1) % int(args.stop)):
input("Hit return for next message: ")