2025-03-07 19:47:58 +01:00
|
|
|
|
|
|
|
|
import { fetcher } from 'pankow';
|
|
|
|
|
import { API_ORIGIN } from '../constants.js';
|
|
|
|
|
|
|
|
|
|
function create() {
|
|
|
|
|
const accessToken = localStorage.token;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
async config(domain) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/mail/${domain}`, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null, result.body];
|
|
|
|
|
},
|
|
|
|
|
async status(domain) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/mail/${domain}/status`, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null, result.body];
|
|
|
|
|
},
|
|
|
|
|
async mailboxCount(domain) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/mail/${domain}/mailbox_count`, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null, result.body.count];
|
|
|
|
|
},
|
2025-03-11 12:38:54 +01:00
|
|
|
async setCatchallAddresses(domain, addresses) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/mail/${domain}/catch_all`, { addresses }, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 202) return [result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
2025-03-11 12:50:05 +01:00
|
|
|
async setMailFromValidation(domain, enabled) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/mail/${domain}/mail_from_validation`, { enabled }, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 202) return [result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
2025-03-11 13:13:02 +01:00
|
|
|
async setMailBanner(domain, text, html) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/mail/${domain}/banner`, { text, html }, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 202) return [result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
2025-03-10 21:06:33 +01:00
|
|
|
async setEnabled(domain, enabled) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/mail/${domain}/enable`, { enabled }, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 202) return [result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
2025-03-07 19:47:58 +01:00
|
|
|
async usage(domain) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/mailserver/usage`, { domain, access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null, result.body.usage];
|
|
|
|
|
},
|
|
|
|
|
async location() {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/mailserver/location`, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null, result.body];
|
|
|
|
|
},
|
|
|
|
|
async setLocation(subdomain, domain) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/mailserver/location`, { subdomain, domain }, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 202) return [result];
|
|
|
|
|
return [null, result.body.taskId];
|
|
|
|
|
},
|
|
|
|
|
async maxEmailSize() {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/mailserver/max_email_size`, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null, result.body.size];
|
|
|
|
|
},
|
|
|
|
|
async setMaxEmailSize(size) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/mailserver/max_email_size`, { size }, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
|
|
|
|
async mailboxSharing() {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/mailserver/mailbox_sharing`, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null, result.body.enabled];
|
|
|
|
|
},
|
|
|
|
|
async setMailboxSharing(enable) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/mailserver/mailbox_sharing`, { enable }, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
|
|
|
|
async virtualAllMail() {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/mailserver/virtual_all_mail`, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null, result.body.enabled];
|
|
|
|
|
},
|
|
|
|
|
async setVirtualAllMail(enable) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/mailserver/virtual_all_mail`, { enable }, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
|
|
|
|
async dnsblConfig() {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/mailserver/dnsbl_config`, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null, result.body.zones];
|
|
|
|
|
},
|
|
|
|
|
async setDnsblConfig(zones) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/mailserver/dnsbl_config`, { zones }, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
|
|
|
|
async ftsConfig() {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/mailserver/fts_config`, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null, result.body];
|
|
|
|
|
},
|
|
|
|
|
async setFtsConfig(enable) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/mailserver/fts_config`, { enable }, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
|
|
|
|
async spamAcl() {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/mailserver/spam_acl`, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null, result.body];
|
|
|
|
|
},
|
|
|
|
|
async setSpamAcl(allowlist, blocklist) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/mailserver/spam_acl`, { allowlist, blocklist }, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
|
|
|
|
async spamCustomConfig() {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/mailserver/spam_custom_config`, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null, result.body.config];
|
|
|
|
|
},
|
|
|
|
|
async setSpamCustomConfig(config) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/mailserver/spam_custom_config`, { config }, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
2025-03-09 20:27:41 +01:00
|
|
|
async sendTestMail(domain, mailToAddress) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/mail/${domain}/send_test_mail`, { to: mailToAddress }, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 202) return [result];
|
|
|
|
|
return [null];
|
2025-03-10 16:16:04 +01:00
|
|
|
},
|
|
|
|
|
async eventlog(types, search, page, perPage) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/mailserver/eventlog`, { page, types, per_page: perPage, search, access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 200) return [result];
|
|
|
|
|
return [null, result.body.eventlogs];
|
|
|
|
|
},
|
2025-03-12 15:05:46 +01:00
|
|
|
async setMailRelay(domain, data) {
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/mail/${domain}/relay`, data, { access_token: accessToken });
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return [e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.status !== 202) return [result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
2025-03-07 19:47:58 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
create,
|
|
|
|
|
};
|