Skip to content

Commit 2103f5f

Browse files
authored
Print the Date header of .eml files as a hex POSIX timestamp (#221)
A little utility trying to reverse-engineer the filenames assigned by the gmail_dump.py tool.
1 parent 6ea7eb9 commit 2103f5f

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

tools/mail/pt.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
"""Print the Date header of .eml files as a hex POSIX timestamp."""
5+
6+
import email
7+
import email.utils
8+
import sys
9+
10+
11+
def main() -> None:
12+
for path in sys.argv[1:]:
13+
with open(path, "rb") as f:
14+
msg = email.message_from_binary_file(f)
15+
date_str = msg["Date"] or ""
16+
parsed = email.utils.parsedate_tz(date_str)
17+
if parsed is None:
18+
hex_ts = "????????"
19+
else:
20+
hex_ts = f"{int(email.utils.mktime_tz(parsed)) * 1000 << 20:016x}"
21+
print(f"{path}\t{date_str:<40}\t{hex_ts}")
22+
23+
24+
if __name__ == "__main__":
25+
main()

0 commit comments

Comments
 (0)