本文整理汇总了Python中models.Email.header_date方法的典型用法代码示例。如果您正苦于以下问题:Python Email.header_date方法的具体用法?Python Email.header_date怎么用?Python Email.header_date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Email
的用法示例。
在下文中一共展示了Email.header_date方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: walk_domain
# 需要导入模块: from models import Email [as 别名]
# 或者: from models.Email import header_date [as 别名]
def walk_domain(domain, path):
new_path = os.path.join(path, 'new')
email_filenames = os.listdir(new_path)
email_count = len(email_filenames)
print 'Reading %s, %d emails.' % (domain, email_count)
for i, email_filename in enumerate(email_filenames):
email_filepath = os.path.join(new_path, email_filename)
try:
message = Parser().parse(open(email_filepath, 'r'))
email = Email()
email.domain = domain
email.header_from = message['from']
email.header_to = message['to']
email.header_subject = message['subject']
email.header_date = parser.parse(message['date'])
email.postgres_filename = email_filename
email.original = message.as_string()
session.add(email)
session.commit()
cur_path = os.path.join(path, 'cur')
os.rename(email_filepath, os.path.join(cur_path, email_filename))
except Exception, exc:
print exc
fail_path = os.path.join(path, 'fail')
if not os.path.exists(fail_path):
os.makedirs(fail_path)
os.rename(email_filepath, os.path.join(fail_path, email_filename))
stdout('\r%5d/%5d : %0.2f%%' % (i, email_count, i * 100.0 / email_count))