Skip to content

Fix fatal error when CUSTOM_EMAIL_QUERY_FUNCTION returns void#431

Merged
jsuto merged 1 commit intojsuto:masterfrom
cnbhl:fix/custom-email-query-function-null-safety
Feb 20, 2026
Merged

Fix fatal error when CUSTOM_EMAIL_QUERY_FUNCTION returns void#431
jsuto merged 1 commit intojsuto:masterfrom
cnbhl:fix/custom-email-query-function-null-safety

Conversation

@cnbhl
Copy link
Contributor

@cnbhl cnbhl commented Feb 19, 2026

Summary

  • Adds null-safety check for the return value of CUSTOM_EMAIL_QUERY_FUNCTION in checkLoginAgainstIMAP()
  • Prevents a fatal error (count(): Argument #1 must be of type Countable|array, null given) when custom auth plugins don't return an array

Background

Since 1.4.8, auth.php line 415 assigns the return value of CUSTOM_EMAIL_QUERY_FUNCTION directly to $emails:

$emails = call_user_func(CUSTOM_EMAIL_QUERY_FUNCTION, $username);

Custom auth plugins written for piler ≤ 1.4.4 (such as mailpiler-mailcow-integration) only modify the session and don't return the email array. This causes $emails to become null, leading to a fatal error on the subsequent count() / array_merge() calls.

Result: Users who authenticate via IMAP with a custom email query function see a blank page (HTTP 500) after login.

Fix

Store the return value in a temporary variable and only overwrite $emails if the result is a non-empty array:

$result = call_user_func(CUSTOM_EMAIL_QUERY_FUNCTION, $username);
if(is_array($result) && count($result) > 0) {
    $emails = $result;
}

This is backwards compatible — old plugins that modify the session directly will continue to work, and new plugins that return the array will also work.

Related

🤖 Generated with Claude Code

Since 1.4.8, checkLoginAgainstIMAP() assigns the return value of
CUSTOM_EMAIL_QUERY_FUNCTION directly to $emails. If the custom function
returns void/null (as older plugins do), this causes a fatal error:

  count(): Argument jsuto#1 must be of type Countable|array, null given

This adds a defensive check so $emails keeps its original value
array($username) when the custom function doesn't return a valid array.

Fixes jsuto#430

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Owner

@jsuto jsuto left a comment

Choose a reason for hiding this comment

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

Thank you!

@jsuto jsuto merged commit 800bdac into jsuto:master Feb 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants