added email forwarding feature
This commit is contained in:
parent
217ce6d6c2
commit
90707e63cf
@ -73,6 +73,11 @@ Apache vhost config:
|
||||
ServerName accounts.domain.tld
|
||||
DocumentRoot /var/www/accounts/static
|
||||
|
||||
<Directory />
|
||||
Options FollowSymLinks
|
||||
AllowOverride None
|
||||
</Directory>
|
||||
|
||||
ErrorLog ${APACHE_LOG_DIR}/accounts_ssl_error.log
|
||||
LogLevel warn
|
||||
CustomLog ${APACHE_LOG_DIR}/accounts_ssl_access.log combined
|
||||
|
69
app.py
69
app.py
@ -136,6 +136,20 @@ def get_domains():
|
||||
i+=1
|
||||
return domains
|
||||
|
||||
# get forwarding alias for user
|
||||
def get_forward(username):
|
||||
a = requests.get(miab_url + "/mail/aliases?format=json", auth=(miab_admin, miab_passwd))
|
||||
aliases = a.json()
|
||||
i=0
|
||||
while i < len(aliases):
|
||||
j=0
|
||||
while j < len(aliases[i]['aliases']):
|
||||
if aliases[i]['aliases'][j]['address'] == username:
|
||||
forward = aliases[i]['aliases'][j]['forwards_to'][0]
|
||||
return forward
|
||||
j+=1
|
||||
i+=1
|
||||
return None
|
||||
|
||||
# routing
|
||||
|
||||
@ -146,8 +160,9 @@ def home():
|
||||
message = request.get_cookie(cookie_name + "_message", secret=cookie_secret)
|
||||
if username:
|
||||
aliases = get_aliases(username)
|
||||
forward = get_forward(username)
|
||||
# render homepage
|
||||
return template('default', username=username, app_name=app_name, message=message, aliases=aliases, max_aliases=max_aliases)
|
||||
return template('default', username=username, app_name=app_name, message=message, aliases=aliases, max_aliases=max_aliases, forward=forward)
|
||||
else:
|
||||
# render login
|
||||
message = request.get_cookie(cookie_name + "_message", secret=cookie_secret)
|
||||
@ -279,6 +294,56 @@ def delete_alias():
|
||||
else:
|
||||
redirect('/')
|
||||
|
||||
# configure email forwarding
|
||||
@post('/forward/add')
|
||||
def add_forward():
|
||||
username = logged_in()
|
||||
forward = request.forms.get('forward')
|
||||
if username:
|
||||
if get_forward(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('/')
|
||||
else:
|
||||
data = { "address": username, "forwards_to": forward }
|
||||
c = requests.post(miab_url + "/mail/aliases/add", data=data, auth=(miab_admin, miab_passwd))
|
||||
if c.status_code == 200:
|
||||
message = { "message": "Email forwarding to " + str(forward) + " has been configured successfully", "alert": "success" }
|
||||
response.set_cookie(cookie_name + "_message", message, secret=cookie_secret, max_age=5, path="/")
|
||||
redirect('/')
|
||||
else:
|
||||
message = { "message": "Something went wrong while configuring email forwarding", "alert": "danger" }
|
||||
response.set_cookie(cookie_name + "_message", message, secret=cookie_secret, max_age=5, path="/")
|
||||
redirect('/')
|
||||
else:
|
||||
redirect('/')
|
||||
|
||||
# deconfigure email forwarding
|
||||
@post('/forward/delete')
|
||||
def delete_forward():
|
||||
username = logged_in()
|
||||
forward = request.forms.get('forward')
|
||||
if username:
|
||||
forwarded = get_forward(username)
|
||||
if forward == forwarded:
|
||||
data = { "address": username, }
|
||||
d = requests.post(miab_url + "/mail/aliases/remove", data=data, auth=(miab_admin, miab_passwd))
|
||||
if d.status_code == 200:
|
||||
message = { "message": "Email forwarding has been deconfigured successfully", "alert": "success" }
|
||||
response.set_cookie(cookie_name + "_message", message, secret=cookie_secret, max_age=5, path="/")
|
||||
redirect('/')
|
||||
else:
|
||||
message = { "message": "Something went wrong while deconfiguring email forwarding", "alert": "danger" }
|
||||
response.set_cookie(cookie_name + "_message", message, secret=cookie_secret, max_age=5, path="/")
|
||||
redirect('/')
|
||||
else:
|
||||
message = { "message": "Your delete request does not match the configured forwarding", "alert": "danger" }
|
||||
response.set_cookie(cookie_name + "_message", message, secret=cookie_secret, max_age=5, path="/")
|
||||
redirect('/')
|
||||
else:
|
||||
redirect('/')
|
||||
|
||||
|
||||
|
||||
@post('/delete')
|
||||
def delete_account():
|
||||
@ -301,6 +366,8 @@ def delete_account():
|
||||
message = { "message": "Your supplied password is wrong", "alert": "danger" }
|
||||
response.set_cookie(cookie_name + "_message", message, secret=cookie_secret, max_age=5, path="/")
|
||||
redirect('/')
|
||||
else:
|
||||
redirect('/')
|
||||
|
||||
|
||||
|
||||
|
@ -81,16 +81,36 @@
|
||||
<input name="add" type="email" class="form-control" id="ceatealiasInput" placeholder="alias@socialnerds.org">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">create</button>
|
||||
%else:
|
||||
<div class="form-group">
|
||||
<input name="add" type="email" class="form-control" id="ceatealiasInput" placeholder="alias@socialnerds.org" disabled>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary" disabled>create</button>
|
||||
%end
|
||||
</form>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="starter-template">
|
||||
<h2>Forward all emails</h2>
|
||||
<hr>
|
||||
<p>Entering an external email address here will forward all incoming mails.
|
||||
<br><small>incl. incoming mails on aliases.</small>
|
||||
</p>
|
||||
%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 }}">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary btn-danger">delete</button>
|
||||
</form>
|
||||
%else:
|
||||
<form class="form-inline" action="/forward/add" method="post">
|
||||
<div class="form-group">
|
||||
<input name="forward" type="email" class="form-control" id="forwardemailInput" placeholder="Email address">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">forward</button>
|
||||
</form>
|
||||
%end
|
||||
|
||||
</div>
|
||||
|
||||
<div class="starter-template">
|
||||
<h2>Delete account</h2>
|
||||
<hr>
|
||||
|
Reference in New Issue
Block a user