mirror of
https://github.com/nodemailer/wildduck.git
synced 2024-11-10 17:47:07 +08:00
allow changign forwarded address
This commit is contained in:
parent
b1ce81be06
commit
04ac71fdd5
5 changed files with 41 additions and 13 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
|||
define({
"name": "wildduck",
"version": "1.0.0",
"description": "WildDuck API docs. Under construction, see old docs here: https://github.com/nodemailer/wildduck/blob/master/docs/api.md",
"title": "WildDuck API",
"url": "http://localhost:8080",
"sampleUrl": false,
"defaultVersion": "0.0.0",
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2018-01-05T15:25:50.791Z",
"url": "http://apidocjs.com",
"version": "0.17.6"
}
});
|
||||
define({
"name": "wildduck",
"version": "1.0.0",
"description": "WildDuck API docs. Under construction, see old docs here: https://github.com/nodemailer/wildduck/blob/master/docs/api.md",
"title": "WildDuck API",
"url": "http://localhost:8080",
"sampleUrl": false,
"defaultVersion": "0.0.0",
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2018-01-08T14:01:31.662Z",
"url": "http://apidocjs.com",
"version": "0.17.6"
}
});
|
||||
|
|
|
@ -1 +1 @@
|
|||
{
"name": "wildduck",
"version": "1.0.0",
"description": "WildDuck API docs. Under construction, see old docs here: https://github.com/nodemailer/wildduck/blob/master/docs/api.md",
"title": "WildDuck API",
"url": "http://localhost:8080",
"sampleUrl": false,
"defaultVersion": "0.0.0",
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2018-01-05T15:25:50.791Z",
"url": "http://apidocjs.com",
"version": "0.17.6"
}
}
|
||||
{
"name": "wildduck",
"version": "1.0.0",
"description": "WildDuck API docs. Under construction, see old docs here: https://github.com/nodemailer/wildduck/blob/master/docs/api.md",
"title": "WildDuck API",
"url": "http://localhost:8080",
"sampleUrl": false,
"defaultVersion": "0.0.0",
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2018-01-08T14:01:31.662Z",
"url": "http://apidocjs.com",
"version": "0.17.6"
}
}
|
||||
|
|
|
@ -1294,7 +1294,8 @@ module.exports = (db, server) => {
|
|||
* "X-Access-Token": "59fc66a03e54454869460e45"
|
||||
* }
|
||||
*
|
||||
* @apiParam {String} address ID of the Address
|
||||
* @apiParam {String} id ID of the Address
|
||||
* @apiParam {String} [address] New address. Only affects normal addresses, special addresses that include \* can not be changed
|
||||
* @apiParam {String[]} [targets] An array of forwarding targets. The value could either be an email address or a relay url to next MX server ("smtp://mx2.zone.eu:25"). If set then overwrites previous targets array
|
||||
* @apiParam {Number} [forwards] Daily allowed forwarding count for this address
|
||||
* @apiParam {Object} [autoreply] Autoreply information
|
||||
|
@ -1330,15 +1331,16 @@ module.exports = (db, server) => {
|
|||
* "error": "This address does not exist"
|
||||
* }
|
||||
*/
|
||||
server.put('/addresses/forwarded/:address', (req, res, next) => {
|
||||
server.put('/addresses/forwarded/:id', (req, res, next) => {
|
||||
res.charSet('utf-8');
|
||||
|
||||
const schema = Joi.object().keys({
|
||||
address: Joi.string()
|
||||
id: Joi.string()
|
||||
.hex()
|
||||
.lowercase()
|
||||
.length(24)
|
||||
.required(),
|
||||
address: Joi.string().email(),
|
||||
targets: Joi.array()
|
||||
.items(
|
||||
Joi.string().email(),
|
||||
|
@ -1384,8 +1386,11 @@ module.exports = (db, server) => {
|
|||
return next();
|
||||
}
|
||||
|
||||
let address = new ObjectID(result.value.address);
|
||||
let id = new ObjectID(result.value.id);
|
||||
let updates = {};
|
||||
if (result.value.address) {
|
||||
updates.address = result.value.address;
|
||||
}
|
||||
|
||||
if (result.value.forwards) {
|
||||
updates.forwards = result.value.forwards;
|
||||
|
@ -1419,7 +1424,7 @@ module.exports = (db, server) => {
|
|||
|
||||
db.users.collection('addresses').findOne(
|
||||
{
|
||||
_id: address
|
||||
_id: id
|
||||
},
|
||||
(err, addressData) => {
|
||||
if (err) {
|
||||
|
@ -1439,6 +1444,22 @@ module.exports = (db, server) => {
|
|||
return next();
|
||||
}
|
||||
|
||||
if (addressData.address.indexOf('*') >= 0 && result.value.address && result.value.address !== addressData.address) {
|
||||
res.json({
|
||||
error: 'Can not change special address',
|
||||
code: 'ChangeNotAllowed'
|
||||
});
|
||||
return next();
|
||||
}
|
||||
|
||||
if (result.value.address && result.value.address.indexOf('*') >= 0 && result.value.address !== addressData.address) {
|
||||
res.json({
|
||||
error: 'Can not change special address',
|
||||
code: 'ChangeNotAllowed'
|
||||
});
|
||||
return next();
|
||||
}
|
||||
|
||||
let targets = result.value.targets;
|
||||
let addrlist = [];
|
||||
let cachedAddrviews = new WeakMap();
|
||||
|
@ -1533,10 +1554,17 @@ module.exports = (db, server) => {
|
|||
},
|
||||
(err, r) => {
|
||||
if (err) {
|
||||
res.json({
|
||||
error: 'MongoDB Error: ' + err.message,
|
||||
code: 'InternalDatabaseError'
|
||||
});
|
||||
if (err.code === 11000) {
|
||||
res.json({
|
||||
error: 'Address already exists',
|
||||
code: 'AddressExistsError'
|
||||
});
|
||||
} else {
|
||||
res.json({
|
||||
error: 'MongoDB Error: ' + err.message,
|
||||
code: 'InternalDatabaseError'
|
||||
});
|
||||
}
|
||||
return next();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue