Skip to content

Commit f82c7f7

Browse files
committed
fix(polling): decouple outlook page size from total email cap so pagination works
1 parent 2949517 commit f82c7f7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

apps/sim/lib/webhooks/polling/outlook.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ export const outlookPollingHandler: PollingProviderHandler = {
170170
/** Hard cap on total emails fetched per poll to prevent unbounded pagination loops. */
171171
const OUTLOOK_HARD_MAX_EMAILS = 200
172172

173+
/** Number of items to request per Graph API page. Decoupled from the total cap so pagination actually runs. */
174+
const OUTLOOK_PAGE_SIZE = 50
175+
173176
async function fetchNewOutlookEmails(
174177
accessToken: string,
175178
config: OutlookWebhookConfig,
@@ -186,7 +189,7 @@ async function fetchNewOutlookEmails(
186189
)
187190
params.append('$orderby', 'receivedDateTime desc')
188191
const maxEmails = Math.min(config.maxEmailsPerPoll || 25, OUTLOOK_HARD_MAX_EMAILS)
189-
params.append('$top', maxEmails.toString())
192+
params.append('$top', OUTLOOK_PAGE_SIZE.toString())
190193

191194
if (config.lastCheckedTimestamp) {
192195
const lastChecked = new Date(config.lastCheckedTimestamp)
@@ -220,7 +223,8 @@ async function fetchNewOutlookEmails(
220223

221224
const data = await response.json()
222225
const pageEmails: OutlookEmail[] = data.value || []
223-
allEmails.push(...pageEmails)
226+
const remaining = maxEmails - allEmails.length
227+
allEmails.push(...pageEmails.slice(0, remaining))
224228

225229
nextUrl =
226230
allEmails.length < maxEmails ? (data['@odata.nextLink'] as string | undefined) : undefined
@@ -230,7 +234,7 @@ async function fetchNewOutlookEmails(
230234

231235
logger.info(`[${requestId}] Fetched ${allEmails.length} emails total`)
232236

233-
const emails = allEmails.slice(0, maxEmails)
237+
const emails = allEmails
234238

235239
let resolvedFolderIds: Map<string, string> | undefined
236240
let skipFolderFilter = false

0 commit comments

Comments
 (0)