@@ -170,6 +170,9 @@ export const outlookPollingHandler: PollingProviderHandler = {
170170/** Hard cap on total emails fetched per poll to prevent unbounded pagination loops. */
171171const 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+
173176async 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