From d7236046bb9a69ea28fe9f07667817a5f20cb06a Mon Sep 17 00:00:00 2001 From: ced <> Date: Wed, 1 Aug 2007 14:03:50 +0000 Subject: [PATCH] crm, tools: improve mailgate - add X-TinyCRM in the header to prevent modification of the subject bzr revid: ced-3309408bfc064865cc8d8e9382723a0129240630 --- addons/crm/crm.py | 14 +++++++++----- .../scripts/tinyerp-mailgate/tinyerp-mailgate.py | 15 +++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/addons/crm/crm.py b/addons/crm/crm.py index fcb762a1a65..5650c94a613 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -386,7 +386,7 @@ class crm_case(osv.osv): emailfrom = case.user_id.address_id.email else: emailfrom = case.section_id.reply_to - tools.email_send(emailfrom, emails, '['+str(case.id)+'] '+case.name, body, reply_to=case.section_id.reply_to) + tools.email_send(emailfrom, emails, '['+str(case.id)+'] '+case.name, body, reply_to=case.section_id.reply_to, tinycrm=str(case.id)) return True def __log(self, cr, uid, cases, keyword, context={}): if not self.pool.get('res.partner.event.type').check(cr, uid, 'crm_case_'+keyword): @@ -444,7 +444,8 @@ class crm_case(osv.osv): src, dest, 'Reminder: '+'['+str(case.id)+']'+' '+case.name, - case.email_last or case.description, reply_to=case.section_id.reply_to + case.email_last or case.description, + reply_to=case.section_id.reply_to, tinycrm=str(case.id) ) else: attach_ids = self.pool.get('ir.attachment').search(cr, uid, [('res_model','=','crm.case'),('res_id','=',case.id)]) @@ -454,8 +455,9 @@ class crm_case(osv.osv): src, dest, 'Reminder: '+'['+str(case.id)+']'+' '+case.name, - case.email_last or case.description, reply_to=case.section_id.reply_to, - attach=res + case.email_last or case.description, + reply_to=case.section_id.reply_to, + attach=res, tinycrm=str(case.id) ) return True @@ -474,7 +476,9 @@ class crm_case(osv.osv): self.write(cr, uid, [case.id], {'description':False, 'som':False, 'canal_id': False, 'email_last':case.description}) emails = [case.email_from] + (case.email_cc or '').split(',') emails = filter(None, emails) - tools.email_send(case.user_id.address_id.email, emails, '['+str(case.id)+'] '+case.name, case.description, reply_to=case.section_id.reply_to) + tools.email_send(case.user_id.address_id.email, emails, + '['+str(case.id)+'] '+case.name, case.description, + reply_to=case.section_id.reply_to, tinycrm=str(case.id)) return True def onchange_partner_id(self, cr, uid, ids, part, email=False): diff --git a/addons/crm/scripts/tinyerp-mailgate/tinyerp-mailgate.py b/addons/crm/scripts/tinyerp-mailgate/tinyerp-mailgate.py index 52e5bf6c001..541c8a8b4d6 100755 --- a/addons/crm/scripts/tinyerp-mailgate/tinyerp-mailgate.py +++ b/addons/crm/scripts/tinyerp-mailgate/tinyerp-mailgate.py @@ -18,7 +18,7 @@ email_re = re.compile(r""" [a-z]{2,3} # TLD ) """, re.VERBOSE) -project_re = re.compile(r"\[([0-9]+)\]", re.UNICODE) +case_re = re.compile(r"\[([0-9]+)\]", re.UNICODE) command_re = re.compile("^Set-([a-z]+) *: *(.+)$", re.I + re.UNICODE) priorities = { @@ -225,8 +225,12 @@ class email_parser(object): return (int(case_str), emails) def parse(self, msg): - case_str = project_re.search(msg.get('Subject', '')) - (case_id, emails) = self.msg_test(msg, case_str and case_str.group(1)) + case_str = msg.get('X-TinyCRM', '') + if not case_str: + case_str = case_re.search(msg.get('Subject', '')) + if case_str: + case_str = case_str.group(1) + (case_id, emails) = self.msg_test(msg, case_str) if case_id: if emails[0] and self.email_get(emails[0])==self.email_get(self._decode_header(msg['From'])): self.msg_user(msg, case_id) @@ -238,7 +242,7 @@ class email_parser(object): if msg.get('Subject', ''): del msg['Subject'] msg['Subject'] = '['+str(case_id)+'] '+subject - print 'Case', case_id, 'created...' + msg['X-TinyCRM'] = str(case_id) emails = self.rpc('crm.case', 'emails_get', case_id) priority = emails[3] @@ -249,9 +253,8 @@ class email_parser(object): msg_mails = map(self.email_get, filter(None, mm)) emails = filter(lambda m: m and m not in msg_mails, emails) - self.msg_send(msg, emails, priority) try: - pass + self.msg_send(msg, emails, priority) except: if self.email_default: a = self._decode_header(msg['Subject'])