def _connect_download_and_return_metadata(
        self,
        access_token: str,
        local_dir: Optional[str] = None,
        item_id: str = None,
        include_subfolders: bool = True,
        mime_types: Optional[List[str]] = None,
        userprincipalname: Optional[str] = None,
        isRelativePath=False,
    ) -> List[_OneDriveResourcePayload]:
        """
        Recursively download files from OneDrive, starting from the specified item_id or the root.

        Parameters
        ----------
        - access_token (str): Token for authorization.
        - local_dir (str, optional): Local directory to store downloaded files.
        - item_id (str, optional): ID of the specific item (folder/file) to start from. If None, starts from the root.
        - include_subfolders (bool, optional): Whether to include subfolders. Defaults to True.
        - mime_types(List[str], optional): the mimeTypes you want to allow e.g.: "application/pdf", default is None which loads all files
        - userprincipalname (str): The userprincipalname(normally organization provided email id) whose ondrive needs to be accessed. Mandatory for App authentication scenarios.
        - isRelativePath (bool): Value to indicate if to query file/folder using relative path

        Returns
        -------
        - dict: Dictionary of file paths and their corresponding metadata.

        Raises
        ------
        - Exception: If items can't be retrieved for the current item.

        """
        data = self._get_items_in_drive_with_maxretries(
            access_token,
            item_id,
            userprincipalname=userprincipalname,
            isRelativePath=isRelativePath,
        )

        if data:
            payloads: List[_OneDriveResourcePayload] = []
            for item in data["value"]:
                if (
                    "folder" in item and include_subfolders
                ):  # It's a folder; traverse if flag is set
                    subfolder_metadata = self._connect_download_and_return_metadata(
                        access_token,
                        local_dir=local_dir,
                        item_id=item["id"],
                        include_subfolders=include_subfolders,
                        mime_types=mime_types,
                        userprincipalname=userprincipalname,
                    )
                    payloads.extend(subfolder_metadata)  # Merge metadata

                elif "file" in item:
                    payload = self._check_approved_mimetype_and_download_file(
                        item,
                        local_dir=local_dir,
                        mime_types=mime_types,
                        access_token=access_token,
                    )
                    payloads.append(payload)

            return payloads

        # No data received; raise exception
        current_item = item_id if item_id else "RootFolder"
        raise Exception(f"Unable to retrieve items for: {current_item}")

        Recursively download files from OneDrive, starting from the specified item_id or the root.

        Parameters
        ----------
        - access_token (str): Token for authorization.
        - local_dir (str, optional): Local directory to store downloaded files.
        - item_id (str, optional): ID of the specific item (folder/file) to start from. If None, starts from the root.
        - include_subfolders (bool, optional): Whether to include subfolders. Defaults to True.
        - mime_types(List[str], optional): the mimeTypes you want to allow e.g.: "application/pdf", default is None which loads all files
        - userprincipalname (str): The userprincipalname(normally organization provided email id) whose ondrive needs to be accessed. Mandatory for App authentication scenarios.
        - isRelativePath (bool): Value to indicate if to query file/folder using relative path

        Returns
        -------
        - dict: Dictionary of file paths and their corresponding metadata.

        Raises
        ------
        - Exception: If items can't be retrieved for the current item.

        
llama-index-integrations/readers/llama-index-readers-microsoft-onedrive/llama_index/readers/microsoft_onedrive/base.py