[MERGE] mail: make post-processing of sent messages extensible

bzr revid: odo@openerp.com-20120329104149-9xjt9gr2sj1fb9m0
This commit is contained in:
Olivier Dony 2012-03-29 12:41:49 +02:00
commit 11f4469e85
1 changed files with 19 additions and 9 deletions

View File

@ -464,6 +464,23 @@ class mail_message(osv.osv):
msg['sub_type'] = msg['subtype'] or 'plain'
return msg
def _postprocess_sent_message(self, cr, uid, message, context=None):
"""Perform any post-processing necessary after sending ``message``
successfully, including deleting it completely along with its
attachment if the ``auto_delete`` flag of the message was set.
Overridden by subclasses for extra post-processing behaviors.
:param browse_record message: the message that was just sent
:return: True
"""
if message.auto_delete:
self.pool.get('ir.attachment').unlink(cr, uid,
[x.id for x in message.attachment_ids \
if x.res_model == self._name and \
x.res_id == message.id],
context=context)
message.unlink()
return True
def send(self, cr, uid, ids, auto_commit=False, context=None):
"""Sends the selected emails immediately, ignoring their current
@ -521,16 +538,9 @@ class mail_message(osv.osv):
message.write({'state':'sent', 'message_id': res})
else:
message.write({'state':'exception'})
# if auto_delete=True then delete that sent messages as well as attachments
message.refresh()
if message.state == 'sent' and message.auto_delete:
self.pool.get('ir.attachment').unlink(cr, uid,
[x.id for x in message.attachment_ids \
if x.res_model == self._name and \
x.res_id == message.id],
context=context)
message.unlink()
if message.state == 'sent':
self._postprocess_sent_message(cr, uid, message, context=context)
except Exception:
_logger.exception('failed sending mail.message %s', message.id)
message.write({'state':'exception'})