Ver código fonte

Email footer refactor (#3807)

* Email footer refactor

* styling fixes

* Unsubscribe message

* fix test
version-14
Faris Ansari 8 anos atrás
committed by Rushabh Mehta
pai
commit
f3f21554b2
5 arquivos alterados com 92 adições e 30 exclusões
  1. +16
    -16
      frappe/email/email_body.py
  2. +24
    -14
      frappe/email/queue.py
  3. +10
    -0
      frappe/public/css/email.css
  4. +13
    -0
      frappe/public/less/email.less
  5. +29
    -0
      frappe/templates/emails/email_footer.html

+ 16
- 16
frappe/email/email_body.py Ver arquivo

@@ -233,7 +233,8 @@ class EMail:
self.make()
return self.msg_root.as_string()

def get_formatted_html(subject, message, footer=None, print_html=None, email_account=None, header=None):
def get_formatted_html(subject, message, footer=None, print_html=None,
email_account=None, header=None, unsubscribe_link=None):
if not email_account:
email_account = get_outgoing_email_account(False)

@@ -247,9 +248,13 @@ def get_formatted_html(subject, message, footer=None, print_html=None, email_acc
"subject": subject
})

sanitized_html = scrub_urls(rendered_email)
transformed_html = inline_style_in_html(sanitized_html)
return transformed_html
html = scrub_urls(rendered_email)

if unsubscribe_link:
html = html.replace("<!--unsubscribe link here-->", unsubscribe_link.html)

html = inline_style_in_html(html)
return html

@frappe.whitelist()
def get_email_html(template, args, subject, header=None):
@@ -341,25 +346,20 @@ def get_footer(email_account, footer=None):
"""append a footer (signature)"""
footer = footer or ""

args = {}

if email_account and email_account.footer:
footer += '<div style="margin: 15px auto;">{0}</div>'.format(email_account.footer)
args.update({'email_account_footer': email_account.footer})

company_address = frappe.db.get_default("email_footer_address")

if company_address:
company_address = company_address.splitlines(True)
footer += '<table width="100%" border=0>'
footer += '<tr><td height=20></td></tr>'
for x in company_address:
footer += '<tr style="margin: 15px auto; text-align: center; color: #8d99a6"><td>{0}</td></tr>'\
.format(x)
footer += "</table>"

footer += "<!--unsubscribe link here-->"
args.update({'company_address': company_address})

if not cint(frappe.db.get_default("disable_standard_email_footer")):
for default_mail_footer in frappe.get_hooks("default_mail_footer"):
footer += '<div style="margin: 15px auto;">{0}</div>'.format(default_mail_footer)
args.update({'default_mail_footer': frappe.get_hooks('default_mail_footer')})

footer += frappe.utils.jinja.get_email_from_template('email_footer', args)[0]

return footer



+ 24
- 14
frappe/email/queue.py Ver arquivo

@@ -75,8 +75,6 @@ def send(recipients=None, sender=None, subject=None, message=None, text_content=
except HTMLParser.HTMLParseError:
text_content = "See html attachment"

formatted = get_formatted_html(subject, message, email_account=email_account, header=header)

if reference_doctype and reference_name:
unsubscribed = [d.email for d in frappe.db.get_all("Email Unsubscribe", "email",
{"reference_doctype": reference_doctype, "reference_name": reference_name})]
@@ -88,14 +86,22 @@ def send(recipients=None, sender=None, subject=None, message=None, text_content=

recipients = [r for r in list(set(recipients)) if r and r not in unsubscribed]

email_content = formatted
email_text_context = text_content

if add_unsubscribe_link and reference_doctype and (unsubscribe_message or reference_doctype=="Newsletter") and add_unsubscribe_link==1:
should_append_unsubscribe = (add_unsubscribe_link
and reference_doctype
and (unsubscribe_message or reference_doctype=="Newsletter")
and add_unsubscribe_link==1)

unsubscribe_link = None
if should_append_unsubscribe or True:
unsubscribe_link = get_unsubscribe_message(unsubscribe_message, expose_recipients)
email_content = email_content.replace("<!--unsubscribe link here-->", unsubscribe_link.html)
email_text_context += unsubscribe_link.text

email_content = get_formatted_html(subject, message,
email_account=email_account, header=header,
unsubscribe_link=unsubscribe_link)

# add to queue
add(recipients, sender, subject,
formatted=email_content,
@@ -230,17 +236,21 @@ def get_emails_sent_this_month():
status='Sent' and MONTH(creation)=MONTH(CURDATE())""")[0][0]

def get_unsubscribe_message(unsubscribe_message, expose_recipients):
if not unsubscribe_message:
unsubscribe_message = _("Unsubscribe from this list")
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 style="margin: 15px auto; padding: 0px 7px; text-align: center; color: #8d99a6;">
html = """<div class="email-unsubscribe">
<!--cc message-->
<p style="margin: 15px auto;">
<a href="<!--unsubscribe url-->" style="color: #8d99a6; text-decoration: underline;"
target="_blank">{unsubscribe_message}
</a>
</p>
</div>""".format(unsubscribe_message=unsubscribe_message)
<div>
{0}
</div>
</div>""".format(unsubscribe_html)

if expose_recipients == "footer":
text = "\n<!--cc message-->"
else:


+ 10
- 0
frappe/public/css/email.css Ver arquivo

@@ -48,6 +48,16 @@ hr {
.body-table.has-header .email-footer {
border-top: none;
}
.email-footer-container {
margin-top: 10px;
}
.email-footer-container > div:not(:last-child) {
margin-bottom: 5px;
}
.email-unsubscribe a {
color: #8D99A6;
text-decoration: underline;
}
.btn {
text-decoration: none;
padding: 7px 10px;


+ 13
- 0
frappe/public/less/email.less Ver arquivo

@@ -63,6 +63,19 @@ hr {
}
}

.email-footer-container {
margin-top: 10px;

& > div:not(:last-child) {
margin-bottom: 5px;
}
}

.email-unsubscribe a {
color: @text-muted;
text-decoration: underline;
}

.btn {
text-decoration: none;
padding: 7px 10px;


+ 29
- 0
frappe/templates/emails/email_footer.html Ver arquivo

@@ -0,0 +1,29 @@
<div class="email-footer-container text-muted">
<!-- email_account_footer -->
{% if email_account_footer %}
<div class="email-account-footer">
{{ email_account_footer }}
</div>
{% endif %}

<!-- company_address -->
{% if company_address %}
<div class="company-address">
{% for line in company_address.splitlines(True) %}
<div>{{ line }}</div>
{% endfor %}
</div>
{% endif %}

<!--unsubscribe link here-->

<!-- default_mail_footer -->
{% if default_mail_footer %}
<div class="default-mail-footer">
{% for line in default_mail_footer %}
<div>{{ line }}</div>
{% endfor %}
</div>
{% endif %}

</div>

Carregando…
Cancelar
Salvar