Convert ext/imap to HNI

Part of #1480

Also makes the extension optional, so the libc-client dependency is now optional too (hooray!)