Merge pull request #17331 from gavindsouza/email-unsubscribe
refactor(minor): get_unsubscribe_message
This commit is contained in:
commit
4036a5704f
4 changed files with 23 additions and 35 deletions
|
|
@ -78,7 +78,7 @@ class _dict(dict):
|
|||
return _dict(self)
|
||||
|
||||
|
||||
def _(msg, lang=None, context=None):
|
||||
def _(msg, lang=None, context=None) -> str:
|
||||
"""Returns translated string in current lang, if exists.
|
||||
Usage:
|
||||
_('Change')
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ def send_mail(email_queue_name, is_background_task=False):
|
|||
|
||||
class SendMailContext:
|
||||
def __init__(self, queue_doc: Document, is_background_task: bool = False):
|
||||
self.queue_doc = queue_doc
|
||||
self.queue_doc: EmailQueue = queue_doc
|
||||
self.is_background_task = is_background_task
|
||||
self.email_account_doc = queue_doc.get_email_account()
|
||||
self.smtp_server = self.email_account_doc.get_smtp_server()
|
||||
|
|
@ -285,16 +285,16 @@ class SendMailContext:
|
|||
).decode()
|
||||
return message
|
||||
|
||||
def get_unsubscribe_str(self, recipient_email):
|
||||
def get_unsubscribe_str(self, recipient_email: str) -> str:
|
||||
unsubscribe_url = ""
|
||||
|
||||
if self.queue_doc.add_unsubscribe_link and self.queue_doc.reference_doctype:
|
||||
doctype, doc_name = self.queue_doc.reference_doctype, self.queue_doc.reference_name
|
||||
unsubscribe_url = get_unsubcribed_url(
|
||||
doctype,
|
||||
doc_name,
|
||||
recipient_email,
|
||||
self.queue_doc.unsubscribe_method,
|
||||
self.queue_doc.unsubscribe_param,
|
||||
reference_doctype=self.queue_doc.reference_doctype,
|
||||
reference_name=self.queue_doc.reference_name,
|
||||
email=recipient_email,
|
||||
unsubscribe_method=self.queue_doc.unsubscribe_method,
|
||||
unsubscribe_params=self.queue_doc.unsubscribe_param,
|
||||
)
|
||||
|
||||
return quopri.encodestring(unsubscribe_url.encode()).decode()
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import re
|
|||
from email import policy
|
||||
from email.header import Header
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from typing import Optional
|
||||
|
||||
import frappe
|
||||
from frappe.email.doctype.email_account.email_account import EmailAccount
|
||||
|
|
@ -353,7 +354,7 @@ def get_formatted_html(
|
|||
print_html=None,
|
||||
email_account=None,
|
||||
header=None,
|
||||
unsubscribe_link=None,
|
||||
unsubscribe_link: Optional[frappe._dict] = None,
|
||||
sender=None,
|
||||
with_container=False,
|
||||
):
|
||||
|
|
|
|||
|
|
@ -67,37 +67,24 @@ def get_emails_sent_today(email_account=None):
|
|||
return frappe.db.sql(q, q_args)[0][0]
|
||||
|
||||
|
||||
def get_unsubscribe_message(unsubscribe_message, expose_recipients):
|
||||
if unsubscribe_message:
|
||||
unsubscribe_html = """<a href="<!--unsubscribe_url-->"
|
||||
target="_blank">{0}</a>""".format(
|
||||
unsubscribe_message
|
||||
)
|
||||
else:
|
||||
unsubscribe_link = """<a href="<!--unsubscribe_url-->"
|
||||
target="_blank">{0}</a>""".format(
|
||||
_("Unsubscribe")
|
||||
)
|
||||
unsubscribe_html = _("{0} to stop receiving emails of this type").format(unsubscribe_link)
|
||||
|
||||
html = """<div class="email-unsubscribe">
|
||||
def get_unsubscribe_message(
|
||||
unsubscribe_message: str, expose_recipients: str
|
||||
) -> frappe._dict[str, str]:
|
||||
unsubscribe_message = unsubscribe_message or _("Unsubscribe")
|
||||
unsubscribe_link = f'<a href="<!--unsubscribe_url-->" target="_blank">{unsubscribe_message}</a>'
|
||||
unsubscribe_html = _("{0} to stop receiving emails of this type").format(unsubscribe_link)
|
||||
html = f"""<div class="email-unsubscribe">
|
||||
<!--cc_message-->
|
||||
<div>
|
||||
{0}
|
||||
{unsubscribe_html}
|
||||
</div>
|
||||
</div>""".format(
|
||||
unsubscribe_html
|
||||
)
|
||||
</div>"""
|
||||
|
||||
text = f"\n\n{unsubscribe_message}: <!--unsubscribe_url-->\n"
|
||||
if expose_recipients == "footer":
|
||||
text = "\n<!--cc_message-->"
|
||||
else:
|
||||
text = ""
|
||||
text += "\n\n{unsubscribe_message}: <!--unsubscribe_url-->\n".format(
|
||||
unsubscribe_message=unsubscribe_message
|
||||
)
|
||||
text = f"\n<!--cc_message-->{text}"
|
||||
|
||||
return frappe._dict({"html": html, "text": text})
|
||||
return frappe._dict(html=html, text=text)
|
||||
|
||||
|
||||
def get_unsubcribed_url(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue