Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Rafael Monnerat
erp5
Commits
13e0b85f
Commit
13e0b85f
authored
Dec 20, 2013
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove old duplicated implementation of sending email
parent
4dad33bd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
177 deletions
+2
-177
product/ERP5/Document/EmailDocument.py
product/ERP5/Document/EmailDocument.py
+0
-173
product/ERP5/Document/Event.py
product/ERP5/Document/Event.py
+2
-4
No files found.
product/ERP5/Document/EmailDocument.py
View file @
13e0b85f
...
...
@@ -564,179 +564,6 @@ class EmailDocument(TextDocument):
content_information = self.getContentInformation()
return content_information.get('
Return
-
Path
', content_information.get('
From
'))
security.declareProtected(Permissions.UseMailhostServices, '
send
')
def send(self, from_url=None, to_url=None, reply_url=None, subject=None,
body=None, attachment_format=None, attachment_list=None, download=False):
"""
Sends the current event content by email. If documents are
attached through the aggregate category, enclose them.
XXX - needs to be unified with Event methods
from_url - the sender of this email. If not provided
we will use source to find a valid
email address
to_url - the recipients of this email. If not provided
we will use destination category to
find a list of valid email addresses
reply_url - the email address to reply to. If nothing
is provided, use the email defined in
preferences.
subject - a custom title. If not provided, we will use
getTitle
body - a body message If not provided, we will
use the text representation of the event
as body (UTF-8)
attachment_list -- list of dictionary which contains raw data and
name and mimetype for attachment.
See NotificationTool.buildEmailMessage.
attachment_format - defines an option format
to convet attachments to (ex. application/pdf)
download - if set to True returns, the message online
rather than sending it.
TODO: support conversion to base format and use
base format rather than original format
TODO2: consider turning this method into a general method for
any ERP5 document.
"""
if not _checkPermission(Permissions.View, self):
raise Unauthorized
additional_headers = {}
#
# Build mail message
# This part will be replaced with MailTemplate soon.
#
if body is None:
body = self.asText()
# Subject
if subject is None:
subject = self.getTitle()
# From
if from_url is None:
sender = self.getSourceValue()
if sender is not None:
from_url = formataddr((sender.getTitle(),
sender.getDefaultEmailText()))
else:
from_url = self.getSender() # Access sender directly
# Return-Path
if reply_url is None:
reply_url = self.portal_preferences.getPreferredEventSenderEmail()
if reply_url:
additional_headers['
Return
-
Path
'] = reply_url
# Reply-To
destination_reference = self.getDestinationReference()
if destination_reference is not None:
additional_headers['
In
-
Reply
-
To
'] = destination_reference
# To (multiple)
to_url_list = set()
to_email_list = []
if to_url is None:
for recipient in self.getDestinationValueList():
email = recipient.getDefaultEmailText()
if email:
if email not in to_email_list:
to_email_list.append(email)
to_url_list.add(formataddr((recipient.getTitle(), email)))
else:
raise ValueError, '
Recipient
%
s
has
no
defined
email
' % recipient
if not to_url_list:
to_url_list.add(self.getRecipient())
elif type(to_url) in types.StringTypes:
to_url_list.add(to_url)
# Attachments
if attachment_list is None:
attachment_list = []
document_type_list = self.getPortalDocumentTypeList()
embedded_attachment_list = []
for attachment in self.getAggregateValueList():
mime_type = None
content = None
name = None
if not attachment.getPortalType() in document_type_list:
mime_type = '
application
/
pdf
'
content = attachment.asPDF() # XXX - Not implemented yet
else:
#
# Document type attachment
#
# WARNING - this could fail since getContentType
# is not (yet) part of Document API
if getattr(attachment, '
getContentType
', None) is not None:
mime_type = attachment.getContentType()
else:
raise ValueError, "Cannot find mimetype of the document."
if mime_type is not None:
try:
mime_type, content = attachment.convert(mime_type)
except ConversionError:
mime_type = attachment.getBaseContentType()
content = attachment.getBaseData()
except (NotImplementedError, MimeTypeException):
pass
if content is None:
if getattr(attachment, '
getTextContent
', None) is not None:
content = attachment.getTextContent()
elif getattr(attachment, '
getData
', None) is not None:
content = attachment.getData()
elif getattr(attachment, '
getBaseData
', None) is not None:
content = attachment.getBaseData()
if not isinstance(content, str):
content = str(content)
embedded_attachment_list.append({'
mime_type
':mime_type,
'
content
':content,
'
name
':attachment.getReference()}
)
mail_message = None
for to_url in to_url_list:
mime_message = buildEmailMessage(from_url=from_url, to_url=to_url,
msg=body, subject=subject,
attachment_list=(attachment_list + embedded_attachment_list),
additional_headers=additional_headers)
mail_message = mime_message.as_string()
self.activate(activity='
SQLQueue
').sendMailHostMessage(mail_message)
# Save one of mail messages.
if mail_message is not None:
if len(embedded_attachment_list):
# do not store aggregated documents in Email document
# to avoid duplicate data
tmp_mime_message = buildEmailMessage(from_url=from_url, to_url=to_url,
msg=body, subject=subject,
attachment_list=attachment_list,
additional_headers=additional_headers)
tmp_mail_message = mime_message.as_string()
self.setData(tmp_mail_message)
else:
self.setData(mail_message)
# Only for debugging purpose
if download:
return mail_message
security.declareProtected(Permissions.UseMailhostServices, '
sendMailHostMessage
')
def sendMailHostMessage(self, message):
"""
...
...
product/ERP5/Document/Event.py
View file @
13e0b85f
...
...
@@ -163,10 +163,8 @@ class Event(Movement, EmailDocument, AcknowledgeableMixin):
"""
send_script
=
self
.
_getTypeBasedMethod
(
'send'
)
if
send_script
is
None
:
return
Event
.
inheritedAttribute
(
'send'
)(
self
,
from_url
,
to_url
,
reply_url
,
subject
,
body
,
attachment_format
,
attachment_list
,
download
)
raise
NotImplementedError
(
"`send` type based method not found. "
"Please update erp5_base and erp5_crm"
)
return
send_script
(
from_url
,
to_url
,
reply_url
,
subject
,
body
,
attachment_format
,
attachment_list
,
download
,
**
kw
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment