Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 11, 2025

Task: Change logic so that we never move email out of a folder other than INBOX

✅ Completed

Changes Made

  1. ThreadEmailMover.php:

    • Added early return in processMailbox() method to only process emails when $mailbox === 'INBOX'
    • Added debug logging when skipping non-INBOX mailboxes for better observability
    • Any call to process non-INBOX folders now returns immediately with empty results
    • Minimal change: only 9 lines added (including debug log)
  2. ThreadEmailMoverTest.php:

    • Replaced 3 obsolete tests that expected non-INBOX processing
    • Added 1 new test: testProcessNonInboxMailboxDoesNothing()
    • Test verifies that processing non-INBOX folders returns empty results and doesn't fetch/move emails
    • Added explanatory comment for test intent
    • Net change: 125 lines removed, 29 lines added (tests simplified)

Test Results

  • ✅ All unit tests for non-INBOX behavior passing
  • ✅ All behavior tests for INBOX processing still pass
  • ⚠️ 3 integration tests require database connection (unrelated to changes)

Impact Analysis

  • processSentFolder() in update-imap-functions.php will now effectively do nothing (as intended)
  • All e2e tests only process INBOX, so no tests broken
  • The change ensures emails in thread folders stay there and aren't moved around
  • Debug logs will now show when folders are being skipped for easier troubleshooting

Security

  • No security vulnerabilities introduced
  • Change reduces complexity by removing folder-to-folder email movement logic
Original prompt

On ThreadEmailMoverTest.php, Change logic so that we never move email out of a folder other then INBOX


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Added check in processMailbox() to only process emails from INBOX folder
- Updated tests to verify non-INBOX folders are not processed
- Removed obsolete tests that expected emails to move between non-INBOX folders
- All 8 unit tests pass (1 integration test requires database)

Co-authored-by: HNygard <168380+HNygard@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix email moving logic to restrict folder changes Restrict email processing to INBOX only Nov 11, 2025
Copilot AI requested a review from HNygard November 11, 2025 20:08
@HNygard HNygard marked this pull request as ready for review December 30, 2025 08:31
Copilot AI review requested due to automatic review settings December 30, 2025 08:31
@cursor
Copy link

cursor bot commented Dec 30, 2025

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on January 27.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR restricts email processing to only the INBOX folder, preventing unintended reorganization of emails in non-INBOX folders like Sent and thread folders. Previously, emails were being moved between these folders, causing already-filed messages to be reorganized unexpectedly.

Key Changes:

  • Added early return guard in ThreadEmailMover::processMailbox() that skips processing for any mailbox other than 'INBOX'
  • Replaced 3 parameterized tests expecting non-INBOX moves with a single test verifying no-op behavior for non-INBOX mailboxes
  • Non-INBOX processing now returns empty results without fetching or moving any emails

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
organizer/src/class/ThreadEmailMover.php Added early return check at the start of processMailbox() to skip any mailbox that isn't 'INBOX', returning empty unmatched list and maxed_out=false
organizer/src/tests/ThreadEmailMoverTest.php Removed data provider and 3 parameterized tests for non-INBOX behavior; added single test testProcessNonInboxMailboxDoesNothing() verifying that no emails are fetched or moved from non-INBOX mailboxes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 46 to 52
// Only process emails from INBOX - never move emails from other folders
if ($mailbox !== 'INBOX') {
return array(
'unmatched' => [],
'maxed_out' => false,
);
}
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

The strict equality check $mailbox !== 'INBOX' will prevent processing of any folder that isn't exactly 'INBOX'. This is the intended behavior based on the PR description.

However, this means functions like processSentFolder() in update-imap-functions.php that call processMailbox() with 'Sent' or 'INBOX.Sent' will now silently return empty results without any indication that they were skipped. Consider adding a debug log message here to make the skip explicit and easier to debug, for example:

$this->connection->logDebug("Skipping mailbox '$mailbox' - only INBOX is processed");

This would help operators understand the behavior when reviewing logs.

Copilot uses AI. Check for mistakes.
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added debug logging in commit 5e6584e. The log message now reads: "Skipping mailbox '$mailbox' - only INBOX is processed"

HNygard and others added 2 commits December 30, 2025 10:34
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Addresses review feedback to make the skip behavior explicit in logs,
helping operators understand when folders are being skipped.

Co-authored-by: HNygard <168380+HNygard@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 30, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/PHPMailer/PHPMailer/zipball/bf74d75a1fde6beaa34a0ddae2ec5fce0f72a144
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/laminas/laminas-loader/zipball/c507d5eccb969f7208434e3980680a1f6c0b1d8d
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/laminas/laminas-mail/zipball/110e04497395123998220e244cceecb167cc6dda
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/laminas/laminas-mime/zipball/08cc544778829b7d68d27a097885bd6e7130135e
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/laminas/laminas-servicemanager/zipball/a8640182b892b99767d54404d19c5c3b3699f79b
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/laminas/laminas-stdlib/zipball/8974a1213be42c3e2f70b2c27b17f910291ab2f4
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/laminas/laminas-validator/zipball/b3ec5865e7aa60a0fbce211500f4a5c6a6e11a30
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/global-state/zipball/987bafff24ecc4c9ac418cab1145b96dd6e9cbd9
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/202d0e344a580d7f7d04b3fafce6933e59dae906
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/24ed13d98130f0e7122df55d06c5c4942a577957
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/05909fb5bc7df4c52992396d0116aed689f93712
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/type/zipball/462699a16464c3944eefc02ebdd77882bd3925bf
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/version/zipball/c51fa83a5d8f43f1402e3f32a005e6262244ef17
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/9614ac4d8061dc257ecc64cba1b140873dce8ad3
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/3833d7255cc303546435cb650316bff708a1c75c
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6d857f4d76bd4b343eac26d6b539585d2bc56493
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/webmozarts/assert/zipball/11cb2199493b2f8a3b53e7f19068fc6aac760991
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JAwFqm /usr/bin/composer install --no-interaction (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from HNygard December 30, 2025 09:40
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