WIP: Webmail

This commit is contained in:
Antoine Nguyen
2025-05-01 18:00:00 +02:00
parent c56264e57d
commit af196f7333
37 changed files with 2910 additions and 14 deletions
+25
View File
@@ -0,0 +1,25 @@
import repository from './repository'
export default {
getUserMailboxes(mailbox) {
const params = {}
if (mailbox) {
params.mailbox = mailbox
}
return repository.get('/webmail/mailboxes/', { params })
},
getMailboxEmails(mailbox, options) {
const params = {
mailbox,
...options,
}
return repository.get(`/webmail/emails/`, { params })
},
getEmailContent(mailbox, mailid) {
const params = {
mailbox,
mailid,
}
return repository.get(`/webmail/emails/content/`, { params })
},
}
+7 -2
View File
@@ -21,7 +21,11 @@
</v-btn>
</div>
<v-list nav>
<v-list
:density="layoutStore.compactLeftMenu ? 'compact' : 'default'"
:lines="layoutStore.compactLeftMenu ? false : true"
nav
>
<template v-for="item in menuItems" :key="item.text">
<template v-if="displayMenuItem(item)">
<v-list-subheader v-if="item.subheader" class="text-white">
@@ -89,7 +93,7 @@
<script setup>
import { useRouter } from 'vue-router'
import { ref, computed, onMounted } from 'vue'
import { useGlobalStore, useAuthStore } from '@/stores'
import { useGlobalStore, useAuthStore, useLayoutStore } from '@/stores'
const props = defineProps({
color: {
@@ -109,6 +113,7 @@ const props = defineProps({
const globalStore = useGlobalStore()
const authStore = useAuthStore()
const layoutStore = useLayoutStore()
const router = useRouter()
const rail = ref(false)
@@ -0,0 +1,113 @@
<template>
<v-card class="mt-6 mb-2">
<v-toolbar color="white" flat>
<v-checkbox class="mr-4" hide-details />
<v-text-field
v-model="search"
prepend-inner-icon="mdi-magnify"
:placeholder="$gettext('Search')"
variant="outlined"
single-line
flat
hide-details
density="compact"
class="flex-grow-0 w-33 mr-4"
></v-text-field>
</v-toolbar>
</v-card>
<v-skeleton-loader v-if="loading" type="card@2"></v-skeleton-loader>
<template v-else>
<v-card
v-for="email in emails"
:key="email.imapid"
density="compact"
class="mb-2"
>
<v-card-text
class="d-flex align-center"
:class="{ 'font-weight-bold': email.style === 'unseen' }"
>
<v-checkbox :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>
</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>
</div>
</div>
</v-card-text>
</v-card>
</template>
</template>
<script setup>
import { ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import api from '@/api/webmail'
const props = defineProps({
mailbox: {
type: String,
default: 'INBOX',
},
})
const router = useRouter()
const loading = ref(false)
const emails = ref([])
const search = ref('')
const openEmail = (emailid) => {
router.push({
name: 'EmailView',
query: { mailbox: props.mailbox, mailid: emailid },
})
}
watch(
() => props.mailbox,
(value) => {
emails.value = []
loading.value = true
api
.getMailboxEmails(value, {})
.then((resp) => {
emails.value = resp.data
loading.value = false
})
.catch(() => {
loading.value = false
})
},
{ immediate: true }
)
</script>
<style lang="scss" scoped>
.v-card-text {
padding: 0;
}
.clickable {
cursor: pointer;
}
</style>
@@ -0,0 +1,103 @@
<template>
<div>
<div
v-for="mailbox in props.mailboxes"
:key="mailbox.name"
class="py-1 pl-3 text-body-2"
>
<div
:class="getBackgroundColorClass(mailbox)"
class="d-flex mailbox pa-1 align-center"
@click="$emit('mailboxSelected', mailbox)"
@mouseover="setHover(mailbox, true)"
@mouseleave="setHover(mailbox, false)"
>
<v-icon :icon="iconByMailboxType[mailbox.type]" class="mr-4" />
{{ getMailboxLabel(mailbox) }}
<v-spacer />
<v-btn
v-if="mailbox.sub"
:icon="getMailboxState(mailbox) ? 'mdi-minus' : 'mdi-plus'"
size="xsmall"
variant="flat"
color="transparent"
@click.stop="toggleMailbox(mailbox)"
/>
</div>
<MailboxList
v-if="getMailboxState(mailbox) && mailbox.sub && mailbox.sub.length"
:mailboxes="mailbox.sub"
class="mt-1"
@mailbox-selected="(mailbox) => $emit('mailboxSelected', mailbox)"
/>
</div>
</div>
</template>
<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,
},
})
const emit = defineEmits(['mailboxSelected'])
const iconByMailboxType = {
inbox: 'mdi-inbox',
draft: 'mdi-file',
junk: 'mdi-fire',
sent: 'mdi-email-fast-outline',
trash: 'mdi-trash-can-outline',
normal: 'mdi-folder-outline',
}
const hoverStates = ref({})
const mailboxStates = ref({})
function getMailboxLabel(mailbox) {
return mailbox.label.split('/').pop()
}
function setHover(mailbox, value) {
hoverStates.value[mailbox.name] = value
}
function getBackgroundColorClass(mailbox) {
if (route.query.mailbox === mailbox.name) {
return 'bg-primary-lighten-1'
}
return hoverStates.value[mailbox.name] ? 'bg-primary-lighten-1' : 'bg-primary'
}
function getMailboxState(mailbox) {
return mailboxStates.value[mailbox.name]
}
function toggleMailbox(mailbox) {
if (!mailboxStates.value[mailbox.name]) {
mailboxStates.value[mailbox.name] = false
}
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
})
}
}
</script>
<style scoped lang="scss">
.mailbox {
cursor: pointer;
&:hover {
border-radius: 5px;
}
}
</style>
@@ -1,6 +1,8 @@
<template>
<v-app>
<NavBar :color="color" :menu-items="menuItems" />
<slot name="navbar">
<NavBar :color="color" :menu-items="menuItems" />
</slot>
<TopMenu :user="authUser" />
<ConnectedView />
<v-snackbar
@@ -0,0 +1,59 @@
<template>
<ConnectedLayout>
<template #navbar>
<v-navigation-drawer
v-model="drawer"
:rail="rail"
permanent
color="primary"
app
>
<div class="d-flex align-center">
<v-img
src="@/assets/Modoboa_RVB-BLANC-SANS.png"
max-width="190"
class="logo"
/>
<v-btn
:icon="rail ? 'mdi-chevron-right' : 'mdi-chevron-left'"
variant="text"
@click.stop="rail = !rail"
>
</v-btn>
</div>
<MailboxList
:mailboxes="userMailboxes"
class="mr-2"
@mailbox-selected="openMailbox"
/>
</v-navigation-drawer>
</template>
</ConnectedLayout>
</template>
<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import ConnectedLayout from '@/layouts/connected/ConnectedLayout.vue'
import MailboxList from '@/components/webmail/MailboxList.vue'
import api from '@/api/webmail'
const router = useRouter()
const drawer = ref(true)
const rail = ref(false)
const userMailboxes = ref([])
function openMailbox(mailbox) {
console.log(mailbox)
router.push({
name: 'MailboxView',
query: { mailbox: mailbox.name },
})
}
api.getUserMailboxes().then((resp) => {
userMailboxes.value = resp.data
})
</script>
+4
View File
@@ -1,5 +1,6 @@
import gettext from './gettext'
import { DateTime } from 'luxon'
import { filesize } from 'filesize'
const { $gettext } = gettext
@@ -17,5 +18,8 @@ export default {
clamp = clamp || '...'
return value.length > length ? value.slice(0, length) + clamp : value
}
app.config.globalProperties.$filesize = (value) => {
return filesize(value, { locale: gettext.current })
}
},
}
+27 -1
View File
@@ -270,7 +270,6 @@ const routes = [
},
{
path: '/user',
component: () => import('@/layouts/user/UserLayout.vue'),
meta: {
requiresAuth: true,
},
@@ -285,6 +284,7 @@ const routes = [
},
{
path: 'contacts',
component: () => import('@/layouts/user/UserLayout.vue'),
meta: {
requiresAuth: true,
},
@@ -301,6 +301,7 @@ const routes = [
},
{
path: 'calendars',
component: () => import('@/layouts/user/UserLayout.vue'),
meta: {
requiresAuth: true,
},
@@ -315,6 +316,31 @@ const routes = [
},
],
},
{
path: 'webmail',
component: () => import('@/layouts/webmail/WebmailLayout.vue'),
meta: {
requiresAuth: true,
},
children: [
{
path: '',
name: 'MailboxView',
component: () => import('@/views/webmail/MailboxView.vue'),
meta: {
requiresAuth: true,
},
},
{
path: 'view',
name: 'EmailView',
component: () => import('@/views/webmail/EmailView.vue'),
meta: {
requiresAuth: true,
},
},
],
},
],
},
{
+3
View File
@@ -3,6 +3,7 @@ import { defineStore } from 'pinia'
export const useLayoutStore = defineStore('layout', () => {
const leftMenuItems = ref([])
const compactLeftMenu = ref(false)
function setLeftMenuItems(items) {
leftMenuItems.value = items
@@ -10,10 +11,12 @@ export const useLayoutStore = defineStore('layout', () => {
async function $reset() {
leftMenuItems.value = []
compactLeftMenu.value = false
}
return {
leftMenuItems,
compactLeftMenu,
setLeftMenuItems,
$reset,
}
+50
View File
@@ -0,0 +1,50 @@
<template>
<v-toolbar color="white" class="mt-12">
<v-btn variant="tonal" @click="close">
<v-icon icon="mdi-arrow-left" />
{{ $gettext('Back') }}
</v-btn>
<v-btn color="primary">
{{ $gettext('Reply') }}
</v-btn>
</v-toolbar>
<div v-if="email" class="mt-4">
<h3>{{ email.subject }}</h3>
<div>{{ email.from_address.name }}</div>
<iframe class="email-frame" />
</div>
</template>
<script setup>
import { nextTick, onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'
import api from '@/api/webmail'
const route = useRoute()
const email = ref(null)
onMounted(() => {
api.getEmailContent(route.query.mailbox, route.query.mailid).then((resp) => {
email.value = resp.data
nextTick(() => {
const iframe = document.createElement('iframe')
iframe.classList.add('email-frame')
document.querySelector('iframe').replaceWith(iframe)
const iframeDoc = iframe.contentDocument
iframeDoc.write(email.value.body)
iframeDoc.close()
})
})
})
</script>
<style>
.email-frame {
width: 100%;
min-height: 1000px;
border: none;
margin-top: 10px;
}
</style>
@@ -0,0 +1,10 @@
<template>
<div class="text-h5 ml-4">
{{ $gettext('Webmail') }}
</div>
<EmailList :mailbox="$route.query.mailbox || 'INBOX'" />
</template>
<script setup>
import EmailList from '@/components/webmail/EmailList.vue'
</script>