[IMP] mail.thread: support stripping attachments

bzr revid: odo@openerp.com-20110908001651-ns4nw0ri18xp7twf
This commit is contained in:
Olivier Dony 2011-09-08 02:16:51 +02:00
parent eca9d6decf
commit da59a314e6
2 changed files with 8 additions and 2 deletions

View File

@ -297,7 +297,8 @@ class mail_thread(osv.osv):
def message_process(self, cr, uid, model, message, custom_values=None,
save_original=False, context=None):
save_original=False, strip_attachments=False,
context=None):
"""Process an incoming RFC2822 email message related to the
given thread model, relying on ``mail.message.parse()``
for the parsing operation, and then calling ``message_new``
@ -315,6 +316,8 @@ class mail_thread(osv.osv):
if the thread record already exists.
:param bool save_original: whether to keep a copy of the original
email source attached to the message after it is imported.
:param bool strip_attachments: whether to strip all attachments
before processing the message, in order to save some space.
"""
# extract message bytes - we are forced to pass the message as binary because
# we don't know its encoding until we parse its headers and hence can't
@ -338,6 +341,9 @@ class mail_thread(osv.osv):
msg_txt = email.message_from_string(message)
msg = mail_message.parse_message(msg_txt, save_original=save_original)
if strip_attachments and 'attachments' in msg:
del msg['attachments']
# Create New Record into particular model
def create_record(msg):
if hasattr(model_pool, 'message_new'):

View File

@ -111,7 +111,7 @@ class thunderbird_partner(osv.osv_memory):
dictcreate = dict(vals)
model = str(dictcreate.get('model'))
message = dictcreate.get('message')
return self.pool.get('mail.thread').message_process(cr, uid, model, message, attach=True, context=None)
return self.pool.get('mail.thread').message_process(cr, uid, model, message)
def search_message(self, cr, uid, message, context=None):
#@param message: string of mail which is read from EML File