Commit 25261b03 authored by Jérome Perrin's avatar Jérome Perrin

base: make Entity_sendEmail raise early for missing email addresses

on python2, this sends an email with address like "Name <None>", on
python3 this fails with an error like this:

  Module script, line 15, in Entity_sendEmail
   - <PythonScript at /portal_2664097758140587659/Entity_sendEmail used for /portal_2664097758140587659/person_module/20241227-13AB7>
   - Line 15
    from_url = formataddr((sender.hasTitle() and sender.getTitle(), sender.getDefaultEmailText()))
  Module email.utils, line 92, in formataddr
    address.encode('ascii')

better to fail early in such a case
parent cef7ffbb
......@@ -12,11 +12,17 @@ sender = event.getSourceValue()
if kw.get("from_url") is not None:
from_url = kw.get("from_url")
elif sender is not None:
from_url = formataddr((sender.hasTitle() and sender.getTitle(), sender.getDefaultEmailText()))
sender_email_text = sender.getDefaultEmailText()
if not sender_email_text:
raise ValueError("Sender %s ( %s ) does not have email address" % (sender.getTitle(), sender.getRelativeUrl()))
from_url = formataddr((sender.hasTitle() and sender.getTitle(), sender_email_text))
else:
from_url = portal.portal_preferences.getPreferredEventSenderEmail()
to_url = formataddr((context.hasTitle() and context.getTitle(), context.getDefaultEmailText()))
recipient_email_text = context.getDefaultEmailText()
if not recipient_email_text:
raise ValueError("Recipient %s ( %s ) does not have email address" % (context.getTitle(), context.getRelativeUrl()))
to_url = formataddr((context.hasTitle() and context.getTitle(), recipient_email_text))
document_type_list = list(event.getPortalEmbeddedDocumentTypeList()) + list(event.getPortalDocumentTypeList())
embedded_file_list = event.getAggregateValueList(portal_type=document_type_list)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment