You can read a tutorial on how to build Apache James Server on http://james.apache.org/server/3/dev-build.html.
The GIT URLs and the project names must be adapted, but the requirements and process are the same and you can inspire from the build the Apache James IMAP libraries.
apache-james-protocols-api contains the interfaces, exceptions and Constants needed by the other projects.
apache-james-protocols-impl provides common services that can be used by any mail protocol.
apache-james-protocols-smtp implements the SMTP protocols with hooks for extensions.
apache-james-imap-api contains the interfaces, exceptions and Constants needed by the other projects.
The following diagram represents some key (not all) interfaces of the IMAP API project.
apache-james-imap-message allows to encode, decode and structure the IMAP requests and responses.
It will provide among other the ImapRequestMessage and ImapResponseMessage implementation to be processed by the apache-james-imap-processor project.
apache-james-imap-processor implements the Chain Of Responsibility design pattern.
ImapRequestMessage and ImapResponder will be passed to the list of Processors that will execute doProcess if applicable.
A specific integration project is responsible to test the IMAP protocol in conjunction with the Apache James mailbox components.