There's a Cyrus2Dovecot migration tool developed by Freie Universität Berlin.
Cyrus2Dovecot is a full-featured command line tool for converting the e-mails of one or more users from Cyrus format to Dovecot Maildir++ folders. It allows for performing a server transition which is fully transparent to both POP and IMAP users.
And other migration solutions in the Dovecot wiki.
I did a little digging and found out a little of what OSX tries to do to auto-configure an email account.
In system preferences when adding a mail account, OSX makes a POST to https://mac-services.apple.com/iconfig/dconf the post parameters are:
domain: EMAIL_DOMAIN_THE_USER_ENTERED.com
version: 1
capabilities: MACOSX
For a service like gmail the following is returned:
<domain>
<name>gmail.com</name>
<description>Gmail</description>
<service>
<hostname>imap.gmail.com</hostname>
<port>993</port>
<protocol>IMAP</protocol>
<ssl/>
<requires>MACOSX</requires>
<authentication>PLAIN</authentication>
</service>
<service>
<hostname>smtp.gmail.com</hostname>
<port>587</port>
<protocol>SMTP</protocol>
<ssl/>
<requires>MACOSX</requires>
<authentication>PLAIN</authentication>
<usernameIncludesDomain/>
</service>
</domain>
Unfortunately, for my domain I receive the following response:
<domain>
<name>EMAIL_DOMAIN_THE_USER_ENTERED.com</name>
<unknown/>
</domain>
As far as I can tell after an unknown response OSX gives up and requires a user to enter the details manually. Capturing network packets I see no attempt by OSX to fallback to using SRV DNS records, or the Exchange Autodiscover.xml mechanism.
If I get a chance I will open a support ticket with apple to see how one gets added to their mac-services list.
Best Answer
A popular command line e-mail clients is Mutt. Use a package manager such as Brew or Macports to install it on MacOS. Have a look at this page for some pointers.
You can find the IMAP settings for iCloud in this Support article.