Think twice on implementing this. Having a client (or worse two) simultaneously accessing the same IMAP mailbox on different hosts may break everything. So you would break things in production whereas you just inteded to make sure you get failover in case of emergency.
Test thoroughly all possibilities and options. To make things easier I would use the second one as semi-cold standby. All SMTP and IMAP will be on one server with a distributed filesystem (DRBD) to the other server. In case of emergency you shutdown the first, switch IPs on the other and restart the other. In this case access to the mailbox storage is easier to manage, no concurrency and therefore no inconsistence.
On the other hand you probably want load balancing where you slice your mailboxes. The one half gets delivered on the one server and the other half on the other server. As you replicate your storage you can switch (in an emergency) to the clean machine and run all mailboxes there.
To sum up: The problem is the concurrent access to the storage. Solve that problem and you can have failover/high availability/load balancing.