274 lines
9.7 KiB
Vue
274 lines
9.7 KiB
Vue
<script setup>
|
|
|
|
import { useI18n } from 'vue-i18n';
|
|
const i18n = useI18n();
|
|
const t = i18n.t;
|
|
|
|
import { ref, onMounted, useTemplateRef } from 'vue';
|
|
import { Button, Checkbox, InputDialog, Dialog, FormGroup, Switch } from 'pankow';
|
|
import Section from '../components/Section.vue';
|
|
import SettingsItem from '../components/SettingsItem.vue';
|
|
import CatchAllSettingsItem from '../components/CatchAllSettingsItem.vue';
|
|
import MailRelaySettingsItem from '../components/MailRelaySettingsItem.vue';
|
|
import MailDomainStatus from '../components/MailDomainStatus.vue';
|
|
import DashboardModel from '../models/DashboardModel.js';
|
|
import DomainsModel from '../models/DomainsModel.js';
|
|
import MailModel from '../models/MailModel.js';
|
|
|
|
const dashboardModel = DashboardModel.create();
|
|
const domainsModel = DomainsModel.create();
|
|
const mailModel = MailModel.create();
|
|
|
|
const inputDialog = useTemplateRef('inputDialog');
|
|
const enableIncomingDialog = useTemplateRef('enableIncomingDialog');
|
|
const connectionDialog = useTemplateRef('connectionDialog');
|
|
const domain = ref('');
|
|
const domainProvider = ref('');
|
|
const mailConfig = ref({});
|
|
const mailFqdn = ref('');
|
|
const refreshBusy = ref(false);
|
|
const incomingEnabled = ref(false);
|
|
const enableIncomeBusy = ref(false);
|
|
const enableIncomingSetupDns = ref(false);
|
|
const infoMenu = ref([]);
|
|
|
|
function onShowConnectionDialog() {
|
|
connectionDialog.value.open();
|
|
}
|
|
|
|
async function onAskIncomingToggle(value) {
|
|
if (value) {
|
|
enableIncomeBusy.value = false;
|
|
return enableIncomingDialog.value.open();
|
|
}
|
|
|
|
const yes = await inputDialog.value.confirm({
|
|
title: t('email.disableEmailDialog.title', { domain: domain.value }),
|
|
message: t('email.disableEmailDialog.description', { domain: domain.value }),
|
|
confirmStyle: 'danger',
|
|
confirmLabel: t('email.disableEmailDialog.disableAction'),
|
|
rejectLabel: t('main.dialog.cancel'),
|
|
rejectStyle: 'secondary',
|
|
});
|
|
|
|
// reset switch
|
|
if (!yes) return incomingEnabled.value = true;
|
|
|
|
const [error] = await mailModel.setEnabled(domain.value, false);
|
|
if (error) return console.error(error);
|
|
|
|
await refreshMailConfig();
|
|
}
|
|
|
|
async function onEnableIncoming() {
|
|
enableIncomeBusy.value = true;
|
|
|
|
const [error] = await mailModel.setEnabled(domain.value, true);
|
|
if (error) return console.error(error);
|
|
|
|
// TODO this has to be done in the backend here! reconfigureEmailApps();
|
|
|
|
if (enableIncomingSetupDns.value) {
|
|
const [error] = await domainsModel.setDnsRecords({ domain: domain.value, type: 'mail' });
|
|
if (error) console.error(error);
|
|
}
|
|
|
|
await refreshMailConfig();
|
|
|
|
enableIncomingDialog.value.close();
|
|
enableIncomeBusy.value = false;
|
|
}
|
|
|
|
|
|
const mailFromValidation = ref(false);
|
|
const mailFromValidationBusy = ref(false);
|
|
|
|
async function onToggleMailFromValidation(value) {
|
|
mailFromValidationBusy.value = true;
|
|
|
|
const [error] = await mailModel.setMailFromValidation(domain.value, value);
|
|
if (error) {
|
|
mailFromValidation.value = !value;
|
|
mailFromValidationBusy.value = false;
|
|
return console.error(error);
|
|
}
|
|
|
|
mailFromValidationBusy.value = false;
|
|
}
|
|
|
|
|
|
const signatureDialog = useTemplateRef('signatureDialog');
|
|
const signatureBusy = ref(false);
|
|
const signatureText = ref('');
|
|
const signatureHtml = ref('');
|
|
|
|
function onShowSignatureDialog() {
|
|
signatureBusy.value = false;
|
|
signatureDialog.value.open();
|
|
}
|
|
|
|
async function onSubmitSignature() {
|
|
signatureBusy.value = true;
|
|
|
|
const [error] = await mailModel.setMailBanner(domain.value, signatureText.value, signatureHtml.value);
|
|
if (error) return console.error(error);
|
|
|
|
signatureDialog.value.close();
|
|
signatureBusy.value = false;
|
|
}
|
|
|
|
|
|
async function refreshMailConfig() {
|
|
refreshBusy.value = true;
|
|
|
|
const [error, result] = await mailModel.config(domain.value);
|
|
if (error) return console.error(error);
|
|
|
|
mailConfig.value = result;
|
|
incomingEnabled.value = result.enabled;
|
|
mailFromValidation.value = result.mailFromValidation;
|
|
signatureText.value = mailConfig.value.banner.text || '';
|
|
signatureHtml.value = mailConfig.value.banner.html || '';
|
|
|
|
infoMenu.value = [{
|
|
label: t('app.docsAction'),
|
|
// TODO support real href links
|
|
action: () => { window.open('https://docs.cloudron.io/email/'); }
|
|
}, {
|
|
label: t('email.config.clientConfiguration'),
|
|
disabled: !mailConfig.value.enabled,
|
|
action: onShowConnectionDialog
|
|
}];
|
|
|
|
refreshBusy.value = false;
|
|
}
|
|
|
|
onMounted(async () => {
|
|
domain.value = window.location.hash.slice('#/email/'.length);
|
|
if (!domain.value) return;
|
|
|
|
let [error, result] = await domainsModel.get(domain.value);
|
|
if (error) return console.error(error);
|
|
|
|
domainProvider.value = result.provider;
|
|
|
|
[error, result] = await dashboardModel.config();
|
|
if (error) return console.error(error);
|
|
|
|
mailFqdn.value = result.mailFqdn;
|
|
|
|
await refreshMailConfig();
|
|
});
|
|
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<InputDialog ref="inputDialog"/>
|
|
|
|
<Dialog ref="connectionDialog"
|
|
:title="$t('email.howToConnectInfoModal')"
|
|
:reject-label="$t('main.dialog.close')"
|
|
>
|
|
<div>
|
|
<p v-html="$t('email.incoming.howToConnectDescription', { domain: domain })"></p>
|
|
|
|
<p><b>{{ $t('email.incoming.incomingUserInfo') }}</b><br/><i>mailboxname</i>@{{ domain }}</p>
|
|
<p><b>{{ $t('email.incoming.incomingPasswordInfo') }}</b><br/>{{ $t('email.incoming.incomingPasswordUsage') }}</p>
|
|
<p><b>{{ $t('email.incoming.incomingServerInfo') }}</b><br/>{{ $t('email.incoming.server') }}: <span>{{ mailFqdn }}</span><br/>{{ $t('email.incoming.port') }}: 993 (TLS)</p>
|
|
<p><b>{{ $t('email.incoming.outgointServerInfo') }}</b><br/>{{ $t('email.incoming.server') }}: <span>{{ mailFqdn }}</span><br/>{{ $t('email.incoming.port') }}: 587 (STARTTLS) or 465 (TLS)</p>
|
|
<p><b>{{ $t('email.incoming.sieveServerInfo') }}</b><br/>{{ $t('email.incoming.server') }}: <span>{{ mailFqdn }}</span><br/>{{ $t('email.incoming.port') }}: 4190 (STARTTLS)</p>
|
|
</div>
|
|
</Dialog>
|
|
|
|
<Dialog ref="enableIncomingDialog"
|
|
:title="$t('email.enableEmailDialog.title', { domain: domain })"
|
|
:confirm-label="$t('email.enableEmailDialog.enableAction')"
|
|
:confirm-busy="enableIncomeBusy"
|
|
:reject-label="enableIncomeBusy ? '' : $t('main.dialog.cancel')"
|
|
reject-style="secondary"
|
|
@confirm="onEnableIncoming()"
|
|
@reject="incomingEnabled = false"
|
|
>
|
|
<div>
|
|
<p v-html="$t('email.enableEmailDialog.description', { domain: domain, requiredPortsDocsLink: 'https://docs.cloudron.io/email/#required-ports' })"></p>
|
|
<!-- TODO <p class="text-danger" v-if="adminDomain.provider === 'cloudflare'" v-html="$t('email.enableEmailDialog.cloudflareInfo', { adminDomain: config.adminDomain, mailFqdn: config.mailFqdn })"></p> -->
|
|
<div v-if="domainProvider === 'noop' || domainProvider === 'manual'" v-html="$t('email.enableEmailDialog.noProviderInfo')"></div>
|
|
<div v-else>
|
|
<Checkbox v-model="enableIncomingSetupDns" :label="$t('email.enableEmailDialog.setupDnsCheckbox')"/>
|
|
<div v-html="$t('email.enableEmailDialog.setupDnsInfo', { importEmailDocsLink: 'https://docs.cloudron.io/guides/import-email' })"></div>
|
|
</div>
|
|
</div>
|
|
</Dialog>
|
|
|
|
<Dialog ref="signatureDialog"
|
|
:title="$t('email.signature.title')"
|
|
:confirm-label="$t('main.dialog.save')"
|
|
:confirm-busy="signatureBusy"
|
|
:reject-label="signatureBusy ? '' : $t('main.dialog.cancel')"
|
|
reject-style="secondary"
|
|
@confirm="onSubmitSignature()"
|
|
>
|
|
<div>
|
|
<form @submit.prevent="onSubmitSignature()" autocomplete="off">
|
|
<fieldset :disabled="signatureBusy">
|
|
<input type="submit" style="display: none"/>
|
|
|
|
<FormGroup>
|
|
<label for="sinatureTextInput">{{ $t('email.signature.plainTextFormat') }}</label>
|
|
<textarea id="sinatureTextInput" v-model="signatureText" rows="4"></textarea>
|
|
</FormGroup>
|
|
|
|
<FormGroup>
|
|
<label class="sinatureHtmlInput">{{ $t('email.signature.htmlFormat') }}</label>
|
|
<textarea id="sinatureHtmlInput" v-model="signatureHtml" rows="4"></textarea>
|
|
</FormGroup>
|
|
|
|
</fieldset>
|
|
</form>
|
|
</div>
|
|
</Dialog>
|
|
|
|
<h1 style="display: flex; justify-content: space-between; padding-right: 20px">
|
|
{{ $t('email.config.title', { domain: domain }) }}
|
|
<Button secondary tool icon="fa-solid fa-book" v-tooltip="$t('app.docsActionTooltip')" :menu="infoMenu" />
|
|
</h1>
|
|
|
|
<!-- v-if here ensures the prop is already set when passed down to MailDomainStatus -->
|
|
<MailDomainStatus v-if="domain" :domain="domain"/>
|
|
|
|
<Section :title="$t('emails.settings.title')">
|
|
<SettingsItem>
|
|
<FormGroup>
|
|
<label>{{ $t('email.incoming.title') }}</label>
|
|
<div>{{ $t(mailConfig.enabled ? 'email.incoming.enabled' : 'email.incoming.disabled') }}</div>
|
|
</FormGroup>
|
|
<Switch v-model="incomingEnabled" :disabled="refreshBusy" @change="onAskIncomingToggle"/>
|
|
</SettingsItem>
|
|
|
|
<MailRelaySettingsItem v-if="domain" :domain="domain"/>
|
|
|
|
<SettingsItem>
|
|
<FormGroup>
|
|
<label>{{ $t('email.masquerading.title') }}</label>
|
|
<div v-html="$t('email.masquerading.description')"></div>
|
|
</FormGroup>
|
|
<Switch v-model="mailFromValidation" @change="onToggleMailFromValidation" :disabled="mailFromValidationBusy"/>
|
|
</SettingsItem>
|
|
|
|
<CatchAllSettingsItem :domain-config="mailConfig" />
|
|
|
|
<SettingsItem>
|
|
<FormGroup>
|
|
<label>{{ $t('email.signature.title') }}</label>
|
|
<div v-html="$t('email.signature.description')"></div>
|
|
</FormGroup>
|
|
<div style="display: flex; align-items: center">
|
|
<!-- TODO translate -->
|
|
<Button tool plain @click="onShowSignatureDialog()">Edit</Button>
|
|
</div>
|
|
</SettingsItem>
|
|
</Section>
|
|
</div>
|
|
</template>
|