From 69a7e6e1bd8da5cb20fa73d702b9a4d739c8848c Mon Sep 17 00:00:00 2001 From: Mantavya Gajjar Date: Thu, 22 Apr 2010 19:42:24 +0530 Subject: [PATCH] [IMP]: implement file ext based processing for file bzr revid: mga@tinyerp.com-20100422141224-k9ups5b7ztz4plmf --- addons/document_email/document_email.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/addons/document_email/document_email.py b/addons/document_email/document_email.py index 7e5b45bd6cb..a4406f7a4d5 100644 --- a/addons/document_email/document_email.py +++ b/addons/document_email/document_email.py @@ -21,12 +21,17 @@ # ############################################################################## +import os import binascii +import netsvc + from osv import osv from osv import fields from tools.translate import _ +logger = netsvc.Logger() + class email_to_document(osv.osv): _name = 'document.email' @@ -42,7 +47,7 @@ class email_to_document(osv.osv): } _defaults = { - 'accept_files': lambda *a: "['txt', 'ppt', 'doc', 'xls', 'pdf', 'jpg', 'png']", + 'accept_files': lambda *a: "['.txt', '.ppt', '.doc', '.xls', '.pdf', '.jpg', '.png']", 'user_id': lambda self, cr, uid, ctx: uid, } @@ -62,12 +67,19 @@ class email_to_document(osv.osv): file_pool = self.pool.get('ir.attachment') if server_id: ids = self.search(cr, uid, [('server_id', '=', server_id)]) - id = self.browse(cr, uid, ids[0]).directory_id.id + dr = self.browse(cr, uid, ids[0]) + id = dr.directory_id.id partner = self.pool.get('email.server.tools').get_partner(cr, uid, msg.get('from'), context) - + ext = eval(dr.accept_files, {}) attachents = msg.get('attachments', []) + for attactment in attachents: + file_ext = os.path.splitext(attactment) + if file_ext[1] not in ext: + logger.notifyChannel('document', netsvc.LOG_WARNING, 'file type %s is not allows to process for directory %s' % (file_ext[1], dr.directory_id.name)) + continue + data_attach = { 'name': attactment, 'datas':binascii.b2a_base64(str(attachents.get(attactment))), @@ -90,7 +102,7 @@ class email_to_document(osv.osv): @param uid: the current user’s ID for security checks, @param ids: List of update mail’s IDs """ - + logger.notifyChannel('document', netsvc.LOG_WARNING, 'method not implement to keep multipe version of file') return True email_to_document()