correction on reading onet.pl emails

This commit is contained in:
2023-04-06 22:41:35 +02:00
parent 9c9f18c267
commit 0c722621bf
+22 -19
View File
@@ -71,21 +71,24 @@ class MailReader():
messages = imap.search(['SINCE', datetime.datetime.today()])
print("%d messages from our best friend" % len(messages))
for uid, message_data in imap.fetch(messages, 'RFC822').items():
email_message = email.message_from_bytes(message_data[b'RFC822'])
from_address = email_message.get('FROM')
subject = email_message.get('subject')
# print("{}, {},{}".format(from_address, subject, email_message))
body = ""
if "no-reply@hermes.com" in from_address:
for part in email_message.walk():
print(part.get_content_type())
if part.get_content_type() == "text/html":
body = body + part.get_payload()
elif part.get_content_type() == "text/plain":
body = body + part.get_payload()
if VALIDATION_URL_SUBJECT_fr in subject or VALIDATION_URL_SUBJECT_EN in subject:
mail = MailPojo(subject=subject, body=body, from_address=from_address)
mail_messages.append(mail)
try:
email_message = email.message_from_bytes(message_data[b'RFC822'])
from_address = email_message.get('FROM')
subject = email_message.get('subject')
# print("{}, {},{}".format(from_address, subject, email_message))
body = ""
if "no-reply@hermes.com" in from_address:
for part in email_message.walk():
print(part.get_content_type())
if part.get_content_type() == "text/html":
body = body + part.get_payload()
elif part.get_content_type() == "text/plain":
body = body + part.get_payload()
if VALIDATION_URL_SUBJECT_fr in subject or VALIDATION_URL_SUBJECT_EN in subject:
mail = MailPojo(subject=subject, body=body, from_address=from_address)
mail_messages.append(mail)
except Exception as error:
print("error trying to read email_Message for {}".format(self.login))
# for i in data[0].split():
# # fetch the email message by ID
# res, msg = imap.fetch(i, "(RFC822)")
@@ -171,10 +174,10 @@ def need_to_check_email(mail: str, successful_items) -> bool:
def read_mails():
# check time before start checking emails
if is_time_between(time(7, 30), time(20, 30)):
if is_time_between(time(7, 30), time(19, 30)):
# get email address
mail_list = MONGO_STORE_MANAGER.get_destination_emails()
# mail_address1 = MailAddress(mail="brasentuncau1973@onet.pl", password="Ex#Mhz9Fom6")
# mail_address1 = MailAddress(mail="enasremor1973@onet.pl", password=")ozBUE0RjZ8N")
# mail_address1 = MailAddress(mail="chenpeijun@aol.com", password="ytifuwguknzifqyb")
# # mail_address2 = MailAddress(mail="sdfgfhgf1986@aol.com", password="fjwcgvhxxlywqfwm")
# # mail_address3 = MailAddress(mail="ciyuexie@aol.com", password="czezlmmyypokdfce")
@@ -195,8 +198,8 @@ def read_mails():
for mail in mails_messages:
match = re.search(VALIDATION_URL_REGEX, mail.body.replace("\n", ""))
if match:
url_to_validate= match.group(0)
url = "https://rendezvousparis.hermes.com/"+url_to_validate
url_to_validate = match.group(0)
url = "https://rendezvousparis.hermes.com/" + url_to_validate
if need_to_valid_url(url, successful_items):
MONGO_STORE_MANAGER.save_links_to_validate(url)
# url_validator = LinkValidator(url)