php-imap icon indicating copy to clipboard operation
php-imap copied to clipboard

Fix Empty Child Folder Error

Open bierpub opened this issue 1 year ago • 2 comments

I have multiple Outlook 365 accounts that are receiving the failed to fetch any folders exception. The problem is happening on the Contacts and Conversation History folders. These have the HasChildren flag set but there are no child folders. Contacts is not a message folder and I suspect is related to the contact address book. Conversation History can store messages and have subfolders, but there are none right now. It seems incorrect that HasChildren is set, but this ends up causing an exception to be thrown when looking for those subfolders even though many primary folders were successfully found.

This can be fixed by setting $soft_fail to true only when checking the child folders. If no child folders are found it can continue on normally and return all of the folders that were found. This will still throw the normal exception if the primary folders were not found.

This resolves Issue #453

image

bierpub avatar Feb 08 '24 17:02 bierpub

Hi @bierpub , many thanks for your pull request and suggested improvements. However I have a question before merging your pull request. You've replaced $soft_fail with true - why not simply set the $soft_fail method argument to archive the same? Perhaps I'm missing something :)

Best regards & happy coding,

Webklex avatar Apr 11 '24 14:04 Webklex

Hi @bierpub , many thanks for your pull request and suggested improvements. However I have a question before merging your pull request. You've replaced $soft_fail with true - why not simply set the $soft_fail method argument to archive the same? Perhaps I'm missing something :)

Best regards & happy coding,

Hi @Webklex, Are you suggesting to do this? It would have the same outcome.

$soft_fail = true;
$children = $this->getFolders(true, $pattern, $soft_fail);

Or are you wondering why I don't set it to true when first calling getFolders? The reason is that it seems valid to throw an exception if the top level folders are all missing. This suggested change preserves that functionality. What I am trying to prevent is throwing an exception if one of those folders does not have child folders. We might find multiple top level folders, meaning it should not throw an exception. But if the error gets thrown when checking for child folders, it is incorrect to say it failed to fetch any folders.

bierpub avatar Apr 11 '24 14:04 bierpub