switching to argument based domain for mail script
This commit is contained in:
parent
5ffeebbd1d
commit
b8f206ee32
25
ovh-mail.py
25
ovh-mail.py
@ -6,19 +6,19 @@ import pycurl
|
||||
import json
|
||||
import argparse
|
||||
|
||||
def writeRedirectionsToFile(client):
|
||||
def writeRedirectionsToFile(client,domain):
|
||||
# Grab bill list
|
||||
mailbox = client.get('/email/domain/hyrule.ovh/redirection')
|
||||
mailbox = client.get('/email/domain/' + domain + '/redirection')
|
||||
file = open(redir_file,'wt')
|
||||
for id in mailbox:
|
||||
redirection = client.get('/email/domain/hyrule.ovh/redirection/'+str(id))
|
||||
redirection = client.get('/email/domain/' + domain + '/redirection/'+str(id))
|
||||
file.write(redirection['from']+','+redirection['to']+','+redirection['id']+'\n')
|
||||
file.close()
|
||||
|
||||
def checkRedirExists(client,fr,to):
|
||||
mailbox = client.get('/email/domain/hyrule.ovh/redirection')
|
||||
def checkRedirExists(client,domain, fr,to):
|
||||
mailbox = client.get('/email/domain/' + domain + '/redirection')
|
||||
for id in mailbox:
|
||||
redirection = client.get('/email/domain/hyrule.ovh/redirection/'+str(id))
|
||||
redirection = client.get('/email/domain/' + domain +'/redirection/'+str(id))
|
||||
if (redirection['from'] == fr and redirection['to'] == to):
|
||||
print("Redirection existante")
|
||||
return id
|
||||
@ -28,18 +28,19 @@ def checkRedirExists(client,fr,to):
|
||||
else:
|
||||
return False
|
||||
|
||||
def addRedirection(client,fr,to):
|
||||
result = client.post('/email/domain/hyrule.ovh/redirection',_from=fr,localCopy=False,to=to)
|
||||
def addRedirection(client,domain,fr,to):
|
||||
result = client.post('/email/domain/'+ domain +'/redirection',_from=fr,localCopy=False,to=to)
|
||||
print(json.dumps(result,indent=4))
|
||||
return 0
|
||||
|
||||
parser = argparse.ArgumentParser(description='Process arguments')
|
||||
parser.add_argument('method', metavar='method', type=str, help='Function to use')
|
||||
parser.add_argument('domain', metavar='domain', type=str, help='domain')
|
||||
parser.add_argument('--fr', metavar='fr', type=str, help='from mail address')
|
||||
parser.add_argument('--to', metavar='to', type=str, help='to mail address')
|
||||
args = parser.parse_args()
|
||||
|
||||
redir_file = '/var/scripts/ovh_api/data/redirections.txt'
|
||||
redir_file = './data/redirections.txt'
|
||||
|
||||
try:
|
||||
input = raw_input
|
||||
@ -47,7 +48,7 @@ except NameError:
|
||||
pass
|
||||
client = ovh.Client()
|
||||
if (args.method == "write"):
|
||||
writeRedirectionsToFile(client)
|
||||
writeRedirectionsToFile(client,args.domain)
|
||||
elif (args.method == "add"):
|
||||
if not (checkRedirExists(client,args.fr,args.to)):
|
||||
addRedirection(client,args.fr,args.to)
|
||||
if not (checkRedirExists(client,args.domain,args.fr,args.to)):
|
||||
addRedirection(client,args.domain,args.fr,args.to)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user