read only received from no-reply@hermes.com mails
This commit is contained in:
@@ -231,8 +231,9 @@ class MailReader:
|
|||||||
imap.select(folder)
|
imap.select(folder)
|
||||||
mail_messages = []
|
mail_messages = []
|
||||||
|
|
||||||
# 搜索符合条件的所有邮件ID
|
# 搜索符合条件的所有邮件ID(服务器端同时过滤发件人,减少无关邮件下载量)
|
||||||
search_query = '(SUBJECT "{}" SINCE "{}")'.format(subject, datetime.datetime.today().strftime(DATE_FORMAT))
|
search_query = '(FROM "{}" SUBJECT "{}" SINCE "{}")'.format(
|
||||||
|
HERMES_EMAIL, subject, datetime.datetime.today().strftime(DATE_FORMAT))
|
||||||
typ, data = imap.search(None, search_query)
|
typ, data = imap.search(None, search_query)
|
||||||
|
|
||||||
ids = data[0].split()
|
ids = data[0].split()
|
||||||
@@ -303,7 +304,7 @@ class MailReader:
|
|||||||
print("{}: search terms is {}".format(self.login, search_terms))
|
print("{}: search terms is {}".format(self.login, search_terms))
|
||||||
|
|
||||||
imap.select_folder(folder)
|
imap.select_folder(folder)
|
||||||
messages = imap.search(['SINCE', datetime.datetime.today()])
|
messages = imap.search(['SINCE', datetime.datetime.today(), 'FROM', HERMES_EMAIL])
|
||||||
print("{}: {} messages from our best friend".format(self.login, len(messages)))
|
print("{}: {} messages from our best friend".format(self.login, len(messages)))
|
||||||
|
|
||||||
if len(messages) == 0:
|
if len(messages) == 0:
|
||||||
@@ -314,45 +315,37 @@ class MailReader:
|
|||||||
try:
|
try:
|
||||||
email_message = email.message_from_bytes(message_data[b'RFC822'])
|
email_message = email.message_from_bytes(message_data[b'RFC822'])
|
||||||
|
|
||||||
# 获取发件人和主题
|
|
||||||
from_address = email_message.get('FROM') or ""
|
from_address = email_message.get('FROM') or ""
|
||||||
subject = email_message.get('subject') or ""
|
subject = email_message.get('subject') or ""
|
||||||
|
|
||||||
# 检查是否是Hermes邮件
|
# 提取邮件正文(委托给 imap_proxy_reader.extract_body)
|
||||||
hermes_mail_address = "no-reply@hermes.com"
|
body = extract_body(email_message)
|
||||||
if (hermes_mail_address in from_address or
|
|
||||||
"outlook.com" in from_address or
|
|
||||||
"hotmail" in from_address):
|
|
||||||
|
|
||||||
# 提取邮件正文(委托给 imap_proxy_reader.extract_body)
|
# 检查是否是预约验证邮件
|
||||||
body = extract_body(email_message)
|
if (VALIDATION_URL_SUBJECT_FR in subject or
|
||||||
|
VALIDATION_URL_SUBJECT_EN in subject or
|
||||||
|
"Votre=20demande=20de=20rendez-vous" in subject or
|
||||||
|
"Votre demande de rendez-vous" in body):
|
||||||
|
|
||||||
# 检查是否是预约验证邮件
|
mail = MailPojo(
|
||||||
if (VALIDATION_URL_SUBJECT_FR in subject or
|
subject=subject,
|
||||||
VALIDATION_URL_SUBJECT_EN in subject or
|
body=body,
|
||||||
"Votre=20demande=20de=20rendez-vous" in subject or
|
from_address=from_address
|
||||||
"Votre demande de rendez-vous" in body):
|
)
|
||||||
|
mail.isImapClient = True
|
||||||
|
|
||||||
mail = MailPojo(
|
print("email is {}".format(self.login))
|
||||||
subject=subject,
|
print("subject is {}".format(subject))
|
||||||
body=body,
|
|
||||||
from_address=from_address
|
|
||||||
)
|
|
||||||
mail.isImapClient = True
|
|
||||||
|
|
||||||
print("email is {}".format(self.login))
|
# 设置收件人地址
|
||||||
print("body is {}".format(body))
|
if len(mail.to_address) == 0:
|
||||||
print("subject is {}".format(subject))
|
if "outlook.com" in from_address or "hotmail.com" in from_address:
|
||||||
|
# 转发邮件
|
||||||
|
mail.to_address = extract_email_from_from_address(from_address)
|
||||||
|
else:
|
||||||
|
mail.to_address = self.login
|
||||||
|
|
||||||
# 设置收件人地址
|
mail_messages.append(mail)
|
||||||
if len(mail.to_address) == 0:
|
|
||||||
if "outlook.com" in from_address or "hotmail.com" in from_address:
|
|
||||||
# 转发邮件
|
|
||||||
mail.to_address = extract_email_from_from_address(from_address)
|
|
||||||
else:
|
|
||||||
mail.to_address = self.login
|
|
||||||
|
|
||||||
mail_messages.append(mail)
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print("Error trying to read email_Message for {}: {}".format(self.login, error))
|
print("Error trying to read email_Message for {}: {}".format(self.login, error))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user