feat(mail-ingest): read forwarded booking mails and add what passes the checks to its trip

Addresses per person and per trip (random base32 token, stored hashed and
encrypted), an intake every transport shares, and a job that reads each
mail once under a lease: filters without AI, machine-readable data always,
one AI request with the person's trips, the server's checks G1 to G9, then
one transaction per mail that adds what passed, keeps the rest in the inbox
with a reason, and notifies the forwarder and co-travellers. Undo within
7 days, manual apply, filing as documents, a prefilled form and a nightly
retention complete it; on a managed install the operator's switch decides.
This commit is contained in:
Maurice
2026-11-13 16:04:26 +01:00
parent 340454cfc7
commit de7de4b8de
36 changed files with 4038 additions and 54 deletions
@@ -1,6 +1,6 @@
import { readEnv } from '../../app-config';
import type { AppSettingsRepository } from '../../db/repositories/AppSettings.repository';
import { aiPolicySchema } from '@trek/shared';
import { aiPolicySchema, mailIngestTransportSettingSchema } from '@trek/shared';
import { z } from 'zod';
@@ -161,6 +161,15 @@ export const APP_SETTINGS = {
synology_capture_repair_3019: { schema: text, default: null },
/** How many starts have tried that so far, while some photo could not be confirmed. */
synology_capture_repair_3019_tries: { schema: intText, default: null },
// The booking mail import (mail-ingest). Off until switched on: on a self-hosted install by its
// admin, on a managed one by the operator, for the plans that include it and never for Start.
mail_ingest_enabled: { schema: flag, default: 'false' },
/** How mail reaches the install: not at all (uploads only), IMAP, a signed webhook, or the TREK Cloud relay. */
mail_ingest_transport: { schema: mailIngestTransportSettingSchema, default: 'off' },
/** The forwarding address, `{token}` standing where a person's token goes: `trek+{token}@example.com`. */
mail_ingest_address_template: { schema: text, default: null },
/** How many forwarded mails a day an AI reads for one person. */
mail_ingest_ai_per_user_daily: { schema: intText, default: '10' },
} as const satisfies Record<string, AppSettingDef>;
export type AppSettingKey = keyof typeof APP_SETTINGS;