Przeglądaj źródła

[minor] added reply-to in frappe.sendmail and cleanup

version-14
Rushabh Mehta 10 lat temu
rodzic
commit
8bf7d1ded8
11 zmienionych plików z 32 dodań i 31 usunięć
  1. +6
    -4
      frappe/__init__.py
  2. +2
    -6
      frappe/desk/doctype/event/event.py
  3. +3
    -3
      frappe/desk/doctype/todo/todo.json
  4. +2
    -3
      frappe/desk/page/messages/messages.py
  5. +4
    -4
      frappe/email/__init__.py
  6. +4
    -4
      frappe/email/bulk.py
  7. +2
    -2
      frappe/email/doctype/bulk_email/bulk_email.json
  8. +2
    -2
      frappe/email/doctype/email_account/email_account.py
  9. +2
    -1
      frappe/email/email_body.py
  10. +1
    -2
      frappe/tasks.py
  11. +4
    -0
      frappe/utils/user.py

+ 6
- 4
frappe/__init__.py Wyświetl plik

@@ -268,7 +268,7 @@ def get_request_header(key, default=None):


def sendmail(recipients=(), sender="", subject="No Subject", message="No Message", def sendmail(recipients=(), sender="", subject="No Subject", message="No Message",
as_markdown=False, bulk=False, ref_doctype=None, ref_docname=None, as_markdown=False, bulk=False, ref_doctype=None, ref_docname=None,
add_unsubscribe_link=False, attachments=None, content=None, doctype=None, name=None):
add_unsubscribe_link=False, attachments=None, content=None, doctype=None, name=None, reply_to=None):
"""Send email using user's default **Email Account** or global default **Email Account**. """Send email using user's default **Email Account** or global default **Email Account**.




