diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py
index eea2dfc73e..6ee106bb12 100755
--- a/frappe/email/doctype/email_account/email_account.py
+++ b/frappe/email/doctype/email_account/email_account.py
@@ -19,7 +19,7 @@ from frappe.utils import (validate_email_address, cint, cstr, get_datetime,
from frappe.utils.user import is_system_user
from frappe.utils.jinja import render_template
from frappe.email.smtp import SMTPServer
-from frappe.email.receive import EmailServer, Email, InboundMail, SentEmailInInboxError
+from frappe.email.receive import EmailServer, InboundMail, SentEmailInInboxError
from poplib import error_proto
from dateutil.relativedelta import relativedelta
from datetime import datetime, timedelta
@@ -469,12 +469,12 @@ class EmailAccount(Document):
"""retrive and return inbound mails.
"""
- if not self.enable_incoming:
- return []
-
if frappe.local.flags.in_test:
return [InboundMail(msg, self) for msg in test_mails or []]
+ if not self.enable_incoming:
+ return []
+
email_sync_rule = self.build_email_sync_rule()
try:
email_server = self.get_incoming_server(in_receive=True, email_sync_rule=email_sync_rule)
diff --git a/frappe/email/doctype/email_account/test_email_account.py b/frappe/email/doctype/email_account/test_email_account.py
index 7bf49593f4..35cacac45a 100644
--- a/frappe/email/doctype/email_account/test_email_account.py
+++ b/frappe/email/doctype/email_account/test_email_account.py
@@ -1,23 +1,23 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
-from __future__ import unicode_literals
-from frappe.core.doctype import communication
-from frappe.core.doctype.communication.communication import Communication
+import os
+import email
+import unittest
+from datetime import datetime, timedelta
+
from frappe.email.receive import InboundMail, SentEmailInInboxError, Email
from frappe.email.email_body import get_message_id
-import frappe, os
-import unittest, email
-
+import frappe
from frappe.test_runner import make_test_records
+from frappe.core.doctype.communication.email import make
+from frappe.desk.form.load import get_attachments
+from frappe.email.doctype.email_account.email_account import notify_unreplied
make_test_records("User")
make_test_records("Email Account")
-from frappe.core.doctype.communication.email import make
-from frappe.desk.form.load import get_attachments
-from frappe.email.doctype.email_account.email_account import notify_unreplied
-from datetime import datetime, timedelta
+
class TestEmailAccount(unittest.TestCase):
@classmethod
@@ -240,7 +240,7 @@ class TestInboundMail(unittest.TestCase):
email_account = frappe.get_doc("Email Account", "_Test Email Account 1")
email_account.db_set("enable_incoming", 0)
- def tearDown(self):
+ def setUp(self):
cleanup()
frappe.db.sql('delete from `tabEmail Queue`')
frappe.db.sql('delete from `tabToDo`')
diff --git a/frappe/email/receive.py b/frappe/email/receive.py
index 52b9110ddb..7b3623df21 100644
--- a/frappe/email/receive.py
+++ b/frappe/email/receive.py
@@ -821,7 +821,6 @@ class InboundMail(Email):
@staticmethod
def get_doc(doctype, docname, ignore_error=False):
try:
- print(doctype, docname)
return frappe.get_doc(doctype, docname)
except frappe.DoesNotExistError:
if ignore_error:
@@ -862,7 +861,6 @@ class InboundMail(Email):
for field in email_fields:
if hasattr(meta, field):
fields[field] = getattr(meta, field)
- print("FIELDS::::", fields)
return fields
@staticmethod
diff --git a/frappe/tests/test_email.py b/frappe/tests/test_email.py
index ff7e6d534c..a37d1a519c 100644
--- a/frappe/tests/test_email.py
+++ b/frappe/tests/test_email.py
@@ -1,8 +1,6 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
-from __future__ import unicode_literals
-
import unittest, frappe, re, email
from six import PY3
@@ -176,7 +174,8 @@ class TestEmail(unittest.TestCase):
frappe.db.sql('''delete from `tabCommunication` where sender = 'sukh@yyy.com' ''')
with open(frappe.get_app_path('frappe', 'tests', 'data', 'email_with_image.txt'), 'r') as raw:
- communication = email_account.insert_communication(raw.read())
+ mails = email_account.get_inbound_mails(test_mails=[raw.read()])
+ communication = mails[0].process()
self.assertTrue(re.search('''
]*src=["']/private/files/rtco1.png[^>]*>''', communication.content))
self.assertTrue(re.search('''
]*src=["']/private/files/rtco2.png[^>]*>''', communication.content))