Archive: fix TypeError when archiving all messages via select-all (#10107) - #10263
Open
MiMoHo wants to merge 1 commit into
Open
Archive: fix TypeError when archiving all messages via select-all (#10107)#10263MiMoHo wants to merge 1 commit into
MiMoHo wants to merge 1 commit into
Conversation
Member
|
The fix is not that simple. |
…undcube#10107) With "select all", rcmail_action::get_uids() yields the string '*' (the IMAP wildcard) as $uids. move_messages() and move_messages_worker() then called count() on it, which throws a TypeError on PHP 8 ("count(): Argument roundcube#1 must be of type Countable|array, string given") and aborts the whole archive action with a server error. Treat a non-array $uids (the '*' wildcard) as a single unit, matching how core handles it in program/actions/mail/move.php ($count += is_array($uids) ? count($uids) : 1;). set_flag() and move_message() already accept '*', so the wildcard is passed through unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Author
|
Thanks, you're right — |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Using "select all" and then archiving produces a fatal server error ("Serverfault - moving all Mails in the archive"). On PHP 8 the request dies with:
TypeError: count(): Argument #1 ($value) must be of type Countable|array, string givenRoot cause
With select-all,
rcmail_action::get_uids()yields the string'*'as$uids(the IMAP wildcard). The archive plugin then callscount()on it in two places:plugins/archive/archive.php:346—move_messages_worker()doesreturn count($uids);plugins/archive/archive.php:160—move_messages()does$count = count($uids);for the archive-folder-source branchcount()on a string throws aTypeErroron PHP 8, aborting the whole archive action.Fix
Mirror how core handles
'*'inprogram/actions/mail/move.php($count += is_array($uids) ? count($uids) : 1;): treat a non-array$uids(the'*'wildcard) as a single unit instead of callingcount()on it.set_flag()andmove_message()already accept'*', so the wildcard is passed through unchanged.Both
count($uids)calls are replaced withis_array($uids) ? count($uids) : 1.Testing
Added
test_move_messages_worker_select_all()inplugins/archive/tests/ArchiveTest.php. It mocks storage soset_flag()/move_message()return true and invokesmove_messages_worker('*', ...)via reflection. Before the fix the test fails with thecount()TypeError at archive.php:346; after the fix it passes and asserts the correct return value and recorded source/destination folders. Full ArchiveTest.php passes (4 tests) and phpstan (level 4) reports no errors on the changed files.Fixes #10107