def searchUID(self, searchConditions: SearchConditions=SearchConditions()): conditions = searchConditions.formatConditions() self._debug("searchUID", "%s"% conditions) # (typ, [data]) # e.g. ('OK', [b'2'] response = self.imap.uid('SEARCH', conditions) self._debugResponse("searchUID", response) status, data = response if status == 'OK': messages = Messages() for uid in data[0].decode(ENCODING).split(' '): messages.add(Message(int(uid))) return messages data = data.decode(ENCODING) raise ImapCommandError(data)
class TestMessages(unittest.TestCase): def setUp(self): self.message1 = Message(1) self.message2 = Message(2) self.message3 = Message(3) self.messagesI = Messages(self.message2, self.message1) def test_00_in(self): self.assertIn(self.message2, self.messagesI) def test_01_add(self): self.messagesI.add(self.message1) self.assertIn(self.message1, self.messagesI) def test_02_remove(self): self.messagesI.remove(self.message2) self.assertNotIn(self.message2, self.messagesI)
def getMessages(self, messages: Messages, attributes: FetchAttributes) -> Messages: self._debug("getMessages", repr(messages)) # (typ, [data, ...]) # e.g. ('OK', [b'1 (UID 1 FLAGS (\\Seen) INTERNALDATE "15-Nov-2015 # 00:00:46 +0100")', b'2 (UID 2 FLAGS () INTERNALDATE "15-Nov-2015 # 00:00:46 +0100")']) response = self.imap.uid('FETCH', messages.coalesceUIDs(), str(attributes)) self._debugResponse("getMessages", response) status, data = response if status == 'OK': for item in data: item = item.decode(ENCODING) uid = int(item[0]) #TODO: item must be of type MessageAttributes. messages.setAttributes(uid, item) return messages raise ImapCommandError(data)
def search(self, conditions): return Messages() #TODO
def setUp(self): self.message1 = Message(1) self.message2 = Message(2) self.message3 = Message(3) self.messagesI = Messages(self.message2, self.message1)