When moving to my new mail server I wanted to keep all existing messages. I had IMAP access to the old mailbox so I made this small program to export all messages into a set of raw .eml files.
Features
supports SSL connection
exports any IMAP folder, not just INBOX
supports custom file name pattern that may include message sender, charset, date, flags, recipient and others
to see full list of variables connect to the server, click on the green plus button and select Set output file name pattern
if file with the same name existed new file will be suffixed with (2), (3), etc. similar to the way Explorer acts when renaming multiple files
can skip messages prior to a certain date – useful when creating regular backups
if Save settings on exit is checked this date can be automatically set to now after completing each export
can show/export individual message(s) by their number
to do this connect to the server, click on the green plus button and select Show message by its index
can remember connection and other settings on exit
if you wish to save all but Password fields check Save settings on exit, close the program, open ImapExport.ini, and clear the part after = symbol of Password=... line and then open ImapExport again – from now on Password will be remembered blank
last connected IMAP folder is remembered but if you wish to always select INBOX (or another folder that’s first in your mailbox) do the same as above but for DefaultFolder=... line
press Esc to close the program
Download
ImapExport (with sources), version from 8thMarch 2012. Tested on Windows XP, compatibility with modern Windows is unknown.
If you have problems or suggestions feel free to drop a comment below.
Updated 8.03.2013:
added patterns for exported file names as per request by Alain B.;
added ability to skip messages prior to certain date as per same request;
added Save settings on exit checkbox;
fixed various minor issues (masked Password field, etc.).
Source code
ImapExport is written in Delphi 7 using Indy 10 (aka Internet Direct) components. Note:Indy 9 that comes with Delphi 7 has some bugs in IMAP support so it’s not recommended to use it; Indy 10 sources are available from the official website and are easily integrated into Delphi.
phpBB import script
Shortly after the creation of this program I used it to import a lengthy discussion into a phpBB forum. First I have made a separate folder on my GMail account holding the entire conversation, then exported it into a hundred of .eml files and then ran a Ruby script that I’d written to convert them into a SQL dump (.sql file) that I have then imported into the forum’s database.
The Ruby script is available here: eml2phpBB.rb. You will need a Ruby interpreter to run it.
This script has several options-variables that are located in its beginning:
emlMask – path plus file mask to read .eml files from
phpBbSqlFile – name of the produced .sql file
$sqlTopicID – ID of the forum thread to put the new messages into
$sqlForumID – ID of the forum where the above thread is located
$sqlPosterIDs – connect message author with their forum profile ID; these will require modification of the script’s code