Skip to content

Instantly share code, notes, and snippets.

@saiful7
Forked from nosmall/imapsync.md
Created January 11, 2023 20:44
Show Gist options
  • Save saiful7/d3d87b278a5e8770315bfe0cc9f12ddd to your computer and use it in GitHub Desktop.
Save saiful7/d3d87b278a5e8770315bfe0cc9f12ddd to your computer and use it in GitHub Desktop.
Imapsync on Ubuntu 20.04 (lazy guide)

Imapsync on Ubuntu 20.04 (lazy guide)

sudo apt install -y libauthen-ntlm-perl libclass-load-perl libcrypt-ssleay-perl libdata-uniqid-perl libdigest-hmac-perl libdist-checkconflicts-perl libencode-imaputf7-perl libfile-copy-recursive-perl libfile-tail-perl libio-compress-perl libio-socket-inet6-perl libio-socket-ssl-perl libio-tee-perl libmail-imapclient-perl libmodule-scandeps-perl libnet-dbus-perl libnet-ssleay-perl libpar-packer-perl libreadonly-perl libregexp-common-perl libsys-meminfo-perl libterm-readkey-perl libtest-fatal-perl libtest-mock-guard-perl libtest-mockobject-perl libtest-pod-perl libtest-requires-perl libtest-simple-perl libunicode-string-perl liburi-perl libtest-nowarnings-perl libtest-deep-perl libtest-warn-perl make cpanminus && \
cd ~/ && \
git clone https://github.com/imapsync/imapsync.git && \
cd ~/imapsync/ && \
sudo ln -s ~/imapsync/imapsync /usr/bin/imapsync && \
imapsync --testslive

MOVE messages from Gmail account to Archive Gmail Account

imapsync \
 --search "SENTSINCE 1-Jan-2014 SENTBEFORE 2-Jun-2015" \
 --host1 imap.gmail.com \
 --ssl1 \
 --user1 [email protected] \
 --password1 StrongPass123 \
 --host2 imap.gmail.com \
 --ssl2 \
 --user2 [email protected] \
 --password2 StrongPass123 \
 --maxbytespersecond 20_000 \
 --maxbytesafter 1_000_000_000 \
 --automap \
 --maxsleep 2 \
 --synclabels \
 --resynclabels \
 --delete1 \
 --noexpungeaftereach \
 --no-modulesversion \
 --nofoldersizes \
 --exclude "\[Gmail\]$" \
 --folderlast "[Gmail]/All Mail" --dry

SYNC GMAIl to GMAIL

imapsync \
           --host1 imap.gmail.com \
           --ssl1 \
           --user1 [email protected] \
           --password1 gmailsecret1 \
           --host2 imap.gmail.com \
           --ssl2 \
           --user2 [email protected] \
           --password2 gmailsecret2 \
           --maxbytespersecond 20_000 \
           --maxbytesafter 1_000_000_000 \
           --automap \
           --maxsleep 2 \
           --synclabels \
           --resynclabels \
           --exclude "\[Gmail\]$" \
           --folderlast  "[Gmail]/All Mail"

With --gmail1 --gmail2 you can override the parameters
that are activated by them, for example:

imapsync ... --gmail1 --gmail2 --maxbytespersecond 50_000 --noautomap

Explanations:


--maxbytespersecond 20_000 ( 20 kBytes/s ) option is here to avoid 
locking or errors when imap transfers exceed Gmail maximum limit. 
See http://support.google.com/a/bin/answer.py?hl=en&answer=1071518
--maxbytespersecond 20_000 is not mandatory in the sense Gmail may 
allow you to use an upper value than 1 GBytes per 24h without 
disconnections. If you count well, it should be 10_000, not 20_000.

--maxbytesafter 1_000_000_000 option is there because 
option --maxbytespersecond 20000 is unnecessarily slow if the Gmail 
account size is less than 1 GB.

--maxsleep 2 is to avoid sleeping more than 2 seconds when 
the --maxbytespersecond value implies a long sleep between 2 copies.

--automap is not mandatory but it's a feature to automatically
map folder names based on the Gmail user configuration itself, par account.
It will save manual folder names changes or the use of --regextrans2 
or --f1f2 to map folder names.
For example, imap folder "[Gmail]/Sent Mail" may be mapped as one of
E-mails enviados
Enviada
Enviado
Gesendet
Gönderildi
Inviati
Sendt
Skickat
Verzonden
etc.
on both sides, host1 or host2, maybe differently, sometimes in 
incomprehensible alphabets, a headache for imap sysadmins.
See a listing here:
http://stackoverflow.com/questions/2185391/localized-gmail-imap-folders/2185548#2185548

--exclude "\[Gmail\]$"   is just there to avoid a warning error
when selecting this not used folder.

Be aware that --gmail1 --gmail2 is a special case, it's not what
--gmail1 does plus what --gmail2 does when they are not invoked 
together.

  imapsync ... --search "SENTSINCE 1-Jan-2010" 
  
or 
  
  imapsync ... --search "SENTBEFORE 31-Dec-2010"

or
  
  imapsync ... --search "SENTSINCE 1-Jan-2010 SENTBEFORE 31-Dec-2010"

  Months are specified like this:
  
   Jan
   Feb
   Mar
   Apr
   May 
   Jun
   Jul 
   Aug
   Sep
   Oct 
   Nov
   Dec

sources

https://github.com/imapsync/imapsync/blob/master/INSTALL.d/INSTALL.Ubuntu.txt https://imapsync.lamiral.info/FAQ.d/FAQ.Gmail.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment