summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarry Youd <harry@harryyoud.co.uk>2021-02-21 14:04:35 +0000
committerHarry Youd <harry@harryyoud.co.uk>2021-12-23 10:21:30 +0000
commitcf642dfd5beae204682c27a195d568c61e57c136 (patch)
tree6a5e813fd71dc202e194636c8df2d1f0c90ad3c3 /src
parent7ffaab3edaf0426159c2483b447065913d884c17 (diff)
Allow sending emails to contact group (#1848)
Signed-off-by: Harry Youd <harry@harryyoud.co.uk>
Diffstat (limited to 'src')
-rw-r--r--src/components/AppNavigation/GroupNavigationItem.vue32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/components/AppNavigation/GroupNavigationItem.vue b/src/components/AppNavigation/GroupNavigationItem.vue
index 2185304b..98f95373 100644
--- a/src/components/AppNavigation/GroupNavigationItem.vue
+++ b/src/components/AppNavigation/GroupNavigationItem.vue
@@ -38,6 +38,11 @@
@click="downloadGroup(group)">
{{ t('contacts', 'Download') }}
</ActionButton>
+ <ActionButton
+ icon="icon-mail"
+ @click="emailGroup(group)">
+ {{ t('contacts', 'Send email') }}
+ </ActionButton>
</template>
<AppNavigationCounter v-if="group.contacts.length > 0" slot="counter">
@@ -126,6 +131,33 @@ export default {
download(response.data, filename, 'text/vcard')
})
},
+
+ /**
+ * Open mailto: for contacts in a group
+ *
+ * @param {Object} group of contacts to be emailed
+ */
+ emailGroup(group) {
+ const emails = []
+ group.contacts.forEach(key => {
+ // The email property could contain "John Doe <john.doe@example.com>", but vcard spec only
+ // allows addr-spec, not name-addr, so to stay compliant, replace everything outside of <>
+ const email = this.contacts[key].email.replace(/(.*<)([^>]*)(>)/g, '$2').trim()
+ const name = this.contacts[key].fullName.replace(/[,<>]/g, '').trim()
+ if (email === '') {
+ return
+ }
+ if (name === null || name === '') {
+ emails.push(email)
+ return
+ }
+ emails.push(`${name} <${email}>`)
+ })
+ // We could just do mailto:${emails}, but if we want to use name-addr, not addr-spec, then we
+ // have to explicitly set the "To:" header.
+ window.location.href = `mailto:?to=${emails.map(encodeURIComponent).join(',')}`
+ },
+
},
}
</script>