2016-03-01 10:47:22 +08:00
|
|
|
export default {
|
2016-02-24 16:19:17 +08:00
|
|
|
applySignature(body, signature) {
|
2016-03-10 04:05:28 +08:00
|
|
|
// https://regex101.com/r/nC0qL2/1
|
|
|
|
const signatureRegex = /<div class="nylas-n1-signature">[^]*<\/div>/;
|
2016-02-24 16:19:17 +08:00
|
|
|
|
|
|
|
let signatureHTML = '<div class="nylas-n1-signature">' + signature + '</div>';
|
2016-03-01 10:47:22 +08:00
|
|
|
let insertionPoint = body.search(signatureRegex);
|
2016-02-24 16:19:17 +08:00
|
|
|
let newBody = body;
|
|
|
|
|
|
|
|
// If there is a signature already present
|
|
|
|
if (insertionPoint !== -1) {
|
|
|
|
// Remove it
|
2016-03-01 10:47:22 +08:00
|
|
|
newBody = newBody.replace(signatureRegex, "");
|
2016-02-24 16:19:17 +08:00
|
|
|
} else {
|
|
|
|
insertionPoint = newBody.indexOf('<blockquote');
|
|
|
|
|
|
|
|
if (insertionPoint === -1) {
|
2016-03-01 10:47:22 +08:00
|
|
|
insertionPoint = newBody.length;
|
|
|
|
signatureHTML = '<br/><br/>' + signatureHTML;
|
2016-02-24 16:19:17 +08:00
|
|
|
}
|
|
|
|
}
|
2016-03-01 10:47:22 +08:00
|
|
|
return newBody.slice(0, insertionPoint) + signatureHTML + newBody.slice(insertionPoint);
|
2016-02-24 16:19:17 +08:00
|
|
|
},
|
2016-03-01 10:47:22 +08:00
|
|
|
};
|