How can I back up a complete IMAP account? I have a huge IMAP email account that contains a lot of subfolders and a lot of messages (dating back to 2005). Is there a simple way to back up these folders and messages so I can delete them from the server?

I would like to retain the ability to browse and manage these archived messages, reply, or add addresses from these messages to my contacts - all preferably within Apple Mail.

If Apple Mail can't do it, what other options do I have?
You can do it with offlineimap. I'm using it for my GMail and Fastmail accounts.

Install Homebrew (you must also install Xcode). With Homebrew, brew install offline-imap. 

Create ~/.offlineimaprc config file: 

[general]
ui = ttyui
accounts = fastmail
maxsyncaccounts = 4
socktimeout = 60

[Account fastmail]
localrepository = fastmail-local
remoterepository = fastmail-remote

[Repository fastmail-local]
type = Maildir
localfolders = ~/Mail/Fastmail

[Repository fastmail-remote]
type = IMAP
remotehost = mail.messagingengine.com
remoteuser = username
remotepass = password

expunge = no
folderfilter = lambda foldername: foldername not in ['INBOX.Trash']


A big advantage of offlineimap is that it creates the folders you have on your IMAP server.

I'm reading my backup with mutt.