diff --git a/apps/web/utils/get-email-from-message.ts b/apps/web/utils/get-email-from-message.ts index 68c59f1991..498cad4cbb 100644 --- a/apps/web/utils/get-email-from-message.ts +++ b/apps/web/utils/get-email-from-message.ts @@ -15,5 +15,10 @@ export function getEmailForLLM( subject: message.headers.subject, content: emailToContent(message, contentOptions), date: internalDateToDate(message.internalDate), + attachments: message.attachments?.map((attachment) => ({ + filename: attachment.filename, + mimeType: attachment.mimeType, + size: attachment.size, + })), }; } diff --git a/apps/web/utils/stringify-email.ts b/apps/web/utils/stringify-email.ts index 4d05990bde..75b924fd20 100644 --- a/apps/web/utils/stringify-email.ts +++ b/apps/web/utils/stringify-email.ts @@ -13,6 +13,16 @@ export function stringifyEmail(email: EmailForLLM, maxLength: number) { `${truncate(removeExcessiveWhitespace(email.content), maxLength)}`, ]; + if (email.attachments && email.attachments.length > 0) { + const attachmentsXml = email.attachments + .map( + (att) => + ``, + ) + .join("\n"); + emailParts.push(`\n${attachmentsXml}\n`); + } + return emailParts.filter(Boolean).join("\n"); } diff --git a/apps/web/utils/types.ts b/apps/web/utils/types.ts index 0e8f716785..39ff9dd149 100644 --- a/apps/web/utils/types.ts +++ b/apps/web/utils/types.ts @@ -113,4 +113,9 @@ export type EmailForLLM = { subject: string; content: string; date?: Date; + attachments?: Array<{ + filename: string; + mimeType: string; + size: number; + }>; };