Last active
October 5, 2017 11:33
-
-
Save lucasff/b74b45a65a236da732da to your computer and use it in GitHub Desktop.
imapSync collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#Configure User | |
SERVER1= | |
UNAME1= | |
PWORD1= | |
SERVER2=localhost | |
UNAME2= | |
PWORD2= | |
#Blank this out if you want to see folder sizes | |
HIDE="" | |
imapsync --syncinternaldates --useheader 'Message-Id' \ | |
--host1 ${SERVER1} --user1 ${UNAME1} \ | |
--password1 ${PWORD1} --ssl1 \ | |
--host2 ${SERVER2} \ | |
--port2 993 --user2 ${UNAME2} \ | |
--password2 ${PWORD2} --ssl2 \ | |
--authmech1 LOGIN --authmech2 LOGIN --split1 200 --split2 200 ${HIDE} \ | |
#--exclude 'Drafts|Trash|Spam|Sent' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOGFILE=imapsync.log | |
FOLDERS=( 'Folder1' 'Folder2' 'Folder3' 'Folder4' '...' 'FolderN' 'INBOX' 'All Mail' 'Bin' 'Drafts' 'Starred' 'Sent Mail' ) | |
TIMES=( '--minage 1090' '--maxage 1091 --minage 999' '--maxage 1000 --minage 908' '--maxage 909 --minage 817' '--maxage 818 --minage 726' '--maxage 727 --minage 635' '--maxage 636 --minage 544' '--maxage 545 --minage 453' '--maxage 454 --minage 362' '--maxage 363 --minage 271' '--maxage 272 --minage 180' '--maxage 181 --minage 89' '--maxage 90' ) | |
SRC_EMAIL='' | |
DST_EMAIL='' | |
echo "Starting" > $LOGFILE | |
for FOLDER in "$@" | |
do | |
for ((j=0;j<${#TIMES};j++)) | |
do | |
TIME=${TIMES[${j}]} | |
echo "" >> $LOGFILE | |
echo "*** $FOLDER $TIME ***" >> $LOGFILE | |
echo "" >> $LOGFILE | |
while ! ~/imapsync-1.267/imapsync --host1 imap.gmail.com \ | |
--port1 993 --user1 $SRC_EMAIL \ | |
--passfile1 ./passfile --ssl1 \ | |
--host2 imap.gmail.com \ | |
--port2 993 --user2 $DST_EMAIL \ | |
--passfile2 ./passfile --ssl2 \ | |
--syncinternaldates --split1 100 --split2 100 \ | |
--authmech1 LOGIN --authmech2 LOGIN \ | |
--include "$FOLDER" \ | |
$TIME \ | |
--useheader "Message-ID" \ | |
--useheader "Date" --skipsize \ | |
--regexmess 's/Delivered-To: email\@domain.com/Delivered-To: email\@anotherdomain.com/gi' \ | |
--regexmess 's/<lucas\@falcondc.com.br>/<lucas\@falcondesigner.com.br>/gi' \ | |
--regexmess 's/^((To|From|Cc|Bcc):.*)email\@domain.com(.*)$/$1email\@anotherdomain.com$3/gim' \ | |
--regexmess 's/Subject:(\s*)\n/Subject: (no--subject)$1\n/ig' \ | |
--regexmess 's/Subject: ([Rr][Ee]):(\s*)\n/Subject: $1: (no--subject)$2\n/gi' >> $LOGFILE 2>&1; do | |
echo "" >> $LOGFILE | |
echo "***** NOT COMPLETE - $FOLDER $TIME *****" >> $LOGFILE | |
echo "" >> $LOGFILE | |
tail -100 $LOGFILE | mail -s "Imapsync Restarting for $FOLDER $TIME" "$DST_EMAIL" | |
echo -n "Sleeping..." >> $LOGFILE | |
sleep 1m | |
echo "Done." >> $LOGFILE | |
done | |
echo "" >> $LOGFILE | |
echo "***** COMPLETE - $FOLDER $TIME*****" >> $LOGFILE | |
echo "" >> $LOGFILE | |
tail -100 $LOGFILE | mail -s "Imapsync Complete for $FOLDER $TIME" "$DST_EMAIL" | |
done | |
done | |
echo "**** DONE ****" >> $LOGFILE | |
tail -100 $LOGFILE | mail -s "Imapsync Complete" -c "$DST_EMAIL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#Configure User | |
SERVER1=$1 | |
UNAME1=$2 | |
PWORD1=$3 | |
SERVER2=$4 | |
UNAME2=$5 | |
PWORD2=$6 | |
#Blank this out if you want to see folder sizes | |
HIDE="--nofoldersizes --skipsize" | |
imapsync --syncinternaldates --useheader 'Message-Id' \ | |
--host1 ${SERVER1} --user1 ${UNAME1} \ | |
--password1 ${PWORD1} --ssl1 \ | |
--host2 ${SERVER2} \ | |
--port2 993 --user2 ${UNAME2} \ | |
--password2 ${PWORD2} --ssl2 \ | |
--authmech1 LOGIN --authmech2 LOGIN --split1 200 --split2 200 ${HIDE} \ | |
--exclude 'Drafts|Trash|Spam|Sent' | |
#TO Sync Special Folders to Gmail | |
imapsync --syncinternaldates --useheader 'Message-Id' \ | |
--host1 ${SERVER1} --user1 ${UNAME1} \ | |
--password1 ${PWORD1} --ssl1 \ | |
--host2 imap.googlemail.com \ | |
--port2 993 --user2 ${UNAME2} \ | |
--password2 ${PWORD2} --ssl2 \ | |
--ssl2 --noauthmd5 --split1 200 --split2 200 ${HIDE} \ | |
--folder "Inbox/Sent" --prefix2 '[Gmail]/' --regextrans2 's/Inbox\/Sent/Sent Mail/' \ | |
--folder "Inbox/Spam" --prefix2 '[Gmail]/' --regextrans2 's/Inbox\/Spam/Spam/' \ | |
--folder "Inbox/Trash" --prefix2 '[Gmail]/' --regextrans2 's/Inbox\/Trash/Trash/' \ | |
--folder "Inbox/Drafts" --prefix2 '[Gmail]/' --regextrans2 's/Inbox\/Drafts/Drafts/' \ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment