Mailspring/internal_packages/composer-signature/lib/signature-utils.es6
Annie bd361c8abb refactor(signatures): Removed old signature imgs and made static empty signatures page
Summary:
Refactored signature preferences page to allow more signatures than the previous 1-1 mapping for signatures and accounts. Created a multi select dropdown of the accounts for which a certain signature is set as default for. Added a button into the draft header From field to toggle between saved signatures.

refactor(signatures): Add basic add/remove capabilities to static

refactor(signatures): Hooked up signature actions and signature store for basic functionality

fix(signatures): Cleaned up signature store and started on multiselectdropdown

fix(signatures): Add multi signature toggle select to multiselect dropdown

build(signatures): Built framework for multiselect dropdown

build(signatures): Toggle button functionality for dropdown

build(signatures): Build multi select from components and add debounce

refactor(signatures): Move signature actions and signature store into flux

fix(signatures): Styled composer signatures button/dropdown and fixed preferences checkmarks

build(signatures): Finish main functionality, about to refactor composer signature button into injected component

fix(signatures): Changed position styles

fix(signatures): Fixed background color for dropdown button when blurred

build(signatures): Began to write tests for signatures store, preferences and dropdown

Test Plan: Wrote tests for preferences signatures, signature store, signature composer dropdown and refactored tests for signature composer extension. For signature composer extension I removed applyTransformsToDraft and unapplyTransformsToDraft and tested by sending emails with signatures to different providers to make sure the <signature> tag caused problems.

Reviewers: bengotow, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3073
2016-07-11 12:35:41 -07:00

28 lines
970 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 = '';
// Remove any existing signature in the body
newBody = newBody.replace(signatureRegex, "");
const signatureInPrevious = newBody !== body
// 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;
if (!signatureInPrevious) paddingBefore = '<br><br>'
}
const contentBefore = newBody.slice(0, insertionPoint);
const contentAfter = newBody.slice(insertionPoint);
return `${contentBefore}${paddingBefore}<signature>${signature}</signature>${contentAfter}`;
},
};