@@ -282,22 +282,24 @@ def sendmail(recipients=(), sender="", subject="No Subject", message="No Message
:param ref_docname: (or `name`) Append as communication to this document name. :param ref_docname: (or `name`) Append as communication to this document name.
:param add_unsubscribe_link: Allow user to unsubscribe from these emails. :param add_unsubscribe_link: Allow user to unsubscribe from these emails.
:param attachments: List of attachments. :param attachments: List of attachments.
:param reply_to: Reply-To email id.
""" """


if bulk: if bulk:
import frappe.email.bulk import frappe.email.bulk
frappe.email.bulk.send(recipients=recipients, sender=sender, frappe.email.bulk.send(recipients=recipients, sender=sender,
subject=subject, message=content or message, ref_doctype = doctype or ref_doctype, subject=subject, message=content or message, ref_doctype = doctype or ref_doctype,
ref_docname = name or ref_docname, add_unsubscribe_link=add_unsubscribe_link, attachments=attachments)
ref_docname = name or ref_docname, add_unsubscribe_link=add_unsubscribe_link, attachments=attachments,
reply_to=reply_to)


else: else:
import frappe.email import frappe.email
if as_markdown: if as_markdown:
frappe.email.sendmail_md(recipients, sender=sender, frappe.email.sendmail_md(recipients, sender=sender,
subject=subject, msg=content or message, attachments=attachments)
subject=subject, msg=content or message, attachments=attachments, reply_to=reply_to)
else: else:
frappe.email.sendmail(recipients, sender=sender, frappe.email.sendmail(recipients, sender=sender,
subject=subject, msg=content or message, attachments=attachments)
subject=subject, msg=content or message, attachments=attachments, reply_to=reply_to)


logger = None logger = None
whitelisted = [] whitelisted = []


+ 2
- 6
frappe/desk/doctype/event/event.py Wyświetl plik

@@ -5,8 +5,8 @@ from __future__ import unicode_literals
import frappe import frappe


from frappe.utils import getdate, cint, add_months, date_diff, add_days, nowdate from frappe.utils import getdate, cint, add_months, date_diff, add_days, nowdate
from frappe.core.doctype.user.user import STANDARD_USERS
from frappe.model.document import Document from frappe.model.document import Document
from frappe.utils.user import get_enabled_system_users


weekdays = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"] weekdays = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]


@@ -46,11 +46,7 @@ def has_permission(doc, user):


def send_event_digest(): def send_event_digest():
today = nowdate() today = nowdate()
for user in frappe.db.sql("""select name, email, language
from tabUser where ifnull(enabled,0)=1
and user_type='System User' and name not in ({})""".format(", ".join(["%s"]*len(STANDARD_USERS))),
STANDARD_USERS, as_dict=1):

for user in get_enabled_system_users():
events = get_events(today, today, user.name, for_reminder=True) events = get_events(today, today, user.name, for_reminder=True)
if events: if events:
text = "" text = ""


+ 3
- 3
frappe/desk/doctype/todo/todo.json Wyświetl plik

@@ -52,7 +52,7 @@
"fieldtype": "Select", "fieldtype": "Select",
"hidden": 0, "hidden": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 1,
"in_list_view": 0,
"label": "Priority", "label": "Priority",
"no_copy": 0, "no_copy": 0,
"oldfieldname": "priority", "oldfieldname": "priority",
@@ -70,7 +70,7 @@
"fieldtype": "Date", "fieldtype": "Date",
"hidden": 0, "hidden": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 1,
"in_list_view": 0,
"label": "Due Date", "label": "Due Date",
"no_copy": 0, "no_copy": 0,
"oldfieldname": "date", "oldfieldname": "date",
@@ -170,7 +170,7 @@
"in_dialog": 0, "in_dialog": 0,
"issingle": 0, "issingle": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2015-01-07 10:56:03.251872",
"modified": "2015-01-22 17:54:50.026008",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Desk", "module": "Desk",
"name": "ToDo", "name": "ToDo",


+ 2
- 3
frappe/desk/page/messages/messages.py Wyświetl plik

@@ -5,6 +5,7 @@ from __future__ import unicode_literals
import frappe import frappe
from frappe.desk.notifications import delete_notification_count_for from frappe.desk.notifications import delete_notification_count_for
from frappe.core.doctype.user.user import STANDARD_USERS from frappe.core.doctype.user.user import STANDARD_USERS
from frappe.utils.user import get_enabled_system_users
from frappe.utils import cint from frappe.utils import cint


@frappe.whitelist() @frappe.whitelist()
@@ -83,9 +84,7 @@ def post(txt, contact, parenttype=None, notify=False, subject=None):


if notify and cint(notify): if notify and cint(notify):
if contact==frappe.session.user: if contact==frappe.session.user:
_notify([user.name for user in frappe.get_list("User",
{"user_type":"System User", "enabled": 1}) \
if user.name not in ("Guest", "Administrator")], txt)
_notify([user.name for user in get_enabled_system_users()], txt)
else: else:
_notify(contact, txt, subject) _notify(contact, txt, subject)




+ 4
- 4
frappe/email/__init__.py Wyświetl plik

@@ -7,14 +7,14 @@ import frappe
from frappe.email.email_body import get_email from frappe.email.email_body import get_email
from frappe.email.smtp import send from frappe.email.smtp import send


def sendmail_md(recipients, sender=None, msg=None, subject=None, attachments=None, content=None):
def sendmail_md(recipients, sender=None, msg=None, subject=None, attachments=None, content=None, reply_to=None):
"""send markdown email""" """send markdown email"""
import markdown2 import markdown2
sendmail(recipients, sender, markdown2.markdown(content or msg), subject, attachments)
sendmail(recipients, sender, markdown2.markdown(content or msg), subject, attachments, reply_to=reply_to)


def sendmail(recipients, sender='', msg='', subject='[No Subject]', attachments=None, content=None):
def sendmail(recipients, sender='', msg='', subject='[No Subject]', attachments=None, content=None, reply_to=None):
"""send an html email as multipart with attachments and all""" """send an html email as multipart with attachments and all"""
send(get_email(recipients, sender, content or msg, subject, attachments=attachments))
send(get_email(recipients, sender, content or msg, subject, attachments=attachments, reply_to=reply_to))


def sendmail_to_system_managers(subject, content): def sendmail_to_system_managers(subject, content):
send(get_email(get_system_managers(), None, content, subject)) send(get_email(get_system_managers(), None, content, subject))


+ 4
- 4
frappe/email/bulk.py Wyświetl plik

@@ -15,7 +15,7 @@ class BulkLimitCrossedError(frappe.ValidationError): pass


def send(recipients=None, sender=None, doctype='User', email_field='email', def send(recipients=None, sender=None, doctype='User', email_field='email',
subject='[No Subject]', message='[No Content]', ref_doctype=None, subject='[No Subject]', message='[No Content]', ref_doctype=None,
ref_docname=None, add_unsubscribe_link=True, attachments=None):
ref_docname=None, add_unsubscribe_link=True, attachments=None, reply_to=None):


def is_unsubscribed(rdata): def is_unsubscribed(rdata):
if not rdata: if not rdata:
@@ -79,17 +79,17 @@ def send(recipients=None, sender=None, doctype='User', email_field='email',
except HTMLParser.HTMLParseError: except HTMLParser.HTMLParseError:
text_content = "[See html attachment]" text_content = "[See html attachment]"


add(r, sender, subject, updated, text_content, ref_doctype, ref_docname, attachments)
add(r, sender, subject, updated, text_content, ref_doctype, ref_docname, attachments, reply_to)


def add(email, sender, subject, formatted, text_content=None, def add(email, sender, subject, formatted, text_content=None,
ref_doctype=None, ref_docname=None, attachments=None):
ref_doctype=None, ref_docname=None, attachments=None, reply_to=None):
"""add to bulk mail queue""" """add to bulk mail queue"""
e = frappe.new_doc('Bulk Email') e = frappe.new_doc('Bulk Email')
e.sender = sender e.sender = sender
e.recipient = email e.recipient = email
try: try:
e.message = get_email(email, sender=e.sender, formatted=formatted, subject=subject, e.message = get_email(email, sender=e.sender, formatted=formatted, subject=subject,
text_content=text_content, attachments=attachments).as_string()
text_content=text_content, attachments=attachments, reply_to=reply_to).as_string()
except frappe.InvalidEmailAddressError: except frappe.InvalidEmailAddressError:
# bad email id - don't add to queue # bad email id - don't add to queue
return return


+ 2
- 2
frappe/email/doctype/bulk_email/bulk_email.json Wyświetl plik

@@ -22,7 +22,7 @@
}, },
{ {
"fieldname": "message", "fieldname": "message",
"fieldtype": "Long Text",
"fieldtype": "Code",
"in_list_view": 0, "in_list_view": 0,
"label": "Message", "label": "Message",
"permlevel": 0 "permlevel": 0
@@ -64,7 +64,7 @@
"icon": "icon-envelope", "icon": "icon-envelope",
"idx": 1, "idx": 1,
"in_create": 1, "in_create": 1,
"modified": "2015-01-21 14:41:14.336182",
"modified": "2015-01-23 04:32:39.175147",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Email", "module": "Email",
"name": "Bulk Email", "name": "Bulk Email",


+ 2
- 2
frappe/email/doctype/email_account/email_account.py Wyświetl plik

@@ -189,5 +189,5 @@ def pull():
"""Will be called via scheduler, pull emails from all enabled POP3 email accounts.""" """Will be called via scheduler, pull emails from all enabled POP3 email accounts."""
import frappe.tasks import frappe.tasks
for email_account in frappe.get_list("Email Account", filters={"enable_incoming": 1}): for email_account in frappe.get_list("Email Account", filters={"enable_incoming": 1}):
#frappe.tasks.pull_from_email_account.delay(frappe.local.site, email_account.name)
frappe.tasks.pull_from_email_account(frappe.local.site, email_account.name)
frappe.tasks.pull_from_email_account.delay(frappe.local.site, email_account.name)
#frappe.tasks.pull_from_email_account(frappe.local.site, email_account.name)

+ 2
- 1
frappe/email/email_body.py Wyświetl plik

@@ -171,7 +171,8 @@ class EMail:
return email return email


if not self.sender: if not self.sender:
self.sender = get_outgoing_email_account().email_id
email_account = get_outgoing_email_account()
self.sender = "{0} <{1}>".format(email_account.name, email_account.email_id)


self.sender = _validate(self.sender) self.sender = _validate(self.sender)
self.reply_to = _validate(self.reply_to) self.reply_to = _validate(self.reply_to)


+ 1
- 2
frappe/tasks.py Wyświetl plik

@@ -118,5 +118,4 @@ def pull_from_email_account(site, email_account):
email_account.receive() email_account.receive()
frappe.db.commit() frappe.db.commit()
finally: finally:
pass
#frappe.destroy()
frappe.destroy()

+ 4
- 0
frappe/utils/user.py Wyświetl plik

@@ -225,3 +225,7 @@ def get_roles(user=None, with_standard=True):
roles = filter(lambda x: x not in ['All', 'Guest', 'Administrator'], roles) roles = filter(lambda x: x not in ['All', 'Guest', 'Administrator'], roles)


return roles return roles

def get_enabled_system_users():
return frappe.db.sql("""select * from tabUser where
user_type='System User' and enabled=1 and name not in ('Administrator', 'Guest')""", as_dict=1)

Ładowanie…
Anuluj
Zapisz