From d7bb903212513b6e301e873d4aca196daee674a9 Mon Sep 17 00:00:00 2001
From: chillaranand
Date: Tue, 12 Jul 2022 19:28:11 +0530
Subject: [PATCH] refactor: Removed parse package
---
.../doctype/communication/communication.py | 12 ++++++----
.../communication/test_communication.py | 23 +++++++++++++++++--
pyproject.toml | 1 -
3 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/frappe/core/doctype/communication/communication.py b/frappe/core/doctype/communication/communication.py
index fac8ac74b9..c049ccff45 100644
--- a/frappe/core/doctype/communication/communication.py
+++ b/frappe/core/doctype/communication/communication.py
@@ -5,7 +5,7 @@ from collections import Counter
from email.utils import getaddresses
from urllib.parse import unquote
-from parse import compile
+from bs4 import BeautifulSoup
import frappe
from frappe import _
@@ -144,8 +144,8 @@ class Communication(Document, CommunicationEmailMixin):
if not self.content:
return
- quill_parser = compile('{}
')
- email_body = quill_parser.parse(self.content)
+ soup = BeautifulSoup(self.content, "html.parser")
+ email_body = soup.find("div", {"class": "ql-editor read-mode"})
if not email_body:
return
@@ -169,7 +169,11 @@ class Communication(Document, CommunicationEmailMixin):
if not signature:
return
- _signature = quill_parser.parse(signature)[0] if "ql-editor" in signature else None
+ soup = BeautifulSoup(signature, "html.parser")
+ html_signature = soup.find("div", {"class": "ql-editor read-mode"})
+ _signature = None
+ if html_signature:
+ _signature = html_signature.renderContents()
if (_signature or signature) not in self.content:
self.content = f'{self.content}
{signature}'
diff --git a/frappe/core/doctype/communication/test_communication.py b/frappe/core/doctype/communication/test_communication.py
index 77f83b7f91..ba586f3f3a 100644
--- a/frappe/core/doctype/communication/test_communication.py
+++ b/frappe/core/doctype/communication/test_communication.py
@@ -6,11 +6,12 @@ from urllib.parse import quote
import frappe
from frappe.core.doctype.communication.communication import get_emails
from frappe.email.doctype.email_queue.email_queue import EmailQueue
+from frappe.tests.utils import FrappeTestCase
test_records = frappe.get_test_records("Communication")
-class TestCommunication(unittest.TestCase):
+class TestCommunication(FrappeTestCase):
def test_email(self):
valid_email_list = [
"Full Name ",
@@ -259,8 +260,25 @@ class TestCommunication(unittest.TestCase):
self.assertEqual(emails[1], "first.lastname@email.com")
self.assertEqual(emails[2], "test@user.com")
+ def test_signature_in_email_content(self):
+ email_account = create_email_account()
+ signature = email_account.signature
+ comm = frappe.get_doc(
+ {
+ "doctype": "Communication",
+ "communication_medium": "Email",
+ "subject": "Document Link in Email",
+ "sender": "comm_sender@example.com",
+ "content": """
+ Hi,
+ How are you?
+
""",
+ }
+ ).insert(ignore_permissions=True)
+ assert signature in comm.content
-class TestCommunicationEmailMixin(unittest.TestCase):
+
+class TestCommunicationEmailMixin(FrappeTestCase):
def new_communication(self, recipients=None, cc=None, bcc=None):
recipients = ", ".join(recipients or [])
cc = ", ".join(cc or [])
@@ -345,6 +363,7 @@ def create_email_account():
"append_to": "ToDo",
"email_account_name": "_Test Comm Account 1",
"enable_outgoing": 1,
+ "default_outgoing": 1,
"smtp_server": "test.example.com",
"email_id": "test_comm@example.com",
"password": "password",
diff --git a/pyproject.toml b/pyproject.toml
index a1706ac33e..ca69113400 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -43,7 +43,6 @@ dependencies = [
"num2words~=0.5.10",
"oauthlib~=3.1.0",
"openpyxl~=3.0.7",
- "parse~=1.19.0",
"passlib~=1.7.4",
"pdfkit~=1.0.0",
"phonenumbers==8.12.40",