def test_IMAP4Logger_err(self): """ Make sure L{IMAP4Logger.err} works when twisted.mail.imap4 calls log.err(). """ class DummyTransport(object): def __init__(self): self.called = False def loseConnection(self): self.called = True imap4 = IMAP4DownloadProtocol() imap4.transport = DummyTransport() imap4.state = "FOOBAR" imap4.dispatchCommand("A001", "OK") self.assertTrue(imap4.transport.called)
def test_deletion(self): """ Verify the IMAP protocol will delete messages only when the right conditions are met. Either: A) We've been told to delete all mail B) We've not been told to delete all mail, but it was a message we processed """ def stubFetchNextMessage(): pass def stubCbFlagDeleted(result): self.flagDeletedResult = result return succeed(None) proto = IMAP4DownloadProtocol() self.patch(proto, "fetchNextMessage", stubFetchNextMessage) self.patch(proto, "cbFlagDeleted", stubCbFlagDeleted) results = {"ignored": ({"RFC822": "a message"})} # Delete all mail = False; action taken = submitted; result = deletion proto.factory = StubFactory(MailReceiver.INJECTION_SUBMITTED, False) self.flagDeletedResult = None yield proto.cbGotMessage(results, "xyzzy") self.assertEquals(self.flagDeletedResult, "xyzzy") # Delete all mail = False; action taken = not submitted; result = no deletion proto.factory = StubFactory(MailReceiver.NO_TOKEN, False) self.flagDeletedResult = None yield proto.cbGotMessage(results, "xyzzy") self.assertEquals(self.flagDeletedResult, None) # Delete all mail = True; action taken = submitted; result = deletion proto.factory = StubFactory(MailReceiver.INJECTION_SUBMITTED, True) self.flagDeletedResult = None yield proto.cbGotMessage(results, "xyzzy") self.assertEquals(self.flagDeletedResult, "xyzzy") # Delete all mail = True; action taken = not submitted; result = deletion proto.factory = StubFactory(MailReceiver.NO_TOKEN, True) self.flagDeletedResult = None yield proto.cbGotMessage(results, "xyzzy") self.assertEquals(self.flagDeletedResult, "xyzzy")
def test_missingIMAPMessages(self): """ Make sure L{IMAP4DownloadProtocol.cbGotMessage} can deal with missing messages. """ class DummyResult(object): def __init__(self): self._values = [] def values(self): return self._values noResult = DummyResult() missingKey = DummyResult() missingKey.values().append({}) imap4 = IMAP4DownloadProtocol() imap4.messageUIDs = [] imap4.fetchNextMessage = lambda: None result = yield imap4.cbGotMessage(noResult, []) self.assertTrue(result is None) result = yield imap4.cbGotMessage(missingKey, []) self.assertTrue(result is None)