1
0
Fork 0
mirror of https://github.com/myvesta/vesta synced 2025-08-10 16:47:39 -07:00

imapsync tools

This commit is contained in:
myvesta 2024-02-08 21:26:03 +01:00 committed by GitHub
commit 2aca86432f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 83 additions and 11 deletions
src/deb/for-download/tools/imapsync

View file

@ -35,18 +35,35 @@ fi
TESTOPT=""
if [[ $TEST -eq 1 ]]; then
TESTOPT="--justlogin"
TESTOPT="--justlogin"
fi
if [ ! -d "accounts" ]; then
mkdir accounts
fi
if [ -f "accounts/$EMAIL" ]; then
echo "********* $EMAIL ALREADY EXISTS !!! ************"
echo "********* EMAIL $EMAIL ALREADY EXISTS !!! ************"
exit 1;
exit
fi
euser=$(echo $EMAIL | cut -d '@' -f 1)
domain=$(echo $EMAIL | cut -d '@' -f 2)
user=$(/usr/local/vesta/bin/v-search-domain-owner $domain)
if [ "$user" != "" ]; then
echo "=== Email '$EMAIL' has username email part '$euser', domain is '$domain', and belongs to myVesta account: $user"
if [ ! -d "/home/$user/mail/$domain" ]; then
echo "======= Creating '$domail' in MAIL section"
/usr/local/vesta/bin/v-add-mail-domain "$user" "$domain"
fi
if [ ! -d "/home/$user/mail/$domain/$euser" ]; then
echo "======= Creating '$euser' mail account for domain '$domain'"
/usr/local/vesta/bin/v-add-mail-account "$user" "$domain" "$euser" "$PASS2"
echo ""
fi
fi
echo "Writing to: accounts/$EMAIL"
echo "#!/bin/bash
@ -67,21 +84,20 @@ exit;
chmod a=rwx accounts/$EMAIL
if [[ $TEST -eq 0 ]]; then
exit 0;
exit 0;
fi
accounts/$EMAIL
RET=$?
if [ $RET -eq 0 ]; then
# echo "./create-mail-sync.sh $EMAIL $PASS $PASS2 $TEST"
sed -i "s/--justlogin//g" accounts/$EMAIL
echo "--- OK! ---"
echo "./create-mail-sync.sh '$SRCHOST' '$EMAIL' '$PASS' '$PASS2' $TEST" >> accounts.log
# echo "./create-mail-sync.sh $EMAIL $PASS $PASS2 $TEST"
sed -i "s/--justlogin//g" accounts/$EMAIL
echo "--- OK! ---"
echo "./create-mail-sync.sh '$SRCHOST' '$EMAIL' '$PASS' '$PASS2' $TEST" >> accounts.log
else
echo "********* $EMAIL ERROR !!! [ret: $RET ] ************"
echo "********* $EMAIL ERROR !!! [ret: $RET ] ************"
echo "********* $EMAIL ERROR !!! [ret: $RET ] ************"
rm accounts/$EMAIL
echo "********* $EMAIL ERROR !!! [ret: $RET ] ************"
rm accounts/$EMAIL
read -p "=== Press ENTER to continue ===" entered
fi
exit $RET;

View file

@ -0,0 +1,56 @@
#!/bin/bash
#
# This script reads email and password=s in following format:
# email1 pass
# email2 pass
# email3 pass
# The first parameter is the text file from which we read emails and passwords
# The second parameter is SMTP Hostname
# The third parameter is domain if lines contains only username part
host=''
if [ $# -gt 1 ]; then
host=$2
else
echo "Usage: ./import-from-file.sh 'FILE' 'SMTPHOST' ['DOMAIN']"
exit 1;
fi
domain=''
if [ $# -gt 2 ]; then
domain=$3
fi
end_of_file=0
while [[ $end_of_file == 0 ]]; do
read -r line
end_of_file=$?
if [ "$line" == "" ]; then
if [[ $end_of_file == 1 ]]; then
echo "===EOF==="
break;
fi
continue
fi
email=$(echo "$line" | awk '{print $1}')
pass=$(echo "$line" | awk '{print $2}')
if [[ $email != *"@"* ]]; then
email="$email@$domain"
fi
echo "Extracted: '$email' = '$pass'"
./create-mail-sync.sh "$host" "$email" "$pass"
if [[ $end_of_file == 1 ]]; then
echo "===EOF==="
break;
fi
done < $1