Skip to content

Instantly share code, notes, and snippets.

@marcus-crane
Created March 31, 2021 06:26
Show Gist options
  • Save marcus-crane/7eaf3a8e8f295eeeedde44d1253014fe to your computer and use it in GitHub Desktop.
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
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