Imap and pop proxy?

Can someone give me an example of how to do an IMAP and POP3 proxy in
nginx. What i need to do is send all requests for domain1.com to one
server and all requests for domain2.com to another. I have read the
examples on the wiki but I do not understand them. I have a working
HTTP and HTTPS install now and would like to further secure my servers.
Any help would be appreciated

Brian.