diff --git a/app/alias_suffix.py b/app/alias_suffix.py index 56f4809f..8d21884a 100644 --- a/app/alias_suffix.py +++ b/app/alias_suffix.py @@ -99,7 +99,12 @@ def get_alias_suffixes(user: User) -> [AliasSuffix]: # for each user domain, generate both the domain and a random suffix version for custom_domain in user_custom_domains: if custom_domain.random_prefix_generation: - suffix = "." + user.get_random_alias_suffix() + "@" + custom_domain.domain + suffix = ( + "." + + user.get_random_alias_suffix(custom_domain) + + "@" + + custom_domain.domain + ) alias_suffix = AliasSuffix( is_custom=True, suffix=suffix, diff --git a/app/models.py b/app/models.py index b27a71b0..525118fa 100644 --- a/app/models.py +++ b/app/models.py @@ -1000,16 +1000,21 @@ class User(Base, ModelMixin, UserMixin, PasswordOracle): > 0 ) - def get_random_alias_suffix(self): + def get_random_alias_suffix(self, custom_domain: Optional["CustomDomain"] = None): """Get random suffix for an alias based on user's preference. + Use a shorter suffix in case of custom domain Returns: str: the random suffix generated """ if self.random_alias_suffix == AliasSuffixEnum.random_string.value: return random_string(config.ALIAS_RANDOM_SUFFIX_LENGTH, include_digits=True) - return random_words(1, 3) + + if custom_domain is None: + return random_words(1, 3) + + return random_words(1) def __repr__(self): return f""