mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-01-02 21:52:34 +08:00
replace image links
This commit is contained in:
parent
650e622d7b
commit
cb0de3a15b
1 changed files with 17 additions and 1 deletions
18
api.js
18
api.js
|
@ -1809,9 +1809,14 @@ server.get('/users/:user/mailboxes/:mailbox/messages/:message', (req, res, next)
|
|||
const schema = Joi.object().keys({
|
||||
user: Joi.string().hex().lowercase().length(24).required(),
|
||||
mailbox: Joi.string().hex().lowercase().length(24).required(),
|
||||
message: Joi.string().regex(/^[0-9a-f]{24}:\d{1,10}/).lowercase().required()
|
||||
message: Joi.string().regex(/^[0-9a-f]{24}:\d{1,10}/).lowercase().required(),
|
||||
replaceCidLinks: Joi.boolean().truthy(['Y', 'true', 'yes', 1]).default(false)
|
||||
});
|
||||
|
||||
if (req.query.replaceCidLinks) {
|
||||
req.params.replaceCidLinks = req.query.replaceCidLinks;
|
||||
}
|
||||
|
||||
const result = Joi.validate(req.params, schema, {
|
||||
abortEarly: false,
|
||||
convert: true
|
||||
|
@ -1829,6 +1834,7 @@ server.get('/users/:user/mailboxes/:mailbox/messages/:message', (req, res, next)
|
|||
let mailbox = new ObjectID(result.value.mailbox);
|
||||
let message = new ObjectID(messageparts[0]);
|
||||
let uid = Number(messageparts[1]);
|
||||
let replaceCidLinks = result.value.replaceCidLinks;
|
||||
|
||||
db.users.collection('messages').findOne({
|
||||
_id: message,
|
||||
|
@ -1921,6 +1927,16 @@ server.get('/users/:user/mailboxes/:mailbox/messages/:message', (req, res, next)
|
|||
expires = new Date(messageData.rdate).toISOString();
|
||||
}
|
||||
|
||||
if (replaceCidLinks) {
|
||||
messageData.html = (messageData.html || [])
|
||||
.map(html =>
|
||||
html.replace(
|
||||
/attachment:([a-f0-9]+)\/(ATT\d+)/g,
|
||||
(str, mid, aid) => '/users/' + user + '/mailboxes/' + mailbox + '/messages/' + message + ':' + uid + '/attachments/' + aid
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
id: message.toString() + ':' + uid,
|
||||
|
|
Loading…
Reference in a new issue