diff --git a/src/mail/mail_confirmation.py b/src/mail/mail_confirmation.py index 8b630c2..e9f2ebb 100755 --- a/src/mail/mail_confirmation.py +++ b/src/mail/mail_confirmation.py @@ -6,14 +6,13 @@ from builtins import list from concurrent.futures import ThreadPoolExecutor from email.header import decode_header from email.message import Message + from imapclient import IMAPClient from src.db.mirgration.migration_tools import migre_accepted_appointment from src.db.mongo_manager import MONGO_STORE_MANAGER -from src.logs.AppLogging import init_logger from src.mail.mail_constants import create_imap, show_folders from src.notification.AcceptedResultPojo import get_accepted_result_from -from src.notification.SignalSender import SignalSender from src.notification.mailer import Mailer from src.pojo.ResultEnum import ResultEnum from src.pojo.mail.mail_pojo import MailPojo, MailAddress @@ -71,19 +70,19 @@ class MailConfirmationReader(): from_address = email_message.get('FROM') subject = email_message.get('subject') 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 + str(part.get_payload(decode=True).decode("utf-8")) - elif part.get_content_type() == "text/plain": - body = body + part.get_payload() - logger.info("mail is {} and subject is {}, body is {}".format(self.login, subject, body)) - if CONFIRMATION_SUBJECT_FR in subject or CONFIRMATION_SUBJECT_EN in subject or "Votre_rendez-vous_est_confirm" in subject: - mail = MailPojo(subject=subject, body=body, from_address=from_address) - mail.isImapClient = True - mail.mail_address = self.login - mail_messages.append(mail) + # 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 + str(part.get_payload(decode=True).decode("utf-8")) + elif part.get_content_type() == "text/plain": + body = body + part.get_payload() + logger.info("mail is {} and subject is {}, body is {}".format(self.login, subject, body)) + if CONFIRMATION_SUBJECT_FR in subject or CONFIRMATION_SUBJECT_EN in subject or "Votre_rendez-vous_est_confirm" in subject or "Votre rendez-vous est confirm" in body: + mail = MailPojo(subject=subject, body=body, from_address=from_address) + mail.isImapClient = True + mail.mail_address = self.login + mail_messages.append(mail) except Exception as error: print(error) print("error trying to read email_Message for {}".format(self.login)) @@ -155,7 +154,7 @@ def accept_appointment_found(accepted_result_list: list): for user in _all_register_account: if user.mail == result.email: result.account_password = user.password - mailer.send_email(result, to_all=True) + mailer.send_email(result, to_all=False) MONGO_STORE_MANAGER.update_reserve_result(reserve.id, ResultEnum.ACCEPTED, reserve.message) # sginal.send_result(result) @@ -172,14 +171,18 @@ def find_confirmation_contacts_for_today(): for _item in _all_appointments_today: for _mail in _all_mail_list: if _mail.mail == _item.mail: - # if _item.url_validated is True: - _mail_list_to_scan.append(_mail) + # do not need to scan outlook + if "outlook.com" not in _mail.mail: + # if _item.url_validated is True: + _mail_list_to_scan.append(_mail) break print("Found {} emails to scan".format(len(_mail_list_to_scan))) return _mail_list_to_scan def find_confirmation_contacts_mail_list(mail_list): + # mail_list = [MailAddress("saigecong1990@pissmail.com", "cvExXKOP8oY1D@")] + mail_list.append(MailAddress("saigecong1990@pissmail.com", "cvExXKOP8oY1D@")) mails_messages = [] # read all the emails with ThreadPoolExecutor(max_workers=200) as executor: