diff --git a/addons/mail_gateway/mail_gateway.py b/addons/mail_gateway/mail_gateway.py index c2e1da843ca..3cb2019e85a 100644 --- a/addons/mail_gateway/mail_gateway.py +++ b/addons/mail_gateway/mail_gateway.py @@ -112,7 +112,7 @@ class mailgate_thread(osv.osv): if history: for att in attach: attachments.append(att_obj.create(cr, uid, {'name': att[0], 'datas': base64.encodestring(att[1])})) - + for param in (email, email_cc, email_bcc): if isinstance(param, list): param = ", ".join(param) @@ -141,7 +141,7 @@ class mailgate_thread(osv.osv): mailgate_thread() def format_date_tz(date, tz=None): - if not date: + if not date: return 'n/a' format = tools.DEFAULT_SERVER_DATETIME_FORMAT return tools.server_to_local_timestamp(date, format, format, tz) @@ -191,7 +191,7 @@ class mailgate_message(osv.osv): 'description': fields.text('Description', readonly=True), 'partner_id': fields.many2one('res.partner', 'Partner', required=False), 'attachment_ids': fields.many2many('ir.attachment', 'message_attachment_rel', 'message_id', 'attachment_id', 'Attachments', readonly=True), - 'display_text': fields.function(_get_display_text, method=True, type='text', size="512", string='Display Text'), + 'display_text': fields.function(_get_display_text, method=True, type='text', size="512", string='Display Text'), } def init(self, cr): @@ -224,7 +224,7 @@ class mailgate_tool(osv.osv_memory): @param cr: the current row, from the database cursor, @param uid: the current user’s ID for security checks, @param model: OpenObject Model - @param res_ids: Ids of the record of OpenObject model created + @param res_ids: Ids of the record of OpenObject model created @param msg: Email details @param attach: Email attachments """ @@ -241,7 +241,7 @@ class mailgate_tool(osv.osv_memory): 'res_model': model, 'email_cc': msg.get('cc'), 'email_from': msg.get('from'), - 'email_to': msg.get('to'), + 'email_to': msg.get('to'), 'message_id': msg.get('message-id'), 'references': msg.get('references') or msg.get('in-reply-to'), 'res_id': res_id, @@ -283,6 +283,7 @@ class mailgate_tool(osv.osv_memory): tools.misc._email_send(smtp_from, self.to_email(email_error), msg, openobject_id=res.id) def process_email(self, cr, uid, model, message, attach=True, context=None): + print "processssss_emaillllllllll",model """This function Processes email and create record for given OpenERP model @param self: The object pointer @param cr: the current row, from the database cursor, diff --git a/addons/thunderbird/__openerp__.py b/addons/thunderbird/__openerp__.py index 703aec6ad67..ed16b4909a9 100644 --- a/addons/thunderbird/__openerp__.py +++ b/addons/thunderbird/__openerp__.py @@ -22,11 +22,11 @@ { "name" : "Thunderbird Interface", "version" : "1.0", - "author" : "Axelor", - "website" : "http://www.axelor.com/", - "depends" : ["base"], + "author" : "OpenERP SA & Axelor", + "website" : "http://www.openerp.com/", + "depends" : ["base","mail_gateway"], "category" : "Generic Modules/Thunderbird interface", - "description": ''' + "description": """ This module is required for the thuderbird plug-in to work properly. @@ -35,8 +35,7 @@ a project, an analytical account, or any other object and attach selected mail as .eml file in attachment of selected record. - You can create new case in crm using Create Case button. - Select a section for which you want to create case.''', + """, "init_xml" : [], "demo_xml" : [], "update_xml" : ['thunderbird_installer.xml', diff --git a/addons/thunderbird/partner/partner.py b/addons/thunderbird/partner/partner.py index 9d351841f55..4e5baf25904 100644 --- a/addons/thunderbird/partner/partner.py +++ b/addons/thunderbird/partner/partner.py @@ -25,27 +25,117 @@ from osv import osv,fields import base64 import netsvc from tools.translate import _ +import email +import tools +import binascii +class email_server_tools(osv.osv_memory): + _inherit = "email.server.tools" + def history_message(self, cr, uid, model, res_id, message): + #@param message: string of mail which is read from EML File + attachment_pool = self.pool.get('ir.attachment') + msg = self.parse_message(message) + attachments = msg.get('attachments', []) + att_ids = [] + for attachment in attachments: + data_attach = { + 'name': attachment, + 'datas': binascii.b2a_base64(str(attachments.get(attachment))), + 'datas_fname': attachment, + 'description': 'Mail attachment From Thunderbird msg_id: %s' %(msg.get('message_id', '')), + 'res_model': model, + 'res_id': res_id, + } + att_ids.append(attachment_pool.create(cr, uid, data_attach)) + return self.history(cr, uid, model, res_id, msg, att_ids) + + def parse_message(self, message): + #TOCHECK: put this function in mailgateway + msg_txt = email.message_from_string(message) + message_id = msg_txt.get('message-id', False) + msg = {} + msg_txt = email.message_from_string(message) + fields = msg_txt.keys() + msg['id'] = message_id + msg['message-id'] = message_id + + if 'Subject' in fields: + msg['subject'] = self._decode_header(msg_txt.get('Subject')) + + if 'Content-Type' in fields: + msg['content-type'] = msg_txt.get('Content-Type') + + if 'From' in fields: + msg['from'] = self._decode_header(msg_txt.get('From')) + + if 'Delivered-To' in fields: + msg['to'] = self._decode_header(msg_txt.get('Delivered-To')) + + if 'CC' in fields: + msg['cc'] = self._decode_header(msg_txt.get('CC')) + + if 'Reply-to' in fields: + msg['reply'] = self._decode_header(msg_txt.get('Reply-To')) + + if 'Date' in fields: + msg['date'] = self._decode_header(msg_txt.get('Date')) + + if 'Content-Transfer-Encoding' in fields: + msg['encoding'] = msg_txt.get('Content-Transfer-Encoding') + + if 'References' in fields: + msg['references'] = msg_txt.get('References') + + if 'In-Reply-To' in fields: + msg['in-reply-to'] = msg_txt.get('In-Reply-To') + + if 'X-Priority' in fields: + msg['priority'] = msg_txt.get('X-Priority', '3 (Normal)').split(' ')[0] + + if not msg_txt.is_multipart() or 'text/plain' in msg.get('Content-Type', ''): + encoding = msg_txt.get_content_charset() + body = msg_txt.get_payload(decode=True) + msg['body'] = tools.ustr(body, encoding) + + attachments = {} + has_plain_text = False + if msg_txt.is_multipart() or 'multipart/alternative' in msg.get('content-type', ''): + body = "" + for part in msg_txt.walk(): + if part.get_content_maintype() == 'multipart': + continue + + encoding = part.get_content_charset() + filename = part.get_filename() + if part.get_content_maintype()=='text': + content = part.get_payload(decode=True) + if filename: + attachments[filename] = content + elif not has_plain_text: + # main content parts should have 'text' maintype + # and no filename. we ignore the html part if + # there is already a plaintext part without filename, + # because presumably these are alternatives. + content = tools.ustr(content, encoding) + if part.get_content_subtype() == 'html': + body = tools.ustr(tools.html2plaintext(content)) + elif part.get_content_subtype() == 'plain': + body = content + has_plain_text = True + elif part.get_content_maintype() in ('application', 'image'): + if filename : + attachments[filename] = part.get_payload(decode=True) + else: + res = part.get_payload(decode=True) + body += tools.ustr(res, encoding) + + msg['body'] = body + msg['attachments'] = attachments + return msg +email_server_tools() class thunderbird_partner(osv.osv_memory): _name = "thunderbird.partner" _description="Thunderbid mails" - _rec_name="sender" - - def mailcreate(self,cr,user,vals): - dictcreate = dict(vals) - import email - header_name = email.Header.decode_header(dictcreate['name']) - dictcreate['name'] = header_name and header_name[0] and header_name[0][0] - address_obj = self.pool.get('res.partner.address') - case_pool = self.pool.get(dictcreate.get('object','crm.lead')) - partner_ids = address_obj.search(cr,user,[('email','=',dictcreate['email_from'])]) - partner = address_obj.read(cr,user,partner_ids,['partner_id','name']) - if partner and partner[0] and partner[0]['partner_id']: - dictcreate.update({'partner_id':partner[0]['partner_id'][0],'partner_name':partner[0]['name']}) - create_id = case_pool.create(cr, user, dictcreate) - cases = case_pool.browse(cr,user,[create_id]) - case_pool._history(cr, user, cases, _('Archive'), history=True, email=False) - return create_id def create_contact(self,cr,user,vals): dictcreate = dict(vals) @@ -54,6 +144,21 @@ class thunderbird_partner(osv.osv_memory): create_id = self.pool.get('res.partner.address').create(cr, user, dictcreate) return create_id + def history_message(self,cr,uid,vals): + dictcreate = dict(vals) + server_tools_pool = self.pool.get('email.server.tools') + res_id = int(dictcreate.get('res_id')) + model = str(dictcreate.get('model')) + message = str(dictcreate.get('message')) + server_tools_pool.history_message(cr,uid,model,res_id,message) + return True + + def process_email(self,cr,uid,vals): + dictcreate = dict(vals) + model = str(dictcreate.get('model')) + message = str(dictcreate.get('message')) + return self.pool.get('email.server.tools').process_email(cr, uid, model, message, attach=True, context=None) + def search_contact(self, cr, user, vals): address_obj = self.pool.get('res.partner.address') partner = address_obj.search(cr, user,[('email','=',vals)]) @@ -161,21 +266,7 @@ class thunderbird_partner(osv.osv_memory): name_get.append(er_val) return name_get - def create_attachment(self,cr,user,vals): - dictcreate = dict(vals) - datas = [dictcreate['datas']] - name = [dictcreate['name']] - f_name = [dictcreate['datas_fname']] - if(dictcreate['datas'].__contains__(',')): - name = dictcreate['name'].split(',') - datas = dictcreate['datas'].split(',') - f_name = dictcreate['datas_fname'].split(',') - for i in range(0,datas.__len__()): - dictcreate['name'] = name[i] - dictcreate['datas'] = datas[i] - dictcreate['datas_fname'] = f_name[i] - create_id = self.pool.get('ir.attachment').create(cr,user,dictcreate) - return 0 + def list_alldocument(self,cr,user,vals): obj_list= [('crm.lead','Lead'),('project.issue','Project Issue'), ('hr.applicant','HR Recruitment')] diff --git a/addons/thunderbird/plugin/chrome/openerp_plugin.jar b/addons/thunderbird/plugin/chrome/openerp_plugin.jar index ac560f93909..b5ce0747bcd 100644 Binary files a/addons/thunderbird/plugin/chrome/openerp_plugin.jar and b/addons/thunderbird/plugin/chrome/openerp_plugin.jar differ diff --git a/addons/thunderbird/plugin/chrome/openerp_plugin/content/address.xul b/addons/thunderbird/plugin/chrome/openerp_plugin/content/address.xul index 407821ef4db..2d6f0e2dec1 100644 --- a/addons/thunderbird/plugin/chrome/openerp_plugin/content/address.xul +++ b/addons/thunderbird/plugin/chrome/openerp_plugin/content/address.xul @@ -17,13 +17,14 @@