Skip to content

Config options options.fetch_body and options.fetch_flags are silently ignored #620

@manitu-opensource

Description

@manitu-opensource

Description

The configuration options options.fetch_body and options.fetch_flags from src/config/imap.php are silently ignored. The Query class hardcodes both to true and never reads them from config, so setting them in the ClientManager options has no effect on the default query behavior.

Users have to explicitly chain ->setFetchBody(false) / ->setFetchFlags(false) for every query for it to take effect, which contradicts the existence and documentation of these config options.

Verified against current master (src/Query/Query.php).

To Reproduce

use Webklex\PHPIMAP\ClientManager;

$cm = new ClientManager([
    'accounts' => [
        'default' => [/* ...credentials... */],
    ],
    'options' => [
        'fetch_body'  => false,   // expected: bodies NOT fetched
        'fetch_flags' => false,   // expected: flags NOT fetched
    ],
]);

$client = $cm->account('default');
$client->connect();

$msg = $client->getFolder('INBOX')
    ->messages()->all()->limit(1)->get()->first();

var_dump(strlen($msg->getRawBody() ?? '')); // > 0 -> bug

Expected behavior

When options.fetch_body is set to false in config, queries built via $folder->messages() should default to not fetching message bodies, without requiring ->setFetchBody(false) on every call. Same for options.fetch_flags.

Actual behavior

Bodies and flags are always fetched. The config values are never consulted on the standard query path.

Root cause

src/Query/Query.php hardcodes the defaults:

protected bool $fetch_body = true;
protected bool $fetch_flags = true;

The Query::__construct() already reads several other options from config (options.sequence, options.fetch, options.fetch_order, options.soft_fail, date_format), but options.fetch_body and options.fetch_flags are missing.

Suggested fix

Add two lines in Query::__construct(), alongside the existing config reads:

$this->fetch_body  = (bool) $config->get('options.fetch_body', true);
$this->fetch_flags = (bool) $config->get('options.fetch_flags', true);

Backwards compatible (default stays true), and matches the existing pattern in the same constructor.

Environment

  • webklex/php-imap version: 6.2 (also reproducible on master)
  • PHP version: 8.1/8.2/8.3/8.4
  • OS: Gentoo linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions