Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
7af969617e
commit
f905abb05b
@@ -41,6 +41,7 @@ export const Route = createFileRoute("/hooks/poll-imap")({
|
||||
let imported = 0;
|
||||
let highestUid = settings.last_uid ?? 0;
|
||||
let errorMessage: string | null = null;
|
||||
const newEmailIds: string[] = [];
|
||||
|
||||
try {
|
||||
await client.connect();
|
||||
@@ -191,7 +192,24 @@ export const Route = createFileRoute("/hooks/poll-imap")({
|
||||
if (errorMessage) {
|
||||
return json({ ok: false, imported, error: errorMessage }, 500);
|
||||
}
|
||||
return json({ ok: true, imported, last_uid: highestUid });
|
||||
|
||||
// Run case-matching on freshly imported emails.
|
||||
let matchStats = { matched: 0, suggested: 0, unmatched: 0 };
|
||||
if (newEmailIds.length > 0) {
|
||||
try {
|
||||
matchStats = await matchAndUpdateEmails(newEmailIds);
|
||||
} catch (e) {
|
||||
console.error("Case matching failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
return json({
|
||||
ok: true,
|
||||
imported,
|
||||
last_uid: highestUid,
|
||||
matched: matchStats.matched,
|
||||
suggested: matchStats.suggested,
|
||||
});
|
||||
} catch (e) {
|
||||
const message = e instanceof Error ? e.message : String(e);
|
||||
console.error("poll-imap fatal", message);
|
||||
|
||||
Reference in New Issue
Block a user