I search a solution to download (for archiving) a large mail directory via imap from a mail-server and stores all mails in a local maildir. I need a robust solution, which repeatedly tries if time-outs occur. So far I have tried using regular mail clients for this. Apparently the server restricts downloads in a way which confuses the clients I have tried so far in that they eventually give up and even loose mails. I am thinking of a tool like fetchmail, but the howtos I have seen are either a bit long or don't fit exactly my needs, such as http://llg.cubic.org/docs/imapbackup.html which describes download to mbox files. It remains unclear to me whether the maildir format is supported.
Try isync which sounds like it should fit your purpose:
isync is a command line application which synchronizes mailboxes; currently Maildir and IMAP4 mailboxes are supported. New messages, message deletions and flag changes can be propagated both ways. isync is suitable for use in IMAP-disconnected mode.