Ticket #1105: test_imap_flags.py

File test_imap_flags.py, 2.3 KB (added by therve, 14 years ago)

Test imap unsolocited flags messages

Line 
1Index: test_imap.py
2===================================================================
3--- test_imap.py        (revision 16040)
4+++ test_imap.py        (working copy)
5@@ -1659,7 +1659,56 @@
6 
7         self.server.connectionLost(error.ConnectionDone("Connection done."))
8 
9+    def testUnsolicitedResponseMixedWithSolicitedResponse(self):
10 
11+        class StillSimplerClient(imap4.IMAP4Client):
12+            events = []
13+            def flagsChanged(self, newFlags):
14+                self.events.append(['flagsChanged', newFlags])
15+
16+        transport = StringTransport()
17+        c = StillSimplerClient()
18+        c.makeConnection(transport)
19+        c.lineReceived('* OK [IMAP4rev1]')
20+
21+        def login():
22+            d = c.login('blah', 'blah')
23+            c.dataReceived('0001 OK LOGIN\r\n')
24+            return d
25+        def select():
26+            d = c.select('inbox')
27+            c.lineReceived('0002 OK SELECT')
28+            return d
29+        def fetch():
30+            d = c.fetchSpecific('1:*',
31+                headerType='HEADER.FIELDS',
32+                headerArgs=['SUBJECT'])
33+            c.dataReceived('* 1 FETCH (BODY[HEADER.FIELDS ("SUBJECT")] {38}\r\n')
34+            c.dataReceived('Subject: Suprise for your woman...\r\n')
35+            c.dataReceived('\r\n')
36+            c.dataReceived(')\r\n')
37+            c.dataReceived('* 1 FETCH (FLAGS (\Seen))\r\n')
38+            c.dataReceived('* 2 FETCH (BODY[HEADER.FIELDS ("SUBJECT")] {75}\r\n')
39+            c.dataReceived('Subject: What you been doing. Order your meds here . ,. handcuff madsen\r\n')
40+            c.dataReceived('\r\n')
41+            c.dataReceived(')\r\n')
42+            c.dataReceived('0003 OK FETCH completed\r\n')
43+            return d
44+        def test(res):
45+            print "HERE"
46+            self.assertEquals(res, {
47+                1: [['BODY', ['HEADER.FIELDS', ['SUBJECT']],
48+                    'Subject: Suprise for your woman...\r\n\r\n']],
49+                2: [['BODY', ['HEADER.FIELDS', ['SUBJECT']],
50+                    'Subject: What you been doing. Order your meds here . ,. handcuff madsen\r\n\r\n']]
51+            })
52+
53+            self.assertEquals(c.events, [['flagsChanged', {1: ['\\Seen']}]])
54+
55+        login().addCallback(strip(select)
56+            ).addCallback(strip(fetch)
57+            ).addCallback(test)
58+
59 class FakeyServer(imap4.IMAP4Server):
60     state = 'select'
61     timeout = None