commit 666e339d86b43b47220e33d73bfad9fdab35a42d Author: dede Date: Sun May 11 17:36:16 2025 +0200 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6049ac0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.env +sync/accounts.txt +sync/failures.txt \ No newline at end of file diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..8a6fc24 --- /dev/null +++ b/compose.yml @@ -0,0 +1,8 @@ +services: + imapsync: + image: gilleslamiral/imapsync + restart: "no" + # command: imapsync --host1 $HOST1 --user1 $USR1 --password1 $IMAPSYNC_PASSWORD1 --host2 $HOST2 --user2 $USR2 --password2 $IMAPSYNC_PASSWORD2 --delete2duplicates --automap + command: bash /sync/sync_loop_unix.sh + volumes: + - "./sync:/sync" diff --git a/sync/accounts.txt.sample b/sync/accounts.txt.sample new file mode 100644 index 0000000..4bb661b --- /dev/null +++ b/sync/accounts.txt.sample @@ -0,0 +1 @@ +host001_1;user001_1;password001_1;host001_2;user001_2;password001_2;; \ No newline at end of file diff --git a/sync/sync_loop_unix.sh b/sync/sync_loop_unix.sh new file mode 100644 index 0000000..8ce9d72 --- /dev/null +++ b/sync/sync_loop_unix.sh @@ -0,0 +1,69 @@ +#!/bin/sh +# +# $Id: sync_loop_unix.sh,v 1.14 2024/12/25 21:17:38 gilles Exp gilles $ + +# Example for imapsync massive migration on Unix systems. +# See also http://imapsync.lamiral.info/FAQ.d/FAQ.Massive.txt +# +# Data is supposed to be in accounts.txt in the following format: +# host001_1;user001_1;password001_1;host001_2;user001_2;password001_2;; +# ... +# The separator is the character semi-colon ";" +# this separator character can be changed to any character +# by changing IFS=';' in the while loop below. +# +# Each line contains 7 columns. These columns are the 6 parameter values +# for the imapsync command options +# --host1 --user1 --password1 --host2 --user2 --password2 +# plus an extra column for extra parameters and a trailing fake column +# to avoid CR LF part going in the 7th parameter extra. +# So don't forget the last semicolon, especially on MacOS systems. +# +# You can also add extra options in this script after the variable "$@" +# Those options will be applied in every imapsync run, for every line. + +# The imapsync command below is written in two lines to avoid a long line. +# The character backslash \ at the end of the first line is means +# "the command continues on the next line". +# +# Use character backslash \ at the end of each supplementary line, +# except for the last line. +# + +# You can also pass extra options via the parameters of this script since +# they will be in "$@". Shell knowledge is your friend. + +# The credentials filename "accounts.txt" used for the loop can be renamed +# by changing "accounts.txt" below. + +# The file file_failures.txt will contain the lines from accounts.txt that ended +# up in error, for whatever reason. It's there to notice and replay easily +# the failed imapsync runs. Is is emptied at the beginning of the loop run. +# I let you junggle with it. + +SRC_FILE=/sync/accounts.txt +FAIL_FILE=/sync/failures.txt +GLOBAL_FLAGS="--noreleasecheck" + +echo Looping on accounts credentials found in $SRC_FILE +echo +line_counter=0 +# Empty the error listing +> "$FAIL_FILE" +{ while IFS=';' read h1 u1 p1 h2 u2 p2 extra fake + do + line_counter=$(expr 1 + $line_counter) + { echo "$h1" | tr -d '\r' | grep -E '^#|^ *$' ; } > /dev/null && continue # this skip commented lines in accounts.txt + echo "==== Starting imapsync with --host1 $h1 --user1 $u1 --host2 $h2 --user2 $u2 $extra $GLOBAL_FLAGS $@ ====" + echo Got those values from $SRC_FILE presented inside brackets: [$h1] [$u1] [$h2] [$u2] [$extra] [$fake] + if eval imapsync --host1 "$h1" --user1 "$u1" --password1 "$p1" \ + --host2 "$h2" --user2 "$u2" --password2 "$p2" $extra $GLOBAL_FLAGS "$@" + then + echo "success sync for line $line_counter " + else + echo "$h1;$u1;$p1;$h2;$u2;$p2;$extra;" | tee -a $FAIL_FILE + fi + echo "==== Ended imapsync with --host1 $h1 --user1 $u1 --host2 $h2 --user2 $u2 $extra $GLOBAL_FLAGS $@ ====" + echo + done +} < $SRC_FILE