From 115303ac07ddea375c4a8dafd7cfd74ab1f99943 Mon Sep 17 00:00:00 2001 From: Yuri Yaryshev Date: Mon, 23 Nov 2026 16:41:33 +0300 Subject: [PATCH] =?UTF-8?q?accounting=5Fautomation:=20=D0=BE=D0=BF=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20gmailIncludeSpam=20(=D0=BF=D0=B8=D1=81=D1=8C?= =?UTF-8?q?=D0=BC=D0=B0=20=D0=BF=D0=BE=D0=B4=D1=80=D1=8F=D0=B4=D1=87=D0=B8?= =?UTF-8?q?=D0=BA=D0=BE=D0=B2=20=D0=B2=20=D1=81=D0=BF=D0=B0=D0=BC=D0=B5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5.5 --- packages/accounting_automation/src/gmail.ts | 3 +++ packages/accounting_automation/src/main.ts | 1 + packages/accounting_automation/src/settings.ts | 2 ++ 3 files changed, 6 insertions(+) diff --git a/packages/accounting_automation/src/gmail.ts b/packages/accounting_automation/src/gmail.ts index ab5fa5f..ea97f4a 100644 --- a/packages/accounting_automation/src/gmail.ts +++ b/packages/accounting_automation/src/gmail.ts @@ -68,6 +68,8 @@ export class GmailClient implements MailSource { processedIds: (ids: string[]) => Promise>; fetchFn?: FetchFn; query?: string; + /** Искать и в папке «Спам» (письма подрядчиков иногда попадают туда). */ + includeSpam?: boolean; }, ) {} @@ -85,6 +87,7 @@ export class GmailClient implements MailSource { let pageToken: string | undefined; do { const params: Record = { q: this.o.query ?? "has:attachment filename:pdf", maxResults: "50" }; + if (this.o.includeSpam) params.includeSpamTrash = "true"; if (pageToken) params.pageToken = pageToken; const list = await this.get<{ messages?: { id: string }[]; nextPageToken?: string }>("/messages", params); const ids = (list.messages ?? []).map((x) => x.id); diff --git a/packages/accounting_automation/src/main.ts b/packages/accounting_automation/src/main.ts index 36cfb27..762c927 100644 --- a/packages/accounting_automation/src/main.ts +++ b/packages/accounting_automation/src/main.ts @@ -65,6 +65,7 @@ const app = buildApi({ auth, user: s.google.gmailUser, query: s.google.gmailQuery, + includeSpam: s.google.gmailIncludeSpam, processedIds: async (ids) => { const { rows } = await pool.query("select message_id from acc_mail_processed where message_id = any($1) and result <> 'error'", [ids]); return new Set(rows.map((r) => r.message_id as string)); diff --git a/packages/accounting_automation/src/settings.ts b/packages/accounting_automation/src/settings.ts index 695108d..5041036 100644 --- a/packages/accounting_automation/src/settings.ts +++ b/packages/accounting_automation/src/settings.ts @@ -30,6 +30,8 @@ export const accountingSchema = z.object({ /** Ящик пользователя, который читаем (делегирование домена; группа invoice@ доставляет письма в ящик участника agents@). */ gmailUser: z.string().default("agents@khbuild.pro"), /** Поиск писем в ящике: только письма, пришедшие на группу invoice@ (или алиас invoices@), с PDF. */ + /** Искать письма и в «Спаме» (Gmail при этом захватывает и корзину). */ + gmailIncludeSpam: z.boolean().default(false), gmailQuery: z.string().default("has:attachment filename:pdf (to:invoice@khbuild.pro OR cc:invoice@khbuild.pro OR to:invoices@khbuild.pro OR cc:invoices@khbuild.pro)"), /** Корневая папка Google Drive для инвойсов, чеков и т.д. (подпапки создаются сервисом). */ rootFolderId: z.string().optional(),