aero-mail/src/main/workers/retention-worker.ts
r.rasputin 69a3c74187 Ограничение количества сообщений в папке
Позволяет задать для папки (рекурсивно — с наследованием вложенными)
лимит хранимых сообщений: старые письма сверх лимита удаляются.
Проверка тикает в отдельном worker-потоке main-процесса с частотой
автопроверки почты, само удаление выполняет main через IMAP.
2026-07-30 12:53:57 +07:00

28 lines
1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { parentPort } from 'node:worker_threads'
// Отдельный поток: только тикающий таймер, никакой работы с IMAP здесь не делаем —
// imapflow-соединения и расшифрованные credentials живут в main-потоке (AccountManager),
// worker_threads не имеют доступа к Electron API (safeStorage и т.п.), поэтому реальная
// очистка выполняется в RetentionService по сигналу тика.
type WorkerMessage =
| { type: 'setInterval'; intervalMinutes: number }
let timer: ReturnType<typeof setInterval> | null = null
function applyInterval(intervalMinutes: number): void {
if (timer) {
clearInterval(timer)
timer = null
}
if (intervalMinutes > 0) {
timer = setInterval(() => {
parentPort?.postMessage({ type: 'tick' })
}, intervalMinutes * 60_000)
}
}
parentPort?.on('message', (msg: WorkerMessage) => {
if (msg.type === 'setInterval') {
applyInterval(msg.intervalMinutes)
}
})