php-imap
php-imap copied to clipboard
Header parsing issue
Describe the bug
If a header like the received
-header is per definition a multi value (header key exists multiple times), the parsed headers are broken.
Used config default config.
Code to Reproduce The troubling code section which produces the reported bug.
new ClientManager();
$header = new Header('
Received: from RECEIVED-BY-SERVER-1.localhost (RECEIVED-BY-SERVER-1.localhost [127.0.0.1])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
(No client certificate requested)
by OUR-MAIL-SERVER.localhost (Postfix) with ESMTPS id BDB91E00EE
for <TO-EMAIL@localhost>; Tue, 26 Mar 2024 10:29:52 +0100 (CET)
Received: by RECEIVED-BY-SERVER-1.localhost with SMTP id 111111-111111.1
for <TO-EMAIL@localhost>; Tue, 26 Mar 2024 02:29:52 -0700 (PDT)
');
print_r($header);
Current behaviour
[attributes:protected] => Array
(
[received] => Webklex\PHPIMAP\Attribute Object
(
[name:protected] => received
[values:protected] => Array
(
[0] => from RECEIVED-BY-SERVER-1.localhost (RECEIVED-BY-SERVER-1.localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by OUR-MAIL-SERVER.localhost (Postfix) with ESMTPS id BDB91E00EE for <TO-EMAIL@localhost>; Tue, 26 Mar 2024 10:29:52 +0100 (CET) by RECEIVED-BY-SERVER-1.localhost with SMTP id 111111-111111.1 for <TO-EMAIL@localhost>; Tue, 26 Mar 2024 02:29:52 -0700 (PDT)
[1] => from RECEIVED-BY-SERVER-1.localhost (RECEIVED-BY-SERVER-1.localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by OUR-MAIL-SERVER.localhost (Postfix) with ESMTPS id BDB91E00EE for <TO-EMAIL@localhost>
)
)
[priority] => Webklex\PHPIMAP\Attribute Object
(
[name:protected] => priority
[values:protected] => Array
(
[0] => 0
)
)
)
Expected behavior
[attributes:protected] => Array
(
[received] => Webklex\PHPIMAP\Attribute Object
(
[name:protected] => received
[values:protected] => Array
(
[0] => from RECEIVED-BY-SERVER-1.localhost (RECEIVED-BY-SERVER-1.localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by OUR-MAIL-SERVER.localhost (Postfix) with ESMTPS id BDB91E00EE for <TO-EMAIL@localhost>; Tue, 26 Mar 2024 10:29:52 +0100 (CET)
[1] => by RECEIVED-BY-SERVER-1.localhost with SMTP id 111111-111111.1 for <TO-EMAIL@localhost>; Tue, 26 Mar 2024 02:29:52 -0700 (PDT)
)
)
[priority] => Webklex\PHPIMAP\Attribute Object
(
[name:protected] => priority
[values:protected] => Array
(
[0] => 0
)
)
)
Screenshots
Desktop / Server (please complete the following information):
- OS: Ubuntu 20.04
- PHP: 8.0.14
- Version v5.5.0
- Provider Dovecot
Additional context
Also the extractHeaderExtensions will modify the received headers, as i noticed, so also with a "hacky" fix, to just return $values for received key arround line 298 in Header.php, it will use it as an extension and add the first received header value without the timestamp to be end of the received header array.