can read sina mails
This commit is contained in:
@@ -42,13 +42,14 @@ def show_folders(imap) -> list:
|
|||||||
def create_imap(login: str):
|
def create_imap(login: str):
|
||||||
# create an IMAP4 class with SSL
|
# create an IMAP4 class with SSL
|
||||||
if DOMAIN_163 in login:
|
if DOMAIN_163 in login:
|
||||||
imap = imaplib.IMAP4_SSL(IMAP_SERVER_163)
|
imap = IMAPClient(IMAP_SERVER_163, use_uid=True)
|
||||||
elif DOMAIN_YAHOO in login:
|
elif DOMAIN_YAHOO in login:
|
||||||
imap = imaplib.IMAP4_SSL(YAHOO_IMAP_SERVER)
|
imap = imaplib.IMAP4_SSL(YAHOO_IMAP_SERVER)
|
||||||
elif DOMAIN_GMX in login:
|
elif DOMAIN_GMX in login:
|
||||||
imap = imaplib.IMAP4_SSL(SERVER_GMX)
|
imap = imaplib.IMAP4_SSL(SERVER_GMX)
|
||||||
elif DOMAIN_SINA in login:
|
elif DOMAIN_SINA in login:
|
||||||
imap = imaplib.IMAP4_SSL(IMAP_SERVER_SINA)
|
# imap = imaplib.IMAP4_SSL(IMAP_SERVER_SINA)
|
||||||
|
imap = IMAPClient(IMAP_SERVER_SINA, use_uid=True)
|
||||||
elif DOMAIN_HOTMAIL in login:
|
elif DOMAIN_HOTMAIL in login:
|
||||||
imap = imaplib.IMAP4_SSL(HOTMAIL_IMAP_SERVER)
|
imap = imaplib.IMAP4_SSL(HOTMAIL_IMAP_SERVER)
|
||||||
elif DOMAIN_RAMBLER_RU in login:
|
elif DOMAIN_RAMBLER_RU in login:
|
||||||
|
|||||||
+25
-16
@@ -13,9 +13,7 @@ from src.db.mongo_manager import MONGO_STORE_MANAGER
|
|||||||
from src.logs.AppLogging import init_logger
|
from src.logs.AppLogging import init_logger
|
||||||
from src.mail.mail_constants import DOMAIN_HOTMAIL, create_imap
|
from src.mail.mail_constants import DOMAIN_HOTMAIL, create_imap
|
||||||
from src.pojo.mail.mail_pojo import MailPojo, MailAddress
|
from src.pojo.mail.mail_pojo import MailPojo, MailAddress
|
||||||
from src.utils.excel_reader import ExcelHelper
|
|
||||||
from src.utils.timeutiles import is_time_between
|
from src.utils.timeutiles import is_time_between
|
||||||
from src.workers.link_validator import LinkValidator
|
|
||||||
|
|
||||||
VALIDATION_URL_SUBJECT_fr = 'Validation de votre demande de rendez-vous'
|
VALIDATION_URL_SUBJECT_fr = 'Validation de votre demande de rendez-vous'
|
||||||
VALIDATION_URL_SUBJECT_EN = 'Please confirm your appointment request'
|
VALIDATION_URL_SUBJECT_EN = 'Please confirm your appointment request'
|
||||||
@@ -60,10 +58,18 @@ class MailReader():
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def show_folders(imap) -> list:
|
def show_folders(imap) -> list:
|
||||||
folders = []
|
folders = []
|
||||||
for i in imap.list()[1]:
|
isImapClient = isinstance(imap, IMAPClient)
|
||||||
l = i.decode().split(' "/" ')
|
if not isImapClient:
|
||||||
folders.append(l[1])
|
for i in imap.list()[1]:
|
||||||
return folders
|
l = i.decode().split(' "/" ')
|
||||||
|
folders.append(l[1])
|
||||||
|
return folders
|
||||||
|
else:
|
||||||
|
list = imap.list_folders()
|
||||||
|
for i in list:
|
||||||
|
name = i[-1]
|
||||||
|
folders.append(name)
|
||||||
|
return folders
|
||||||
|
|
||||||
def read_emails(self, mails_messages: list) -> list:
|
def read_emails(self, mails_messages: list) -> list:
|
||||||
imap = create_imap(self.login)
|
imap = create_imap(self.login)
|
||||||
@@ -88,10 +94,13 @@ class MailReader():
|
|||||||
mail_list.extend(self._get_messages_from_folder(imap, subject=VALIDATION_URL_SUBJECT_EN,
|
mail_list.extend(self._get_messages_from_folder(imap, subject=VALIDATION_URL_SUBJECT_EN,
|
||||||
folder=folder))
|
folder=folder))
|
||||||
else:
|
else:
|
||||||
mail_list.extend(self._get_messages_from_folder_for_imapclient(imap))
|
folder_list = self.show_folders(imap)
|
||||||
# if DOMAIN_HOTMAIL in self.login:
|
for folder in folder_list:
|
||||||
# mail_list.extend(
|
print("folder is " + folder)
|
||||||
# self._get_messages_from_folder_for_imapclient(imap, folder="Junk"))
|
mail_list.extend(self._get_messages_from_folder_for_imapclient(imap, folder=folder))
|
||||||
|
if DOMAIN_HOTMAIL in self.login:
|
||||||
|
mail_list.extend(
|
||||||
|
self._get_messages_from_folder_for_imapclient(imap, folder="Junk"))
|
||||||
if not isImapClient:
|
if not isImapClient:
|
||||||
imap.close()
|
imap.close()
|
||||||
imap.logout()
|
imap.logout()
|
||||||
@@ -168,7 +177,7 @@ class MailReader():
|
|||||||
subject = email_message.get('subject')
|
subject = email_message.get('subject')
|
||||||
# print("{}, {},{}".format(from_address, subject, email_message))
|
# print("{}, {},{}".format(from_address, subject, email_message))
|
||||||
body = ""
|
body = ""
|
||||||
if "no-reply@hermes.com" in from_address:
|
if "no-reply@hermes.com" in from_address or "appointment2022@aol.com":
|
||||||
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":
|
||||||
@@ -189,7 +198,7 @@ class MailReader():
|
|||||||
|
|
||||||
|
|
||||||
def need_to_valid_url(url: str, successful_items) -> bool:
|
def need_to_valid_url(url: str, successful_items) -> bool:
|
||||||
# return True
|
return True
|
||||||
if len(successful_items) == 0:
|
if len(successful_items) == 0:
|
||||||
return False
|
return False
|
||||||
print("url is :" + url)
|
print("url is :" + url)
|
||||||
@@ -221,7 +230,9 @@ def need_to_check_email(mail: str, successful_items) -> bool:
|
|||||||
if mail == "lakrishstarko@aol.com":
|
if mail == "lakrishstarko@aol.com":
|
||||||
print("found")
|
print("found")
|
||||||
if len(filtered_items) > 0:
|
if len(filtered_items) > 0:
|
||||||
validated_items = list(filter(lambda filtered_item: filtered_item.url_validated is not None and filtered_item.url_validated is True, filtered_items))
|
validated_items = list(filter(
|
||||||
|
lambda filtered_item: filtered_item.url_validated is not None and filtered_item.url_validated is True,
|
||||||
|
filtered_items))
|
||||||
if len(validated_items) > 0:
|
if len(validated_items) > 0:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
@@ -247,10 +258,8 @@ def read_mails():
|
|||||||
if is_time_between(time(7, 30), time(19, 30)):
|
if is_time_between(time(7, 30), time(19, 30)):
|
||||||
# get email address
|
# get email address
|
||||||
mail_list = MONGO_STORE_MANAGER.get_destination_emails()
|
mail_list = MONGO_STORE_MANAGER.get_destination_emails()
|
||||||
# excel_reader = ExcelHelper()
|
|
||||||
# mail_list =excel_reader.read_email_pojo(file_name="/Users/lpan/Desktop/hotmail_list.xlsx")
|
|
||||||
# mail_address1 = MailAddress(mail="appointment2022@aol.com", password="gyilpmvyyvlcaviq")
|
# mail_address1 = MailAddress(mail="appointment2022@aol.com", password="gyilpmvyyvlcaviq")
|
||||||
# mail_address1 = MailAddress(mail="sayedyepesv@hotmail.com", password="JGc1UH41")
|
# mail_address1 = MailAddress(mail="chenpeijun@aol.com", password="ytifuwguknzifqyb")
|
||||||
# # mail_address3 = MailAddress(mail="ciyuexie@aol.com", password="czezlmmyypokdfce")
|
# # mail_address3 = MailAddress(mail="ciyuexie@aol.com", password="czezlmmyypokdfce")
|
||||||
# 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()
|
||||||
|
|||||||
Reference in New Issue
Block a user