Created
March 31, 2021 06:26
-
-
Save marcus-crane/7eaf3a8e8f295eeeedde44d1253014fe to your computer and use it in GitHub Desktop.
A small script used for changing Maildir message creation date to match date within the email itself
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
from mailbox import MaildirMessage | |
import time | |
from datetime import datetime | |
import os | |
from glob import glob | |
files = glob("*") | |
def update_mod_date(directory): | |
with open(directory, 'r') as f: | |
try: | |
data = f.read() | |
message = MaildirMessage(data) | |
date = datetime.strptime(message.get('Date'), "%a, %d %b %Y %H:%M:%S %z") | |
mod = time.mktime(date.timetuple()) | |
os.utime(directory, (mod, mod)) | |
print(directory) | |
except Exception as ex: | |
print(ex) | |
for file in files: | |
update_mod_date(file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment