mirror of
https://github.com/Mailu/Mailu.git
synced 2024-12-14 10:53:30 +02:00
575f6b1691
1296: fetchmail: print unhandled exceptions, but don't crash r=Nebukadneza a=Al2Klimov fixes #1295 1322: Bump validators from 0.12.5 to 0.12.6 in /core/admin r=Nebukadneza a=dependabot[bot] Bumps [validators](https://github.com/kvesteri/validators) from 0.12.5 to 0.12.6. <details> <summary>Changelog</summary> *Sourced from [validators's changelog](https://github.com/kvesteri/validators/blob/master/CHANGES.rst).* > 0.12.6 (2019-05-08) > ^^^^^^^^^^^^^^^^^^^ > > - Fixed domain validator for single character domains ([#118](https://github-redirect.dependabot.com/kvesteri/validators/issues/118), pull request courtesy kingbuzzman) </details> <details> <summary>Commits</summary> - See full diff in [compare view](https://github.com/kvesteri/validators/commits) </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=validators&package-manager=pip&previous-version=0.12.5&new-version=0.12.6)](https://help.github.com/articles/configuring-automated-security-fixes) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot ignore this [patch|minor|major] version` will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) - `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language - `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language - `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language - `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/Mailu/Mailu/network/alerts). </details> 1337: Add IPv6 to allow_nets r=Nebukadneza a=PhilRW Roundcube was not connecting to sieve with IPv6 enabled. Fixes #1336 1358: Add port to relay if it contains a colon r=Nebukadneza a=PhilRW ## What type of PR? enhancement ## What does this PR do? Allows relaying domains to non-standard SMTP ports by appending `:port` to the destination host/IP. E.g., `mx1.internal:2525` ### Related issue(s) Closes #1357 ## Prerequistes Before we can consider review and merge, please make sure the following list is done and checked. If an entry in not applicable, you can check it or remove it from the list. - [x] In case of feature or enhancement: documentation updated accordingly - [x] Unless it's docs or a minor change: add [changelog](https://mailu.io/master/contributors/guide.html#changelog) entry file. Co-authored-by: Alexander A. Klimov <grandmaster@al2klimov.de> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Philip Rosenberg-Watt <p.rosenberg-watt@cablelabs.com>
107 lines
3.7 KiB
Python
107 lines
3.7 KiB
Python
from mailu import models
|
|
from mailu.internal import internal
|
|
|
|
import flask
|
|
import re
|
|
import srslib
|
|
|
|
|
|
@internal.route("/postfix/domain/<domain_name>")
|
|
def postfix_mailbox_domain(domain_name):
|
|
if re.match("^\[.*\]$", domain_name):
|
|
return flask.abort(404)
|
|
domain = models.Domain.query.get(domain_name) or \
|
|
models.Alternative.query.get(domain_name) or \
|
|
flask.abort(404)
|
|
return flask.jsonify(domain.name)
|
|
|
|
|
|
@internal.route("/postfix/mailbox/<path:email>")
|
|
def postfix_mailbox_map(email):
|
|
user = models.User.query.get(email) or flask.abort(404)
|
|
return flask.jsonify(user.email)
|
|
|
|
|
|
@internal.route("/postfix/alias/<path:alias>")
|
|
def postfix_alias_map(alias):
|
|
localpart, domain_name = models.Email.resolve_domain(alias)
|
|
if localpart is None:
|
|
return flask.jsonify(domain_name)
|
|
destination = models.Email.resolve_destination(localpart, domain_name)
|
|
return flask.jsonify(",".join(destination)) if destination else flask.abort(404)
|
|
|
|
|
|
@internal.route("/postfix/transport/<path:email>")
|
|
def postfix_transport(email):
|
|
if email == '*' or re.match("(^|.*@)\[.*\]$", email):
|
|
return flask.abort(404)
|
|
localpart, domain_name = models.Email.resolve_domain(email)
|
|
relay = models.Relay.query.get(domain_name) or flask.abort(404)
|
|
ret = "smtp:[{0}]".format(relay.smtp)
|
|
if ":" in relay.smtp:
|
|
split = relay.smtp.split(':')
|
|
ret = "smtp:[{0}]:{1}".format(split[0], split[1])
|
|
return flask.jsonify(ret)
|
|
|
|
|
|
@internal.route("/postfix/recipient/map/<path:recipient>")
|
|
def postfix_recipient_map(recipient):
|
|
""" Rewrite the envelope recipient if it is a valid SRS address.
|
|
|
|
This is meant for bounces to go back to the original sender.
|
|
"""
|
|
srs = srslib.SRS(flask.current_app.config["SECRET_KEY"])
|
|
if srslib.SRS.is_srs_address(recipient):
|
|
try:
|
|
return flask.jsonify(srs.reverse(recipient))
|
|
except srslib.Error as error:
|
|
return flask.abort(404)
|
|
return flask.abort(404)
|
|
|
|
|
|
@internal.route("/postfix/sender/map/<path:sender>")
|
|
def postfix_sender_map(sender):
|
|
""" Rewrite the envelope sender in case the mail was not emitted by us.
|
|
|
|
This is for bounces to come back the reverse path properly.
|
|
"""
|
|
srs = srslib.SRS(flask.current_app.config["SECRET_KEY"])
|
|
domain = flask.current_app.config["DOMAIN"]
|
|
try:
|
|
localpart, domain_name = models.Email.resolve_domain(sender)
|
|
except Exception as error:
|
|
return flask.abort(404)
|
|
if models.Domain.query.get(domain_name):
|
|
return flask.abort(404)
|
|
return flask.jsonify(srs.forward(sender, domain))
|
|
|
|
|
|
@internal.route("/postfix/sender/login/<path:sender>")
|
|
def postfix_sender_login(sender):
|
|
localpart, domain_name = models.Email.resolve_domain(sender)
|
|
if localpart is None:
|
|
return flask.abort(404)
|
|
destination = models.Email.resolve_destination(localpart, domain_name, True)
|
|
return flask.jsonify(",".join(destination)) if destination else flask.abort(404)
|
|
|
|
|
|
@internal.route("/postfix/sender/access/<path:sender>")
|
|
def postfix_sender_access(sender):
|
|
""" Simply reject any sender that pretends to be from a local domain
|
|
"""
|
|
if not is_void_address(sender):
|
|
localpart, domain_name = models.Email.resolve_domain(sender)
|
|
return flask.jsonify("REJECT") if models.Domain.query.get(domain_name) else flask.abort(404)
|
|
else:
|
|
return flask.abort(404)
|
|
|
|
|
|
def is_void_address(email):
|
|
'''True if the email is void (null) email address.
|
|
'''
|
|
if email.startswith('<') and email.endswith('>'):
|
|
email = email[1:-1]
|
|
# Some MTAs use things like '<MAILER-DAEMON>' instead of '<>'; so let's
|
|
# consider void any such thing.
|
|
return '@' not in email
|