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 `<a href=${thumbUrl}><img alt="Attachment image" src=${thumbUrl}></a>` + } + } + return message +} + export default (assignee, notificationId, settingType, caseTitle, caseId, user, message) => ({ subject: `New message on case "${caseTitle}"`, html: `<img src="cid:logo@unee-t.com"/> @@ -9,7 +22,7 @@ export default (assignee, notificationId, settingType, caseTitle, caseId, user, <p>New message by ${resolveUserName(user)}:</p> -<p><strong>${message}</strong></p> +<p><strong>${linkAttachment(message)}</strong></p> <p>Please follow <a href='${ createEngagementLink({ diff --git a/imports/ui/case/case-messages.jsx b/imports/ui/case/case-messages.jsx index b8d1d68e..f0993a20 100644 --- a/imports/ui/case/case-messages.jsx +++ b/imports/ui/case/case-messages.jsx @@ -224,7 +224,7 @@ class CaseMessages extends Component { } renderMessageImageContent ({isSelf, text, creationTime, id, process}) { - const attachmentUrl = text.split('\n')[1] + const attachmentUrl = text.split(/\s+/m)[1] const { computedMessageWidth } = this.state const thumbUrl = computedMessageWidth && matchWidth(attachmentUrl, computedMessageWidth) return ( diff --git a/imports/util/matchers.js b/imports/util/matchers.js index eaf3770b..cc56c501 100644 --- a/imports/util/matchers.js +++ b/imports/util/matchers.js @@ -3,8 +3,9 @@ import { Meteor } from 'meteor/meteor' export const attachmentTextMatcher = text => { 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}.*$/