[NEW] Enforce plain text emails converting from HTML when no text version supplied (#16063)

pull/16183/head
Rodrigo Nascimento 5 years ago committed by Diego Sampaio
parent d761ccb9f7
commit 91fe4a70a9
  1. 12
      app/mailer/server/api.js
  2. 90
      package-lock.json
  3. 1
      package.json

@ -4,6 +4,7 @@ import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import _ from 'underscore';
import s from 'underscore.string';
import juice from 'juice';
import stripHtml from 'string-strip-html';
import { settings } from '../../settings';
@ -93,14 +94,19 @@ export const rfcMailPatternWithName = /^(?:.*<)?([a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-
export const checkAddressFormat = (from) => rfcMailPatternWithName.test(from);
export const sendNoWrap = ({ to, from, replyTo, subject, html, headers }) => {
export const sendNoWrap = ({ to, from, replyTo, subject, html, text, headers }) => {
if (!checkAddressFormat(to)) {
return;
}
Meteor.defer(() => Email.send({ to, from, replyTo, subject, html, headers }));
if (!text) {
text = stripHtml(html);
}
Meteor.defer(() => Email.send({ to, from, replyTo, subject, html, text, headers }));
};
export const send = ({ to, from, replyTo, subject, html, data, headers }) => sendNoWrap({ to, from, replyTo, subject: replace(subject, data), html: wrap(html, data), headers });
export const send = ({ to, from, replyTo, subject, html, text, data, headers }) => sendNoWrap({ to, from, replyTo, subject: replace(subject, data), text: text ? replace(text, data) : stripHtml(replace(html, data)), html: wrap(html, data), headers });
export const checkAddressFormatAndThrow = (from, func) => {
if (checkAddressFormat(from)) {

90
package-lock.json generated

@ -20665,8 +20665,12 @@
"is-natural-number": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/is-natural-number/-/is-natural-number-4.0.1.tgz",
"integrity": "sha1-q5124dtM7VHjXeDHLr7PCfc0zeg=",
"dev": true
"integrity": "sha1-q5124dtM7VHjXeDHLr7PCfc0zeg="
},
"is-natural-number-string": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-natural-number-string/-/is-natural-number-string-1.0.1.tgz",
"integrity": "sha1-0OvxwBH64tOwc02MgBFuJRKkoug="
},
"is-number": {
"version": "3.0.0",
@ -21968,6 +21972,11 @@
"resolved": "https://registry.npmjs.org/lodash.toarray/-/lodash.toarray-4.4.0.tgz",
"integrity": "sha1-JMS/zWsvuji/0FlNsRedjptlZWE="
},
"lodash.trim": {
"version": "4.5.1",
"resolved": "https://registry.npmjs.org/lodash.trim/-/lodash.trim-4.5.1.tgz",
"integrity": "sha1-NkJefukL5KpeJ7zruFt9EepHqlc="
},
"lodash.unescape": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/lodash.unescape/-/lodash.unescape-4.0.1.tgz",
@ -21984,6 +21993,11 @@
"integrity": "sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=",
"dev": true
},
"lodash.without": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/lodash.without/-/lodash.without-4.4.0.tgz",
"integrity": "sha1-PNRXSgC2e643OpS3SHcmQFB7eqw="
},
"log-symbols": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz",
@ -26687,6 +26701,45 @@
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==",
"dev": true
},
"ranges-apply": {
"version": "3.0.46",
"resolved": "https://registry.npmjs.org/ranges-apply/-/ranges-apply-3.0.46.tgz",
"integrity": "sha512-RhumyuPWm5tm96LVcU1vLQmKpuRF1F30omdcLPOashxOxBw41ANt3RVzL6YzKeUg2vbLOXVaXukFn/ImOdmqQA==",
"requires": {
"is-natural-number-string": "^1.0.1",
"ranges-merge": "^4.2.29"
}
},
"ranges-merge": {
"version": "4.2.29",
"resolved": "https://registry.npmjs.org/ranges-merge/-/ranges-merge-4.2.29.tgz",
"integrity": "sha512-1CeZASV8XqpQ3ItcbsuqVp4a6uqHvfUa65Y3j9AyFBH3zhjZVlP5dRGf5U5Ym8fKOQ1fZYcn6lQJ577lyojCzA==",
"requires": {
"lodash.clonedeep": "^4.5.0",
"lodash.isplainobject": "^4.0.6",
"ranges-sort": "^3.10.46"
}
},
"ranges-push": {
"version": "3.6.13",
"resolved": "https://registry.npmjs.org/ranges-push/-/ranges-push-3.6.13.tgz",
"integrity": "sha512-HDXJUwA4xbdbkYxCzne64+mCHYoHXOnTtukQ7RwB3eFLnunU2iqTL6zuktr5iJ2Hizr8am5ZaEsM38HMm6EQGA==",
"requires": {
"is-natural-number-string": "^1.0.1",
"lodash.clonedeep": "^4.5.0",
"ranges-merge": "^4.2.29",
"string-collapse-leading-whitespace": "^2.0.10",
"string-trim-spaces-only": "^2.8.9"
}
},
"ranges-sort": {
"version": "3.10.46",
"resolved": "https://registry.npmjs.org/ranges-sort/-/ranges-sort-3.10.46.tgz",
"integrity": "sha512-H07aLdjKQRz3tUNHCj5P9Tof1vH35J4c3atXl8T/fs3SATKgzpkjACz9MfuuKgvQsXOFau2GDvQ/hl6Szw39/Q==",
"requires": {
"is-natural-number": "^4.0.1"
}
},
"raw-body": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.3.tgz",
@ -29227,11 +29280,44 @@
"resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz",
"integrity": "sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM="
},
"string-collapse-leading-whitespace": {
"version": "2.0.10",
"resolved": "https://registry.npmjs.org/string-collapse-leading-whitespace/-/string-collapse-leading-whitespace-2.0.10.tgz",
"integrity": "sha512-Hpm6voTLToJW8zAioRF11ertTDPIT0v7J0xsVTpcDcTFgDBLm0byln3L9XthbaBSIghAM36IIRxAnW8RW0FD/g=="
},
"string-left-right": {
"version": "2.3.12",
"resolved": "https://registry.npmjs.org/string-left-right/-/string-left-right-2.3.12.tgz",
"integrity": "sha512-mz7bncqHVrxBWvAZn3HhHKg/tm55x+INd2BE7IRn/CRAVHZQd5fhanJjCq7hGdsWjQ0QX2lnU3bhGE6KopcAAA==",
"requires": {
"lodash.clonedeep": "^4.5.0",
"lodash.isplainobject": "^4.0.6"
}
},
"string-strip-html": {
"version": "4.3.12",
"resolved": "https://registry.npmjs.org/string-strip-html/-/string-strip-html-4.3.12.tgz",
"integrity": "sha512-f8er5/6SQ9sABwnJZBU6o7aoIUtGMQdMNcBP1nOrRRizIN8HvxWN7doiJltMbwJ8hgewbNFP3qDh+iayqcbUtQ==",
"requires": {
"ent": "^2.2.0",
"lodash.isplainobject": "^4.0.6",
"lodash.trim": "^4.5.1",
"lodash.without": "^4.4.0",
"ranges-apply": "^3.0.46",
"ranges-push": "^3.6.13",
"string-left-right": "^2.3.12"
}
},
"string-template": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/string-template/-/string-template-1.0.0.tgz",
"integrity": "sha1-np8iM9wA8hhxjsN5oopWc+zKi5Y="
},
"string-trim-spaces-only": {
"version": "2.8.9",
"resolved": "https://registry.npmjs.org/string-trim-spaces-only/-/string-trim-spaces-only-2.8.9.tgz",
"integrity": "sha512-atfGwUCChsXQ0WEqX1Ju2YYC/6yqpnq8fL8jl2BUpjNR13b+s6q/SmmdDG10H+t4JB8/cRi9klyYuwctvgjFJg=="
},
"string-width": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",

@ -204,6 +204,7 @@
"sharp": "^0.22.1",
"speakeasy": "^2.0.0",
"stream-buffers": "^3.0.2",
"string-strip-html": "^4.3.12",
"styled-components": "^4.4.0",
"tar-stream": "^1.6.2",
"toastr": "^2.1.4",

Loading…
Cancel
Save