2025-03-13 16:16:07 +01:00
|
|
|
<script setup>
|
|
|
|
|
|
|
|
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
|
const i18n = useI18n();
|
|
|
|
|
const t = i18n.t;
|
|
|
|
|
|
2025-06-27 14:02:17 +02:00
|
|
|
import { ref, onMounted, useTemplateRef, inject, computed } from 'vue';
|
2025-08-18 15:59:40 +02:00
|
|
|
import { Button, TableView, Dialog, Checkbox, TextInput, Menu } from '@cloudron/pankow';
|
2025-07-10 11:55:11 +02:00
|
|
|
import { prettyDecimalSize } from '@cloudron/pankow/utils';
|
2025-03-13 16:16:07 +01:00
|
|
|
import { eachLimit } from 'async';
|
|
|
|
|
import Section from '../components/Section.vue';
|
2025-03-14 18:48:13 +01:00
|
|
|
import MailboxDialog from '../components/MailboxDialog.vue';
|
2025-03-13 16:16:07 +01:00
|
|
|
import DomainsModel from '../models/DomainsModel.js';
|
|
|
|
|
import MailModel from '../models/MailModel.js';
|
2025-03-14 18:48:13 +01:00
|
|
|
import GroupsModel from '../models/GroupsModel.js';
|
|
|
|
|
import UsersModel from '../models/UsersModel.js';
|
|
|
|
|
import MailboxesModel from '../models/MailboxesModel.js';
|
2025-03-13 16:16:07 +01:00
|
|
|
|
|
|
|
|
const domainsModel = DomainsModel.create();
|
|
|
|
|
const mailModel = MailModel.create();
|
2025-03-14 18:48:13 +01:00
|
|
|
const groupsModel = GroupsModel.create();
|
|
|
|
|
const mailboxesModel = MailboxesModel.create();
|
|
|
|
|
const usersModel = UsersModel.create();
|
2025-03-13 16:16:07 +01:00
|
|
|
|
|
|
|
|
const columns = {
|
2025-03-26 16:04:58 +01:00
|
|
|
fullName: {
|
|
|
|
|
label: t('email.incoming.mailboxes.name'),
|
|
|
|
|
sort: true
|
|
|
|
|
},
|
|
|
|
|
ownerDisplayName: {
|
|
|
|
|
label: t('email.incoming.mailboxes.owner'),
|
|
|
|
|
sort: true,
|
|
|
|
|
hideMobile: true,
|
|
|
|
|
},
|
|
|
|
|
aliases: {
|
|
|
|
|
label: t('email.incoming.mailboxes.aliases'),
|
|
|
|
|
sort: true,
|
|
|
|
|
hideMobile: true,
|
|
|
|
|
},
|
|
|
|
|
usage: {
|
|
|
|
|
label: t('email.incoming.mailboxes.usage'),
|
|
|
|
|
sort: true,
|
|
|
|
|
hideMobile: true,
|
|
|
|
|
},
|
2025-07-15 15:57:38 +02:00
|
|
|
quota: {
|
|
|
|
|
label: 'Quota',
|
|
|
|
|
sort: true,
|
|
|
|
|
hideMobile: true,
|
|
|
|
|
},
|
2025-03-13 16:16:07 +01:00
|
|
|
actions: {}
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-18 15:59:40 +02:00
|
|
|
const actionMenuModel = ref([]);
|
|
|
|
|
const actionMenuElement = useTemplateRef('actionMenuElement');
|
|
|
|
|
function onActionMenu(mailbox, event) {
|
|
|
|
|
actionMenuModel.value = [{
|
|
|
|
|
icon: 'fa-solid fa-pencil-alt',
|
|
|
|
|
label: t('main.action.edit'),
|
|
|
|
|
action: onAddOrEdit.bind(null, mailbox),
|
|
|
|
|
}, {
|
|
|
|
|
separator: true,
|
|
|
|
|
}, {
|
|
|
|
|
icon: 'fa-solid fa-trash-alt',
|
|
|
|
|
label: t('main.action.remove'),
|
|
|
|
|
action: onRemove.bind(null, mailbox),
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
actionMenuElement.value.open(event, event.currentTarget);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 16:16:07 +01:00
|
|
|
const busy = ref(true);
|
|
|
|
|
const mailboxes = ref([]);
|
|
|
|
|
const domains = ref([]);
|
2025-03-14 18:48:13 +01:00
|
|
|
const users = ref([]);
|
|
|
|
|
const groups = ref([]);
|
2025-06-27 14:02:17 +02:00
|
|
|
const searchFilter = ref('');
|
2025-03-13 16:16:07 +01:00
|
|
|
|
2025-05-07 15:51:22 +02:00
|
|
|
const features = inject('features');
|
|
|
|
|
const subscriptionRequiredDialog = inject('subscriptionRequiredDialog');
|
|
|
|
|
|
2025-06-27 14:02:17 +02:00
|
|
|
const filteredMailboxes = computed(() => {
|
|
|
|
|
if (!searchFilter.value) return mailboxes.value;
|
|
|
|
|
|
|
|
|
|
return mailboxes.value.filter(m => {
|
|
|
|
|
const search = searchFilter.value.toLowerCase();
|
|
|
|
|
|
|
|
|
|
if (m.fullName.toLowerCase().indexOf(search) !== -1) return true;
|
|
|
|
|
if (m.ownerId.indexOf(search) !== -1) return true;
|
|
|
|
|
if (m.ownerDisplayName.indexOf(search) !== -1) return true;
|
|
|
|
|
if (m.aliases.find(a => a.domain.toLowerCase().indexOf(search) !== -1 || a.name.toLowerCase().indexOf(search) !== -1)) return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const filteredMailboxesUsage = computed(() => {
|
|
|
|
|
return filteredMailboxes.value.reduce((acc, m) => acc + (m.usage && m.usage.diskSize), 0);
|
|
|
|
|
});
|
|
|
|
|
|
2025-03-13 16:16:07 +01:00
|
|
|
function renderAliases(aliases) {
|
|
|
|
|
return aliases.map(a => `${a.name}@${a.domain}`).join(', ');
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-14 18:48:13 +01:00
|
|
|
const mailboxDialog = useTemplateRef('mailboxDialog');
|
2025-03-13 16:16:07 +01:00
|
|
|
|
2025-03-14 18:48:13 +01:00
|
|
|
async function onAddOrEdit(mailbox = null) {
|
2025-05-07 15:51:22 +02:00
|
|
|
if (mailbox || features.value.mailboxMaxCount > mailboxes.value.length) mailboxDialog.value.open(mailbox);
|
|
|
|
|
else subscriptionRequiredDialog.value.open();
|
2025-03-14 18:48:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const removeDialog = useTemplateRef('removeDialog');
|
|
|
|
|
const removeBusy = ref(false);
|
|
|
|
|
const removeError = ref('');
|
|
|
|
|
const removePurge = ref(false);
|
|
|
|
|
const removeMailbox = ref({});
|
2025-03-13 16:16:07 +01:00
|
|
|
|
2025-03-14 18:48:13 +01:00
|
|
|
function onRemove(mailbox) {
|
|
|
|
|
removeBusy.value = false;
|
|
|
|
|
removePurge.value = false;
|
|
|
|
|
removeError.value = '';
|
|
|
|
|
removeMailbox.value = mailbox;
|
2025-03-13 16:16:07 +01:00
|
|
|
|
2025-03-14 18:48:13 +01:00
|
|
|
removeDialog.value.open();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function onSubmitRemove() {
|
|
|
|
|
removeBusy.value = true;
|
|
|
|
|
removeError.value = '';
|
2025-03-13 16:16:07 +01:00
|
|
|
|
2025-03-14 18:48:13 +01:00
|
|
|
const [error] = await mailboxesModel.remove(removeMailbox.value.domain, removeMailbox.value.name, removePurge.value);
|
|
|
|
|
if (error) {
|
|
|
|
|
removeBusy.value = false;
|
|
|
|
|
removeError.value = error.body ? error.body.message : 'Internal error';
|
|
|
|
|
return console.error(error);
|
|
|
|
|
}
|
2025-03-13 16:16:07 +01:00
|
|
|
|
2025-03-14 18:48:13 +01:00
|
|
|
await refresh();
|
|
|
|
|
removeDialog.value.close();
|
2025-03-13 16:16:07 +01:00
|
|
|
|
2025-03-14 18:48:13 +01:00
|
|
|
removeBusy.value = false;
|
2025-03-13 16:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function refresh() {
|
2025-03-14 18:48:13 +01:00
|
|
|
let tmp = [];
|
|
|
|
|
async function refreshForDomain(domain) {
|
|
|
|
|
let [error, result] = await mailModel.usage(domain);
|
2025-08-11 19:07:02 +02:00
|
|
|
// retry if mail addon cannot be reached during restarts
|
|
|
|
|
if (error && error.status === 424) return setTimeout(refresh, 2000);
|
|
|
|
|
else if (error) return console.error(error);
|
2025-03-14 18:48:13 +01:00
|
|
|
|
|
|
|
|
const usage = result;
|
|
|
|
|
|
2025-03-14 21:51:26 +01:00
|
|
|
[error, result] = await mailboxesModel.list(domain);
|
2025-03-14 18:48:13 +01:00
|
|
|
if (error) throw error;
|
|
|
|
|
|
|
|
|
|
result.forEach((m) => {
|
|
|
|
|
m.fullName = m.name + '@' + m.domain;
|
|
|
|
|
|
|
|
|
|
m.owner = users.value.find(u => u.id === m.ownerId) || null;
|
|
|
|
|
if (!m.owner) m.owner = groups.value.find(g => g.id === m.ownerId) || null;
|
|
|
|
|
|
|
|
|
|
m.ownerDisplayName = m.owner ? (m.owner.username || m.owner.name) : '';
|
|
|
|
|
m.usage = usage[m.fullName] || null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tmp = tmp.concat(result);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 16:16:07 +01:00
|
|
|
try {
|
|
|
|
|
await eachLimit(domains.value.map(d => d.domain), 10, refreshForDomain);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return console.error(error);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-14 18:48:13 +01:00
|
|
|
mailboxes.value = tmp;
|
2025-03-13 16:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
2025-03-14 21:10:35 +01:00
|
|
|
busy.value = true;
|
|
|
|
|
|
2025-03-14 18:48:13 +01:00
|
|
|
let [error, result] = await domainsModel.list();
|
2025-03-13 16:16:07 +01:00
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
domains.value = result;
|
|
|
|
|
|
2025-03-14 18:48:13 +01:00
|
|
|
[error, result] = await usersModel.list();
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
users.value = result;
|
|
|
|
|
|
|
|
|
|
[error, result] = await groupsModel.list();
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
groups.value = result;
|
|
|
|
|
|
2025-03-13 16:16:07 +01:00
|
|
|
await refresh();
|
2025-03-14 21:10:35 +01:00
|
|
|
|
|
|
|
|
busy.value = false;
|
2025-03-13 16:16:07 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-03-23 10:37:33 +01:00
|
|
|
<div class="content">
|
2025-08-18 15:59:40 +02:00
|
|
|
<Menu ref="actionMenuElement" :model="actionMenuModel" />
|
2025-03-14 18:48:13 +01:00
|
|
|
<Dialog ref="removeDialog"
|
|
|
|
|
:title="$t('email.deleteMailboxDialog.title', { name: removeMailbox.name, domain: removeMailbox.domain })"
|
|
|
|
|
:confirm-label="$t('email.deleteMailboxDialog.deleteAction')"
|
|
|
|
|
:confirm-busy="removeBusy"
|
|
|
|
|
:confirm-active="!removeBusy"
|
|
|
|
|
confirm-style="danger"
|
|
|
|
|
:reject-label="removeBusy ? '' : $t('main.dialog.cancel')"
|
|
|
|
|
reject-style="secondary"
|
|
|
|
|
@confirm="onSubmitRemove()"
|
|
|
|
|
>
|
|
|
|
|
<div>
|
|
|
|
|
<div class="text-danger" v-if="removeError">{{ removeError }}</div>
|
|
|
|
|
<div v-html="$t('email.deleteMailboxDialog.description')"></div>
|
|
|
|
|
<br/>
|
|
|
|
|
<Checkbox v-model="removePurge" :label="$t('email.deleteMailboxDialog.purgeMailboxCheckbox')" />
|
|
|
|
|
</div>
|
|
|
|
|
</Dialog>
|
|
|
|
|
|
|
|
|
|
<MailboxDialog ref="mailboxDialog" :users="users" :groups="groups" :domains="domains" @success="refresh()"/>
|
|
|
|
|
|
2025-03-13 16:16:07 +01:00
|
|
|
<Section :title="$t('email.incoming.mailboxes.title')">
|
|
|
|
|
<template #header-buttons>
|
2025-06-27 14:02:17 +02:00
|
|
|
<TextInput :placeholder="$t('main.searchPlaceholder')" style="flex-grow: 1;" v-model="searchFilter"/>
|
2025-03-14 18:48:13 +01:00
|
|
|
<Button @click="onAddOrEdit()">{{ $t('email.incoming.mailboxes.addAction') }}</Button>
|
2025-03-13 16:16:07 +01:00
|
|
|
</template>
|
|
|
|
|
|
2025-07-15 15:40:49 +02:00
|
|
|
<TableView :columns="columns" :model="filteredMailboxes" :busy="busy">
|
2025-03-13 16:16:07 +01:00
|
|
|
<template #aliases="mailbox">{{ renderAliases(mailbox.aliases) }}</template>
|
|
|
|
|
<template #usage="mailbox">
|
2025-07-15 15:57:38 +02:00
|
|
|
<span v-if="mailbox.usage">{{ prettyDecimalSize(mailbox.usage.diskSize) }}</span>
|
2025-03-14 18:48:13 +01:00
|
|
|
<span v-else>{{ $t('main.loadingPlaceholder') }} ...</span>
|
|
|
|
|
</template>
|
2025-07-15 15:57:38 +02:00
|
|
|
<template #quota="mailbox">
|
|
|
|
|
<span v-if="mailbox.usage && mailbox.usage.quotaLimit">{{ prettyDecimalSize(mailbox.usage.quotaLimit) }}</span>
|
|
|
|
|
</template>
|
2025-03-14 18:48:13 +01:00
|
|
|
<template #actions="mailbox">
|
2025-08-18 15:59:40 +02:00
|
|
|
<div style="text-align: right;">
|
|
|
|
|
<Button tool plain secondary @click.capture="onActionMenu(mailbox, $event)" icon="fa-solid fa-ellipsis" />
|
2025-03-14 18:48:13 +01:00
|
|
|
</div>
|
2025-03-13 16:16:07 +01:00
|
|
|
</template>
|
|
|
|
|
</TableView>
|
2025-06-27 14:02:17 +02:00
|
|
|
|
|
|
|
|
<div style="margin-top: 20px; font-weight: bold;">{{ $t('emails.domains.stats', { mailboxCount: filteredMailboxes.length, usage: prettyDecimalSize(filteredMailboxesUsage) }) }}</div>
|
2025-03-13 16:16:07 +01:00
|
|
|
</Section>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|