diff --git a/webnotes/utils/email_lib/bulk.py b/webnotes/utils/email_lib/bulk.py index 928da58751..d8eb6f3158 100644 --- a/webnotes/utils/email_lib/bulk.py +++ b/webnotes/utils/email_lib/bulk.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals import webnotes import HTMLParser import urllib +from webnotes import msgprint, throw, _ from webnotes.utils.email_lib.smtp import SMTPServer, send from webnotes.utils.email_lib.email_body import get_email, get_formatted_html from webnotes.utils.email_lib.html2text import html2text @@ -27,8 +28,11 @@ def send(recipients=None, sender=None, doctype='Profile', email_field='email', monthly_bulk_mail_limit = webnotes.conf.get('monthly_bulk_mail_limit') or 500 if this_month + len(recipients) > monthly_bulk_mail_limit: - webnotes.msgprint("""Monthly Bulk Mail Limit (%s) Crossed""" % monthly_bulk_mail_limit, - raise_exception=BulkLimitCrossedError) + throw("{bulk} ({limit}) {cross}".format(**{ + "bulk": _("Monthly Bulk Mail Limit"), + "limit": monthly_bulk_mail_limit, + "cross": _("crossed") + }), exc=BulkLimitCrossedError) def update_message(formatted, doc, add_unsubscribe_link): updated = formatted @@ -59,11 +63,11 @@ def send(recipients=None, sender=None, doctype='Profile', email_field='email', text_content = "[See html attachment]" formatted = get_formatted_html(subject, message) - + for r in filter(None, list(set(recipients))): rdata = webnotes.conn.sql("""select * from `tab%s` where %s=%s""" % (doctype, email_field, '%s'), (r,), as_dict=1) - + doc = rdata and rdata[0] or {} if not is_unsubscribed(doc): @@ -114,7 +118,7 @@ def flush(from_test=False): auto_commit = not from_test if webnotes.flags.mute_emails or webnotes.conf.get("mute_emails") or False: - webnotes.msgprint("Emails are muted") + msgprint(_("Emails are muted")) from_test = True for i in xrange(500): @@ -141,4 +145,4 @@ def flush(from_test=False): def clear_outbox(): """remove mails older than 30 days in Outbox""" webnotes.conn.sql("""delete from `tabBulk Email` where - datediff(now(), creation) > 30""") + datediff(now(), creation) > 30""") \ No newline at end of file diff --git a/webnotes/utils/email_lib/email_body.py b/webnotes/utils/email_lib/email_body.py index 4675277039..57eb3ea772 100644 --- a/webnotes/utils/email_lib/email_body.py +++ b/webnotes/utils/email_lib/email_body.py @@ -2,9 +2,8 @@ # MIT License. See license.txt from __future__ import unicode_literals - import webnotes - +from webnotes import msgprint, throw, _ from webnotes.utils import scrub_urls import email.utils from inlinestyler.utils import inline_css @@ -153,19 +152,19 @@ class EMail: def _validate(email): """validate an email field""" if email and not validate_email_add(email): - webnotes.msgprint("%s is not a valid email id" % email, - raise_exception = 1) + throw("{email} {msg}".format(**{ + "email": email, + "msg": _("is not a valid email id") + })) return email if not self.sender: self.sender = webnotes.conn.get_value('Email Settings', None, 'auto_email_id') or webnotes.conf.get('auto_email_id') or None if not self.sender: - webnotes.msgprint("""Please specify 'Auto Email Id' \ - in Setup > Email Settings""") + msgprint(_("Please specify 'Auto Email Id' in Setup > Email Settings")) if not "expires_on" in webnotes.conf: - webnotes.msgprint("""Alternatively, \ - you can also specify 'auto_email_id' in site_config.json""") + msgprint(_("Alternatively, you can also specify 'auto_email_id' in site_config.json")) raise webnotes.ValidationError self.sender = _validate(self.sender) @@ -206,7 +205,7 @@ def get_footer(footer=None): footer = footer or "" # control panel - footer += webnotes.conn.get_value('Control Panel',None,'mail_footer') or '' + footer += webnotes.conn.get_value('Control Panel', None, 'mail_footer') or '' # hooks for f in webnotes.get_hooks("mail_footer"): @@ -214,4 +213,4 @@ def get_footer(footer=None): footer += "" - return footer + return footer \ No newline at end of file