mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-10-06 20:05:58 +08:00
Make sure that addressregister addresses are decoded from mime-words
This commit is contained in:
parent
d5503a202e
commit
ce15670d7c
6 changed files with 52 additions and 18 deletions
|
@ -1421,7 +1421,7 @@ paths:
|
||||||
tags:
|
tags:
|
||||||
- Messages
|
- Messages
|
||||||
summary: Upload Message
|
summary: Upload Message
|
||||||
description: 'This method allows to upload either an RFC822 formatted message or a message structure to a mailbox. Raw message is stored unmodified, no headers are added or removed. If you want to generate the uploaded message from strucutred data fields, then do not use the raw property.'
|
description: 'This method allows to upload either an RFC822 formatted message or a message structure to a mailbox. Raw message is stored unmodified, no headers are added or removed. If you want to generate the uploaded message from structured data fields, then do not use the raw property.'
|
||||||
operationId: uploadMessage
|
operationId: uploadMessage
|
||||||
requestBody:
|
requestBody:
|
||||||
content:
|
content:
|
||||||
|
|
|
@ -7,6 +7,7 @@ const ObjectID = require('mongodb').ObjectID;
|
||||||
const tools = require('../tools');
|
const tools = require('../tools');
|
||||||
const consts = require('../consts');
|
const consts = require('../consts');
|
||||||
const roles = require('../roles');
|
const roles = require('../roles');
|
||||||
|
const libmime = require('libmime');
|
||||||
const { nextPageCursorSchema, previousPageCursorSchema, pageNrSchema, sessSchema, sessIPSchema, booleanSchema, metaDataSchema } = require('../schemas');
|
const { nextPageCursorSchema, previousPageCursorSchema, pageNrSchema, sessSchema, sessIPSchema, booleanSchema, metaDataSchema } = require('../schemas');
|
||||||
const log = require('npmlog');
|
const log = require('npmlog');
|
||||||
const isemail = require('isemail');
|
const isemail = require('isemail');
|
||||||
|
@ -1199,11 +1200,22 @@ module.exports = (db, server, userHandler) => {
|
||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
|
|
||||||
results: addresses.map(addressData => ({
|
results: addresses.map(addressData => {
|
||||||
id: addressData._id.toString(),
|
let name = addressData.name || false;
|
||||||
name: addressData.name || false,
|
try {
|
||||||
address: addressData.address
|
// try to decode
|
||||||
}))
|
if (name) {
|
||||||
|
name = libmime.decodeWords(name);
|
||||||
|
}
|
||||||
|
} catch (E) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
id: addressData._id.toString(),
|
||||||
|
name: addressData.name || false,
|
||||||
|
address: addressData.address
|
||||||
|
};
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
|
|
|
@ -1805,7 +1805,11 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
|
||||||
let envelope = compiled.getEnvelope();
|
let envelope = compiled.getEnvelope();
|
||||||
|
|
||||||
let envelopeFrom = envelope.from;
|
let envelopeFrom = envelope.from;
|
||||||
envelope.from = data.from.address = await validateFromAddress(userData, envelopeFrom);
|
|
||||||
|
if (result.value.draft) {
|
||||||
|
// override From addresses for drafts
|
||||||
|
envelope.from = data.from.address = await validateFromAddress(userData, envelopeFrom);
|
||||||
|
}
|
||||||
|
|
||||||
if (!result.value.to && !envelope.to.length && referencedMessage && ['reply', 'replyAll'].includes(result.value.reference.action)) {
|
if (!result.value.to && !envelope.to.length && referencedMessage && ['reply', 'replyAll'].includes(result.value.reference.action)) {
|
||||||
envelope.to = envelope.to.concat(parseAddresses(referencedMessage.replyTo || [])).concat(parseAddresses(referencedMessage.replyCc || []));
|
envelope.to = envelope.to.concat(parseAddresses(referencedMessage.replyTo || [])).concat(parseAddresses(referencedMessage.replyCc || []));
|
||||||
|
|
|
@ -150,6 +150,12 @@ class MessageHandler {
|
||||||
let updates = { updated: new Date() };
|
let updates = { updated: new Date() };
|
||||||
if (addr.name) {
|
if (addr.name) {
|
||||||
updates.name = addr.name;
|
updates.name = addr.name;
|
||||||
|
try {
|
||||||
|
// try to decode
|
||||||
|
updates.name = libmime.decodeWords(updates.name);
|
||||||
|
} catch (E) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.database.collection('addressregister').findOneAndUpdate(
|
await this.database.collection('addressregister').findOneAndUpdate(
|
||||||
|
@ -514,6 +520,7 @@ class MessageHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
let parsed = messageData.mimeTree && messageData.mimeTree.parsedHeader;
|
let parsed = messageData.mimeTree && messageData.mimeTree.parsedHeader;
|
||||||
|
|
||||||
if (parsed) {
|
if (parsed) {
|
||||||
let keyList = mailboxData.specialUse === '\\Sent' ? ['to', 'cc', 'bcc'] : ['from'];
|
let keyList = mailboxData.specialUse === '\\Sent' ? ['to', 'cc', 'bcc'] : ['from'];
|
||||||
for (let key of keyList) {
|
for (let key of keyList) {
|
||||||
|
|
18
package.json
18
package.json
|
@ -16,20 +16,20 @@
|
||||||
"author": "Andris Reinman",
|
"author": "Andris Reinman",
|
||||||
"license": "EUPL-1.2",
|
"license": "EUPL-1.2",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ajv": "7.2.3",
|
"ajv": "8.1.0",
|
||||||
"chai": "4.3.4",
|
"chai": "4.3.4",
|
||||||
"docsify-cli": "4.4.3",
|
"docsify-cli": "4.4.3",
|
||||||
"eslint": "7.22.0",
|
"eslint": "7.24.0",
|
||||||
"eslint-config-nodemailer": "1.2.0",
|
"eslint-config-nodemailer": "1.2.0",
|
||||||
"eslint-config-prettier": "8.1.0",
|
"eslint-config-prettier": "8.2.0",
|
||||||
"grunt": "1.3.0",
|
"grunt": "1.3.0",
|
||||||
"grunt-cli": "1.4.1",
|
"grunt-cli": "1.4.2",
|
||||||
"grunt-eslint": "23.0.0",
|
"grunt-eslint": "23.0.0",
|
||||||
"grunt-mocha-test": "0.13.3",
|
"grunt-mocha-test": "0.13.3",
|
||||||
"grunt-shell-spawn": "0.4.0",
|
"grunt-shell-spawn": "0.4.0",
|
||||||
"grunt-wait": "0.3.0",
|
"grunt-wait": "0.3.0",
|
||||||
"imapflow": "1.0.56",
|
"imapflow": "1.0.56",
|
||||||
"mailparser": "3.1.0",
|
"mailparser": "3.2.0",
|
||||||
"mocha": "8.3.2",
|
"mocha": "8.3.2",
|
||||||
"request": "2.88.2",
|
"request": "2.88.2",
|
||||||
"supertest": "6.1.3"
|
"supertest": "6.1.3"
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@phc/pbkdf2": "1.1.14",
|
"@phc/pbkdf2": "1.1.14",
|
||||||
"accesscontrol": "2.2.1",
|
"accesscontrol": "2.2.1",
|
||||||
"argon2-browser": "1.15.3",
|
"argon2-browser": "1.15.4",
|
||||||
"axios": "0.21.1",
|
"axios": "0.21.1",
|
||||||
"base32.js": "0.1.0",
|
"base32.js": "0.1.0",
|
||||||
"bcryptjs": "2.4.3",
|
"bcryptjs": "2.4.3",
|
||||||
|
@ -49,10 +49,10 @@
|
||||||
"humanname": "0.2.2",
|
"humanname": "0.2.2",
|
||||||
"iconv-lite": "0.6.2",
|
"iconv-lite": "0.6.2",
|
||||||
"ioredfour": "1.0.2-ioredis-03",
|
"ioredfour": "1.0.2-ioredis-03",
|
||||||
"ioredis": "4.24.4",
|
"ioredis": "4.26.0",
|
||||||
"isemail": "3.2.0",
|
"isemail": "3.2.0",
|
||||||
"joi": "17.4.0",
|
"joi": "17.4.0",
|
||||||
"js-yaml": "4.0.0",
|
"js-yaml": "4.1.0",
|
||||||
"key-fingerprint": "1.1.0",
|
"key-fingerprint": "1.1.0",
|
||||||
"libbase64": "1.2.1",
|
"libbase64": "1.2.1",
|
||||||
"libmime": "5.0.0",
|
"libmime": "5.0.0",
|
||||||
|
@ -60,7 +60,7 @@
|
||||||
"mailsplit": "5.0.1",
|
"mailsplit": "5.0.1",
|
||||||
"mobileconfig": "2.3.1",
|
"mobileconfig": "2.3.1",
|
||||||
"mongo-cursor-pagination": "7.4.0",
|
"mongo-cursor-pagination": "7.4.0",
|
||||||
"mongodb": "3.6.5",
|
"mongodb": "3.6.6",
|
||||||
"mongodb-extended-json": "1.11.0",
|
"mongodb-extended-json": "1.11.0",
|
||||||
"node-forge": "0.10.0",
|
"node-forge": "0.10.0",
|
||||||
"nodemailer": "6.5.0",
|
"nodemailer": "6.5.0",
|
||||||
|
|
|
@ -466,9 +466,15 @@ describe('API tests', function () {
|
||||||
it('should POST /users/:user/mailboxes/:mailbox/messages with text and html', async () => {
|
it('should POST /users/:user/mailboxes/:mailbox/messages with text and html', async () => {
|
||||||
const message = {
|
const message = {
|
||||||
from: {
|
from: {
|
||||||
name: 'test tester',
|
name: 'test töster',
|
||||||
address: 'testuser@example.com'
|
address: 'bestöser@öxample.com'
|
||||||
},
|
},
|
||||||
|
to: [
|
||||||
|
{
|
||||||
|
name: 'best böster',
|
||||||
|
address: 'bestöser2@öxample.com'
|
||||||
|
}
|
||||||
|
],
|
||||||
subject: 'hello world',
|
subject: 'hello world',
|
||||||
text: 'Hello hello world!',
|
text: 'Hello hello world!',
|
||||||
html: '<p>Hello hello world!</p>'
|
html: '<p>Hello hello world!</p>'
|
||||||
|
@ -559,5 +565,10 @@ describe('API tests', function () {
|
||||||
const deleteResponse = await server.delete(`/users/${userId}/outbound/${submitResponse.body.queueId}`).expect(200);
|
const deleteResponse = await server.delete(`/users/${userId}/outbound/${submitResponse.body.queueId}`).expect(200);
|
||||||
expect(deleteResponse.body.deleted).to.equal(2);
|
expect(deleteResponse.body.deleted).to.equal(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should GET /users/:user/addressregister', async () => {
|
||||||
|
const response = await server.get(`/users/${userId}/addressregister?query=best`);
|
||||||
|
expect(response.body.results[0].name).to.equal('test töster');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue