@@ -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.user import is_system_user | ||||
from frappe.utils.jinja import render_template | from frappe.utils.jinja import render_template | ||||
from frappe.email.smtp import SMTPServer | 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 poplib import error_proto | ||||
from dateutil.relativedelta import relativedelta | from dateutil.relativedelta import relativedelta | ||||
from datetime import datetime, timedelta | from datetime import datetime, timedelta | ||||
@@ -469,12 +469,12 @@ class EmailAccount(Document): | |||||
"""retrive and return inbound mails. | """retrive and return inbound mails. | ||||
""" | """ | ||||
if not self.enable_incoming: | |||||
return [] | |||||
if frappe.local.flags.in_test: | if frappe.local.flags.in_test: | ||||
return [InboundMail(msg, self) for msg in test_mails or []] | return [InboundMail(msg, self) for msg in test_mails or []] | ||||
if not self.enable_incoming: | |||||
return [] | |||||
email_sync_rule = self.build_email_sync_rule() | email_sync_rule = self.build_email_sync_rule() | ||||
try: | try: | ||||
email_server = self.get_incoming_server(in_receive=True, email_sync_rule=email_sync_rule) | email_server = self.get_incoming_server(in_receive=True, email_sync_rule=email_sync_rule) | ||||
@@ -1,23 +1,23 @@ | |||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors | ||||
# See license.txt | # 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.receive import InboundMail, SentEmailInInboxError, Email | ||||
from frappe.email.email_body import get_message_id | 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.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("User") | ||||
make_test_records("Email Account") | 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): | class TestEmailAccount(unittest.TestCase): | ||||
@classmethod | @classmethod | ||||
@@ -240,7 +240,7 @@ class TestInboundMail(unittest.TestCase): | |||||
email_account = frappe.get_doc("Email Account", "_Test Email Account 1") | email_account = frappe.get_doc("Email Account", "_Test Email Account 1") | ||||
email_account.db_set("enable_incoming", 0) | email_account.db_set("enable_incoming", 0) | ||||
def tearDown(self): | |||||
def setUp(self): | |||||
cleanup() | cleanup() | ||||
frappe.db.sql('delete from `tabEmail Queue`') | frappe.db.sql('delete from `tabEmail Queue`') | ||||
frappe.db.sql('delete from `tabToDo`') | frappe.db.sql('delete from `tabToDo`') | ||||
@@ -821,7 +821,6 @@ class InboundMail(Email): | |||||
@staticmethod | @staticmethod | ||||
def get_doc(doctype, docname, ignore_error=False): | def get_doc(doctype, docname, ignore_error=False): | ||||
try: | try: | ||||
print(doctype, docname) | |||||
return frappe.get_doc(doctype, docname) | return frappe.get_doc(doctype, docname) | ||||
except frappe.DoesNotExistError: | except frappe.DoesNotExistError: | ||||
if ignore_error: | if ignore_error: | ||||
@@ -862,7 +861,6 @@ class InboundMail(Email): | |||||
for field in email_fields: | for field in email_fields: | ||||
if hasattr(meta, field): | if hasattr(meta, field): | ||||
fields[field] = getattr(meta, field) | fields[field] = getattr(meta, field) | ||||
print("FIELDS::::", fields) | |||||
return fields | return fields | ||||
@staticmethod | @staticmethod | ||||
@@ -1,8 +1,6 @@ | |||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors | ||||
# MIT License. See license.txt | # MIT License. See license.txt | ||||
from __future__ import unicode_literals | |||||
import unittest, frappe, re, email | import unittest, frappe, re, email | ||||
from six import PY3 | from six import PY3 | ||||
@@ -176,7 +174,8 @@ class TestEmail(unittest.TestCase): | |||||
frappe.db.sql('''delete from `tabCommunication` where sender = 'sukh@yyy.com' ''') | 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: | 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('''<img[^>]*src=["']/private/files/rtco1.png[^>]*>''', communication.content)) | self.assertTrue(re.search('''<img[^>]*src=["']/private/files/rtco1.png[^>]*>''', communication.content)) | ||||
self.assertTrue(re.search('''<img[^>]*src=["']/private/files/rtco2.png[^>]*>''', communication.content)) | self.assertTrue(re.search('''<img[^>]*src=["']/private/files/rtco2.png[^>]*>''', communication.content)) | ||||