diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py index f20a25f88f..3a1b683398 100755 --- a/frappe/email/doctype/email_account/email_account.py +++ b/frappe/email/doctype/email_account/email_account.py @@ -421,10 +421,10 @@ class EmailAccount(Document): def get_failed_attempts_count(self): return cint(frappe.cache().get('{0}:email-account-failed-attempts'.format(self.name))) - def receive(self, test_mails=None): + def receive(self): """Called by scheduler to receive emails from this EMail account using POP3/IMAP.""" exceptions = [] - inbound_mails = self.get_inbound_mails(test_mails=test_mails) + inbound_mails = self.get_inbound_mails() for mail in inbound_mails: try: communication = mail.process() @@ -457,7 +457,7 @@ class EmailAccount(Document): if exceptions: raise Exception(frappe.as_json(exceptions)) - def get_inbound_mails(self, test_mails=None) -> List[InboundMail]: + def get_inbound_mails(self) -> List[InboundMail]: """retrive and return inbound mails. """ @@ -466,8 +466,8 @@ class EmailAccount(Document): def process_mail(messages, append_to=None): for index, message in enumerate(messages.get("latest_messages", [])): uid = messages['uid_list'][index] if messages.get('uid_list') else None - seen_status = 1 if messages.get('seen_status', {}).get(uid) == 'SEEN' else 0 - if not (self.email_sync_option == 'UNSEEN' and seen_status): + seen_status = messages.get('seen_status', {}).get(uid) + if self.email_sync_option != 'UNSEEN' or seen_status != "SEEN": # only append the emails with status != 'SEEN' if sync option is set to 'UNSEEN' mails.append(InboundMail(message, self, uid, seen_status, append_to)) diff --git a/frappe/email/doctype/email_account/test_email_account.py b/frappe/email/doctype/email_account/test_email_account.py index c0ce177f4b..f609c2947d 100644 --- a/frappe/email/doctype/email_account/test_email_account.py +++ b/frappe/email/doctype/email_account/test_email_account.py @@ -195,7 +195,8 @@ class TestEmailAccount(unittest.TestCase): # parse reply messages = { - '"INBOX"': { # append_to = ToDo + # append_to = ToDo + '"INBOX"': { 'latest_messages': [ raw ], @@ -226,7 +227,8 @@ class TestEmailAccount(unittest.TestCase): # parse reply messages = { - '"INBOX"': { # append_to = ToDo + # append_to = ToDo + '"INBOX"': { 'latest_messages': test_mails, 'seen_status': { 2: 'UNSEEN', diff --git a/frappe/tests/test_email.py b/frappe/tests/test_email.py index 34c401b7b0..ad9f8fdd11 100644 --- a/frappe/tests/test_email.py +++ b/frappe/tests/test_email.py @@ -176,7 +176,8 @@ class TestEmail(unittest.TestCase): with open(frappe.get_app_path('frappe', 'tests', 'data', 'email_with_image.txt'), 'r') as raw: messages = { - '"INBOX"': { # append_to = ToDo + # append_to = ToDo + '"INBOX"': { 'latest_messages': [ raw.read() ],