def findOldestInInbox(): import mailutil m = mailutil.imapclient(imapHost, imapUser, cache=True, pwd=getPassword(imapHost, imapUser)) m.select("INBOX", False) last_seen = time.time() l = m.list() oldUIDs = [] mostBack = 0 done = 0 for uid in l: done = done + 1 msg = m.fetch(uid, True) m.get_cache().update({"_id": m.get_id(uid)}, {"$set": { "lastSeen": last_seen }}) headers = msg["headers"] if not headers: continue who = headers["from"] subject = headers["subject"] if not subject.startswith("jira summary @"): continue pcs = subject.split("@") if len(pcs) != 3: raise Exception("bad subject [%s]" % subject) hoursFromSubject = 1 + int(pcs[1].strip()) thing = dateutil.parser.parse(pcs[2].strip()) now = datetime.datetime.utcnow() diff = now - thing hours = int(diff.total_seconds() / 3600) oldUIDs.append(uid) if hours > mostBack: mostBack = hours if hoursFromSubject > mostBack: mostBack = hoursFromSubject return mostBack, oldUIDs
def archiveOldMail( uids ): if len(uids) == 0: return import mailutil m = mailutil.imapclient( imapHost, imapUser, cache=True, pwd=getPassword( imapHost, imapUser ) ) m.select( "INBOX" , False ) for uid in uids: m.archive( uid ) m.expunge()
def findOldestInInbox(): import mailutil m = mailutil.imapclient( imapHost, imapUser, cache=True, pwd=getPassword( imapHost, imapUser ) ) m.select( "INBOX" , False ) last_seen = time.time() l = m.list() oldUIDs = [] mostBack = 0 done = 0 for uid in l: done = done + 1 msg = m.fetch( uid , True ) m.get_cache().update( { "_id" : m.get_id( uid ) }, { "$set" : { "lastSeen" : last_seen } } ) headers = msg["headers"] if not headers: continue who = headers["from"] subject = headers["subject"] if not subject.startswith( "jira summary @" ): continue pcs = subject.split( "@" ) if len(pcs) != 3: raise Exception( "bad subject [%s]" % subject ) hoursFromSubject = 1 + int(pcs[1].strip()) thing = dateutil.parser.parse( pcs[2].strip() ) now = datetime.datetime.utcnow() diff = now-thing hours = int(diff.total_seconds() / 3600) oldUIDs.append( uid ) if hours > mostBack: mostBack = hours if hoursFromSubject > mostBack: mostBack = hoursFromSubject return mostBack,oldUIDs
def archiveOldMail(uids): if len(uids) == 0: return import mailutil m = mailutil.imapclient(imapHost, imapUser, cache=True, pwd=getPassword(imapHost, imapUser)) m.select("INBOX", False) for uid in uids: m.archive(uid) m.expunge()