use utf-8 to decode pl emails

This commit is contained in:
2023-04-07 22:36:29 +02:00
parent 8454e6f2e8
commit 49246d5f03
+15 -13
View File
@@ -141,13 +141,15 @@ class MailReader():
for part in email_message.walk(): for part in email_message.walk():
print(part.get_content_type()) print(part.get_content_type())
if part.get_content_type() == "text/html": if part.get_content_type() == "text/html":
body = body + part.get_payload() body = body + part.get_payload(decode=True).decode("utf-8")
elif part.get_content_type() == "text/plain": elif part.get_content_type() == "text/plain":
body = body + part.get_payload() body = body + part.get_payload()
if VALIDATION_URL_SUBJECT_fr in subject or VALIDATION_URL_SUBJECT_EN in subject: 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 = MailPojo(subject=subject, body=body, from_address=from_address)
mail.isImapClient = True mail.isImapClient = True
print("email is {}".format(self.login))
print("body is {}".format(body)) print("body is {}".format(body))
print("subject is {}".format(subject))
mail_messages.append(mail) mail_messages.append(mail)
except Exception as error: except Exception as error:
print(error) print(error)
@@ -196,17 +198,17 @@ def need_to_check_email(mail: str, successful_items) -> bool:
def read_mails(): def read_mails():
# check time before start checking emails # check time before start checking emails
if is_time_between(time(7, 30), time(19, 30)): if is_time_between(time(7, 30), time(23, 30)):
# get email address # get email address
mail_list = MONGO_STORE_MANAGER.get_destination_emails() # mail_list = MONGO_STORE_MANAGER.get_destination_emails()
# mail_address1 = MailAddress(mail="enasremor1973@onet.pl", password=")ozBUE0RjZ8N") mail_address1 = MailAddress(mail="enasremor1973@onet.pl", password=")ozBUE0RjZ8N")
# mail_address1 = MailAddress(mail="chenpeijun@aol.com", password="ytifuwguknzifqyb") # mail_address1 = MailAddress(mail="chenpeijun@aol.com", password="ytifuwguknzifqyb")
# # mail_address2 = MailAddress(mail="sdfgfhgf1986@aol.com", password="fjwcgvhxxlywqfwm") # # mail_address2 = MailAddress(mail="sdfgfhgf1986@aol.com", password="fjwcgvhxxlywqfwm")
# # mail_address3 = MailAddress(mail="ciyuexie@aol.com", password="czezlmmyypokdfce") # # mail_address3 = MailAddress(mail="ciyuexie@aol.com", password="czezlmmyypokdfce")
# # mail_address4 = MailAddress(mail="hongjiang176@aol.com", password="ftzpscgzvwneelmn") # # mail_address4 = MailAddress(mail="hongjiang176@aol.com", password="ftzpscgzvwneelmn")
# mail_address4 = MailAddress(mail="ryan_meacham2856@yahoo.com", password="ulgggkodxqbvrpgm") # mail_address4 = MailAddress(mail="ryan_meacham2856@yahoo.com", password="ulgggkodxqbvrpgm")
# mail_list = [mail_address3, mail_address2, mail_address1, mail_address4] # mail_list = [mail_address3, mail_address2, mail_address1, mail_address4]
# mail_list = [mail_address1] mail_list = [mail_address1]
successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day() successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
mails_messages = [] mails_messages = []
with ThreadPoolExecutor(max_workers=200) as executor: with ThreadPoolExecutor(max_workers=200) as executor:
@@ -218,16 +220,16 @@ def read_mails():
with ThreadPoolExecutor(max_workers=10) as executor: with ThreadPoolExecutor(max_workers=10) as executor:
for mail in mails_messages: for mail in mails_messages:
if mail.isImapClient: # if mail.isImapClient:
match = re.search(PART_VALIDATION_URL_REGEX, mail.body.replace("\n", "")) # match = re.search(PART_VALIDATION_URL_REGEX, mail.body.replace("\n", ""))
else: # else:
match = re.search(VALIDATION_URL_REGEX, mail.body) match = re.search(VALIDATION_URL_REGEX, mail.body)
if match: if match:
url_to_validate = match.group(0) url_to_validate = match.group(0)
if mail.isImapClient: # if mail.isImapClient:
url = "https://rendezvousparis.hermes.com/" + url_to_validate.replace("3D", "") # url = "https://rendezvousparis.hermes.com/" + url_to_validate.replace("3D", "")
else: # else:
url = match.group(0) url = match.group(0)
if need_to_valid_url(url, successful_items): if need_to_valid_url(url, successful_items):
MONGO_STORE_MANAGER.save_links_to_validate(url) MONGO_STORE_MANAGER.save_links_to_validate(url)
# url_validator = LinkValidator(url) # url_validator = LinkValidator(url)