Answer the question
In order to leave comments, you need to log in
How to transfer all email from mail.ru to your debian 8 + iredmail mail server using imapsync?
Good time of the day!!!
Task: Switch from biz.mail.ru (mail.ru using corporate domain) to your own debian 8 + iredmail (LDAP) server. Number of mailboxes 105.
Done: Installed, configured and tested iRedMail on Debian 8. Everything works fine: A, MX, TXT (DKIM) records are correct, SSL is configured, in short everything works and letters go.
All that's left is "PAILLESS", that is, without disturbing users, transfer all mailboxes in a working rhythm. As a result, the imapsync tool was found. Quite
an interesting and simple utility with the ability to transfer several mailboxes at once.
It is easy to use (in my opinion), since it is written in Perl, except for libraries, nothing else needs to be installed, it works as a "one-liner", but you can enter all the necessary parameters into a script and run it. And you can also configure it to synchronize taking into account the already existing duplicates, that is, it transfers only newly appeared letters ( but there is a BUT ), a good FAQ, in general, a worthwhile thing.
After studying the manual, I launched 4 mailboxes for synchronization (an average of 1.5k letters in the inbox, and a certain number in the rest of the folders). I was pleasantly surprised by the process:
0. There is a connection
1. I counted the available folders on the first email box (from where we transfer)
2. I counted the available folders on the second email box (where we transfer)
3. Compared them and issued a discrepancy, then created the missing folders on the second email box, for the correct transfer of mail ( but there is a second BUT )
4. Started the transfer, the transfer occurs in stages, first one folder - reading the headers, transferring the "body" itself, etc. .d.
5. Displays the final output on the screen - what, where, why and why.
Everything happens beautifully, relatively quickly, BUT
Now BUT :
1. When comparing folders on mailboxes, and as we know, where we transfer this mail.ru from and where we transfer it , iredmail displays the following:
++++ Listing folders
All foldernames are presented between brackets like [X] where X is the foldername.
When a foldername contains non-ASCII characters it is presented in the form
[X] = [Y] where
X is the imap foldername you have to use in command line options and
Y is the uft8 output just printed for convenience, to recognize it.
Host1 folders list:
[&BB4EQgQ,BEAEMAQyBDsENQQ9BD0ESwQ1-] = [Отправленные]
[&BBoEPgRABDcEOAQ9BDA-] = [Корзина]
[&BCEEPwQwBDw-] = [Спам]
[&BCcENQRABD0EPgQyBDgEOgQ4-] = [Черновики]
[INBOX]
Host2 folders list:
[Drafts]
[INBOX]
[Junk]
[Sent]
[Trash]
Folders in host2 not in host1:
[Trash]
[Sent]
[Junk]
[Drafts]
--regextrans2 's,^drafts,Drafts,' \
--regextrans2 's,^sent,Sent,' \
--regextrans2 's,^spam,Junk,' \
--regextrans2 's,^trash,Trash,' # тут не нужно ставить обратный слэш так как является последним аргументом
--regextrans2 's,^Черновики,Drafts,' \
--regextrans2 's,^Отправленные,Sent,' \
--regextrans2 's,^Спам,Junk,' \
--regextrans2 's,^Корзина,Trash,'
--regextrans2 's,^&BCcENQRABD0EPgQyBDgEOgQ4-,Drafts,' \
--regextrans2 's,^&BB4EQgQ,BEAEMAQyBDsENQQ9BD0ESwQ1-,Sent,' \
--regextrans2 's,^&BCEEPwQwBDw-,Junk,' \
--regextrans2 's,^&BBoEPgRABDcEOAQ9BDA-,Trash,'
Host1 folders list:
[&BB4EQgQ,BEAEMAQyBDsENQQ9BD0ESwQ1-] = [Отправленные]
[&BBoEPgRABDcEOAQ9BDA-] = [Корзина]
[&BCEEPwQwBDw-] = [Спам]
[&BCcENQRABD0EPgQyBDgEOgQ4-] = [Черновики]
[INBOX]
Host2 folders list:
[Drafts]
[INBOX]
[Junk]
[Sent]
[Trash]
Answer the question
In order to leave comments, you need to log in
The solution of two "BUT" is found, thanks to dimonchik2013 for the hint on the first point:
did you try it on p1?
serverfault.com/questions/598364/imapsync-doesnt-s...
As a result, the working sync_loop_unix.sh script looks like this:
#!/bin/sh
echo Looping on account credentials found in file.txt
echo
{ while IFS=';' read h1 u1 p1 h2 u2 p2 fake
do
{ echo "$h1" | egrep "^#" ; } > /dev/null && continue # this skip commented lines in file.txt
echo "==== Starting imapsync from host1 $h1 user1 $u1 to host2 $h2 user2 $u2 ===="
./imapsync --host1 "$h1" --user1 "$u1" --password1 "$p1" \
--host2 "$h2" --user2 "$u2" --password2 "$p2" \
--ssl1 \
--port1 993 \
--folderfirst INBOX \
--regextrans2 "s/&BB4EQgQ,BEAEMAQyBDsENQQ9BD0ESwQ1-/Sent/" \
--regextrans2 "s/&BBoEPgRABDcEOAQ9BDA-/Trash/" \
--regextrans2 "s/&BCEEPwQwBDw-/Junk/" \
--regextrans2 "s/&BCcENQRABD0EPgQyBDgEOgQ4-/Drafts/" \
--regexflag 's/\\Unseen//g' \
--useheader Message-Id
"[email protected]"
echo "==== Ended imapsync from host1 $h1 user1 $u1 to host2 $h2 user2 $u2 ===="
echo
done
} < file.txt
host001_1;user001_1;password001_1;host001_2;user001_2;password001_2;
host002_1;user002_1;password002_1;host002_2;user002_2;password002_2;
host003_1;user003_1;password003_1;host003_2;user003_2;password003_2;
# вариант с использованием посредника, то есть на другой машине выполняете скрипт
imap.mail.ru;[email protected];[email protected];imap.newdomain.ru;[email protected];[email protected];
imap.mail.ru;[email protected];[email protected];imap.newdomain.ru;[email protected];[email protected];
... и т.д.
# если выполняете скрипт локально на новом почтовом сервере
imap.mail.ru;[email protected];[email protected];localhost;[email protected];[email protected];
imap.mail.ru;[email protected];[email protected];localhost;[email protected];[email protected];
... и т.д.
...
# папка Отправленные
--regextrans2 "s/&BB4EQgQ,BEAEMAQyBDsENQQ9BD0ESwQ1-/Sent/" \
# папка Корзина
--regextrans2 "s/&BBoEPgRABDcEOAQ9BDA-/Trash/" \
# папка СПАМ
--regextrans2 "s/&BCEEPwQwBDw-/Junk/" \
# папка Черновики
--regextrans2 "s/&BCcENQRABD0EPgQyBDgEOgQ4-/Drafts/" \
...
...
--regexflag 's/\\Unseen//g' \
...
Maybe it's easier to rename folders or move emails and delete unnecessary folders directly in the maildirs on the server, or look in your IMAP server for naming settings for special folders? If there is no such setting, then it is trivial to move. if the server does not give service folders with the same names, the folders will still be duplicated in the client programs and you will have to change them in the settings.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question