From 04de49aad539473e6c3e55e82aac4bb6d46eeb48 Mon Sep 17 00:00:00 2001 From: alma Date: Fri, 16 Jan 2026 22:48:55 +0100 Subject: [PATCH] Fondation --- lib/services/email-service.ts | 12 ++++++------ lib/services/microsoft-graph-mail.ts | 23 ++++++++--------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/lib/services/email-service.ts b/lib/services/email-service.ts index 6a73729..c7afc85 100644 --- a/lib/services/email-service.ts +++ b/lib/services/email-service.ts @@ -955,9 +955,9 @@ export async function getEmails( if (graphCheck.useGraph && graphCheck.mailCredentialId) { // Use Microsoft Graph API logger.debug('[EMAIL] Using Microsoft Graph API', { - userId, + userIdHash: Buffer.from(userId).toString('base64').slice(0, 12), folder, - mailCredentialId: graphCheck.mailCredentialId, + mailCredentialIdHash: graphCheck.mailCredentialId ? Buffer.from(graphCheck.mailCredentialId).toString('base64').slice(0, 12) : null, }); try { @@ -1141,7 +1141,7 @@ export async function getEmails( const end = Math.max(1, totalEmails - ((page - 1) * perPage)); logger.debug('[EMAIL] Fetching messages range', { folder, - accountId: resolvedAccountId, + accountIdHash: Buffer.from(resolvedAccountId).toString('base64').slice(0, 12), start, end, }); @@ -1763,8 +1763,8 @@ export async function sendEmail( if (graphCheck.useGraph && graphCheck.mailCredentialId) { // Use Microsoft Graph API to send email logger.debug('[EMAIL] Sending email via Microsoft Graph API', { - userId, - mailCredentialId: graphCheck.mailCredentialId, + userIdHash: Buffer.from(userId).toString('base64').slice(0, 12), + mailCredentialIdHash: graphCheck.mailCredentialId ? Buffer.from(graphCheck.mailCredentialId).toString('base64').slice(0, 12) : null, }); try { @@ -1788,7 +1788,7 @@ export async function sendEmail( }; } catch (error) { logger.error('[EMAIL] Error sending email via Graph API', { - userId, + userIdHash: Buffer.from(userId).toString('base64').slice(0, 12), error: error instanceof Error ? error.message : String(error), }); return { diff --git a/lib/services/microsoft-graph-mail.ts b/lib/services/microsoft-graph-mail.ts index 51d5972..c1976b3 100644 --- a/lib/services/microsoft-graph-mail.ts +++ b/lib/services/microsoft-graph-mail.ts @@ -143,19 +143,16 @@ export async function fetchGraphEmails( url += `?${params.toString()}`; logger.debug('Fetching emails from Microsoft Graph API', { - mailCredentialId, - folderId, + mailCredentialIdHash: Buffer.from(mailCredentialId).toString('base64').slice(0, 12), top, skip, skipToken: skipToken ? 'present' : 'none', - url, }); const response = await client.get(url); logger.debug('Microsoft Graph API response', { - mailCredentialId, - folderId, + mailCredentialIdHash: Buffer.from(mailCredentialId).toString('base64').slice(0, 12), emailCount: response.data?.value?.length || 0, hasNextLink: !!response.data?.['@odata.nextLink'], }); @@ -163,8 +160,7 @@ export async function fetchGraphEmails( return response.data; } catch (error: any) { logger.error('Error fetching emails from Microsoft Graph', { - mailCredentialId, - folderId, + mailCredentialIdHash: Buffer.from(mailCredentialId).toString('base64').slice(0, 12), error: error instanceof Error ? error.message : String(error), status: error.response?.status, statusText: error.response?.statusText, @@ -198,8 +194,7 @@ export async function fetchGraphEmail( return response.data; } catch (error: any) { logger.error('Error fetching email from Microsoft Graph', { - mailCredentialId, - messageId, + mailCredentialIdHash: Buffer.from(mailCredentialId).toString('base64').slice(0, 12), error: error instanceof Error ? error.message : String(error), }); @@ -230,7 +225,7 @@ export async function fetchGraphMailFolders( return response.data.value || []; } catch (error: any) { logger.error('Error fetching mail folders from Microsoft Graph', { - mailCredentialId, + mailCredentialIdHash: Buffer.from(mailCredentialId).toString('base64').slice(0, 12), error: error instanceof Error ? error.message : String(error), }); @@ -317,7 +312,7 @@ export async function sendGraphEmail( return { id: draftId }; } catch (error: any) { logger.error('Error sending email via Microsoft Graph', { - mailCredentialId, + mailCredentialIdHash: Buffer.from(mailCredentialId).toString('base64').slice(0, 12), error: error instanceof Error ? error.message : String(error), status: error.response?.status, statusText: error.response?.statusText, @@ -347,8 +342,7 @@ export async function markGraphEmailAsRead( }); } catch (error: any) { logger.error('Error marking email as read via Microsoft Graph', { - mailCredentialId, - messageId, + mailCredentialIdHash: Buffer.from(mailCredentialId).toString('base64').slice(0, 12), isRead, error: error instanceof Error ? error.message : String(error), }); @@ -376,8 +370,7 @@ export async function getGraphUnreadCount( return response.data.unreadItemCount || 0; } catch (error: any) { logger.error('Error getting unread count from Microsoft Graph', { - mailCredentialId, - folderId, + mailCredentialIdHash: Buffer.from(mailCredentialId).toString('base64').slice(0, 12), error: error instanceof Error ? error.message : String(error), });