summaryrefslogtreecommitdiff
path: root/addons/mail/mail_thread.py
diff options
context:
space:
mode:
authorThibault Delavallée <tde@openerp.com>2013-03-07 14:25:17 +0100
committerThibault Delavallée <tde@openerp.com>2013-03-07 14:25:17 +0100
commitfcea61b6ebce561743bfe3876dd5a705ce6a7bad (patch)
treed7c805a2deb3281d9227cb2958a29854f01cdd4c /addons/mail/mail_thread.py
parent1aac220ee25b7dc45c073c76112e50c68a3c4944 (diff)
[IMP] mail: added a cron job to delete mail attachments (lost user input or reports generated on-the-fly). They have: res_model = mail.compose.message; res_id 0; more than one day of inactivity.
bzr revid: tde@openerp.com-20130307132517-4xivu90dzn3o744a
Diffstat (limited to 'addons/mail/mail_thread.py')
-rw-r--r--addons/mail/mail_thread.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py
index 173ec951b32..2d43b93dd9a 100644
--- a/addons/mail/mail_thread.py
+++ b/addons/mail/mail_thread.py
@@ -389,6 +389,26 @@ class mail_thread(osv.AbstractModel):
return [('message_unread', '=', True)]
return []
+ def _garbage_collect_attachments(self, cr, uid, context=None):
+ """ Garbage collect lost mail attachments. Those are attachments
+ - linked to res_model 'mail.compose.message', the composer wizard
+ - with res_id 0, because they were created outside of an existing
+ wizard (typically user input through Chatter or reports
+ created on-the-fly by the templates)
+ - unused since at least one day (create_date and write_date)
+ """
+ limit_date = datetime.datetime.utcnow() - datetime.timedelta(days=1)
+ limit_date_str = datetime.datetime.strftime(limit_date, tools.DEFAULT_SERVER_DATETIME_FORMAT)
+ ir_attachment_obj = self.pool.get('ir.attachment')
+ attach_ids = ir_attachment_obj.search(cr, uid, [
+ ('res_model', '=', 'mail.compose.message'),
+ ('res_id', '=', 0),
+ ('create_date', '<', limit_date_str),
+ ('write_date', '<', limit_date_str),
+ ], context=context)
+ ir_attachment_obj.unlink(cr, uid, attach_ids, context=context)
+ return True
+
#------------------------------------------------------
# Email specific
#------------------------------------------------------