try to correct the probleme of multi emails

This commit is contained in:
2023-04-19 20:13:53 +02:00
parent 7bbdf6ca9c
commit 83b6c91f80
4 changed files with 44 additions and 10 deletions
+5 -3
View File
@@ -175,13 +175,15 @@ def read_mails_and_find_confirmation_contacts():
for mail in mails_messages:
message_body = mail.body
for item in successful_items:
if item.id in message_body and item.id != "welcome":
if item.id in message_body and item.id != "welcome" and len(item.id) > 0:
item.message = message_body
accepted_appointment_list.append(item)
elif "10:30" in message_body and (item.email == mail.mail_address or item.email in message_body):
elif "10:30" in message_body and (
item.email == mail.mail_address or item.email in message_body) and len(item.id) > 0:
item.message = message_body
accepted_appointment_list.append(item)
elif "11:30" in message_body and (item.email == mail.mail_address or item.email in message_body):
elif "11:30" in message_body and (
item.email == mail.mail_address or item.email in message_body) and len(item.id) > 0:
item.message = message_body
accepted_appointment_list.append(item)
print(mail.mail_address)
+36 -6
View File
@@ -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)
+2
View File
@@ -22,6 +22,7 @@ class MailAddress:
class MailPojo:
from_address: str
to_address: str
body: str
subject: str
mail_address: str = ""
@@ -32,3 +33,4 @@ class MailPojo:
self.subject = subject
self.from_address = from_address
self.isImapClient = False
self.to_address = ""
+1 -1
View File
@@ -90,7 +90,7 @@ def write_new_contacts_to_excel(valid_contacts: list):
if __name__ == '__main__':
db_manager = MongoDbManager()
mail_list = db_manager.get_destination_emails()[301:500]
mail_list = db_manager.get_destination_emails()[501:1000]
# mail_list = db_manager.get_destination_emails()[50:200]
generate_contacts = []
for mail in mail_list: