From 36b8517df852b09f37fc2914185dddbba46e2ef7 Mon Sep 17 00:00:00 2001 From: Shahidh K Muhammed Date: Sun, 27 Oct 2024 21:37:11 -0700 Subject: [PATCH] Update gmail.ts to support parsed date --- ndc-duckduckapi/src/services/gmail.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/ndc-duckduckapi/src/services/gmail.ts b/ndc-duckduckapi/src/services/gmail.ts index d5e3ffe..7e24007 100644 --- a/ndc-duckduckapi/src/services/gmail.ts +++ b/ndc-duckduckapi/src/services/gmail.ts @@ -42,15 +42,15 @@ CREATE TABLE IF NOT EXISTS gmail_messages ( message_id VARCHAR, subject VARCHAR, from_address VARCHAR, - to_addresses JSON, - cc_addresses JSON, - bcc_addresses JSON, - date VARCHAR, + to_addresses TEXT, + cc_addresses TEXT, + bcc_addresses TEXT, + date TIMESTAMP WITH TIME ZONE, body_plain TEXT, body_html TEXT, attachment_count INTEGER, - attachments JSON, - headers JSON, + attachments TEXT, + headers TEXT, sync_status VARCHAR, last_synced TIMESTAMP WITH TIME ZONE, is_draft BOOLEAN, @@ -385,7 +385,11 @@ export class SyncManager { const to = headers.find(h => h.name?.toLowerCase() === 'to')?.value; const cc = headers.find(h => h.name?.toLowerCase() === 'cc')?.value; const bcc = headers.find(h => h.name?.toLowerCase() === 'bcc')?.value; - const date = headers.find(h => h.name?.toLowerCase() === 'date')?.value; + const headerDate = headers.find(h => h.name?.toLowerCase() === 'date')?.value; + let date: string | null = null; + if (headerDate) { + date = new Date(headerDate).toISOString(); + } const labelIds = message.labelIds || []; const attachments = this.extractAttachments(message.payload); @@ -658,3 +662,4 @@ last_synced: new Date().toISOString(), await db.close(); } } +