mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-11 18:32:20 +08:00
94badcda15
There could be a few lurking bugs. Please test!
23 lines
754 B
JavaScript
23 lines
754 B
JavaScript
export default {
|
|
applySignature(body, signature) {
|
|
const signatureRegex = /<div class="nylas-n1-signature">.*<\/div>/;
|
|
|
|
let signatureHTML = '<div class="nylas-n1-signature">' + signature + '</div>';
|
|
let insertionPoint = body.search(signatureRegex);
|
|
let newBody = body;
|
|
|
|
// If there is a signature already present
|
|
if (insertionPoint !== -1) {
|
|
// Remove it
|
|
newBody = newBody.replace(signatureRegex, "");
|
|
} else {
|
|
insertionPoint = newBody.indexOf('<blockquote');
|
|
|
|
if (insertionPoint === -1) {
|
|
insertionPoint = newBody.length;
|
|
signatureHTML = '<br/><br/>' + signatureHTML;
|
|
}
|
|
}
|
|
return newBody.slice(0, insertionPoint) + signatureHTML + newBody.slice(insertionPoint);
|
|
},
|
|
};
|