IMAP (webklex-imap): messages in INBOX are never imported when INBOX has subfolders

Author: raizen10Created Sep 23, 2026Updated Sep 23, 2026

Bug report

Title

IMAP (webklex-imap): messages in INBOX are never imported when INBOX has subfolders

Issue Description

With MAIL_RECEIVER_DRIVER=webklex-imap, no email is ever imported (0 rows in emails, no error in the CLI or in laravel.log) when the mail server exposes INBOX as a parent folder with its own subfolders (e.g. INBOX.Sent, INBOX.Trash, INBOX.Drafts — the usual Dovecot / cPanel layout).

The cause is processMessagesFromLeafFolders() in packages/Webkul/Email/src/InboundEmailProcessor/WebklexImapEmailProcessor.php (branch 2.2, ~line 164): when a folder has children it recurses into them and returns without processing the folder's own messages, assuming only leaf folders contain mail:

php
if (! $folder->children->isEmpty()) {
    $this->processMessagesFromLeafFolders($folder->children);

    return; // INBOX's own messages are skipped
}

Since INBOX has children on these servers, the messages in INBOX itself — i.e. all incoming mail — are never processed.

Preconditions

  1. Krayin CRM v2.2.6 (same code on the current 2.2 branch), PHP 8.5, Laravel 12.
  2. MAIL_RECEIVER_DRIVER=webklex-imap, IMAP settings configured and connecting fine.
  3. IMAP account whose INBOX has subfolders (Dovecot namespace INBOX.*).

Steps to reproduce

  1. Configure IMAP against a Dovecot/cPanel mailbox where INBOX has subfolders.
  2. Send a new email to that mailbox.
  3. Run php artisan inbound-emails:process.

Expected result

The new email is imported into Mail → Inbox.

Actual result

Nothing is imported and no error is shown. Connecting with Webklex\IMAP\Facades\Client::make([...]) directly confirms the messages are in INBOX.

Suggested fix

Process every folder's own messages and recurse into its children (processMessage() already de-duplicates by message_id, so this is safe):

php
$rootFoldersCollection->each(function ($folder) {
    if (! $folder->children->isEmpty()) {
        $this->processMessagesFromLeafFolders($folder->children);
    }

    if (in_array($folder->name, ['All Mail'])) {
        return;
    }

    $folder->query()->since(now()->subDays(10))->get()->each(function ($message) {
        $this->processMessage($message);
    });
});

We've been running this change in production without issues.