source: node_modules/nodemailer/lib/well-known/index.js@ 81bc7da

finki-main main
Last change on this file since 81bc7da was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago

Initial commit

  • Property mode set to 100644
File size: 1.2 KB
Line 
1'use strict';
2
3const services = require('./services.json');
4const normalized = {};
5
6Object.keys(services).forEach(key => {
7 let service = services[key];
8
9 normalized[normalizeKey(key)] = normalizeService(service);
10
11 [].concat(service.aliases || []).forEach(alias => {
12 normalized[normalizeKey(alias)] = normalizeService(service);
13 });
14
15 [].concat(service.domains || []).forEach(domain => {
16 normalized[normalizeKey(domain)] = normalizeService(service);
17 });
18});
19
20function normalizeKey(key) {
21 return key.replace(/[^a-zA-Z0-9.-]/g, '').toLowerCase();
22}
23
24function normalizeService(service) {
25 let filter = ['domains', 'aliases'];
26 let response = {};
27
28 Object.keys(service).forEach(key => {
29 if (filter.indexOf(key) < 0) {
30 response[key] = service[key];
31 }
32 });
33
34 return response;
35}
36
37/**
38 * Resolves SMTP config for given key. Key can be a name (like 'Gmail'), alias (like 'Google Mail') or
39 * an email address (like 'test@googlemail.com').
40 *
41 * @param {String} key [description]
42 * @returns {Object} SMTP config or false if not found
43 */
44module.exports = function (key) {
45 key = normalizeKey(key.split('@').pop());
46 return normalized[key] || false;
47};
Note: See TracBrowser for help on using the repository browser.