Просмотр исходного кода

Merge pull request #424 from akhileshdarjee/4.0-hotfix

Minor changes
version-14
Rushabh Mehta 11 лет назад
Родитель
Сommit
75467d6196
2 измененных файлов: 19 добавлений и 16 удалений
  1. +10
    -6
      webnotes/utils/email_lib/bulk.py
  2. +9
    -10
      webnotes/utils/email_lib/email_body.py

+ 10
- 6
webnotes/utils/email_lib/bulk.py Просмотреть файл

@@ -5,6 +5,7 @@ from __future__ import unicode_literals
import webnotes import webnotes
import HTMLParser import HTMLParser
import urllib import urllib
from webnotes import msgprint, throw, _
from webnotes.utils.email_lib.smtp import SMTPServer, send 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.email_body import get_email, get_formatted_html
from webnotes.utils.email_lib.html2text import html2text 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 monthly_bulk_mail_limit = webnotes.conf.get('monthly_bulk_mail_limit') or 500


if this_month + len(recipients) > monthly_bulk_mail_limit: 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): def update_message(formatted, doc, add_unsubscribe_link):
updated = formatted updated = formatted
@@ -59,11 +63,11 @@ def send(recipients=None, sender=None, doctype='Profile', email_field='email',
text_content = "[See html attachment]" text_content = "[See html attachment]"
formatted = get_formatted_html(subject, message) formatted = get_formatted_html(subject, message)
for r in filter(None, list(set(recipients))): for r in filter(None, list(set(recipients))):
rdata = webnotes.conn.sql("""select * from `tab%s` where %s=%s""" % (doctype, rdata = webnotes.conn.sql("""select * from `tab%s` where %s=%s""" % (doctype,
email_field, '%s'), (r,), as_dict=1) email_field, '%s'), (r,), as_dict=1)
doc = rdata and rdata[0] or {} doc = rdata and rdata[0] or {}
if not is_unsubscribed(doc): if not is_unsubscribed(doc):
@@ -114,7 +118,7 @@ def flush(from_test=False):
auto_commit = not from_test auto_commit = not from_test
if webnotes.flags.mute_emails or webnotes.conf.get("mute_emails") or False: 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 from_test = True
for i in xrange(500): for i in xrange(500):
@@ -141,4 +145,4 @@ def flush(from_test=False):
def clear_outbox(): def clear_outbox():
"""remove mails older than 30 days in Outbox""" """remove mails older than 30 days in Outbox"""
webnotes.conn.sql("""delete from `tabBulk Email` where webnotes.conn.sql("""delete from `tabBulk Email` where
datediff(now(), creation) > 30""")
datediff(now(), creation) > 30""")

+ 9
- 10
webnotes/utils/email_lib/email_body.py Просмотреть файл

@@ -2,9 +2,8 @@
# MIT License. See license.txt # MIT License. See license.txt


from __future__ import unicode_literals from __future__ import unicode_literals

import webnotes import webnotes
from webnotes import msgprint, throw, _
from webnotes.utils import scrub_urls from webnotes.utils import scrub_urls
import email.utils import email.utils
from inlinestyler.utils import inline_css from inlinestyler.utils import inline_css
@@ -153,19 +152,19 @@ class EMail:
def _validate(email): def _validate(email):
"""validate an email field""" """validate an email field"""
if email and not validate_email_add(email): 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 return email
if not self.sender: if not self.sender:
self.sender = webnotes.conn.get_value('Email Settings', None, self.sender = webnotes.conn.get_value('Email Settings', None,
'auto_email_id') or webnotes.conf.get('auto_email_id') or None 'auto_email_id') or webnotes.conf.get('auto_email_id') or None
if not self.sender: 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: 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 raise webnotes.ValidationError
self.sender = _validate(self.sender) self.sender = _validate(self.sender)
@@ -206,7 +205,7 @@ def get_footer(footer=None):
footer = footer or "" footer = footer or ""
# control panel # 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 # hooks
for f in webnotes.get_hooks("mail_footer"): for f in webnotes.get_hooks("mail_footer"):
@@ -214,4 +213,4 @@ def get_footer(footer=None):
footer += "<!--unsubscribe link here-->" footer += "<!--unsubscribe link here-->"
return footer
return footer

Загрузка…
Отмена
Сохранить