Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A bash script to clone multiple email-password combinations from one imap host to another. Requires imapsync installed/compiled and a csv file for email list. Uses port 993+ssl as default.
#!/bin/sh
# CSV file line example:
# some.name@domain.com,PASSWORD
if [ -z "$1" ]
then
echo "CSV file is not specified!"
exit 1
fi
if [ -z "$2" ]
then
echo "Missing host name (ex: imap.gmail.com or outlook.office365.com)"
exit 1
fi
FILE=$1
HOST=$2
EMAIL=()
PASS=()
counter=0
for line in `cat $FILE`; do
{
EMAIL[counter]=`echo "$line" | cut -d, -f1`
PASS[counter]=`echo "$line" | cut -d, -f2`
((counter++))
};
done;
lastitem=$counter
counter=0
function doOne {
if [ "$counter" -eq "$lastitem" ]; then
return
fi
E=${EMAIL[counter]}
P=${PASS[counter]}
imapsync --tmpdir /var/tmp --usecache --useuid \
--host1 $HOST --user1 $E --password1 $P --port1 993 --ssl1 --authmech1 LOGIN \
--host2 server.emrg.me --user2 $E --password2 $P --port2 993 --ssl2 &
((counter++))
modulo=$((counter%5))
if [ "$modulo" -eq "0" ]; then
wait
doOne
else
doOne
fi
}
doOne
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment