From 412b0eab4e6cf9fe90e548294129fb2273add3ac Mon Sep 17 00:00:00 2001 From: "Christophe Chauvet (Sylean)" <> Date: Fri, 12 Mar 2010 13:35:28 +0100 Subject: [PATCH 01/10] [FIX] crm, mail_gateway: Use the utf8 encoding bzr revid: stephane@openerp.com-20100312123528-ppvn4w9sdi20iw6v --- addons/crm/crm_action_rule.py | 30 +++++++++++++++---- addons/crm/crm_mailgate.py | 13 +++++--- .../crm/wizard/wizard_crm_new_send_email.py | 2 +- addons/crm/wizard/wizard_crm_send_email.py | 10 +++++-- addons/mail_gateway/mail_gateway.py | 6 ++-- 5 files changed, 44 insertions(+), 17 deletions(-) diff --git a/addons/crm/crm_action_rule.py b/addons/crm/crm_action_rule.py index 1e7c50588db..0ca078d9b36 100644 --- a/addons/crm/crm_action_rule.py +++ b/addons/crm/crm_action_rule.py @@ -55,11 +55,12 @@ class case(osv.osv): if case.section_id.reply_to and case.email_from: src = case.email_from dest = case.section_id.reply_to + body = "" body = case.email_last or case.description if not destination: src, dest = dest, src - if case.user_id.signature: - body += '\n\n%s' % (case.user_id.signature or '') + if body and case.user_id.signature: + body += '\n\n%s' % (case.user_id.signature).encode('utf8') dest = [dest] attach_to_send = None @@ -79,10 +80,10 @@ class case(osv.osv): openobject_id=str(case.id), attach=attach_to_send ) - if flag: - raise osv.except_osv(_('Email!'),("Email Successfully Sent")) - else: - raise osv.except_osv(_('Email Fail!'),("Email is not sent successfully")) + #if flag: + # raise osv.except_osv(_('Email!'),("Email Successfully Sent")) + #else: + # raise osv.except_osv(_('Email Fail!'),("Email is not sent successfully")) return True def _check(self, cr, uid, ids=False, context={}): @@ -120,6 +121,23 @@ case() class base_action_rule(osv.osv): _inherit = 'base.action.rule' _description = 'Action Rules' + + def email_send(self, cr, uid, obj, emails, body, emailfrom=tools.config.get('email_from',False), context={}): + body = self.format_mail(obj, body) + if not emailfrom: + if hasattr(obj, 'user_id') and obj.user_id and obj.user_id.address_id and obj.user_id.address_id.email: + emailfrom = obj.user_id.address_id.email + + name = '[%d] %s' % (obj.id, tools.ustr(obj.name)) + emailfrom = tools.ustr(emailfrom) + if obj.section_id and obj.section_id.reply_to: + reply_to = obj.section_id.reply_to + else: + reply_to = emailfrom + if not emailfrom: + raise osv.except_osv(_('Error!'), + _("No E-Mail ID Found for your Company address!")) + return tools.email_send(emailfrom, emails, name, body, reply_to=reply_to, openobject_id=str(obj.id)) def do_check(self, cr, uid, action, obj, context={}): ok = super(base_action_rule, self).do_check(cr, uid, action, obj, context=context) diff --git a/addons/crm/crm_mailgate.py b/addons/crm/crm_mailgate.py index 8b2f3bdef88..f500e3e082f 100644 --- a/addons/crm/crm_mailgate.py +++ b/addons/crm/crm_mailgate.py @@ -36,13 +36,18 @@ class crm_cases(osv.osv): _name = "crm.case" _inherit = "crm.case" + def _decode_header(self, s): + from email.Header import decode_header + s = decode_header(s) + return ''.join(map(lambda x:x[0].decode(x[1] or 'ascii', 'replace'), s)) + def msg_new(self, cr, uid, msg): mailgate_obj = self.pool.get('mail.gateway') msg_body = mailgate_obj.msg_body_get(msg) data = { - 'name': msg['Subject'], - 'email_from': msg['From'], - 'email_cc': msg['Cc'], + 'name': self._decode_header(msg['Subject']), + 'email_from': self._decode_header(msg['From']), + 'email_cc': msg['Cc'] and self._decode_header(msg['Cc']), 'user_id': False, 'description': msg_body['body'], } @@ -51,7 +56,7 @@ class crm_cases(osv.osv): data.update(res) res = self.create(cr, uid, data) cases = self.browse(cr, uid, [res]) - self._history(cr, uid, cases, _('Receive'), history=True, email=msg['From']) + self._history(cr, uid, cases, _('Receive'), history=True, email=self._decode_header(msg['From'])) return res def msg_update(self, cr, uid, ids, msg, data={}, default_act='pending'): diff --git a/addons/crm/wizard/wizard_crm_new_send_email.py b/addons/crm/wizard/wizard_crm_new_send_email.py index 0114ac9408f..61491fe437d 100644 --- a/addons/crm/wizard/wizard_crm_new_send_email.py +++ b/addons/crm/wizard/wizard_crm_new_send_email.py @@ -81,7 +81,7 @@ def _mass_mail_send(self, cr, uid, data, context): emails = filter(None, emails) body = data['form']['text'] if case.user_id.signature: - body += '\n\n%s' % (case.user_id.signature) + body += '\n\n%s' % (case.user_id.signature).encode('utf8') case_pool._history(cr, uid, [case], _('Send'), history=True, email=data['form']['to'], details=body) flag = tools.email_send( case.user_id.address_id.email, diff --git a/addons/crm/wizard/wizard_crm_send_email.py b/addons/crm/wizard/wizard_crm_send_email.py index d6b3732d5e7..02f8f2abe04 100644 --- a/addons/crm/wizard/wizard_crm_send_email.py +++ b/addons/crm/wizard/wizard_crm_send_email.py @@ -61,11 +61,17 @@ def _mass_mail_send(self, cr, uid, data, context): 'som': False, 'canal_id': False, }) - emails = [data['form']['to']] + (data['form']['cc'] or '').split(',') + from_to = tools.email_re.search(data['form']['to']).group(1) + emails = [] + if from_to: + emails.append(from_to) + for cc in (data['form']['cc'] or '').split(','): + if cc: + emails.append(tools.email_re.search(cc).group(1)) emails = filter(None, emails) body = data['form']['text'] if case.user_id.signature: - body += '\n\n%s' % (case.user_id.signature) + body += '\n\n%s' % (case.user_id.signature).encode('utf8') tools.email_send( case.user_id.address_id.email, emails, diff --git a/addons/mail_gateway/mail_gateway.py b/addons/mail_gateway/mail_gateway.py index ee7676d4423..a25816d28b2 100644 --- a/addons/mail_gateway/mail_gateway.py +++ b/addons/mail_gateway/mail_gateway.py @@ -362,13 +362,11 @@ class mail_gateway(osv.osv): del msg['Subject'] msg['Subject'] = '[%s] %s' %(str(res_id), subject) - em = [user_email, from_email] + (cc_email or '').split(',') + em = [user_email or '', from_email] + (cc_email or '').split(',') emails = map(self.emails_get, filter(None, em)) - mm = [self._decode_header(msg['From']), self._decode_header(msg['To'])]+self._decode_header(msg.get('Cc','')).split(',') msg_mails = map(self.emails_get, filter(None, mm)) - - emails = filter(lambda m: m and m not in msg_mails, emails) + emails = filter(lambda m: m and m not in msg_mails, emails) try: self.msg_send(msg, mailgateway.reply_to, emails, priority, res_id) if hasattr(self.pool.get(res_model), 'msg_send'): From 5f80bdb7e604b19a8b1ed8c5e463a5ac2b9c230f Mon Sep 17 00:00:00 2001 From: "Harry (Open ERP)" Date: Tue, 30 Mar 2010 19:04:13 +0530 Subject: [PATCH 02/10] [FIX]crm : fixed problems regardig email_from/email_to bzr revid: hmo@tinyerp.com-20100330133413-35za8j33reo3eoyg --- addons/crm/crm.py | 13 +++++++++---- .../scripts/openerp_mailgate/openerp_mailgate.py | 6 +++--- addons/crm/wizard/crm_send_email.py | 7 ++++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/addons/crm/crm.py b/addons/crm/crm.py index 45d043426cd..f19cd4bfb19 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -316,14 +316,19 @@ class crm_case(osv.osv): self.write(cr, uid, [case.id], {'stage_id': s[section][st]}) return True - def history(self, cr, uid, ids, keyword, history=False, email=False, details=None, context={}): + def history(self, cr, uid, ids, keyword, history=False, email=False, details=None, email_from=False, context={}): cases = self.browse(cr, uid, ids, context=context) - return self.__history(cr, uid, cases, keyword=keyword,\ - history=history, email=email, details=details,\ + return self._history(cr, uid, cases, keyword=keyword,\ + history=history, email=email, details=details, email_from=email_from, \ context=context) def __history(self, cr, uid, cases, keyword, history=False, email=False, details=None, email_from=False, context={}): - model_obj = self.pool.get('ir.model') + model_obj = self.pool.get('ir.model') + if email and type(email) == type([]): + email = ','.join(email) + if email_from and type(email_from) == type([]): + email_from = ','.join(email_from) + for case in cases: model_ids = model_obj.search(cr, uid, [('model','=',case._name)]) data = { diff --git a/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py b/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py index 3a7bf182fc3..5a7b888f52c 100755 --- a/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py +++ b/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py @@ -175,7 +175,7 @@ class email_parser(object): try: id = self.rpc(self.model, 'create', data) - self.rpc(self.model, 'history', [id], 'Receive', True, msg['From'], message['body']) + self.rpc(self.model, 'history', [id], 'Receive', True, False, message['body'], msg['From']) #self.rpc(self.model, 'case_open', [id]) except Exception, e: if getattr(e, 'faultCode', '') and 'AccessError' in e.faultCode: @@ -290,7 +290,7 @@ class email_parser(object): self.rpc(self.model, act, [id]) self.rpc(self.model, 'write', [id], data) - self.rpc(self.model, 'history', [id], 'Receive', True, details=body['body'], email_from=msg['From']) + self.rpc(self.model, 'history', [id], 'Receive', True, False, body['body'], msg['From']) return id def msg_send(self, msg, emails, priority=None): @@ -322,7 +322,7 @@ class email_parser(object): # 'description':body, #} #self.rpc(self.model, 'write', [id], data) - self.rpc(self.model, 'history', [id], 'Receive', True, details=message['body'], email_from=msg['From']) + self.rpc(self.model, 'history', [id], 'Receive', True, False, message['body'], msg['From']) return id def msg_test(self, msg, case_str): diff --git a/addons/crm/wizard/crm_send_email.py b/addons/crm/wizard/crm_send_email.py index ce1673939af..f76e212eaa1 100644 --- a/addons/crm/wizard/crm_send_email.py +++ b/addons/crm/wizard/crm_send_email.py @@ -181,10 +181,11 @@ class crm_send_new_email(osv.osv_memory): model = hist.log_id.model_id.model model_pool = self.pool.get(model) case = model_pool.browse(cr, uid, hist.log_id.res_id) - if 'email_to' in fields and hist.email_to: - res.update({'email_to': hist.email_to}) + if 'email_to' in fields: + res.update({'email_to': hist.email_from or (case.user_id and case.user_id.address_id and \ + case.user_id.address_id.email) or tools.config.get('email_from',False)}) if 'email_from' in fields: - res.update({'email_from': (case.user_id and case.user_id.address_id and \ + res.update({'email_from': hist.email_to or (case.user_id and case.user_id.address_id and \ case.user_id.address_id.email) or tools.config.get('email_from',False)}) if 'text' in fields: header = '-------- Original Message --------' From d4916302335e5325d0fb04e8ff3695e79bc8944d Mon Sep 17 00:00:00 2001 From: "Harry (Open ERP)" Date: Tue, 30 Mar 2010 20:19:13 +0530 Subject: [PATCH 03/10] [FIX] crm: made common view of reply mail and send new mail wizard bzr revid: hmo@tinyerp.com-20100330144913-2oy0fk8o3ii1txzl --- addons/crm/crm_claims_view.xml | 2 +- addons/crm/crm_fund_view.xml | 2 +- addons/crm/crm_helpdesk_view.xml | 2 +- addons/crm/crm_lead_view.xml | 2 +- addons/crm/crm_opportunity_view.xml | 2 +- addons/crm/crm_view.xml | 2 +- .../openerp_mailgate/openerp_mailgate.py | 8 ++- addons/crm/wizard/crm_send_email.py | 6 +-- addons/crm/wizard/crm_send_email_view.xml | 52 +++---------------- addons/hr_recruitment/hr_recruitment_view.xml | 2 +- addons/project_issue/project_issue_view.xml | 2 +- 11 files changed, 23 insertions(+), 59 deletions(-) diff --git a/addons/crm/crm_claims_view.xml b/addons/crm/crm_claims_view.xml index c1a3345e51b..2104c1c8d94 100644 --- a/addons/crm/crm_claims_view.xml +++ b/addons/crm/crm_claims_view.xml @@ -157,7 +157,7 @@