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/33] [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 5420c142e2bc2b13337f31f0e69a2735ce9f5598 Mon Sep 17 00:00:00 2001 From: "RVO(OpenERP)" <> Date: Fri, 19 Mar 2010 16:28:38 +0530 Subject: [PATCH 02/33] [IMP] security-rule-improvement bzr revid: hda@tinyerp.com-20100319105838-m3gy80pai28t0mcc --- bin/addons/base/ir/ir.xml | 15 +++++-- bin/addons/base/ir/ir_rule.py | 30 +++++++++---- bin/osv/orm.py | 84 +++++++++++++++++------------------ 3 files changed, 75 insertions(+), 54 deletions(-) diff --git a/bin/addons/base/ir/ir.xml b/bin/addons/base/ir/ir.xml index 0c280d2c0b3..2e589ef361e 100644 --- a/bin/addons/base/ir/ir.xml +++ b/bin/addons/base/ir/ir.xml @@ -369,7 +369,7 @@ - + @@ -431,7 +431,7 @@ - @@ -570,7 +570,7 @@ - + @@ -1176,6 +1176,11 @@