From fb8925fe8a4bf0db7391509d86c3be94a957609e Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 12 Feb 2014 21:13:07 +0530 Subject: [PATCH] Fixes in Bulk Email and Email Template --- .../core/doctype/bulk_email/bulk_email.txt | 4 +-- webnotes/templates/emails/standard.html | 28 ++++++++++++++++++- webnotes/templates/includes/inline_post.html | 4 +-- webnotes/utils/__init__.py | 13 +++++++-- webnotes/utils/email_lib/bulk.py | 22 +++++++-------- webnotes/utils/email_lib/smtp.py | 2 +- 6 files changed, 53 insertions(+), 20 deletions(-) diff --git a/webnotes/core/doctype/bulk_email/bulk_email.txt b/webnotes/core/doctype/bulk_email/bulk_email.txt index 11c747500f..c47da6d4d3 100644 --- a/webnotes/core/doctype/bulk_email/bulk_email.txt +++ b/webnotes/core/doctype/bulk_email/bulk_email.txt @@ -2,7 +2,7 @@ { "creation": "2012-08-02 15:17:28", "docstatus": 0, - "modified": "2013-12-20 19:23:58", + "modified": "2014-02-12 21:11:05", "modified_by": "Administrator", "owner": "Administrator" }, @@ -55,7 +55,7 @@ { "doctype": "DocField", "fieldname": "message", - "fieldtype": "Text", + "fieldtype": "Long Text", "label": "Message" }, { diff --git a/webnotes/templates/emails/standard.html b/webnotes/templates/emails/standard.html index 3a3381b454..aabe51d5ce 100644 --- a/webnotes/templates/emails/standard.html +++ b/webnotes/templates/emails/standard.html @@ -78,6 +78,19 @@ body { padding:10px 0; } +.left-padding { + padding-left: 10px; +} + +.breadcrumb { + list-style: none; +} + +.breadcrumb > li { + display: inline-block; + margin-left: 0px; + margin-right: 5px; +} /* ------------------------------------- BODY @@ -183,6 +196,19 @@ table.footer-wrap a{ width: 100%; } +a.no-decoration { + text-decoration: none; + color: inherit; +} + +small, .small { + font-size: 85%; +} + +.text-muted { + color: #999999; +} + @@ -240,7 +266,7 @@ table.footer-wrap a{ - + \ No newline at end of file diff --git a/webnotes/templates/includes/inline_post.html b/webnotes/templates/includes/inline_post.html index ac9c547763..df584b0235 100644 --- a/webnotes/templates/includes/inline_post.html +++ b/webnotes/templates/includes/inline_post.html @@ -5,13 +5,13 @@ data-name="{{ post.name }}" data-group="{{ post.website_group }}" itemscope itemtype="http://schema.org/Article"> - +
{%- if not post.parent_post -%}

- {%- if view != "post" -%} + {%- if view.name != "post" -%} {{ post.title }} {%- else -%} diff --git a/webnotes/utils/__init__.py b/webnotes/utils/__init__.py index 9b4ad265c8..035eeb3605 100644 --- a/webnotes/utils/__init__.py +++ b/webnotes/utils/__init__.py @@ -903,9 +903,16 @@ def scrub_urls(html): def expand_relative_urls(html): # expand relative urls url = get_url() - if not url.endswith("/"): url += "/" - return re.sub('(href|src){1}([\s]*=[\s]*[\'"]?)((?!http)[^\'" >]+)([\'"]?)', - '\g<1>\g<2>{}\g<3>\g<4>'.format(url), html) + if url.endswith("/"): url = url[:-1] + + def _expand_relative_urls(match): + to_expand = list(match.groups()) + if not to_expand[2].startswith("/"): + to_expand[2] = "/" + to_expand[2] + to_expand.insert(2, url) + return "".join(to_expand) + + return re.sub('(href|src){1}([\s]*=[\s]*[\'"]?)((?!http)[^\'" >]+)([\'"]?)', _expand_relative_urls, html) def quote_urls(html): def _quote_url(match): diff --git a/webnotes/utils/email_lib/bulk.py b/webnotes/utils/email_lib/bulk.py index d8eb6f3158..4ab448f4c6 100644 --- a/webnotes/utils/email_lib/bulk.py +++ b/webnotes/utils/email_lib/bulk.py @@ -47,7 +47,7 @@ def send(recipients=None, sender=None, doctype='Profile', email_field='email', "type": doctype, "email_field": email_field })) - + updated = updated.replace("", unsubscribe_link) return updated @@ -57,11 +57,6 @@ def send(recipients=None, sender=None, doctype='Profile', email_field='email', sender = webnotes.conn.get_value('Email Settings', None, 'auto_email_id') check_bulk_limit(len(recipients)) - try: - text_content = html2text(message) - except HTMLParser.HTMLParseError: - text_content = "[See html attachment]" - formatted = get_formatted_html(subject, message) for r in filter(None, list(set(recipients))): @@ -72,8 +67,13 @@ def send(recipients=None, sender=None, doctype='Profile', email_field='email', if not is_unsubscribed(doc): # add to queue - add(r, sender, subject, update_message(formatted, doc, add_unsubscribe_link), - text_content, ref_doctype, ref_docname) + updated = update_message(formatted, doc, add_unsubscribe_link) + try: + text_content = html2text(updated) + except HTMLParser.HTMLParseError: + text_content = "[See html attachment]" + + add(r, sender, subject, updated, text_content, ref_doctype, ref_docname) def add(email, sender, subject, formatted, text_content=None, ref_doctype=None, ref_docname=None): @@ -83,7 +83,7 @@ def add(email, sender, subject, formatted, text_content=None, e.recipient = email try: e.message = get_email(email, sender=e.sender, formatted=formatted, subject=subject, - text_content = text_content).as_string() + text_content=text_content).as_string() except webnotes.ValidationError: # bad email id - don't add to queue return @@ -113,7 +113,7 @@ def unsubscribe(): def flush(from_test=False): """flush email queue, every time: called from scheduler""" - smptserver = SMTPServer() + smtpserver = SMTPServer() auto_commit = not from_test @@ -133,7 +133,7 @@ def flush(from_test=False): (email["name"],), auto_commit=auto_commit) try: if not from_test: - smptserver.sess.sendmail(email["sender"], email["recipient"], email["message"]) + smtpserver.sess.sendmail(email["sender"], email["recipient"], email["message"]) webnotes.conn.sql("""update `tabBulk Email` set status='Sent' where name=%s""", (email["name"],), auto_commit=auto_commit) diff --git a/webnotes/utils/email_lib/smtp.py b/webnotes/utils/email_lib/smtp.py index 3e0b4774a7..2228380a51 100644 --- a/webnotes/utils/email_lib/smtp.py +++ b/webnotes/utils/email_lib/smtp.py @@ -21,7 +21,7 @@ def send(email, as_bulk=False): if not email.reply_to: email.reply_to = email.sender email.sender = smtpserver.login - + smtpserver.sess.sendmail(email.sender, email.recipients + (email.cc or []), email.as_string())