[IMP] mail: implement parent message resolution when parsing incoming message + cleanup lint
bzr revid: odo@openerp.com-20120828173901-8y9y16crvii8d2qg
This commit is contained in:
parent
fe03a7f1ed
commit
b19d73525d
|
@ -180,10 +180,7 @@ class mail_mail(osv.Model):
|
|||
references = message.references,
|
||||
object_id=message.res_id and ('%s-%s' % (message.res_id,message.model)),
|
||||
subtype=message.content_subtype,
|
||||
subtype_alternative=content_subtype_alternative,
|
||||
# TDE FIXME: what to do with headers ? currently ycommented to avoid bugs
|
||||
# headers=message.headers and ast.literal_eval(message.headers))
|
||||
)
|
||||
subtype_alternative=content_subtype_alternative)
|
||||
res = ir_mail_server.send_email(cr, uid, msg,
|
||||
mail_server_id=message.mail_server_id.id,
|
||||
context=context)
|
||||
|
|
|
@ -50,8 +50,7 @@ class mail_message(osv.Model):
|
|||
def _shorten_name(self, name):
|
||||
if len(name) <= (self._message_record_name_length+3):
|
||||
return name
|
||||
else:
|
||||
return name[:18] + '...'
|
||||
return name[:self._message_record_name_length] + '...'
|
||||
|
||||
def _get_record_name(self, cr, uid, ids, name, arg, context=None):
|
||||
""" Return the related document name, using get_name. """
|
||||
|
@ -318,6 +317,8 @@ class mail_message(osv.Model):
|
|||
self.pool.get(model).check_access_rule(cr, uid, mids, mode, context=context)
|
||||
|
||||
def create(self, cr, uid, values, context=None):
|
||||
if not values.get('message_id') and values.get('res_id') and values.get('model'):
|
||||
values['message_id'] = tools.generate_tracking_message_id('%(model)s-%(res_id)s'% values)
|
||||
newid = super(mail_message, self).create(cr, uid, values, context)
|
||||
self.check(cr, uid, [newid], mode='create', context=context)
|
||||
self.notify(cr, uid, newid, context=context)
|
||||
|
|
|
@ -553,9 +553,16 @@ class mail_thread(osv.Model):
|
|||
date_server_datetime_str = date_server_datetime.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
msg_dict['date'] = date_server_datetime_str
|
||||
|
||||
# FP Note: todo - find parent_id
|
||||
if 'In-Reply-To' in message:
|
||||
pass
|
||||
parent_ids = self.pool.get('mail.message').search(cr, uid, [('message_id','=',decode(message['In-Reply-To']))])
|
||||
if parent_ids:
|
||||
msg_dict['parent_id'] = parent_ids[0]
|
||||
|
||||
if 'References' in message and 'parent_id' not in msg_dict:
|
||||
parent_ids = self.pool.get('mail.message').search(cr, uid, [('message_id','in',
|
||||
[x.strip() for x in decode(message['References']).split()])])
|
||||
if parent_ids:
|
||||
msg_dict['parent_id'] = parent_ids[0]
|
||||
|
||||
msg_dict['body'], msg_dict['attachments'] = self._message_extract_payload(message)
|
||||
return msg_dict
|
||||
|
|
|
@ -313,7 +313,7 @@ class test_mail(common.TransactionCase):
|
|||
for val in read_dict:
|
||||
current = {'_id': val['id']}
|
||||
if val.get('child_ids'):
|
||||
current['child_ids'] = _flatten(val.get('child_ids'))
|
||||
current['child_ids'] = _simplify_struct(val.get('child_ids'))
|
||||
res.append(current)
|
||||
return res
|
||||
|
||||
|
@ -395,14 +395,12 @@ class test_mail(common.TransactionCase):
|
|||
('read', '=', False)
|
||||
])
|
||||
na_count = self.mail_message._needaction_count(cr, uid, domain = [])
|
||||
self.assertTrue(len(notif_ids) == na_count,
|
||||
self.assertEqual(len(notif_ids), na_count,
|
||||
'Number of unread notifications (%s) does not match the needaction count (%s)' % (len(notif_ids), na_count))
|
||||
|
||||
# Post 4 message on group_pigs
|
||||
msgid1 = group_pigs.message_post(body='My Body')
|
||||
msgid2 = group_pigs.message_post(body='My Body')
|
||||
msgid3 = group_pigs.message_post(body='My Body')
|
||||
msgid4 = group_pigs.message_post(body='My Body')
|
||||
for dummy in range(4):
|
||||
group_pigs.message_post(body='My Body')
|
||||
|
||||
# Check there are 4 new needaction on mail.message
|
||||
notif_ids = self.mail_notification.search(cr, uid, [
|
||||
|
@ -410,10 +408,39 @@ class test_mail(common.TransactionCase):
|
|||
('read', '=', False)
|
||||
])
|
||||
na_count = self.mail_message._needaction_count(cr, uid, domain = [])
|
||||
self.assertTrue(len(notif_ids) == na_count,
|
||||
self.assertEqual(len(notif_ids), na_count,
|
||||
'Number of unread notifications after posting messages (%s) does not match the needaction count (%s)' % (len(notif_ids), na_count))
|
||||
|
||||
# Check there are 4 needaction on mail.message with particular domain
|
||||
na_count = self.mail_message._needaction_count(cr, uid, domain = [('model', '=', 'mail.group'), ('res_id', '=', self.group_pigs_id)])
|
||||
self.assertTrue(na_count == 4,
|
||||
self.assertEqual(na_count, 4,
|
||||
'Number of posted message (4) does not match the needaction count with domain mail.group - group pigs (%s)' % (na_count))
|
||||
|
||||
def test_50_thread_parent_resolution(self):
|
||||
"""Verify parent/child relationships are correctly established when processing incoming mails"""
|
||||
cr, uid = self.cr, self.uid
|
||||
group_pigs = self.mail_group.browse(cr, uid, self.group_pigs_id)
|
||||
msg1 = group_pigs.message_post(body='My Body', subject='1')
|
||||
msg2 = group_pigs.message_post(body='My Body', subject='2')
|
||||
msg1, msg2 = self.mail_message.browse(cr, uid, [msg1,msg2])
|
||||
self.assertTrue(msg1.message_id, "New message should have a proper message_id")
|
||||
|
||||
# Reply to msg1, make sure the reply is properly attached using the various reply identification mechanisms
|
||||
# 1. In-Reply-To header
|
||||
reply_msg = MAIL_TEMPLATE.format(to='Pretty Pigs <group+pigs@example.com>, other@gmail.com', subject='Re: 1',
|
||||
extra='In-Reply-To: %s' % msg1.message_id)
|
||||
self.mail_thread.message_process(cr, uid, None, reply_msg)
|
||||
# 2. References header
|
||||
reply_msg2 = MAIL_TEMPLATE.format(to='Pretty Pigs <group+pigs@example.com>, other@gmail.com', subject='Re: Re: 1',
|
||||
extra='References: <2233@a.com>\r\n\t<3edss_dsa@b.com> %s' % msg1.message_id)
|
||||
self.mail_thread.message_process(cr, uid, None, reply_msg2)
|
||||
# 3. Subject contains [<ID>] + model passed to message+process -> only attached to group, not to mail
|
||||
reply_msg3 = MAIL_TEMPLATE.format(to='Pretty Pigs <group+pigs@example.com>, other@gmail.com',
|
||||
extra='', subject='Re: [%s] 1' % self.group_pigs_id)
|
||||
self.mail_thread.message_process(cr, uid, 'mail.group', reply_msg3)
|
||||
group_pigs.refresh()
|
||||
msg1.refresh()
|
||||
self.assertEqual(5, len(group_pigs.message_ids), 'group should contain 5 messages')
|
||||
self.assertEqual(2, len(msg1.child_ids), 'msg1 should have 2 children now')
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue