[hotfix] pull emails from all incoming email accounts instead of enqueue single email account (#4199)

This commit is contained in:
Makarand Bauskar 2017-09-28 12:14:00 +05:30 committed by Nabin Hait
parent d0fd1482c4
commit 780df0be60
2 changed files with 30 additions and 17 deletions

View file

@ -685,27 +685,36 @@ def pull(now=False):
frappe.cache().set_value("workers:no-internet", False)
else:
return
queued_jobs = get_jobs(site=frappe.local.site, key='job_name')[frappe.local.site]
for email_account in frappe.get_list("Email Account",
filters={"enable_incoming": 1, "awaiting_password": 0}):
if now:
pull_from_email_account(email_account.name)
email_accounts = frappe.db.sql_list("""select name from `tabEmail Account` where
enable_incoming=1 and awaiting_password=0""")
else:
# job_name is used to prevent duplicates in queue
job_name = 'pull_from_email_account|{0}'.format(email_account.name)
# No incoming email account available
if not email_accounts:
return
if job_name not in queued_jobs:
enqueue(pull_from_email_account, 'short', event='all', job_name=job_name,
email_account=email_account.name)
if now:
pull_from_email_accounts(email_accounts)
else:
# job_name is used to prevent duplicates in queue
job_name = 'pull_from_email_accounts|{0}'.format(",".join(email_accounts))
def pull_from_email_account(email_account):
if job_name not in queued_jobs:
enqueue(pull_from_email_accounts, 'short', event='all', job_name=job_name,
email_accounts=email_accounts)
def pull_from_email_accounts(email_accounts):
'''Runs within a worker process'''
email_account = frappe.get_doc("Email Account", email_account)
email_account.receive()
if not email_accounts:
return
# mark Email Flag Queue mail as read
email_account.mark_emails_as_read_unread()
for email_account in email_accounts:
email_account = frappe.get_doc("Email Account", email_account)
email_account.receive()
# mark Email Flag Queue mail as read
email_account.mark_emails_as_read_unread()
def get_max_email_uid(email_account):
# get maximum uid of emails

View file

@ -47,7 +47,9 @@ def get_outgoing_email_account(raise_exception_not_set=True, append_to=None, sen
if not getattr(frappe.local, "outgoing_email_account", None):
frappe.local.outgoing_email_account = {}
if not frappe.local.outgoing_email_account.get(append_to or sender_email_id or "default"):
if not frappe.local.outgoing_email_account.get(append_to) \
or frappe.local.outgoing_email_account.get(sender_email_id) \
or frappe.local.outgoing_email_account.get("default"):
email_account = None
if append_to:
@ -77,7 +79,9 @@ def get_outgoing_email_account(raise_exception_not_set=True, append_to=None, sen
frappe.local.outgoing_email_account[append_to or sender_email_id or "default"] = email_account
return frappe.local.outgoing_email_account[append_to or sender_email_id or "default"]
return frappe.local.outgoing_email_account.get(append_to) \
or frappe.local.outgoing_email_account.get(sender_email_id) \
or frappe.local.outgoing_email_account.get("default")
def get_default_outgoing_email_account(raise_exception_not_set=True):
'''conf should be like: