Skip to content

Instantly share code, notes, and snippets.

@antoine-briand
Last active August 29, 2023 12:39
Show Gist options
  • Save antoine-briand/636ba063be1d24ab0a9d to your computer and use it in GitHub Desktop.
Save antoine-briand/636ba063be1d24ab0a9d to your computer and use it in GitHub Desktop.
Interactive ImapSync tool written in python 3. Useful to sync imap accounts across different mail servers. Python 3 and imapsync must be installed on the machine.
# coding: utf8
import os, csv
print("Welcome to the ImapSync interactive")
mode = input("Interactive mode or Read CSV file ? (1/2) ")
if mode == "2":
#host1;user1;password1;host2;user2;password2
file = input("File path : ")
if file:
print("Reading file")
with open(file, 'r') as csvfile:
reader = csv.reader(csvfile, delimiter=';', quotechar='|')
for row in reader:
command = "imapsync --host1 " + row[0] + " -user1 " + row[1] + " --password1 " + row[2] +\
" --ssl1 --host2 " + row[3] + " --user2 " + row[4] + " --password2 " + row[5] + " --ssl2"
print(command)
os.system(command)
else:
host1 = input("What is the host 1 (mail1.example.com) ? ")
host2 = input("What is the host 2 (mail2.example.com) ? ")
ssl1 = input("ssl on host 1 ? (y/n)")
ssl2 = input("ssl on host 2 ? (y/n)")
if ssl1 == "y":
ssl1 = '--ssl1'
else:
ssl1 = ''
if ssl2 == "y":
ssl2 = '--ssl2'
else:
ssl2 = ''
user1 = input("User on host 1 ? ")
password1 = input("Password for the user on host 1 ? ")
same_users = input("Does users/passwords are the same on both servers ? (y/n) ")
if same_users == "y":
command = "imapsync --host1 " + host1 + " -user1 " + user1 + " --password1 " + password1 + " " + ssl1 + " --host2 " + host2 + " --user2 " + user1 + " --password2 " + password1 + " " + ssl2 + ""
print(command)
execute = input("Executer ? (y/n)")
if execute == "y":
os.system(command)
else:
user2 = input("User on host 2 ? ")
password2 = input("Password for the user on host 2 ? ")
command = "imapsync --host1 " + host1 + " -user1 " + user1 + " --password1 " + password1 + " " + ssl1 + " --host2 " + host2 + " --user2 " + user2 + " --password2 " + password2 + " " + ssl2 + ""
print(command)
execute = input("Executer ? (y/n)")
if execute == "y":
os.system(command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment