Mailspring/internal_packages/composer-signature/lib/signature-utils.es6
Juan Tejada 579d4ad71b fix(signature): Update signature when account is changed in composer
Summary:
- Fixes #1239
- Adds action in composer view to indicate when draft partcipants have
  changed. This seemed like the simplest way to listen for this change without
  adding another extension point
- Updates signature plugin to listen to this action and update signature
  accordingly
- Adds test

Test Plan: - Unit tests

Reviewers: evan, bengotow

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D2614
2016-02-24 00:19:55 -08:00

29 lines
792 B
JavaScript

const SignatureUtils = {
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)
},
}
export default SignatureUtils;