def ack(self, message, addr): self.client.write_json( address.py_address(addr), { 'type':'ejmail-mark', 'data':[message.hash], } )
def send(self, msg, recipients=None): ''' Send ejmail.message.Message object to its recipients. >>> import time >>> m3addr = ['udp4', ['localhost',9003], 'britta'] >>> m4addr = ['udp4', ['localhost',9004], 'jeff'] >>> m3 = Mailbox(m3addr) >>> m4 = Mailbox(m4addr) >>> m4.client.encryptor_cache = m3.client.encryptor_cache >>> m3.client.encryptor_set(m3addr, ['rotate', 5]) >>> m3.client.encryptor_set(m4addr, ['rotate', -14]) >>> msg = Message({ ... 'to':[['Jeff Winger', m4addr]], ... 'from':['Britta Perry', m3addr], ... 'conversation':'Wazzaaaappp', ... 'content':"I'm druunnkkkk", ... }) >>> m3.send(msg); time.sleep(0.1) #doctest: +ELLIPSIS UDPJack out: ... >>> m4.conversations.keys() [u'Wazzaaaappp'] >>> m4.conversations['Wazzaaaappp'].timeline()[0].content u"I'm druunnkkkk" >>> m3.unread {'["udp4",["localhost",9004],"jeff"]': {}} ''' convo = msg.conversation self.add_conversation(convo) convo_obj = self.conversations[convo] convo_obj.register_message(msg) recipients = recipients or msg.data['to'] for recipient in recipients: name, addr = recipient self.client.write_json(address.py_address(addr), { 'type':'ejmail-message', 'data':msg.data, }) saddr = address.str_address(addr) if not saddr in self.unread: self.unread[saddr] = {} self.unread[saddr][msg.hash] = msg
def _assert(self, expected, value): self.assertEqual(expected, py_address(value))
def address(self): return py_address(self.header)