def test_Twisted_16_6_bug(self): """ Make sure L{IMAP4DownloadProtocol.cbGotSearch} works. There is a bug in Twisted 16.6 where the IMAP4Client._fetch method does not accept a MessageSet argument - though it previously did. We also need to double check that IMAP4Client._store works with a MessageSet. """ imap4 = IMAP4DownloadProtocol() imap4.sendCommand = lambda cmd: succeed(cmd) imap4._cbFetch = lambda result, requestedParts, structured: { 123: { "UID": "456" } } imap4.cbGotMessage = lambda results, messageList: succeed(True) result = yield imap4.cbGotSearch((123, )) self.assertTrue(result is None) imap4 = IMAP4DownloadProtocol() imap4.sendCommand = lambda cmd: succeed(cmd) imap4._cbFetch = lambda result, requestedParts, structured: { "123": { "UID": "456" } } imap4.cbMessageUnseen = lambda results, messageList: succeed(True) ms = MessageSet() ms.add(123) result = yield imap4.cbFlagUnseen(ms) self.assertTrue(result is None) imap4 = IMAP4DownloadProtocol() imap4.sendCommand = lambda cmd: succeed(cmd) imap4._cbFetch = lambda result, requestedParts, structured: { "123": { "UID": "456" } } imap4.cbMessageDeleted = lambda results, messageList: succeed(True) ms = MessageSet() ms.add(123) result = yield imap4.cbFlagDeleted(ms) self.assertTrue(result is None)
def _foundMail(_self, result): self.output("imap: found %d messages" % (len(result))) if result: messages = MessageSet() for uid in result: messages.add(uid) d = _self.fetchMessage(messages, uid=True) d = d.addCallback(_self._gotMail) else: d = _self.logout() d = d.addCallback(_self._done) return d.addErrback(_self.catchErrors)
def _gotMail(_self, result): self.output("imap: got mail") messages = MessageSet() for data in result.itervalues(): message = message_from_string(data['RFC822']) toRepoId = message.get('X-chandler-p2p-to') if toRepoId is None or UUID(toRepoId) == self._repoId: args = (data['UID'], message, peerId) self.worker.queueRequest(('receive', args)) messages.add(data['UID']) # d = _self.logout() # d = d.addCallback(_self._done) d = _self.addFlags(messages, ('\\Deleted', ), uid=True) d = d.addCallback(_self._flagsAdded) return d.addErrback(_self.catchErrors)