try to correct the probleme of multi emails
This commit is contained in:
+36
-6
@@ -20,11 +20,37 @@ VALIDATION_URL_SUBJECT_EN = 'Please confirm your appointment request'
|
||||
VALIDATION_URL_REGEX = """https:\/\/rendezvousparis.hermes.com\/client\/register\/[A-Z0-9]+\/validate.code=[A-Z0-9]+"""
|
||||
PART_VALIDATION_URL_REGEX = """client\/register\/[A-Z0-9]+\/validate.code=[A-Z0-9]+"""
|
||||
HERMES_EMAIL = "no-reply@hermes.com"
|
||||
EMAIL_ADDRESS_REGEX = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b'
|
||||
|
||||
date_format = "%d-%b-%Y" # DD-Mon-YYYY e.g., 3-Mar-2014
|
||||
REDIRECTION_MAILS = "appointment2022@aol.com, chenpeijun@aol.com,hongjiang176@aol.com,ciyuexie@aol.com"
|
||||
|
||||
|
||||
def check_email_address(email):
|
||||
# pass the regular expression
|
||||
# and the string into the fullmatch() method
|
||||
if (re.fullmatch(EMAIL_ADDRESS_REGEX, email)):
|
||||
print("Valid Email")
|
||||
return True
|
||||
else:
|
||||
print("Invalid Email")
|
||||
return False
|
||||
|
||||
|
||||
def find_from_mail(param):
|
||||
from_address, encoded_algo = param[0]
|
||||
if isinstance(from_address, bytes):
|
||||
from_address = from_address.decode(encoded_algo)
|
||||
if not check_email_address(from_address) and len(param) == 2:
|
||||
from_address, new_encode = param[1]
|
||||
if new_encode is None:
|
||||
new_encode = encoded_algo
|
||||
if isinstance(from_address, bytes):
|
||||
from_address = from_address.decode(new_encode)
|
||||
return from_address.strip(" ").strip(">").strip("<")
|
||||
return from_address.strip(" ").strip(">").strip("<")
|
||||
|
||||
|
||||
class MailReader():
|
||||
def __init__(self, login, password):
|
||||
self.login = login
|
||||
@@ -92,11 +118,11 @@ class MailReader():
|
||||
# if it's a bytes, decode to str
|
||||
subject = subject.decode(subject_encoded)
|
||||
# decode email sender
|
||||
from_address, subject_encoded = decode_header(msg.get("From"))[0]
|
||||
if isinstance(from_address, bytes):
|
||||
from_address = from_address.decode(subject_encoded)
|
||||
from_address = find_from_mail(decode_header(msg.get("From")))
|
||||
to_email = find_from_mail(decode_header(msg.get("To")))
|
||||
print("Email:", self.login)
|
||||
print("From:", from_address)
|
||||
print("To:", to_email)
|
||||
print("Subject:", subject)
|
||||
# if the email message is multipart
|
||||
if msg.is_multipart():
|
||||
@@ -117,6 +143,10 @@ class MailReader():
|
||||
print(body)
|
||||
if VALIDATION_URL_SUBJECT_fr in subject or VALIDATION_URL_SUBJECT_EN in subject:
|
||||
mail = MailPojo(subject=subject, body=body, from_address=from_address)
|
||||
if to_email is None:
|
||||
mail.to_address = self.login
|
||||
else:
|
||||
mail.to_address = to_email
|
||||
mail.mail_address = self.login
|
||||
mail_messages.append(mail)
|
||||
return mail_messages
|
||||
@@ -158,7 +188,7 @@ class MailReader():
|
||||
|
||||
|
||||
def need_to_valid_url(url: str, successful_items) -> bool:
|
||||
# return True
|
||||
return True
|
||||
if len(successful_items) == 0:
|
||||
return False
|
||||
print("url is :" + url)
|
||||
@@ -214,7 +244,7 @@ def read_mails():
|
||||
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="Saniremvazhaun@yahoo.com", password="hxwgldifdnuacoyr")
|
||||
# mail_address1 = MailAddress(mail="appointment2022@aol.com", password="gyilpmvyyvlcaviq")
|
||||
# mail_address1 = MailAddress(mail="chenpeijun@aol.com", password="ytifuwguknzifqyb")
|
||||
# # mail_address3 = MailAddress(mail="ciyuexie@aol.com", password="czezlmmyypokdfce")
|
||||
# mail_list = [mail_address1]
|
||||
@@ -240,7 +270,7 @@ def read_mails():
|
||||
# else:
|
||||
url = match.group(0)
|
||||
if need_to_valid_url(url, successful_items):
|
||||
MONGO_STORE_MANAGER.save_links_to_validate(url, mail.mail_address)
|
||||
MONGO_STORE_MANAGER.save_links_to_validate(url, mail.to_address)
|
||||
# url_validator = LinkValidator(url)
|
||||
print("need to validate url: " + url)
|
||||
# executor.submit(url_validator.start_page, params.get_proxy(ProxyType.OXYLABS), False)
|
||||
|
||||
Reference in New Issue
Block a user