From: Menno Smits Date: Sun, 5 Jun 2011 14:14:27 +0000 (+0100) Subject: Generate fresh Message-Id headers to work around Gmail's cleverness X-Git-Tag: 0.8~34^2~2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=35dc6790fdf787ac1eef29aad3740bd0186e9a03;p=imapclient.git Generate fresh Message-Id headers to work around Gmail's cleverness When APPENDing to Gmail's IMAP, if the Message-Id of the uploaded message has alrady been seen before, it assumes it's the same message and ignores the content of the appended message. This breaks the tests when the test message is changed. A new Message-Id is now generated each time to work around this. --- diff --git a/livetest.py b/livetest.py index 345b981..0fd418d 100755 --- a/livetest.py +++ b/livetest.py @@ -10,6 +10,7 @@ import os import sys import time from datetime import datetime +from email.utils import make_msgid import imapclient from imapclient.test.util import unittest @@ -26,7 +27,6 @@ MULTIPART_MESSAGE = """\ From: Bob Smith To: Some One , foo@foo.com Date: Tue, 16 Mar 2010 16:45:32 +0000 -Message-ID: <1A472770E042064698CB5ADC83A12ACD39455AAB@ABC> MIME-Version: 1.0 Subject: A multipart message Content-Type: multipart/mixed; boundary="===============1534046211==" @@ -54,6 +54,7 @@ def createLiveTestClass(conf, use_uid): class LiveTest(unittest.TestCase): def setUp(self): + self.maxDiff = None self.client = create_client_from_config(conf) self.client.use_uid = use_uid self.clear_folders() @@ -349,8 +350,15 @@ def createLiveTestClass(conf, use_uid): def test_fetch(self): + # Generate a fresh message-id each time because Gmail is + # clever and will treat appends of messages with + # previously seen message-ids as the same message. This + # breaks our tests when the test message is updated. + msg_id_header = make_msgid() + msg = ('Message-ID: %s\r\n' % msg_id_header) + MULTIPART_MESSAGE + self.client.select_folder('INBOX') - self.client.append('INBOX', MULTIPART_MESSAGE) + self.client.append('INBOX', msg) fields = ['RFC822', 'FLAGS', 'INTERNALDATE', 'ENVELOPE'] msg_id = self.client.search()[0] @@ -361,7 +369,7 @@ def createLiveTestClass(conf, use_uid): self.assertSetEqual(set(msginfo.keys()), set(fields + ['SEQ'])) self.assertEqual(msginfo['SEQ'], 1) - self.assertMultiLineEqual(msginfo['RFC822'], MULTIPART_MESSAGE) + self.assertMultiLineEqual(msginfo['RFC822'], msg) self.assertIsInstance(msginfo['INTERNALDATE'], datetime) self.assertIsInstance(msginfo['FLAGS'], tuple) self.assertTupleEqual(msginfo['ENVELOPE'], @@ -371,8 +379,7 @@ def createLiveTestClass(conf, use_uid): (('Bob Smith', None, 'bob', 'smith.com'),), (('Bob Smith', None, 'bob', 'smith.com'),), (('Some One', None, 'some', 'one.com'), (None, None, 'foo', 'foo.com')), - None, None, None, - '<1A472770E042064698CB5ADC83A12ACD39455AAB@ABC>')) + None, None, None, msg_id_header)) def test_partial_fetch(self):