Browse Source

fixed defunct forwarding feature

main
david 5 years ago
parent
commit
c30c50ec37
  1. 11
      app.py
  2. 4
      views/default.tpl

11
app.py

@ -109,10 +109,10 @@ def get_domains():
return [ user['domain'] for user in users ]
# get forwarding alias for user
def get_forward(username):
def get_forwards(username):
a = requests.get(miab_url + "/mail/aliases?format=json", auth=(miab_admin, miab_passwd))
aliases = a.json()
return [alias['forwards_to'][0][0] for domains in aliases for alias in domains['aliases'] if alias['address'] == username]
return [ alias['forwards_to'][0] for domains in aliases for alias in domains['aliases'] if alias['address'] == username ]
# routing
@ -123,7 +123,7 @@ def home():
message = request.get_cookie(cookie_name + "_message", secret=cookie_secret)
if username:
aliases = get_aliases(username)
forward = get_forward(username)
forward = get_forwards(username)
# render homepage
return template('default', username=username, app_name=app_name, message=message, aliases=aliases, max_aliases=max_aliases, forward=forward)
else:
@ -263,7 +263,7 @@ def add_forward():
username = logged_in()
forward = request.forms.get('forward')
if username:
if get_forward(username):
if get_forwards(username):
message = { "message": "Email forwarding is already configured", "alert": "danger" }
response.set_cookie(cookie_name + "_message", message, secret=cookie_secret, max_age=5, path="/")
redirect('/')
@ -287,8 +287,7 @@ def delete_forward():
username = logged_in()
forward = request.forms.get('forward')
if username:
forwarded = get_forward(username)
if forward == forwarded:
if forward == get_forwards(username)[0]:
data = { "address": username, }
d = requests.post(miab_url + "/mail/aliases/remove", data=data, auth=(miab_admin, miab_passwd))
if d.status_code == 200:

4
views/default.tpl

@ -95,8 +95,8 @@
%if forward:
<form class="form-inline" action="/forward/delete" method="post">
<div class="form-group">
<input type="email" class="form-control" id="forwardemailInput" value="{{ forward }}" disabled>
<input name="forward" type="hidden" class="form-control" id="forwardemailInput2" value="{{ forward }}">
<input type="email" class="form-control" id="forwardemailInput" value="{{ forward[0] }}" disabled>
<input name="forward" type="hidden" class="form-control" id="forwardemailInput2" value="{{ forward[0] }}">
</div>
<button type="submit" class="btn btn-primary btn-danger">delete</button>
</form>

Loading…
Cancel
Save