From 71186185b06e74d71b48ed086be7c32977d736f3 Mon Sep 17 00:00:00 2001 From: pengfeiye Date: Thu, 13 Apr 2023 13:30:22 -0400 Subject: [PATCH] [*] Fixing get_default_folder to only walk the whole folder map when subfolder is not None --- exchangelib/folders.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/exchangelib/folders.py b/exchangelib/folders.py index f649d4c..9673c5e 100644 --- a/exchangelib/folders.py +++ b/exchangelib/folders.py @@ -1009,12 +1009,13 @@ def get_default_folder(self, folder_cls): # folder was found, try as best we can to return the default folder of type 'folder_cls' if not folder_cls.DISTINGUISHED_FOLDER_ID: raise ValueError("'folder_cls' %s must have a DISTINGUISHED_FOLDER_ID value" % folder_cls) - - for f in self._folders_map.values(): - # Require exact class, to not match subclasses, e.g. RecipientCache instead of Contacts - if f.__class__ == folder_cls and f.is_distinguished: - log.debug('Found cached distinguished %s folder', folder_cls) - return f + if self._subfolders is not None: + for f in self._folders_map.values(): + # Require exact class, to not match subclasses, e.g. RecipientCache instead of Contacts + if f.__class__ == folder_cls and f.is_distinguished: + log.debug('Found cached distinguished %s folder', folder_cls) + return f + try: log.debug('Requesting distinguished %s folder explicitly', folder_cls) return folder_cls.get_distinguished(account=self.account)