Przeglądaj źródła

refactor: code cleanup

version-14
kamaljohnson 3 lat temu
rodzic
commit
cb25d894b4
3 zmienionych plików z 11 dodań i 8 usunięć
  1. +5
    -5
      frappe/email/doctype/email_account/email_account.py
  2. +4
    -2
      frappe/email/doctype/email_account/test_email_account.py
  3. +2
    -1
      frappe/tests/test_email.py

+ 5
- 5
frappe/email/doctype/email_account/email_account.py Wyświetl plik

@@ -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))



+ 4
- 2
frappe/email/doctype/email_account/test_email_account.py Wyświetl plik

@@ -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',


+ 2
- 1
frappe/tests/test_email.py Wyświetl plik

@@ -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()
],


Ładowanie…
Anuluj
Zapisz