[refactor] isolate extraction of keys from incoming mails
this refactor was started in Berlin with the idea of making it easy to implement autocrypt capabilities, but it is half-baked. need some work to get tests green again.
This might help to solve an issue we're having concerning
I want to tackle this refactor as part of the incoming rewrite that is happening in soledad.
I'll copy the pseudocode bit here to ease discussion:
for item in self.incoming: for consumer in self.consumers: clear = yield consumer.decrypt(item) parts = yield consumer.process(clear) saved = yield consumer.save(parts) self.delete(item)
what is not clear to me yet is what class this self object belongs to.
my initial idea is that the IncomingService instantiates the MessageInbox (in mail terms: the mailbox that writes to soledad), and creates a SoledadIncomingBox that registers the 'mx' namespace (and the 'openPGP' method).
Then, the incoming loop is handled by soledad - once for every namespace.
The IncomingService also creates a IncomingBoxConsumer instance that implements those three methods - and that instance is called periodically by soledad itself. Maybe the registering of this consumer intance and the instruction to register the 'mx' namespace with soledad is actually one and the same action:
@implementer IInboxConsumer class incomingConsumer: pass handler = incomingConsumer(inbox) soledad.registerIncomingBoxHandler('mx', handler)
This basically accomplishes the long-standing desire of "moving the incoming loop outside of bitmask". It also is quite dependent with soledad and bitmask.mail living in the same process space - although with clear apis it should be simple to do IPC using zmq or whatever if we need to split it.
How does this sound?
I like the idea of passing a handler to soledad, and tagging the incoming boxes with a namespace to make them generic.
I'm not sure if soledad needs to know about the decryption/process/save details. I think I would simplify it making the handler just a function (instead of an object) and having a loop in soledad like:
for item in self.incoming: namespace = get_namespace(item) if namespace not in self.handlers: # if no handler configured leave it there continue for handler in self.handlers[namespace]: try: yield handler(item) except Exception: # if there was an error leave it there # TODO: do something more clever here continue self.delete(item)
I'm not sure if soledad needs to know about the decryption/process/save details
the idea is that it needs because otherwise we won't be deleting the incoming blob, or we'll be marking as failed if decrytion failed (to see if the error can be recovered in the future).
about this refactor, I want to tackle this as part of a demo for incoming blobs.