async def _generate_folder_entities(
        self,
        client: httpx.AsyncClient,
        folder_id: Optional[str] = None,
        parent_breadcrumbs: Optional[List[Breadcrumb]] = None,
    ) -> AsyncGenerator[OutlookMailFolderEntity, None]:
        """Recursively generate OutlookMailFolderEntity objects.

        Traverses the mail folder hierarchy via Microsoft Graph.
        """
        if parent_breadcrumbs is None:
            parent_breadcrumbs = []

        # Decide the endpoint: top-level vs. child folders
        if folder_id:
            url = f"{self.GRAPH_BASE_URL}/me/mailFolders/{folder_id}/childFolders"
            logger.info(f"Fetching child folders for folder ID: {folder_id}")
        else:
            # top-level mail folders
            url = f"{self.GRAPH_BASE_URL}/me/mailFolders"
            logger.info("Fetching top-level mail folders")

        try:
            while url:
                logger.debug(f"Making request to: {url}")
                data = await self._get_with_auth(client, url)
                folders = data.get("value", [])
                logger.info(f"Retrieved {len(folders)} folders")

                for folder in folders:
                    # Create and yield folder entity
                    folder_entity = OutlookMailFolderEntity(
                        entity_id=folder["id"],
                        breadcrumbs=parent_breadcrumbs,
                        display_name=folder["displayName"],
                        parent_folder_id=folder.get("parentFolderId"),
                        child_folder_count=folder.get("childFolderCount", 0),
                        total_item_count=folder.get("totalItemCount", 0),
                        unread_item_count=folder.get("unreadItemCount", 0),
                        well_known_name=folder.get("wellKnownName"),
                    )

                    logger.info(
                        f"Processing folder: {folder_entity.display_name} "
                        f"(ID: {folder_entity.entity_id}, Items: {folder_entity.total_item_count})"
                    )
                    yield folder_entity

                    # Build breadcrumb for this folder
                    folder_breadcrumb = Breadcrumb(
                        entity_id=folder_entity.entity_id,
                        name=folder_entity.display_name,
                        type="folder",
                    )

                    # Process messages in this folder
                    async for entity in self._process_folder_messages(
                        client, folder_entity, folder_breadcrumb
                    ):
                        yield entity

                    # Process child folders recursively
                    async for child_entity in self._process_child_folders(
                        client, folder_entity, parent_breadcrumbs, folder_breadcrumb
                    ):
                        yield child_entity

                # Handle pagination
                next_link = data.get("@odata.nextLink")
                if next_link:
                    logger.debug(f"Following pagination link: {next_link}")
                url = next_link if next_link else None

        except Exception as e:
            logger.error(f"Error fetching folders: {str(e)}")
            raise
Recursively generate OutlookMailFolderEntity objects.

        Traverses the mail folder hierarchy via Microsoft Graph.
        
backend/airweave/platform/sources/outlook_mail.py