56 lines
2.0 KiB
TypeScript
56 lines
2.0 KiB
TypeScript
import { execQueryAsyncWithId, execQueryAsync, execQuery } from "../db";
|
|
|
|
export async function getAllAccounts() {
|
|
const query = `
|
|
SELECT
|
|
app_account.account_id AS id,
|
|
address.email AS user,
|
|
app_account.account_pwd AS password,
|
|
app_account.imap_host,
|
|
app_account.imap_port,
|
|
app_account.smtp_host,
|
|
app_account.smtp_port,
|
|
app_account.tls
|
|
FROM app_account INNER JOIN address
|
|
WHERE address.address_id = app_account.user_id
|
|
`;
|
|
const values = [];
|
|
return await execQueryAsync(query, values);
|
|
}
|
|
|
|
export async function getAllMailboxes(accountId: number) {
|
|
const query = "SELECT * FROM mailbox WHERE mailbox.account_id = ?";
|
|
const values = [accountId];
|
|
return await execQueryAsync(query, values);
|
|
}
|
|
|
|
export async function registerMailbox(accountId: number, mailboxName: string) {
|
|
const query = `INSERT INTO mailbox (account_id, mailbox_name) VALUES (?, ?)`;
|
|
const values = [accountId, mailboxName];
|
|
return await execQueryAsyncWithId(query, values);
|
|
}
|
|
|
|
export async function getMailbox(mailboxId: number) {
|
|
const query = `SELECT * FROM mailbox WHERE mailbox_id = ?`;
|
|
const values = [mailboxId];
|
|
return await execQueryAsync(query, values);
|
|
}
|
|
|
|
export function updateMailbox(mailboxId: number, uidnext: number) {
|
|
const query = `UPDATE mailbox SET uidnext = ? WHERE mailbox_id = ?`;
|
|
const values = [uidnext, mailboxId];
|
|
execQuery(query, values);
|
|
}
|
|
|
|
export async function updateMailboxModseq(mailboxId: number, modseq: number) {
|
|
const query = `UPDATE mailbox SET nextmodseq = ? WHERE mailbox_id = ?`;
|
|
const values = [modseq, mailboxId];
|
|
return await execQueryAsync(query, values);
|
|
}
|
|
|
|
export async function getMailboxModseq(mailboxId: number): Promise<{ modseq: number }[]> {
|
|
const query = `SELECT nextmodseq AS modseq FROM mailbox WHERE mailbox_id = ?`;
|
|
const values = [mailboxId];
|
|
return await execQueryAsync(query, values);
|
|
}
|