diff --git a/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md similarity index 100% rename from CODE_OF_CONDUCT.md rename to .github/CODE_OF_CONDUCT.md diff --git a/README.md b/README.md index 0a671a3..723194e 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Similar to [the mail merge feature available in Microsoft Word](https://support. Details of the add-on is described in the [app's web page](https://www.scriptable-assets.page/add-ons/group-merge/). ## Terms and Conditions -You must agree to the [Terms and Conditions](https://www.scriptable-assets.page/terms-and-conditions/)(TaC) to use this add-on. The [disclosure on privacy and OAuth scopes](https://www.scriptable-assets.page/add-ons/group-merge/#disclosure-on-privacy-and-oauth-scopes) constitutes part of this TaC. +You must agree to the [Terms and Conditions](https://www.scriptable-assets.page/terms-and-conditions/) (TaC) to use this add-on. The [disclosure on privacy and OAuth scopes](https://www.scriptable-assets.page/add-ons/group-merge/#disclosure-on-privacy-and-oauth-scopes) constitutes part of this TaC. ## Attributes The original icon of this add-on was made by [Freepik](https://www.freepik.com) from [www.flaticon.com](https://www.flaticon.com/) and its colors are modified to fit the theme color of the app. diff --git a/src/_debug.js b/src/_debug.js index fa7e10c..534f847 100644 --- a/src/_debug.js +++ b/src/_debug.js @@ -1,9 +1,5 @@ -/* global UP_KEY_CREATED_DRAFT_IDS, UP_KEY_PREV_CONFIG, UP_KEY_USER_CONFIG */ /* exported resetUserProperties */ function resetUserProperties() { - PropertiesService.getUserProperties() - .deleteProperty(UP_KEY_USER_CONFIG) - .deleteProperty(UP_KEY_PREV_CONFIG) - .deleteProperty(UP_KEY_CREATED_DRAFT_IDS); + PropertiesService.getUserProperties().deleteAllProperties(); } \ No newline at end of file diff --git a/src/mailMerge.js b/src/mailMerge.js index 5d702e3..99d3c2e 100644 --- a/src/mailMerge.js +++ b/src/mailMerge.js @@ -312,9 +312,11 @@ function sendDrafts(event) { throw new Error(localizedMessage.messageList.errorNoDraftToSend); } // Send emails - createdDraftIds.forEach(draftId => { - GmailApp.getDraft(draftId).send(); - messageCount += 1; + GmailApp.getDrafts().forEach(draft => { + if (createdDraftIds.includes(draft.getId())) { + draft.send(); + messageCount += 1; + } }); // Empty createdDraftIds createdDraftIds = []; @@ -451,9 +453,7 @@ function mailMerge(draftMode = true, config = DEFAULT_CONFIG, prevProperties = { throw new Error(localizedMessage.messageList.errorNoMatchingTemplateDraft); } // Store template into an object - let messageTo = draftMessages[0].getTo(); - let messageCc = draftMessages[0].getCc(); - let messageBcc = draftMessages[0].getBcc(); + let [messageTo, messageCc, messageBcc] = [draftMessages[0].getTo(), draftMessages[0].getCc(), draftMessages[0].getBcc()]; let template = { 'subject': config.TEMPLATE_SUBJECT, 'plainBody': draftMessages[0].getPlainBody(), @@ -467,6 +467,9 @@ function mailMerge(draftMode = true, config = DEFAULT_CONFIG, prevProperties = { 'labels': draftMessages[0].getThread().getLabels(), 'replyTo': (config.ENABLE_REPLY_TO ? config.REPLY_TO : '') }; + template.to = (template.to.slice(0, 1) === ',' ? template.to.slice(1) : template.to); + template.cc = (template.cc.slice(0, 1) === ',' ? template.cc.slice(1) : template.cc); + template.bcc = (template.bcc.slice(0, 1) === ',' ? template.bcc.slice(1) : template.bcc); debugInfo.processTime.push(`Retrieved template draft data at ${(new Date()).getTime() - debugInfo.start} (millisec from start)`); // Check template format; plain or HTML text. let isPlainText = (template.plainBody === template.htmlBody);