emersion / go-imap

📥 An IMAP library for clients and servers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Client Support for Tagged Messages and Handlers

CyrusRoshan opened this issue · comments

With IMAP, we can request multiple messages simultaneously, and tag them with responses so that the server can process them at the same time:

c: a1 FETCH 1 fast
c: a2 FETCH 2 fast
c: a3 FETCH 3 fast
s: * 1 FETCH (FLAGS (\Seen) INTERNALDATE "07-May-2013 03:31:35 +0000" RFC822.SIZE 18383)
a1 OK Success
s: * 2 FETCH (FLAGS (\Seen) INTERNALDATE "07-May-2013 08:44:38 +0000" RFC822.SIZE 29478)
a2 OK Success
s: * 3 FETCH (FLAGS (\Seen) INTERNALDATE "16-May-2013 15:43:29 +0000" RFC822.SIZE 32642)
a3 OK Success

Support for this would help multithreaded client applications greatly.

go-imap and its message-parsing dependencies do have some support for tagging, though I think they are parsing message tags incorrectly (showing "*" for all response tags on commands with different tags, when I test the client using Gmail servers), and the v1 branch's call to c.registerHandler (inside c.execute) doesn't seem to check tags before handling the request:

if h != nil {
	// Pass the response to the response handler
	// NOTE: we'd probably want to compare cmd.Tag here with the response tag,
	// and return responses.ErrUnhandled if they don't match
	if err := h.Handle(resp); err != nil && err != responses.ErrUnhandled {
		// If the response handler returns an error, abort
		doneHandle <- handleResult{nil, err}
		return errUnregisterHandler
	} else {
		return err
	}
}
return responses.ErrUnhandled

v1 doesn't support pipelining, but v2 does.

The server will return untagged FETCH responses, this is normal and required by the RFC.