[MERGE] Forward-port 7.0 up to 1b49a87
authorOlivier Dony <odo@openerp.com>
Fri, 10 Oct 2014 17:21:18 +0000 (19:21 +0200)
committerOlivier Dony <odo@openerp.com>
Fri, 10 Oct 2014 17:21:18 +0000 (19:21 +0200)
1  2 
addons/mail/mail_thread.py
addons/mail/tests/test_mail_gateway.py
openerp/addons/base/ir/ir_mail_server.py
openerp/addons/base/res/res_users.py
openerp/tools/mail.py

Simple merge
@@@ -143,10 -141,97 +143,57 @@@ X-Attachment-Id: f_hkpb27k0
  dGVzdAo=
  --089e01536c4ed4d17204e49b8e96--"""
  
+ MAIL_MULTIPART_MIXED_TWO = """X-Original-To: raoul@grosbedon.fr
+ Delivered-To: raoul@grosbedon.fr
+ Received: by mail1.grosbedon.com (Postfix, from userid 10002)
+     id E8166BFACA; Fri, 23 Aug 2013 13:18:01 +0200 (CEST)
+ From: "Bruce Wayne" <bruce@wayneenterprises.com>
+ Content-Type: multipart/alternative;
+  boundary="Apple-Mail=_9331E12B-8BD2-4EC7-B53E-01F3FBEC9227"
+ Message-Id: <6BB1FAB2-2104-438E-9447-07AE2C8C4A92@sexample.com>
+ Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\))
+ --Apple-Mail=_9331E12B-8BD2-4EC7-B53E-01F3FBEC9227
+ Content-Transfer-Encoding: 7bit
+ Content-Type: text/plain;
+     charset=us-ascii
+ First and second part
+ --Apple-Mail=_9331E12B-8BD2-4EC7-B53E-01F3FBEC9227
+ Content-Type: multipart/mixed;
+  boundary="Apple-Mail=_CA6C687E-6AA0-411E-B0FE-F0ABB4CFED1F"
+ --Apple-Mail=_CA6C687E-6AA0-411E-B0FE-F0ABB4CFED1F
+ Content-Transfer-Encoding: 7bit
+ Content-Type: text/html;
+     charset=us-ascii
+ <html><head></head><body>First part</body></html>
+ --Apple-Mail=_CA6C687E-6AA0-411E-B0FE-F0ABB4CFED1F
+ Content-Disposition: inline;
+     filename=thetruth.pdf
+ Content-Type: application/pdf;
+     name="thetruth.pdf"
+ Content-Transfer-Encoding: base64
+ SSBhbSB0aGUgQmF0TWFuCg==
+ --Apple-Mail=_CA6C687E-6AA0-411E-B0FE-F0ABB4CFED1F
+ Content-Transfer-Encoding: 7bit
+ Content-Type: text/html;
+     charset=us-ascii
+ <html><head></head><body>Second part</body></html>
+ --Apple-Mail=_CA6C687E-6AA0-411E-B0FE-F0ABB4CFED1F--
+ --Apple-Mail=_9331E12B-8BD2-4EC7-B53E-01F3FBEC9227--
+ """
  
 -class TestMailgateway(TestMailBase):
 +class TestMailgateway(TestMail):
  
 -    def test_00_partner_find_from_email(self):
 -        """ Tests designed for partner fetch based on emails. """
 -        cr, uid, user_raoul, group_pigs = self.cr, self.uid, self.user_raoul, self.group_pigs
 -
 -        # --------------------------------------------------
 -        # Data creation
 -        # --------------------------------------------------
 -        # 1 - Partner ARaoul
 -        p_a_id = self.res_partner.create(cr, uid, {'name': 'ARaoul', 'email': 'test@test.fr'})
 -
 -        # --------------------------------------------------
 -        # CASE1: without object
 -        # --------------------------------------------------
 -
 -        # Do: find partner with email -> first partner should be found
 -        partner_info = self.mail_thread.message_find_partner_from_emails(cr, uid, None, ['Maybe Raoul <test@test.fr>'], link_mail=False)[0]
 -        self.assertEqual(partner_info['full_name'], 'Maybe Raoul <test@test.fr>',
 -                        'mail_thread: message_find_partner_from_emails did not handle email')
 -        self.assertEqual(partner_info['partner_id'], p_a_id,
 -                        'mail_thread: message_find_partner_from_emails wrong partner found')
 -
 -        # Data: add some data about partners
 -        # 2 - User BRaoul
 -        p_b_id = self.res_partner.create(cr, uid, {'name': 'BRaoul', 'email': 'test@test.fr', 'user_ids': [(4, user_raoul.id)]})
 -
 -        # Do: find partner with email -> first user should be found
 -        partner_info = self.mail_thread.message_find_partner_from_emails(cr, uid, None, ['Maybe Raoul <test@test.fr>'], link_mail=False)[0]
 -        self.assertEqual(partner_info['partner_id'], p_b_id,
 -                        'mail_thread: message_find_partner_from_emails wrong partner found')
 -
 -        # --------------------------------------------------
 -        # CASE1: with object
 -        # --------------------------------------------------
 -
 -        # Do: find partner in group where there is a follower with the email -> should be taken
 -        self.mail_group.message_subscribe(cr, uid, [group_pigs.id], [p_b_id])
 -        partner_info = self.mail_group.message_find_partner_from_emails(cr, uid, group_pigs.id, ['Maybe Raoul <test@test.fr>'], link_mail=False)[0]
 -        self.assertEqual(partner_info['partner_id'], p_b_id,
 -                        'mail_thread: message_find_partner_from_emails wrong partner found')
 -
 -    def test_09_message_parse(self):
 +    def test_00_message_parse(self):
          """ Testing incoming emails parsing """
          cr, uid = self.cr, self.uid
  
          self.assertIn('<div dir="ltr">Should create a multipart/mixed: from gmail, <b>bold</b>, with attachment.<br clear="all"><div><br></div>', res.get('body', ''),
                        'message_parse: html version should be in body after parsing multipart/mixed')
  
+         res = self.mail_thread.message_parse(cr, uid, MAIL_MULTIPART_MIXED_TWO)
+         self.assertNotIn('First and second part', res.get('body', ''),
+                          'message_parse: text version should not be in body after parsing multipart/mixed')
+         self.assertIn('First part', res.get('body', ''),
+                       'message_parse: first part of the html version should be in body after parsing multipart/mixed')
+         self.assertIn('Second part', res.get('body', ''),
+                       'message_parse: second part of the html version should be in body after parsing multipart/mixed')
 +    @mute_logger('openerp.addons.mail.mail_thread', 'openerp.osv.orm')
      def test_10_message_process(self):
          """ Testing incoming emails processing. """
          cr, uid, user_raoul = self.cr, self.uid, self.user_raoul
Simple merge
Simple merge