Skip to content

fix(backend): handle undefined array key name#1844

Open
Baraka24 wants to merge 2 commits intocypht-org:masterfrom
Baraka24:fix-undefined-array-key-name
Open

fix(backend): handle undefined array key name#1844
Baraka24 wants to merge 2 commits intocypht-org:masterfrom
Baraka24:fix-undefined-array-key-name

Conversation

@Baraka24
Copy link
Member

🍰 Pullrequest

Issues

  • Issue:
PHP Warning:  Undefined array key "name" in /var/www/html/cypht/modules/core/hm-mailbox.php on line 133

Todo

  • Lgin into your Cypht
  • Click your EWS account Inbox(should request ajax_imap_folder_display request)
  • Check your logs according to your configuration.

}
$result = $this->connection->get_folder_status($folder);
return $result['name'];
return $result['name'] ?? null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't handle the issue properly but simply ignores it. Why is the name not defined? Shouldn't a folder always have a name?
If the ajax call requests non-existing folder, then trace back the code to see why does it do it? Ultimately, if it is a user error (e.g. setting up custom folders for something that doesn't exist), we should show an error to the user, so they can fix. If it is Cypth code handling data incorrectly, we should fix the code error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discovered that an exception is normally thrown at line 182 in the "modules\imap\hm-ews.php" file, but unfortunately its $e->getMessage() is empty, making it impossible to capture the real error behind this behavior. This explains why the get_folder_status() method returns an empty result array in the catch block, which then causes the "undefined array key 'name'" error in the get_folder_name() method - the EWS API is failing silently without providing any meaningful error message, so we need to enhance the exception handling to log more details like the exception type, code, and stack trace to properly diagnose what's causing the folder lookup to fail.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, go for it and debug further the EWS client or API. There should be an underlying issue somewhere. I don't like the current approach. Folder not found means something - if it is a normal folder name, then this is a real issue to debug further. Note that EWS and the client we use is a bit pesky about folder naming having both constants, names and base64 encoded IDs with various ways to search for a folder.

@Baraka24 Baraka24 force-pushed the fix-undefined-array-key-name branch from 013ed34 to 96e63a4 Compare February 1, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants