# # Python / Eudora COM example # # Scan the Eudora inbox for messages that match a # given subject and are older than a specified time. # # Author: Scott Schram # http://schram.net # from win32com.client import Dispatch import time import re import string from string import atoi # Set Eudora options: # Display dates in local time # Fixed %1 %2 %4 # # Then, Eudora dates are of the format: # 10:22 PM 9/20/00 reDate = r'(\d+):(\d+) (\w)M (\d+)/(\d+)/(\d+)' patDate = re.compile(reDate) def MsgDateToTime(sMsgDate): m = patDate.match(sMsgDate) res = m.groups() # res is like this: # ('10', '22', 'P', '9', '20', '00') year = atoi(res[5]) year = year + 1900 if year < 1950: year = year + 100 month = atoi(res[3]) day = atoi(res[4]) hour = atoi(res[0]) # 12 PM doesn't need an extra 12 hours. if ((res[2] == "P") and (hour < 12)): hour = hour + 12 min = atoi(res[1]) # (year, month, day, hour, minute, second, weekday, day, dst) tup = (year, month, day, hour, min, 0, 0, 0, -1) t = time.mktime(tup) print "Message local time: ", time.asctime(time.localtime(t)) return t eu = Dispatch("Eudora.EuApplication.1") folSource = eu.Folder("In", 1) folDest = eu.Folder("Trash", 1) msSource = folSource.Messages nCount = msSource.Count timenow = time.time() # Important to do the messages in reverse order. Moving a message # changes the number of messages in a mailbox. # Item indices go from nCount..1 for i in range(nCount, 0, -1): msg = msSource.Item(i) print "------------------------------" print msg.Subject print msg.Date age = timenow - MsgDateToTime(msg.Date) print "Hours old: ", age / 3600.0 if ((string.find(msg.Subject, "BHM") != -1) and ((age / 3600.0) > 24.0)): print "Moving " + msg.Subject msg.Move(folDest) # Once you move a message, msg is no longer valid.