Sorry for being very inactive but had some jobs to do. But here is the Step-by-step Guide how to migrate mails from an external mail server without any mail loss and using fetchmail:
1st thing is to download ImapCopy
sudo apt-get install imapcopy
2; Configure the imapcopy.cfg file wich is supposed to be in the folder where imapcopy is. ( normally your home folder )
mcedit imapcopy.cfg
3; What you need to edit is sourceserver, destination server, ports, usernames and password. You can find them in the basic config file
SourceServer hostname.sourceserver.com
SourcePort 143
DestServer hostname.destinationserver.com
DestPort 143
..
..
..
Copy "user1@sourceserver.com" "password" "user1@destserver.com" "password"
Copy "user2@sourceserver.com" "password" "user2@destserver.com" "password"
Normallí this will copy all the files/folders and labels as well.
4; Run ImapCopy
imapcopy
5; Take a break. We just copied all the messages to our local mailbox
sudo getadrink
6; Now we will set up fetchmail. I'll show how to start fetchmail manually because new users should use this instead of the daemon and apply these settings to the daemon only if it works 100%. Create a config file for the fetchmail
mcedit .fetchmailrc
7; Add the user, server, protocol and the rest wich will let fetchmail know that we want to keep the mail in our source mailbox
set syslog;
set postmaster "postmaster@destserver.com";
set daemon 60;
set logfile /home/user/fetchmail.log;
defaults
smtpaddress "sysadmin@destserver.com"
poll sourceserver.com protocol imap:
username "user1@sourceserver.com" is "user1@destserver.com"
password "password";
poll sourceserver.com protocol imap:
username "user2@sourceserver.com" is "user2@destserver.com"
password "password";
keep
What could need some explanation:
set daemon 60; = Check incoming mails in every 60 seconds
keep = Keep the mail in the source server
8; Create the logfile since fetchmail can't create it on it's own. What a bastard
mcedit fetchmail.log
Then save it.
9; Start Fetchmail
fetchmail
10; If you want, you can check the log file for any errors. With these settings it is working for me like a charm. It keeps all mails on the server and copies all unread messages the my local mail server. Perfect for testing.
In case if you need any help, do not hesitate to ask.