2025-03-13 16:16:07 +01:00
|
|
|
<script setup>
|
|
|
|
|
|
|
|
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
|
const i18n = useI18n();
|
|
|
|
|
const t = i18n.t;
|
|
|
|
|
|
2025-03-14 18:48:13 +01:00
|
|
|
import { ref, onMounted, useTemplateRef } from 'vue';
|
|
|
|
|
import { Button, TableView, Dialog, Checkbox } from 'pankow';
|
|
|
|
|
import { prettyDecimalSize } from '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 = {
|
|
|
|
|
fullName: { label: t('email.incoming.mailboxes.name'), sort: true },
|
2025-03-14 18:48:13 +01:00
|
|
|
ownerDisplayName: { label: t('email.incoming.mailboxes.owner'), sort: true },
|
2025-03-13 16:16:07 +01:00
|
|
|
aliases: { label: t('email.incoming.mailboxes.aliases'), sort: true },
|
|
|
|
|
usage: { label: t('email.incoming.mailboxes.usage'), sort: true },
|
|
|
|
|
actions: {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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-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) {
|
|
|
|
|
mailboxDialog.value.open(mailbox);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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() {
|
|
|
|
|
busy.value = true;
|
|
|
|
|
|
2025-03-14 18:48:13 +01:00
|
|
|
let tmp = [];
|
|
|
|
|
async function refreshForDomain(domain) {
|
|
|
|
|
let [error, result] = await mailModel.usage(domain);
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
const usage = result;
|
|
|
|
|
|
|
|
|
|
[error, result] = await mailModel.listMailboxes(domain);
|
|
|
|
|
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
|
|
|
busy.value = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
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();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<div>
|
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-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-03-14 18:48:13 +01:00
|
|
|
<TableView :columns="columns" :model="mailboxes" :busy="busy" @row-click="onAddOrEdit">
|
2025-03-13 16:16:07 +01:00
|
|
|
<template #aliases="mailbox">{{ renderAliases(mailbox.aliases) }}</template>
|
|
|
|
|
<template #usage="mailbox">
|
2025-03-14 18:48:13 +01:00
|
|
|
<span v-if="mailbox.usage">{{ prettyDecimalSize(mailbox.usage.quotaValue) }} <span ng-show="mailUsage[mailbox.fullName].quotaLimit">/ {{ prettyDecimalSize(mailbox.usage.quotaLimit) }}</span></span>
|
|
|
|
|
<span v-else>{{ $t('main.loadingPlaceholder') }} ...</span>
|
|
|
|
|
</template>
|
|
|
|
|
<template #actions="mailbox">
|
|
|
|
|
<div class="table-actions">
|
|
|
|
|
<Button tool secondary small icon="fa fa-pencil-alt" @click.stop="onAddOrEdit(mailboxe)"></Button>
|
|
|
|
|
<Button tool danger small icon="fa-solid fa-trash-alt" @click.stop="onRemove(mailbox)"></Button>
|
|
|
|
|
</div>
|
2025-03-13 16:16:07 +01:00
|
|
|
</template>
|
|
|
|
|
</TableView>
|
|
|
|
|
</Section>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|