You've already forked Mailu
mirror of
https://github.com/Mailu/Mailu.git
synced 2025-08-10 22:31:47 +02:00
Make aliases case-insensitive (too)
Even though RFC5321 2.4 explains that local-parts are to be case-sensitive, this does not seem to be how EMail is used today. Thus, instead of reverting user-emails back to being case sensitive, let’s make aliases case-insensitive too. Not only more consistent, this also allows users to enjoy receiving EMails from large airlines or car-rental agencies onto their already existing aliases. For the rare case of case sensitive aliases existing, let’s query for the forced-lowercase alias only in the event that the preserved-case one isn’t found … closes #867
This commit is contained in:
@@ -436,20 +436,37 @@ class Alias(Base, Email):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def resolve(cls, localpart, domain_name):
|
def resolve(cls, localpart, domain_name):
|
||||||
return cls.query.filter(
|
alias_preserve_case = cls.query.filter(
|
||||||
sqlalchemy.and_(cls.domain_name == domain_name,
|
sqlalchemy.and_(cls.domain_name == domain_name,
|
||||||
sqlalchemy.or_(
|
sqlalchemy.or_(
|
||||||
sqlalchemy.and_(
|
sqlalchemy.and_(
|
||||||
cls.wildcard == False,
|
cls.wildcard == False,
|
||||||
cls.localpart == localpart
|
cls.localpart == localpart
|
||||||
), sqlalchemy.and_(
|
), sqlalchemy.and_(
|
||||||
cls.wildcard == True,
|
cls.wildcard == True,
|
||||||
sqlalchemy.bindparam("l", localpart).like(cls.localpart)
|
sqlalchemy.bindparam("l", localpart).like(cls.localpart)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
).order_by(cls.wildcard, sqlalchemy.func.char_length(cls.localpart).desc()).first()
|
||||||
).order_by(cls.wildcard, sqlalchemy.func.char_length(cls.localpart).desc()).first()
|
if alias_preserve_case:
|
||||||
|
return alias_preserve_case
|
||||||
|
|
||||||
|
if localpart:
|
||||||
|
localpart = localpart.lower()
|
||||||
|
return cls.query.filter(
|
||||||
|
sqlalchemy.and_(cls.domain_name == domain_name,
|
||||||
|
sqlalchemy.or_(
|
||||||
|
sqlalchemy.and_(
|
||||||
|
cls.wildcard == False,
|
||||||
|
sqlalchemy.func.lower(cls.localpart) == localpart
|
||||||
|
), sqlalchemy.and_(
|
||||||
|
cls.wildcard == True,
|
||||||
|
sqlalchemy.bindparam("l", localpart).like(sqlalchemy.func.lower(cls.localpart))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).order_by(cls.wildcard, sqlalchemy.func.char_length(sqlalchemy.func.lower(cls.localpart)).desc()).first()
|
||||||
|
|
||||||
class Token(Base):
|
class Token(Base):
|
||||||
""" A token is an application password for a given user.
|
""" A token is an application password for a given user.
|
||||||
|
1
towncrier/newsfragments/867.bugfix
Normal file
1
towncrier/newsfragments/867.bugfix
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Make aliases optionally case-insensitive: After attempting to resolve an alias in its preserved case, also attempt to match it case-insensitively
|
Reference in New Issue
Block a user