old_invoices: сопоставление проектов и вендоров, md-отчёт; pay_method (080); spam-rescue: сравнение без регистра и диакритики, исправлен json в белом списке
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -37,8 +37,11 @@ export function senderEmail(from: string): string {
|
||||
}
|
||||
|
||||
/** Слово для сравнения: имя без формы собственности, не короче 4 символов. */
|
||||
/** Приведение к сравнимому виду: без регистра и диакритики, «&» = «and» («Floor & Decor» = «Floor and Décor»). */
|
||||
export const fold = (s: string): string => s.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/&/g, " and ");
|
||||
|
||||
export function normalizeTerm(name: string): string | null {
|
||||
const t = name.toLowerCase().replace(COMPANY_SUFFIX, " ").replace(/[^a-z0-9а-яё&.\- ]+/g, " ").replace(/\s+/g, " ").trim();
|
||||
const t = fold(name).replace(COMPANY_SUFFIX, " ").replace(/[^a-z0-9а-яё&.\- ]+/g, " ").replace(/\s+/g, " ").trim();
|
||||
return t.length >= 4 ? t : null;
|
||||
}
|
||||
|
||||
@@ -55,7 +58,7 @@ export function decide(mail: SpamMail, rules: RescueRules): RescueDecision {
|
||||
const sender = senderEmail(mail.from);
|
||||
if (rules.whitelist.has(sender)) return { rescue: true, reason: `белый список: ${sender}` };
|
||||
if (!/\binvoices?@khbuild\.pro\b/i.test(mail.recipients)) return { rescue: false, reason: "не на invoice@" };
|
||||
const hay = `${mail.from} ${mail.subject} ${mail.snippet}`.toLowerCase();
|
||||
const hay = fold(`${mail.from} ${mail.subject} ${mail.snippet}`).replace(/\s+/g, " ");
|
||||
for (const n of rules.projectNumbers) if (new RegExp(`(^|[^0-9])${n}([^0-9]|$)`).test(hay)) return { rescue: true, reason: `проект ${n}` };
|
||||
for (const t of rules.terms) if (hay.includes(t)) return { rescue: true, reason: `слово «${t}»` };
|
||||
return { rescue: false, reason: "нет слов из списка" };
|
||||
@@ -163,7 +166,7 @@ class Mailbox {
|
||||
async function learnWhitelist(o: RescueOptions, src: Mailbox, res: RescueResult): Promise<void> {
|
||||
const { rows } = await o.pool.query<{ source_message_id: string; decided_by: string | null }>(
|
||||
`select distinct on (source_message_id) source_message_id, decided_by from acc_invoices
|
||||
where source_message_id is not null and coalesce(conclusion,'') !~* '(reject|отклон)' order by source_message_id, created_at`,
|
||||
where source_message_id is not null and coalesce(conclusion::text,'') !~* '(reject|отклон)' order by source_message_id, created_at`,
|
||||
);
|
||||
for (const r of rows) {
|
||||
let from: string;
|
||||
|
||||
Reference in New Issue
Block a user