dimanche 9 février 2014

Migrer ses méls avec Imapcopy !


Voila, il est l'heure de tourner la page. Prism, snowden, toussa, vous ont poussé à changer votre train-train et tourner la page. Vous avez déjà votre serveur de fichiers, votre owncloud, bref votre vrai cloud privé ? Reste les méls. Vous changez pour un autre serveur mél ? ça tombe bien moi aussi !

Comment faire ? se palucher la copie des méls avec thunderbird ? Non, ça c'est pour les esclaves : risques d'oublis, de désynchro, de plantage, bref, c'est pas le bon outil. Le bon outil, c'est imapcopy !

Mise en œuvre de Imapcopy

 

Facile, apt est ton ami !

sudo apt-get install imapcopy

Créez le fichier appelé imapcopy.cfg dans votre home.
Récupérez l'exemple ici : /usr/share/doc/imapcopy/examples/ImapCopy.cfg.
Paramétrez le à votre sauce : source, destination, comptes ; exemple :

SourceServer imap.foo.tld
SourcePort 143
DestServer imap.bar.tld
DestPort 143
# SourceUser SourcePassword DestinationUser DestinationPassword 
Copy    "user@foo.tld"         "nsa"       "user@bar.tld"           "sn0wd3n"

Votre serveur utilise du SSL ? C'est une bonne chose ! 143 çaïmal !
Mais imapcopy ne sait pas bosser avec SSL/TLS. Aucun problème, un petit tunnel SSL fera l'affaire !

Au cas où vous ne l'auriez pas :

apt-get install stunnel

Et hop on va se créer deux petits tunnels avec l'outil par excellence des adminsys, screen !

$ screen

et "dans ton screen"  DTS(c) :

$ stunnel -c -f -d 1143 -r imap.googlemail.com:993 -P
2014.02.09 10:13:12 LOG5[17648:140167730644800]: stunnel 4.53 on x86_64-pc-linux-gnu platform
2014.02.09 10:13:12 LOG5[17648:140167730644800]: Compiled with OpenSSL 1.0.1c 10 May 2012
2014.02.09 10:13:12 LOG5[17648:140167730644800]: Running  with OpenSSL 1.0.1e 11 Feb 2013
2014.02.09 10:13:12 LOG5[17648:140167730644800]: Update OpenSSL shared libraries or rebuild stunnel
2014.02.09 10:13:12 LOG5[17648:140167730644800]: Threading:PTHREAD SSL:+ENGINE+OCSP Auth:LIBWRAP Sockets:POLL+IPv6
2014.02.09 10:13:12 LOG5[17648:140167730644800]: Reading configuration from descriptor 3
2014.02.09 10:13:12 LOG5[17648:140167730644800]: Configuration successful


Ctrl + a S pour splitter horizontalement l'écran
Ctrl + tab pour changer de fenetre
Ctrl + a c pour créer une nouvelle fenêtre

$ stunnel -c -f -d 1144 -r imap.bar.tld:993 -P
2014.02.09 10:13:58 LOG5[17664:140534229604160]: stunnel 4.53 on x86_64-pc-linux-gnu platform
2014.02.09 10:13:58 LOG5[17664:140534229604160]: Compiled with OpenSSL 1.0.1c 10 May 2012
2014.02.09 10:13:58 LOG5[17664:140534229604160]: Running  with OpenSSL 1.0.1e 11 Feb 2013
2014.02.09 10:13:58 LOG5[17664:140534229604160]: Update OpenSSL shared libraries or rebuild stunnel
2014.02.09 10:13:58 LOG5[17664:140534229604160]: Threading:PTHREAD SSL:+ENGINE+OCSP Auth:LIBWRAP Sockets:POLL+IPv6
2014.02.09 10:13:58 LOG5[17664:140534229604160]: Reading configuration from descriptor 3
2014.02.09 10:13:58 LOG5[17664:140534229604160]: Configuration successful


On modifie alors ImapCopy.cfg pour utiliser :

SourceServer 127.0.0.1
SourcePort 1143
et
DestServer 127.0.0.1
DestPort 1144

Test !

 

$ imapcopy -i
[...]
Login on sourceserver as user@gmail.com OK
Login on destinationserver as user@bar.tld OK
Getting folderlist on sourceserver OK, found 12 folder
Sourceserver:
=============
Server-Info          : Gimap ready for requests from my.ip.ad.dr myid.nb
Capabilities         : IMAP4REV1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH
Personal Namespace   :
Folder sperator      : /
other Users Namespace:
Public Namespace     :
Folders to copy      : ALL
Skip this folders    : NONE

Destinationserver:
==================
Server-Info          : [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE AUTH=PLAIN] Dovecot ready.
Capabilities         : IMAP4REV1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS MULTIAPPEND UNSELECT IDLE CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS QUOTA
Personal Namespace   :
Folder sperator      : .
other Users Namespace:
Public Namespace     :
 


Pour les autres options, imapcopy -h est ton ami !

Et c'est partiiiii

 

Comment ? Benh tout simplement !

$ imapcopy -l

IMAPCopy 1.04 - 2009/07/18 [compiled with FreePascal]
written 2001-2009 by Armin Diehl
Running on Linux

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA 02110-1301, USA.
---------------------------------------------------------------------------
Login on sourceserver as user@gmail.com OK
Login on destinationserver as user@bar.tld OK
Getting folderlist on sourceserver OK, found 12 folder
Getting List of messages in "INBOX" OK, 1234 Messages found
Processing Folder INBOX
reading message 1753


et voilà c'est parti !


Perfectible, sans doute un peu moche, mais ça fait le taff :)

Aucun commentaire:

Enregistrer un commentaire