MCPcopy Index your code
hub / github.com/simstudioai/sim / processOutlookEmails

Function processOutlookEmails

apps/sim/lib/webhooks/polling/outlook.ts:379–486  ·  view source on GitHub ↗
(
  emails: OutlookEmail[],
  webhookData: PollWebhookContext['webhookData'],
  workflowData: PollWebhookContext['workflowData'],
  config: OutlookWebhookConfig,
  accessToken: string,
  requestId: string,
  logger: Logger
)

Source from the content-addressed store, hash-verified

377}
378
379async function processOutlookEmails(
380 emails: OutlookEmail[],
381 webhookData: PollWebhookContext['webhookData'],
382 workflowData: PollWebhookContext['workflowData'],
383 config: OutlookWebhookConfig,
384 accessToken: string,
385 requestId: string,
386 logger: Logger
387) {
388 let processedCount = 0
389 let failedCount = 0
390
391 for (const email of emails) {
392 try {
393 await pollingIdempotency.executeWithIdempotency(
394 'outlook',
395 `${webhookData.id}:${email.id}`,
396 async () => {
397 let attachments: OutlookAttachment[] = []
398 if (config.includeAttachments && email.hasAttachments) {
399 try {
400 attachments = await downloadOutlookAttachments(
401 accessToken,
402 email.id,
403 requestId,
404 logger
405 )
406 } catch (error) {
407 logger.error(
408 `[${requestId}] Error downloading attachments for email ${email.id}:`,
409 error
410 )
411 }
412 }
413
414 const simplifiedEmail: SimplifiedOutlookEmail = {
415 id: email.id,
416 conversationId: email.conversationId,
417 subject: email.subject || '',
418 from: email.from?.emailAddress?.address || '',
419 to: email.toRecipients?.map((r) => r.emailAddress.address).join(', ') || '',
420 cc: email.ccRecipients?.map((r) => r.emailAddress.address).join(', ') || '',
421 date: email.receivedDateTime,
422 bodyText: (() => {
423 const content = email.body?.content || ''
424 const type = (email.body?.contentType || '').toLowerCase()
425 if (!content) return email.bodyPreview || ''
426 if (type === 'text' || type === 'text/plain') return content
427 return convertHtmlToPlainText(content)
428 })(),
429 bodyHtml: email.body?.content || '',
430 hasAttachments: email.hasAttachments,
431 attachments,
432 isRead: email.isRead,
433 folderId: email.parentFolderId,
434 messageId: email.id,
435 threadId: email.conversationId,
436 }

Callers 1

pollWebhookFunction · 0.85

Calls 8

convertHtmlToPlainTextFunction · 0.85
markOutlookEmailAsReadFunction · 0.85
errorMethod · 0.80
joinMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected