Add setting for catch all address

Note that this is not a flag on the mailboxes because we might theoretically
support forwarding to some other external domain in the future.

Part of #33
This commit is contained in:
Girish Ramakrishnan
2017-06-11 17:51:08 -07:00
parent da7648fe3f
commit 0cc980f539
7 changed files with 174 additions and 7 deletions

View File

@@ -44,6 +44,9 @@ exports = module.exports = {
getMailConfig: getMailConfig,
setMailConfig: setMailConfig,
setCatchAllAddress: setCatchAllAddress,
getCatchAllAddress: getCatchAllAddress,
getDefaultSync: getDefaultSync,
getAll: getAll,
@@ -58,6 +61,7 @@ exports = module.exports = {
UPDATE_CONFIG_KEY: 'update_config',
APPSTORE_CONFIG_KEY: 'appstore_config',
MAIL_CONFIG_KEY: 'mail_config',
CATCH_ALL_ADDRESS: 'catch_all_address',
events: null
};
@@ -77,6 +81,7 @@ var assert = require('assert'),
moment = require('moment-timezone'),
net = require('net'),
paths = require('./paths.js'),
platform = require('./platform.js'),
safe = require('safetydance'),
settingsdb = require('./settingsdb.js'),
subdomains = require('./subdomains.js'),
@@ -104,6 +109,7 @@ var gDefaults = (function () {
result[exports.UPDATE_CONFIG_KEY] = { prerelease: false };
result[exports.APPSTORE_CONFIG_KEY] = {};
result[exports.MAIL_CONFIG_KEY] = { enabled: false };
result[exports.CATCH_ALL_ADDRESS] = [ ];
return result;
})();
@@ -653,6 +659,32 @@ function setMailConfig(mailConfig, callback) {
});
}
function getCatchAllAddress(callback) {
assert.strictEqual(typeof callback, 'function');
settingsdb.get(exports.CATCH_ALL_ADDRESS, function (error, value) {
if (error && error.reason === DatabaseError.NOT_FOUND) return callback(null, gDefaults[exports.CATCH_ALL_ADDRESS]);
if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, error));
callback(null, JSON.parse(value));
});
}
function setCatchAllAddress(address, callback) {
assert(Array.isArray(address));
assert.strictEqual(typeof callback, 'function');
settingsdb.set(exports.CATCH_ALL_ADDRESS, JSON.stringify(address), function (error) {
if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, error));
exports.events.emit(exports.CATCH_ALL_ADDRESS, address);
platform.createMailConfig(NOOP_CALLBACK);
callback(null);
});
}
function getAppstoreConfig(callback) {
assert.strictEqual(typeof callback, 'function');