crm, tools: improve mailgate

- add X-TinyCRM in the header to prevent modification of the subject

bzr revid: ced-3309408bfc064865cc8d8e9382723a0129240630
This commit is contained in:
ced
2007-08-01 14:03:50 +00:00
parent 37e830828a
commit d7236046bb
2 changed files with 18 additions and 11 deletions
+9 -5
View File
@@ -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):
@@ -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'])