Merge pull request #127 from astzweig/feature/partial-wildcards

Allow (forward-)partial wildcard addresses
This commit is contained in:
Andris Reinman 2019-05-10 11:36:05 +03:00 committed by GitHub
commit 2434635e2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View file

@ -108,6 +108,25 @@ function normalizeAddress(address, withNames, options) {
return addr;
}
/**
* Generate a list of possible wildcard addresses by generating all posible
* substrings of the username email address part.
*
* @param {String} username - The username part of the email address.
* @param {String} domain - The domain part of the email address.
* @return {Array} The list of all possible username wildcard addresses,
* that would match this email address (as given by the params).
*/
function getWildcardAddresses(username, domain) {
if (typeof username !== 'string' || typeof domain !== 'string') return [];
let result = [];
// <= generates the 'simple' wildcard (a la '*@') address.
for (let i = 1; i <= username.length; i++) {
result.push('*' + username.substr(i) + '@' + domain);
}
return result;
}
// returns a redis config object with a retry strategy
function redisConfig(defaultConfig) {
return defaultConfig;
@ -430,6 +449,7 @@ function uview(address) {
module.exports = {
normalizeAddress,
normalizeDomain,
getWildcardAddresses,
redisConfig,
checkRangeQuery,
decodeAddresses,

View file

@ -121,13 +121,22 @@ class UserHandler {
return false;
}
let _partialWildcards = tools.getWildcardAddresses(
username,
domain
);
let query = {
addrview: '*@' + domain
addrview: { $in: _partialWildcards }
};
if (aliasDomain) {
// search for alias domain as well
query.addrview = { $in: [query.addrview, '*@' + aliasDomain] };
let _aliasWildcards = tools.getWildcardAddresses(
username,
aliasDomain
);
query.addrview.$in = query.addrview.$in.concat(_aliasWildcards);
}
// try to find a catch-all address