Skip to content

Instantly share code, notes, and snippets.

@stephdl
Created June 5, 2020 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephdl/cff01794bbd4eab432709c296356c23f to your computer and use it in GitHub Desktop.
Save stephdl/cff01794bbd4eab432709c296356c23f to your computer and use it in GitHub Desktop.
Migration script for imapsync
#!/bin/bash
# mail_sync h1 u1 p1 h2 u2 p2 check
MAXTRIES=5
if [ $# -lt 6 ]; then
exit 1
fi
JC=""
if [ x$7 = "xcheck" ]; then
JC="--justlogin"
MAXTRIES=1
fi
# sometimes exchange send more or less bytes than real msg size
# the following options disable size checking
# --allowsizemismatch --skipsize \
# by default, only 1000 msg at a time are transfered
# add the following option to change msg per connection
# --split1 100 \
TN=$MAXTRIES
while ! \
imapsync \
$JC \
--noreleasecheck --noauthmd5 \
--allowsizemismatch --skipsize \
--nofoldersizes \
--delete2 --delete2folders \
--fast --fastio1 --fastio2 \
--buffersize 8192000 \
--host1 "$1" --user1 "$2" --password1 "$3" \
--host2 "$4" --user2 "$5" --password2 "$6" \
--exclude 'Public Folders' \
--exclude 'Trash' \
--exclude 'Deleted Items' \
; do
echo RETRYING
TN=$(expr $TN - 1)
if [ $TN -eq 0 ]; then
echo "FAILED syncing user $2:$5 after $MAXTRIES attempts."
exit 1
fi
done
## It's used with a CSV script:
{ while IFS=';' read u1 p1 u2 p2; do ./mail_sync 192.168.0.x $u1 $p1 localhost $u2 $p2; done ; } < elenco_utenti.csv | tee -a mail_sync.log
#But do not need the CSV support, it's just an example of bulk import.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment