Mailspring/internal_packages/composer-signature/lib/signature-utils.es6
Ben Gotow 2e2ecf0647 fix(quoted-text): div vs blockquote, signature cleanup #1746
Summary:
Previously we always created <blockquote class="gmail_quote"> to wrap quoted text. This is not correct.
Gmail uses blockquotes only when it wants visual indentation, and <div>s to wrap other quoted text, like forwarded
messages which are not displayed indented.

This diff updates N1 to match Gmail exactly. Note that for replies, Gmail actually nests a blockquote.gmail_quote
inside a div.gmail_quote.

I also updated signature handling because it turns out the regexp that was removing existing signatures would blow
away any and all divs until it reached a <blockquote> tag.

Test Plan: See updated specs. Manually tested by creating a thread in Google Inbox and then performing fwd and reply in both N1 and Inbox. Results match.

Reviewers: juan, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D2750
2016-03-17 13:11:00 -07:00

28 lines
934 B
JavaScript

export default {
applySignature(body, signature) {
// https://regex101.com/r/nC0qL2/1
const signatureRegex = /<signature>[^]*<\/signature>/;
let newBody = body;
let paddingBefore = '';
let paddingAfter = '';
// Remove any existing signature in the body
newBody = newBody.replace(signatureRegex, "");
// http://www.regexpal.com/?fam=94390
// prefer to put the signature one <br> before the beginning of the quote,
// if possible.
let insertionPoint = newBody.search(/<\w+[^>]*gmail_quote/i);
if (insertionPoint === -1) {
insertionPoint = newBody.length;
paddingBefore = '<br/><br/>';
} else {
paddingAfter = '<br/>';
}
const contentBefore = newBody.slice(0, insertionPoint);
const contentAfter = newBody.slice(insertionPoint);
return `${contentBefore}<signature>${paddingBefore}${signature}${paddingAfter}</signature>${contentAfter}`;
},
};