Merge pull request #41 from XYunknown/master

Adding SQL Like format for aliases
master
kaiyou 8 years ago committed by GitHub
commit 9d7f89285e

@ -86,6 +86,8 @@ class UserReplyForm(Form):
class AliasForm(Form): class AliasForm(Form):
localpart = fields.StringField('Alias', [validators.DataRequired()]) localpart = fields.StringField('Alias', [validators.DataRequired()])
wildcard = fields.BooleanField(
'Use SQL Like Syntax (e.g. for catch-all aliases, admin-%@domain.com)')
destination = DestinationField('Destination') destination = DestinationField('Destination')
comment = fields.StringField('Comment') comment = fields.StringField('Comment')
submit = fields.SubmitField('Create') submit = fields.SubmitField('Create')

@ -189,6 +189,7 @@ class Alias(Email):
""" """
domain = db.relationship(Domain, domain = db.relationship(Domain,
backref=db.backref('aliases', cascade='all, delete-orphan')) backref=db.backref('aliases', cascade='all, delete-orphan'))
wildcard = db.Column(db.Boolean(), default=False)
destination = db.Column(CommaSeparatedList, nullable=False, default=[]) destination = db.Column(CommaSeparatedList, nullable=False, default=[])

@ -12,6 +12,7 @@ Create alias
<form class="form" method="post" role="form"> <form class="form" method="post" role="form">
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
{{ macros.form_field(form.localpart, append='<span class="input-group-addon">@'+domain.name+'</span>') }} {{ macros.form_field(form.localpart, append='<span class="input-group-addon">@'+domain.name+'</span>') }}
{{ macros.form_field(form.wildcard) }}
{{ macros.form_field(form.destination, id='destination') }} {{ macros.form_field(form.destination, id='destination') }}
{{ macros.form_field(form.comment) }} {{ macros.form_field(form.comment) }}
{{ macros.form_field(form.submit) }} {{ macros.form_field(form.submit) }}

@ -3,3 +3,9 @@ query =
SELECT destination SELECT destination
FROM alias FROM alias
WHERE alias.email = '%s' WHERE alias.email = '%s'
AND alias.wildcard = 0
UNION SELECT destination
FROM alias
WHERE '%s' LIKE alias.email
AND alias.wildcard = 1
LIMIT 1

Loading…
Cancel
Save