Help with migration to Dovecot from raw files

Stefano Antonelli dovecot at intheworks.ca
Sun Mar 29 09:54:16 EEST 2020


On 2020-03-26 12:03, Stefano Antonelli wrote:
> On 2020-03-26 03:37, Aki Tuomi wrote:
>> You could try something simple like just
>> 
>> for n in *; do cat $n | doveadm save -u targetuser; done
> 
> Thank you.  This "works" in that it renames the files for me.  However,
> 
> 1. the filename timestamps are all similar (ie. time of import)
> 2. the emails showed up in new rather than cur
> 3. the emails are unseen.

As mentioned previously, I don't have access to the mail server any 
more.  I did manage to bring up a virtual machine and installed the 
server software on to it and restored the mail to the virtual machine.  
However, no imap backup tools (not even doveadm) could complete 
operation without failing.  In all cases, none of the tools preserved 
the timestamp of the email anyway (not even with mbsync using 
CopyArrivalDate).

So I went back to working with the raw .imap files.  I could not coerce 
doveadm into listing the uids in any sane order.  I thought this might 
have something to do with the filename timestamp or mtime on the file 
itself.  So I set out to decode the .imap filenames and convert them to 
proper maildir filenames.  Of course, this was only possible with a 
server I could query.  Then I wrote a script that renamed files as best 
as I could from the old mail server:

2012122513472903CA-000001020000000141996DEF.imap

to maildir files:

1356472049.M000000P12345.icewarp,S=10354,W=10354:2,S

I also set the m-time and a-time after copying into the maildir 
directory.  Followed by:

chown -R mail:mail /path/to/maildir/user
doveadm force-resync -u user at domain INBOX

At first this didn't work.  dovecot-uidlist was not correct.  So then I 
removed all the dovecot files and did a resync again:

rm /path/to/maildir/user/dovecot*
doveadm force-resync -u user at domain INBOX

And this gave me the dovecot-uidlist I was looking for and mails 
displayed properly at the imap client.

I've attached my script in case it's helpful to anyone in a similar 
situation.  It took quite a bit of effort to get this right, highly 
depends on the format of the original mailstore, and I've only tested 
this on one smaller mailbox (<400 messages).  And I wasn't concerned 
with any client having to download everything again since this was a 
fresh import.

In any case, it worked for me.

Thanks,
Stef
-------------- next part --------------
A non-text attachment was scrubbed...
Name: import-from-icewarp-files.sh
Type: text/x-shellscript
Size: 4828 bytes
Desc: not available
URL: <https://dovecot.org/pipermail/dovecot/attachments/20200328/275764d1/attachment.bin>


More information about the dovecot mailing list