try to use proxy for gmx mail
This commit is contained in:
+37
-3
@@ -1,6 +1,8 @@
|
||||
import datetime
|
||||
import email
|
||||
import re
|
||||
import os
|
||||
from typing import Optional
|
||||
from builtins import list
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from datetime import time
|
||||
@@ -11,7 +13,8 @@ from imapclient import IMAPClient
|
||||
|
||||
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.mail.mail_constants import create_imap, show_folders, is_gmx_address
|
||||
from src.mail.imap_proxy_reader import ProxyMailReader, ProxyConfig, MailAccount
|
||||
from src.pojo.mail.mail_pojo import MailPojo
|
||||
from src.utils.timeutiles import is_time_between
|
||||
|
||||
@@ -51,6 +54,33 @@ def find_from_mail(param):
|
||||
return from_address.strip(" ").strip(">").strip("<")
|
||||
|
||||
|
||||
def get_gmx_proxy_config() -> Optional[ProxyConfig]:
|
||||
host = os.environ.get("GMX_PROXY_HOST", "")
|
||||
if not host:
|
||||
return None
|
||||
try:
|
||||
port = int(os.environ.get("GMX_PROXY_PORT", "443"))
|
||||
except ValueError:
|
||||
port = 443
|
||||
return ProxyConfig(
|
||||
host=host,
|
||||
port=port,
|
||||
proxy_type=os.environ.get("GMX_PROXY_TYPE", "SOCKS5"),
|
||||
username=os.environ.get("GMX_PROXY_USERNAME"),
|
||||
password=os.environ.get("GMX_PROXY_PASSWORD"),
|
||||
)
|
||||
|
||||
|
||||
def read_gmx_proxy_emails(mail, mails_messages: list, proxy_config: ProxyConfig) -> None:
|
||||
account = MailAccount(login=mail.mail, password=mail.password)
|
||||
results = ProxyMailReader(account, proxy_config).read(since=datetime.datetime.today())
|
||||
for result in results:
|
||||
mail_pojo = MailPojo(subject=result.subject, body=result.body, from_address=result.from_address)
|
||||
mail_pojo.mail_address = mail.mail
|
||||
mail_pojo.to_address = result.to_address or mail.mail
|
||||
mails_messages.append(mail_pojo)
|
||||
|
||||
|
||||
class MailReader():
|
||||
def __init__(self, login, password):
|
||||
self.login = login
|
||||
@@ -241,6 +271,7 @@ def read_mails():
|
||||
if is_time_between(time(7, 30), time(23, 30)):
|
||||
# get email address
|
||||
mail_list = MONGO_STORE_MANAGER.get_destination_emails()
|
||||
gmx_proxy_config = get_gmx_proxy_config()
|
||||
# excel_reader = ExcelHelper()
|
||||
# mail_list = excel_reader.read_email_pojo(file_name="/Users/panlei/Downloads/hotmail_list.xlsx")
|
||||
# mail_address1 = MailAddress(mail="casandrakaamv@onet.pl", password="8F0o0APeAp0z")
|
||||
@@ -251,8 +282,11 @@ def read_mails():
|
||||
for mail in mail_list:
|
||||
# check whether we need to read mail
|
||||
if need_to_check_email(mail.mail, successful_items):
|
||||
mail_reader = MailReader(mail.mail, mail.password)
|
||||
executor.submit(mail_reader.read_emails, mails_messages)
|
||||
if is_gmx_address(mail.mail) and gmx_proxy_config is not None:
|
||||
executor.submit(read_gmx_proxy_emails, mail, mails_messages, gmx_proxy_config)
|
||||
else:
|
||||
mail_reader = MailReader(mail.mail, mail.password)
|
||||
executor.submit(mail_reader.read_emails, mails_messages)
|
||||
# get ip_country info
|
||||
_refreshed_successful_items = MONGO_STORE_MANAGER.get_all_successful_items_for_day()
|
||||
_all_contact_list = MONGO_STORE_MANAGER.get_all_contacts_to_book()
|
||||
|
||||
Reference in New Issue
Block a user