mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 04:25:31 +08:00
39c37e10b9
Summary: New Calendar Test Plan: TODO Reviewers: drew, juan, bengotow Reviewed By: bengotow Subscribers: jackie Differential Revision: https://phab.nylas.com/D2767
30 lines
983 B
JavaScript
30 lines
983 B
JavaScript
import {RegExpUtils} from 'nylas-exports'
|
|
|
|
export default {
|
|
applySignature(body, signature) {
|
|
// https://regex101.com/r/nC0qL2/2
|
|
const signatureRegex = RegExpUtils.signatureRegex();
|
|
|
|
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(RegExpUtils.n1QuoteStartRegex());
|
|
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}${paddingBefore}<signature>${signature}${paddingAfter}</signature>${contentAfter}`;
|
|
},
|
|
};
|