Skip to content

Commit

Permalink
feat(api-upload): Allow to upload a draft message with incorrect (non…
Browse files Browse the repository at this point in the history
…-emal) `to` addresses ZMS-117 (#595)

* strip to adresses that are incorrect but still save the message

* toObj.to fix to toObj.address as per the model
  • Loading branch information
NickOvt authored Jan 4, 2024
1 parent 6bdeeaa commit 8b7f6c9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/api/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -1882,7 +1882,14 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti

replyTo: AddressOptionalName.description('Address for the Reply-To: header'),

to: AddressOptionalNameArray.description('Addresses for the To: header'),
to: Joi.array()
.items(
Joi.object({
name: Joi.string().empty('').max(255).description('Name of the sender'),
address: Joi.string().email({ tlds: false }).failover('').required().description('Address of the sender')
}).$_setFlag('objectName', 'AddressOptionalName')
)
.description('Addresses for the To: header'),

cc: AddressOptionalNameArray.description('Addresses for the Cc: header'),

Expand Down Expand Up @@ -2121,7 +2128,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
let data = {
from: result.value.from || { name: userData.name, address: userData.address },
date,
to: result.value.to,
to: result.value.to ? result.value.to.filter(toObj => toObj.address !== '') : undefined,
cc: result.value.cc,
bcc: result.value.bcc,
subject: result.value.subject || referencedMessage.subject,
Expand Down Expand Up @@ -2164,7 +2171,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
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 (!data.to && !envelope.to.length && referencedMessage && ['reply', 'replyAll'].includes(result.value.reference.action)) {
envelope.to = envelope.to.concat(parseAddresses(referencedMessage.replyTo || [])).concat(parseAddresses(referencedMessage.replyCc || []));
data.to = [].concat(referencedMessage.replyTo || []);
data.cc = [].concat(referencedMessage.replyCc || []);
Expand Down

0 comments on commit 8b7f6c9

Please sign in to comment.