From 6fdd12d19d66c3246af3f95ed04d6bfb611a12b6 Mon Sep 17 00:00:00 2001 From: Ricardo Garim Date: Mon, 26 Jan 2026 08:36:44 -0300 Subject: [PATCH 1/3] fix: SmarshHistory update to use recommened MongoDB operators --- .../smarsh-connector/server/functions/generateEml.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/meteor/app/smarsh-connector/server/functions/generateEml.ts b/apps/meteor/app/smarsh-connector/server/functions/generateEml.ts index ea9525442e469..10735d2007b71 100644 --- a/apps/meteor/app/smarsh-connector/server/functions/generateEml.ts +++ b/apps/meteor/app/smarsh-connector/server/functions/generateEml.ts @@ -123,9 +123,13 @@ export const generateEml = async (): Promise => { await SmarshHistory.updateOne( { _id: room._id }, { - _id: room._id, - lastRan: date, - lastResult: result, + $set: { + lastRan: date, + lastResult: result, + }, + $setOnInsert: { + _id: room._id, + }, }, { upsert: true }, ); From 230af2fae329f1bd3cc941152d80e9b45565ec6e Mon Sep 17 00:00:00 2001 From: Ricardo Garim Date: Mon, 26 Jan 2026 08:37:54 -0300 Subject: [PATCH 2/3] fix: update Smarsh integration to support multiple files --- .../server/functions/generateEml.ts | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/apps/meteor/app/smarsh-connector/server/functions/generateEml.ts b/apps/meteor/app/smarsh-connector/server/functions/generateEml.ts index 10735d2007b71..7183e7d41a0c6 100644 --- a/apps/meteor/app/smarsh-connector/server/functions/generateEml.ts +++ b/apps/meteor/app/smarsh-connector/server/functions/generateEml.ts @@ -1,3 +1,4 @@ +import type { FileProp, MessageAttachment } from '@rocket.chat/core-typings'; import { MessageTypes } from '@rocket.chat/message-types'; import { Messages, SmarshHistory, Users, Rooms } from '@rocket.chat/models'; import { Meteor } from 'meteor/meteor'; @@ -25,6 +26,19 @@ function _getLink(attachment: { title_link: string }): string { return Meteor.absoluteUrl().replace(/\/$/, '') + __meteor_runtime_config__.ROOT_URL_PATH_PREFIX + url; } +function _processMessageFiles(files: FileProp[], attachments: MessageAttachment[] | undefined): { fileIds: string[]; displayText: string } { + const fileIds = files.map((f) => f._id); + + const fileLinks = + attachments + ?.filter((a): a is MessageAttachment & { title: string } => 'title' in a && a.title !== undefined) + .map((a) => `${a.title} (${_getLink({ title_link: 'title_link' in a ? a.title_link || '' : '' })})`) || []; + + const displayText = fileLinks.join(', '); + + return { fileIds, displayText }; +} + export const generateEml = async (): Promise => { setImmediate(async () => { const smarshMissingEmail = settings.get('Smarsh_MissingEmail_Email'); @@ -93,9 +107,14 @@ export const generateEml = async (): Promise => { } else { rows.push(`${message.msg} (${message.t})`); } + } else if (message.files?.length) { + const fileResult = _processMessageFiles(message.files, message.attachments); + fileResult.fileIds.forEach((id) => data.files.push(id)); + rows.push(fileResult.displayText); } else if (message.file) { - data.files.push(message.file._id); - rows.push(`${message?.attachments?.[0].title} (${_getLink({ title_link: message?.attachments?.[0].title_link || '' })})})`); + const fileResult = _processMessageFiles([message.file], message.attachments); + fileResult.fileIds.forEach((id) => data.files.push(id)); + rows.push(fileResult.displayText); } else if (message.attachments) { const attaches: string[] = []; message.attachments.forEach((a) => { From f9b0265dcdd4506dea25dcb2cae368e7808ea5f8 Mon Sep 17 00:00:00 2001 From: Ricardo Garim Date: Mon, 26 Jan 2026 08:49:18 -0300 Subject: [PATCH 3/3] add changeset --- .changeset/chatty-insects-notice.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/chatty-insects-notice.md diff --git a/.changeset/chatty-insects-notice.md b/.changeset/chatty-insects-notice.md new file mode 100644 index 0000000000000..0cf3ac56be86b --- /dev/null +++ b/.changeset/chatty-insects-notice.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Fixes Smarsh integration to support multiple file attachments per message.