New webmail features.

This commit is contained in:
Antoine Nguyen
2025-05-01 18:02:43 +02:00
parent 6ee4ea1662
commit b30efe6a6c
28 changed files with 1321 additions and 252 deletions
@@ -0,0 +1,96 @@
<template>
<v-card>
<v-card-title>{{ $gettext('Attachments') }}</v-card-title>
<v-card-text>
<v-form ref="formRef">
<v-file-input
v-model="file"
density="compact"
variant="outlined"
:rules="[rules.required]"
/>
<div class="w-100 d-flex justify-center">
<v-btn
color="primary"
variant="tonal"
:text="$gettext('Attach')"
@click="submit"
/>
</div>
</v-form>
<v-table class="mt-4 border-sm">
<tbody>
<tr v-for="attachment in attachments" :key="attachment.fname">
<td>{{ attachment.fname }}</td>
<td>
<v-btn
icon="mdi-trash-can"
color="error"
size="small"
variant="text"
@click="removeAttachment(attachment)"
/>
</td>
</tr>
</tbody>
</v-table>
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn :text="$gettext('Close')" variant="flat" @click="close" />
</v-card-actions>
</v-card>
</template>
<script setup>
import { ref } from 'vue'
import api from '@/api/webmail'
import rules from '@/plugins/rules'
const props = defineProps({
sessionUid: {
type: String,
default: null,
},
})
const emit = defineEmits(['close'])
const attachments = ref([])
const file = ref()
const formRef = ref()
const loading = ref(false)
const close = () => {
emit('close')
}
const submit = async () => {
const { valid } = await formRef.value.validate()
if (!valid) {
return
}
const formData = new FormData()
formData.append('attachment', file.value)
loading.value = true
try {
const resp = await api.uploadAttachment(props.sessionUid, formData)
attachments.value.push(resp.data)
formRef.value.reset()
} finally {
loading.value = false
}
}
const removeAttachment = async (attachment) => {
await api.removeAttachment(props.sessionUid, attachment.tmpname)
const index = attachments.value.findIndex(
(item) => item.tmpname === attachment.tmpname
)
attachments.value.splice(index, 1)
}
api.getUploadedAttachments(props.sessionUid).then((resp) => {
attachments.value = resp.data
})
</script>
@@ -0,0 +1,47 @@
<template>
<HtmlEditor
v-if="htmlMode"
v-model="model"
class="d-flex flex-column flex-grow-1 mt-4"
>
<template #append-toolbar>
<v-btn-toggle
v-model="selection"
base-color="grey-lighten-3"
color="primary"
class="mr-2"
>
<v-btn text="HTML" size="small" @click="toggleHtmlMode" />
</v-btn-toggle>
</template>
</HtmlEditor>
<template v-else>
<div class="mt-8">
<v-btn-toggle
v-model="selection"
base-color="grey-lighten-3"
color="primary"
class="mr-2"
>
<v-btn v-btn text="HTML" size="small" @click="toggleHtmlMode"> </v-btn>
</v-btn-toggle>
</div>
<v-textarea v-model="model" class="border-sm" />
</template>
</template>
<script setup>
import { ref } from 'vue'
import HtmlEditor from '@/components/tools/HtmlEditor'
const model = defineModel()
const emit = defineEmits(['onToggleHtmlMode'])
const htmlMode = ref(false)
const selection = ref()
const toggleHtmlMode = () => {
htmlMode.value = !htmlMode.value
emit('onToggleHtmlMode', htmlMode.value)
}
</script>
@@ -14,6 +14,13 @@
@click="submit"
>
</v-btn>
<v-btn
class="ml-2"
variant="tonal"
prepend-icon="mdi-paperclip"
:text="$gettext('Attachments') + ` (${attachmentCount})`"
@click="openAttachmentsDialog"
/>
</v-toolbar>
<v-form ref="formRef" class="flex-grow-1 d-flex flex-column">
<div>
@@ -24,7 +31,9 @@
<v-col cols="8">
<v-select
v-model="form.sender"
:items="validSenderAddresses"
:items="allowedSenders"
item-title="address"
item-value="address"
variant="outlined"
density="compact"
hide-details="auto"
@@ -37,13 +46,17 @@
<span>{{ $gettext('To') }}</span>
</v-col>
<v-col cols="8">
<v-text-field
<v-combobox
v-model="form.to"
:items="contacts"
item-title="display_name"
return-object
:placeholder="$gettext('Provide one or more addresses')"
variant="outlined"
density="compact"
hide-details="auto"
:rules="[rules.required]"
@update:search="lookForContacts"
/>
</v-col>
<v-col cols="2">
@@ -76,12 +89,19 @@
/>
</v-col>
<v-col cols="8">
<v-text-field
<v-combobox
v-model="form.cc"
:items="contacts"
item-title="display_name"
return-object
:placeholder="$gettext('Provide one or more addresses')"
variant="outlined"
density="compact"
hide-details="auto"
chips
multiple
:hide-no-data="false"
@update:search="lookForContacts"
/>
</v-col>
</v-row>
@@ -96,12 +116,19 @@
/>
</v-col>
<v-col cols="8">
<v-text-field
<v-combobox
v-model="form.bcc"
:items="contacts"
item-title="display_name"
return-object
:placeholder="$gettext('Provide one or more addresses')"
variant="outlined"
density="compact"
hide-details="auto"
chips
multiple
:hide-no-data="false"
@update:search="lookForContacts"
/>
</v-col>
</v-row>
@@ -119,45 +146,60 @@
</v-col>
</v-row>
</div>
<HtmlEditor
<BodyEditor
v-model="form.body"
class="d-flex flex-column flex-grow-1 mt-4"
@on-toggle-html-mode="(value) => emit('onToggleHtmlMode', value)"
/>
</v-form>
</div>
<v-dialog v-model="showAttachmentsDialog" max-width="800">
<AttachmentsDialog
:session-uid="route.query.uid"
@close="closeAttachmentDialog"
/>
</v-dialog>
</template>
<script setup>
import { computed, ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import { useRoute, useRouter } from 'vue-router'
import { useGettext } from 'vue3-gettext'
import { useAuthStore, useBusStore } from '@/stores'
import HtmlEditor from '@/components/tools/HtmlEditor'
import debounce from 'debounce'
import AttachmentsDialog from '@/components/webmail/AttachmentsDialog'
import BodyEditor from '@/components/webmail/BodyEditor'
import rules from '@/plugins/rules'
import api from '@/api/webmail'
import contactsApi from '@/api/contacts'
const props = defineProps({
originalEmail: {
type: Object,
default: null,
},
replyAll: {
type: Boolean,
default: false,
},
})
const emit = defineEmits(['onToggleHtmlMode'])
const route = useRoute()
const router = useRouter()
const { $gettext } = useGettext()
const { displayNotification } = useBusStore()
const authStore = useAuthStore()
const allowedSenders = ref([])
const attachmentCount = ref(0)
const contacts = ref([])
const form = ref({})
const formRef = ref()
const showAttachmentsDialog = ref(false)
const showCcField = ref(false)
const showBccField = ref(false)
const working = ref(false)
const validSenderAddresses = computed(() => {
return [authStore.authUser.username]
})
const close = () => {
router.push({
name: 'MailboxView',
@@ -168,11 +210,27 @@ const initForm = () => {
form.value = {
sender: authStore.authUser.username,
}
console.log(props.originalEmail)
if (props.originalEmail) {
form.value.to = props.originalEmail.from_address.address
form.value.to = props.originalEmail.reply_to
? props.originalEmail.reply_to
: props.originalEmail.from_address.address
if (props.replyAll) {
let addresses = props.originalEmail.to
.filter((rcpt) => rcpt.address !== authStore.authUser.username)
.map((rcpt) => rcpt.fulladdress)
if (props.originalEmail.cc && props.originalEmail.cc.length) {
addresses = addresses.concat(
props.originalEmail.cc.map((rcpt) => rcpt.fulladdress)
)
}
form.value.cc = addresses
showCcField.value = true
}
form.value.subject = props.originalEmail.subject
form.value.body = props.originalEmail.body
if (props.originalEmail.message_id) {
form.value.in_reply_to = props.originalEmail.message_id
}
}
}
@@ -183,7 +241,25 @@ const submit = async () => {
}
working.value = true
const body = { ...form.value }
body.to = [body.to]
if (typeof form.value.to !== 'string') {
body.to = [form.value.to.emails[0].address]
} else {
body.to = [form.value.to]
}
if (body.cc?.length) {
const cc = []
for (const rcpt of body.cc) {
cc.push(typeof rcpt === 'string' ? rcpt : rcpt.emails[0].address)
}
body.cc = cc
}
if (body.bcc?.length) {
const bcc = []
for (const rcpt of body.bcc) {
bcc.push(typeof rcpt === 'string' ? rcpt : rcpt.emails[0].address)
}
body.bcc = bcc
}
try {
await api.sendEmail(body)
router.push({ name: 'MailboxView' })
@@ -195,6 +271,28 @@ const submit = async () => {
}
}
const openAttachmentsDialog = () => {
showAttachmentsDialog.value = true
}
const closeAttachmentDialog = async () => {
showAttachmentsDialog.value = false
const resp = await api.getUploadedAttachments(route.query.uid)
attachmentCount.value = resp.data.length
}
const lookForContacts = debounce(async (search) => {
if (search) {
const params = { search }
const resp = await contactsApi.getContacts(params)
if (resp.data.length) {
contacts.value = resp.data
}
} else {
contacts.value = []
}
}, 500)
watch(
() => props.originalEmail,
() => {
@@ -202,4 +300,19 @@ watch(
},
{ immediate: true }
)
if (!route.query.uid) {
api.createComposeSession().then((resp) => {
const query = { ...route.query, uid: resp.data.uid }
router.push({ name: route.name, query })
})
} else {
api.getUploadedAttachments(route.query.uid).then((resp) => {
attachmentCount.value = resp.data.length
})
}
api.getAllowedSenders().then((resp) => {
allowedSenders.value = resp.data
})
</script>
@@ -0,0 +1,69 @@
<template>
<v-card min-width="300">
<v-list>
<v-list-item
:subtitle="model.name ? model.address : ''"
:title="model.name || model.address"
>
<template #append>
<v-btn
v-if="!model.contact_id"
color="secondary"
icon="mdi-card-account-mail-outline"
variant="text"
:loading="working"
:title="$gettext('Add to contacts')"
@click="addContact"
></v-btn>
<v-btn
v-else
icon="mdi-pencil"
variant="text"
:loading="working"
:title="$gettext('Update contact')"
@click="redirectToContacts"
></v-btn>
</template>
</v-list-item>
</v-list>
</v-card>
</template>
<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useGettext } from 'vue3-gettext'
import { useBusStore } from '@/stores'
import contactsApi from '@/api/contacts'
const emit = defineEmits(['contact-added'])
const model = defineModel()
const router = useRouter()
const { $gettext } = useGettext()
const { displayNotification } = useBusStore()
const working = ref(false)
const addContact = async () => {
const body = {
emails: [{ address: model.value.address, type: 'other' }],
}
if (model.value.name) {
body.display_name = model.value.name
}
working.value = true
let resp
try {
resp = await contactsApi.createContact(body)
} finally {
working.value = false
}
emit('contact-added', resp.data)
displayNotification({ msg: $gettext('Contact added to address book') })
}
const redirectToContacts = () => {
router.push({ name: 'ContactList' })
}
</script>
+80 -37
View File
@@ -11,13 +11,16 @@
<v-text-field
v-model="search"
prepend-inner-icon="mdi-magnify"
:placeholder="$gettext('Search')"
:placeholder="$gettext('Search in messages')"
variant="outlined"
single-line
flat
hide-details
density="compact"
class="flex-grow-0 w-33 mr-4"
clearable
@click:clear="fetchEmails"
@keyup.enter="submitSearch"
></v-text-field>
<v-btn
class="ml-2"
@@ -75,6 +78,12 @@
prepend-icon="mdi-star-outline"
@click="() => flagSelection('unflagged')"
/>
<v-list-item
v-if="$route.params.mailbox !== 'Trash'"
:title="$gettext('Empty mailbox')"
prepend-icon="mdi-trash-can"
@click="emptyMailbox"
/>
</v-list>
</v-menu>
</v-btn>
@@ -104,44 +113,58 @@
<v-skeleton-loader v-if="loading" type="card@2"></v-skeleton-loader>
<template v-else>
<div class="emails position-absolute top-0 bottom-0 w-100 overflow-y-auto">
<v-card
v-for="email in emails.results"
:key="email.imapid"
density="compact"
class="mb-2 mx-1"
>
<v-card-text
class="d-flex align-center"
:class="{ 'font-weight-bold': email.style === 'unseen' }"
<template v-if="emails.results?.length">
<v-card
v-for="email in emails.results"
:key="email.imapid"
density="compact"
class="mb-2 mx-1"
>
<v-checkbox v-model="selection" :value="email.imapid" hide-details />
<v-btn
:icon="email.flagged ? 'mdiu-star' : 'mdi-star-outline'"
variant="flat"
/>
<div class="ml-4 clickable" @click="openEmail(email.imapid)">
<div>{{ email.subject }}</div>
<div class="mt-1 text-grey">
<span
v-if="email.from_address.name"
:title="email.from_address.address"
>{{ email.from_address.name }}</span
>
<span v-else>{{ email.from_address.address }}</span>
<v-card-text
class="d-flex align-center"
:class="{ 'font-weight-bold': email.style === 'unseen' }"
>
<v-checkbox
v-model="selection"
:value="email.imapid"
hide-details
/>
<v-btn
:icon="email.flagged ? 'mdi-star' : 'mdi-star-outline'"
variant="flat"
@click="toggleFollowState(email)"
/>
<div class="ml-4 clickable" @click="openEmail(email.imapid)">
<div>{{ email.subject }}</div>
<div class="mt-1 text-grey">
<span
v-if="email.from_address.name"
:title="email.from_address.address"
>{{ email.from_address.name }}</span
>
<span v-else>{{ email.from_address.address }}</span>
</div>
</div>
</div>
<v-spacer />
<div class="text-right">
<div>{{ email.date }}</div>
<div class="mt-1">
<v-icon v-if="email.answered" icon="mdi-reply-outline" />
<v-icon v-if="email.forwarded" icon="mdi-share-outline" />
<v-icon v-if="email.attachments" icon="mdi-paperclip" />
<span class="text-grey">{{ $filesize(email.size) }}</span>
<v-spacer />
<div class="text-right">
<div>{{ email.date }}</div>
<div class="mt-1">
<v-icon v-if="email.answered" icon="mdi-reply-outline" />
<v-icon v-if="email.forwarded" icon="mdi-share-outline" />
<v-icon v-if="email.attachments" icon="mdi-paperclip" />
<span class="text-grey">{{ $filesize(email.size) }}</span>
</div>
</div>
</div>
</v-card-text>
</v-card>
</v-card-text>
</v-card>
</template>
<v-alert
v-else
class="mt-4"
type="info"
:text="$gettext('No message yet in this mailbox')"
variant="tonal"
/>
</div>
</template>
</template>
@@ -184,7 +207,7 @@ const fetchEmails = () => {
emails.value = {}
loading.value = true
api
.getMailboxEmails(props.mailbox, { page: page.value })
.getMailboxEmails(props.mailbox, { page: page.value, search: search.value })
.then((resp) => {
emails.value = resp.data
loading.value = false
@@ -194,6 +217,12 @@ const fetchEmails = () => {
})
}
const submitSearch = () => {
if (search.value) {
fetchEmails()
}
}
const toggleAllSelection = (value) => {
if (!value) {
selection.value = []
@@ -251,6 +280,20 @@ const flagSelection = (status) => {
})
}
const emptyMailbox = () => {
loading.value = true
api.emptyUserMailbox(route.query.mailbox).then(() => {
emails.value = {}
loading.value = false
})
}
const toggleFollowState = async (email) => {
const flag = email.flagged ? 'unflagged' : 'flagged'
await api.flagSelection(route.query.mailbox, [email.imapid], flag)
email.flagged = flag === 'flagged'
}
watch(
() => props.mailbox,
() => {
@@ -0,0 +1,126 @@
<template>
<v-card :title="title">
<v-card-text>
<v-form ref="formRef">
<v-text-field
v-model="form.name"
:label="$gettext('Name')"
variant="outlined"
density="compact"
:rules="[rules.required]"
/>
<div class="mb-2 rounded-lg">
<h4>{{ $gettext('Parent mailbox') }}</h4>
<MailboxList
v-model="form.parent_mailbox"
:active-mailbox="props.parent"
:mailboxes="props.userMailboxes"
light-mode
compact
:unseen-counters="false"
allow-unselect
/>
</div>
</v-form>
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn
:text="$gettext('Close')"
variant="flat"
:loading="loading"
@click="close"
/>
<v-btn
:text="submitLabel"
variant="tonal"
color="primary"
:loading="loading"
@click="submit"
/>
</v-card-actions>
</v-card>
</template>
<script setup>
import { computed, ref, watch } from 'vue'
import { useGettext } from 'vue3-gettext'
import { useBusStore } from '@/stores'
import MailboxList from '@/components/webmail/MailboxList.vue'
import api from '@/api/webmail'
import rules from '@/plugins/rules'
const props = defineProps({
userMailboxes: Array,
mailbox: {
type: String,
default: null,
},
hdelimiter: {
type: String,
default: null,
},
})
const emit = defineEmits(['close', 'mailboxRenamed'])
const { $gettext } = useGettext()
const { displayNotification } = useBusStore()
const form = ref({})
const formRef = ref()
const loading = ref(false)
const title = computed(() => {
return !props.mailbox
? $gettext('Create new mailbox')
: $gettext('Edit mailbox')
})
const submitLabel = computed(() => {
return !props.mailbox ? $gettext('Create') : $gettext('Update')
})
const close = () => {
form.value = {}
emit('close')
}
const submit = async () => {
const { valid } = await formRef.value.validate()
if (!valid) {
return
}
loading.value = true
try {
const body = { ...form.value }
if (props.mailbox) {
body.oldname = props.mailbox
await api.renameUserMailbox(body)
displayNotification({ msg: $gettext('Mailbox renamed') })
emit(
'mailboxRenamed',
`${body.parent_mailbox}${props.hdelimiter}${body.name}`
)
} else {
await api.createUserMailbox(body)
displayNotification({ msg: $gettext('Mailbox created') })
}
close()
} finally {
loading.value = false
}
}
watch(
() => props.mailbox,
(value) => {
if (value) {
const parts = props.mailbox.split(props.hdelimiter)
form.value.name = parts.slice(-1)[0]
form.value.parent_mailbox = parts.slice(0, -1).join(props.hdelimiter)
} else {
form.value = {}
}
},
{ immediate: true }
)
</script>
+42 -12
View File
@@ -3,17 +3,18 @@
<div
v-for="mailbox in props.mailboxes"
:key="mailbox.name"
class="py-1 pl-3 text-body-2"
class="pl-3 text-body-2"
:class="{ 'py-1': !props.compact }"
>
<div
:class="getBackgroundColorClass(mailbox)"
class="d-flex mailbox pa-1 align-center"
@click="$emit('mailboxSelected', mailbox)"
@click="updateSelection(mailbox.name)"
@mouseover="setHover(mailbox, true)"
@mouseleave="setHover(mailbox, false)"
>
<v-icon :icon="iconByMailboxType[mailbox.type]" class="mr-4" />
<template v-if="mailbox.unseen > 0">
<template v-if="props.unseenCounters && mailbox.unseen > 0">
<span class="font-weight-bold">
{{ getMailboxLabel(mailbox) }} ({{ mailbox.unseen }})
</span>
@@ -33,9 +34,11 @@
</div>
<MailboxList
v-if="getMailboxState(mailbox) && mailbox.sub && mailbox.sub.length"
v-model="model"
:mailboxes="mailbox.sub"
class="mt-1"
@mailbox-selected="(mailbox) => $emit('mailboxSelected', mailbox)"
:light-mode="props.lightMode"
:compact="props.compact"
/>
</div>
</div>
@@ -43,18 +46,32 @@
<script setup>
import { ref } from 'vue'
import { useRoute } from 'vue-router'
import api from '@/api/webmail'
const route = useRoute()
const props = defineProps({
mailboxes: {
type: Array,
default: null,
},
lightMode: {
type: Boolean,
default: false,
},
compact: {
type: Boolean,
default: false,
},
unseenCounters: {
type: Boolean,
default: true,
},
allowUnselect: {
type: Boolean,
default: false,
},
})
const emit = defineEmits(['mailboxSelected'])
const model = defineModel()
const emit = defineEmits(['update:modelValue'])
const iconByMailboxType = {
inbox: 'mdi-inbox',
@@ -77,10 +94,15 @@ function setHover(mailbox, value) {
}
function getBackgroundColorClass(mailbox) {
if (route.query.mailbox === mailbox.name) {
return 'bg-primary-lighten-1'
if (model.value === mailbox.name) {
return `bg-primary-lighten-1`
}
return hoverStates.value[mailbox.name] ? 'bg-primary-lighten-1' : 'bg-primary'
if (!props.lightMode) {
return hoverStates.value[mailbox.name]
? `bg-primary-lighten-1`
: `bg-primary`
}
return hoverStates.value[mailbox.name] ? 'bg-primary' : `bg-white`
}
function getMailboxState(mailbox) {
@@ -94,10 +116,18 @@ function toggleMailbox(mailbox) {
mailboxStates.value[mailbox.name] = !mailboxStates.value[mailbox.name]
if (mailboxStates.value[mailbox.name] && !mailbox.sub.length) {
api.getUserMailboxes(mailbox.name).then((resp) => {
mailbox.sub = resp.data
mailbox.sub = resp.data.mailboxes
})
}
}
function updateSelection(value) {
if (props.allowUnselect && value === model.value) {
emit('update:modelValue', null)
} else {
emit('update:modelValue', value)
}
}
</script>
<style scoped lang="scss">