( payload: any )
| 187 | |
| 188 | // Helper function to extract attachment information from message payload |
| 189 | export function extractAttachmentInfo( |
| 190 | payload: any |
| 191 | ): Array<{ attachmentId: string; filename: string; mimeType: string; size: number }> { |
| 192 | const attachments: Array<{ |
| 193 | attachmentId: string |
| 194 | filename: string |
| 195 | mimeType: string |
| 196 | size: number |
| 197 | }> = [] |
| 198 | |
| 199 | function processPayloadPart(part: any) { |
| 200 | // Check if this part has an attachment |
| 201 | if (part.body?.attachmentId && part.filename) { |
| 202 | attachments.push({ |
| 203 | attachmentId: part.body.attachmentId, |
| 204 | filename: part.filename, |
| 205 | mimeType: part.mimeType || 'application/octet-stream', |
| 206 | size: part.body.size || 0, |
| 207 | }) |
| 208 | } |
| 209 | |
| 210 | // Recursively process nested parts |
| 211 | if (part.parts && Array.isArray(part.parts)) { |
| 212 | part.parts.forEach(processPayloadPart) |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | // Process the main payload |
| 217 | processPayloadPart(payload) |
| 218 | |
| 219 | return attachments |
| 220 | } |
| 221 | |
| 222 | // Helper function to download attachments from Gmail API |
| 223 | export async function downloadAttachments( |
no test coverage detected