mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-01-08 17:07:44 +08:00
Merge pull request #127 from astzweig/feature/partial-wildcards
Allow (forward-)partial wildcard addresses
This commit is contained in:
commit
2434635e2b
2 changed files with 31 additions and 2 deletions
20
lib/tools.js
20
lib/tools.js
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue