diff --git a/imports/email-templates/case-new-message.js b/imports/email-templates/case-new-message.js index 001106a2..e3a2f537 100644 --- a/imports/email-templates/case-new-message.js +++ b/imports/email-templates/case-new-message.js @@ -1,6 +1,19 @@ import url from 'url' +import { matchWidth } from '../util/cloudinary-transformations' import { createEngagementLink, resolveUserName, optOutHtml, optOutText } from './components/helpers' +function linkAttachment (message) { + const msgParts = message.trim().split(/\s+/) + if (msgParts.length > 1 && msgParts[0] === '[!attachment]') { + const attachmentUrl = msgParts[1] + if (attachmentUrl.match(/\.(jpeg|jpg|gif|png)$/) != null) { + const thumbUrl = matchWidth(attachmentUrl, 500) + return `Attachment image` + } + } + return message +} + export default (assignee, notificationId, settingType, caseTitle, caseId, user, message) => ({ subject: `New message on case "${caseTitle}"`, html: ` @@ -9,7 +22,7 @@ export default (assignee, notificationId, settingType, caseTitle, caseId, user,

New message by ${resolveUserName(user)}:

-

${message}

+

${linkAttachment(message)}

Please follow { const cloudinaryDownloadUrl = Meteor.settings.public.CLOUDINARY_URL.replace('/api.', '/res.').replace('/v1_1', '') const previewPrefix = 'data:image/' - const prefix = '[!attachment]\n' - return text.indexOf(prefix + cloudinaryDownloadUrl) === 0 || text.indexOf(prefix + previewPrefix) === 0 + const urlRegex = /^\[!attachment\]\s+(.+)$/m + const match = text.match(urlRegex) + return !!match && (match[1].indexOf(cloudinaryDownloadUrl) === 0 || match[1].indexOf(previewPrefix) === 0) } const isTemporaryEmail = /^temporary\..+@.+\..+\.?.*\.{0,2}.*$/