fix: Add signature to Communication.content if not already added
This fix adds a signature forcibly if found under the sender's User.email_signature or default outgoing email account's signature field. The previous method of adding a comment into the Email didn't work since Quill would discard comments before setting them. Adding signatures in get_formatted_html didn't seem apt since it's used in QueueBuilder to re-construct the Email before processing the Email Queue. This meant that the email content that was added in the Communication record would not be final. Now, we treat the signature as part of the Communication content.
This commit is contained in:
parent
da2dbfaae9
commit
0ef99c3886
5 changed files with 41 additions and 9 deletions
|
|
@ -18,6 +18,7 @@ from urllib.parse import unquote
|
|||
from frappe.utils.user import is_system_user
|
||||
from frappe.contacts.doctype.contact.contact import get_contact_name
|
||||
from frappe.automation.doctype.assignment_rule.assignment_rule import apply as apply_assignment_rule
|
||||
from parse import compile
|
||||
|
||||
exclude_from_linked_with = True
|
||||
|
||||
|
|
@ -114,6 +115,43 @@ class Communication(Document, CommunicationEmailMixin):
|
|||
frappe.publish_realtime('new_message', self.as_dict(),
|
||||
user=self.reference_name, after_commit=True)
|
||||
|
||||
def set_signature_in_email_content(self):
|
||||
"""Set sender's User.email_signature or default outgoing's EmailAccount.signature to the email
|
||||
"""
|
||||
if not self.content:
|
||||
return
|
||||
|
||||
quill_parser = compile('<div class="ql-editor read-mode">{}</div>')
|
||||
email_body = quill_parser.parse(self.content)
|
||||
|
||||
if not email_body:
|
||||
return
|
||||
|
||||
email_body = email_body[0]
|
||||
|
||||
user_email_signature = frappe.db.get_value(
|
||||
"User",
|
||||
self.sender,
|
||||
"email_signature",
|
||||
) if self.sender else None
|
||||
|
||||
signature = user_email_signature or frappe.db.get_value(
|
||||
"Email Account",
|
||||
{"default_outgoing": 1, "add_signature": 1},
|
||||
"signature",
|
||||
)
|
||||
|
||||
if not signature:
|
||||
return
|
||||
|
||||
_signature = quill_parser.parse(signature)[0] if "ql-editor" in signature else None
|
||||
|
||||
if (_signature or signature) not in self.content:
|
||||
self.content = f'{self.content}</p><br><p class="signature">{signature}'
|
||||
|
||||
def before_save(self):
|
||||
self.set_signature_in_email_content()
|
||||
|
||||
def on_update(self):
|
||||
# add to _comment property of the doctype, so it shows up in
|
||||
# comments count for the list view
|
||||
|
|
|
|||
|
|
@ -259,17 +259,12 @@ def get_formatted_html(subject, message, footer=None, print_html=None,
|
|||
|
||||
email_account = email_account or EmailAccount.find_outgoing(match_by_email=sender)
|
||||
|
||||
signature = None
|
||||
if "<!-- signature-included -->" not in message:
|
||||
signature = get_signature(email_account)
|
||||
|
||||
rendered_email = frappe.get_template("templates/emails/standard.html").render({
|
||||
"brand_logo": get_brand_logo(email_account) if with_container or header else None,
|
||||
"with_container": with_container,
|
||||
"site_url": get_url(),
|
||||
"header": get_header(header),
|
||||
"content": message,
|
||||
"signature": signature,
|
||||
"footer": get_footer(email_account, footer),
|
||||
"title": subject,
|
||||
"print_html": print_html,
|
||||
|
|
@ -281,8 +276,7 @@ def get_formatted_html(subject, message, footer=None, print_html=None,
|
|||
if unsubscribe_link:
|
||||
html = html.replace("<!--unsubscribe link here-->", unsubscribe_link.html)
|
||||
|
||||
html = inline_style_in_html(html)
|
||||
return html
|
||||
return inline_style_in_html(html)
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_email_html(template, args, subject, header=None, with_container=False):
|
||||
|
|
|
|||
|
|
@ -750,7 +750,7 @@ frappe.views.CommunicationComposer = class {
|
|||
signature = signature.replace(/\n/g, "<br>");
|
||||
}
|
||||
|
||||
return "<br><!-- signature-included -->" + signature;
|
||||
return "<br>" + signature;
|
||||
}
|
||||
|
||||
get_earlier_reply() {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@
|
|||
<tr>
|
||||
<td valign="top">
|
||||
<p>{{ content }}</p>
|
||||
<p class="signature">{{ signature }}</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ maxminddb-geolite2==2018.703
|
|||
num2words~=0.5.10
|
||||
oauthlib~=3.1.0
|
||||
openpyxl~=3.0.7
|
||||
parse~=1.19.0
|
||||
passlib~=1.7.4
|
||||
paytmchecksum~=1.7.0
|
||||
pdfkit~=0.6.1
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue