forked from nodemailer/nodemailer-wellknown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (37 loc) · 1.23 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
var services = require('./services.json');
var normalized = {};
Object.keys(services).forEach(function(key) {
var service = services[key];
normalized[normalizeKey(key)] = normalizeService(service);
[].concat(service.aliases || []).forEach(function(alias) {
normalized[normalizeKey(alias)] = normalizeService(service);
});
[].concat(service.domains || []).forEach(function(domain) {
normalized[normalizeKey(domain)] = normalizeService(service);
});
});
function normalizeKey(key) {
return key.replace(/[^a-zA-Z0-9.\-]/g, '').toLowerCase();
}
function normalizeService(service) {
var filter = ['domains', 'aliases'];
var response = {};
Object.keys(service).forEach(function(key) {
if (filter.indexOf(key) < 0) {
response[key] = service[key];
}
});
return response;
}
/**
* Resolves SMTP config for given key. Key can be a name (like 'Gmail'), alias (like 'Google Mail') or
* an email address (like '[email protected]').
*
* @param {String} key [description]
* @returns {Object} SMTP config or false if not found
*/
module.exports = function(key) {
key = normalizeKey(key.split('@').pop());
return normalized[key] || false;
};