def mails(self): name = self.mailuser['name'] count = 0 mailinfos = [] for item in self.uidls: i, k = item loginfo('uidl:', i, k) trycount = 0 while True: try: data = self.pop3.retr(i) except Exception, e: logerr(e) trycount += 1 if trycount == 3: break continue trycount = 0 break if trycount == 3: continue filedata = '\n'.join(data[1]) hashdir = '%02d' % (hash(k) % self.hashdir_count) filename = os.path.join(self.time_path, hashdir, '%d.' % (int(time.time())) + k + '.eml') loginfo('file:', filename, 'size:', len(filedata)) try: ret = mailparse.decode_mail_string(filedata) except Exception, e: traceback.print_exc(file=logfile.logobj.log) continue
logerr(e) trycount += 1 if trycount == 3: raise ValueError, 'pop3 retr error:' + str(i) continue trycount = 0 break filedata = '\n'.join(data[1]) hashdir = '%02d' % (hash(k) % self.hashdir_count) filename = os.path.join(self.time_path, hashdir, '%d.' % (int(time.time())) + k + '.eml') loginfo('file:', filename, 'size:', len(filedata)) try: ret = mailparse.decode_mail_string(filedata) except Exception, e: traceback.print_exc(file=logfile.logobj.log) raise f = open(filename, 'w') f.write(filedata) f.close() ret['filename'] = filename[len(self.recvpath):] ret['mailbox'] = 'recv' ret['ctime'] = int(time.time()) ret['uidl'] = k ret['date'] = time.mktime(time.strptime(ret['date'], '%Y-%m-%d %H:%M:%S')) #print ret loginfo('======== pos:', self.uidl_pos, ' of ', len(self.uidls))