laminas / laminas-mail

Provides generalized functionality to compose and send both text and MIME-compliant multipart e-mail messages
https://docs.laminas.dev/laminas-mail/
BSD 3-Clause "New" or "Revised" License
93 stars 64 forks source link

Zend\Mail\Storage\Mbox can't fetch messages due to header issues #37

Open michalbundyra opened 4 years ago

michalbundyra commented 4 years ago

PHP 7.2.2, Zend Mail at it's latest version as of today.

I'm opening an old mailbox file generated by Mozilla Thunderbird (please note that I get the same issue with other Thunderbird mailbox files). It has 2,521 messages and every single one of them causes this Zend\Mail\Exception\RuntimeException.

This issue happens:

  1. When trying to iterate through the mailbox file with a foreach (as shown in the docs);
  2. When trying to fetch a specific message after iterating via a count() + regular for loop .

And it's located at zendframework/zend-mail/src/Headers.php on line 109.

The exact headers causing the issue are X-Mozilla-Status and X-Account-Key. See the sample below (I've removed [potentially] sensitive data such as e-mail addresses, etc... for obvious reasons).

Line "X-Mozilla-Status: 0019
X-Mozilla-Status2: 00000000
X-Mozilla-Keys:                                                                                 
Received: (qmail 20021 invoked from network); 24 Apr 2008 14:23:38 -0300
Received: from [redacted].google.com (216.239.58.185) by [redacted]
        with SMTP; 24 Apr 2008 14:23:38 -0300
Received-SPF: softfail ([redacted]: transitioning SPF record at
        [redacted] does not designate [redacted] as permitted sender)
Received: by [redacted].google.com with SMTP id [redacted] for
        <[redacted]>; Thu, 24 Apr 2008 11:36:07 -0700 (PDT)
Received: by 10.150.49.1 with SMTP id [redacted]; Thu,
        24 Apr 2008 11:35:17 -0700 (PDT)
Received: by [redacted] with HTTP; Thu, 24 Apr 2008 11:35:17 -0700 (PDT)
Message-ID: <[redacted]@mail.gmail.com>
Date: Thu, 24 Apr 2008 15:35:17 -0300
From: "[redacted]" <[redacted]>
To: [redacted]
Subject: =?ISO-8859-1?[redacted]?=
In-Reply-To: <[redacted]>
MIME-Version: 1.0
Content-Type: multipart/related;  boundary="----=_Part_22_2026612.1209062117791"
References: <[redacted]>
X-Evolution-Source: [redacted]
X-Evolution: [redacted]
" does not match header format!

Originally posted by @galvao at https://github.com/zendframework/zend-mail/issues/193

michalbundyra commented 4 years ago

I believe a clarification is in order: I simply cannot fetch these messages. It doesn't matter if I catch this Exception or not, which is the reason for this issue.


Originally posted by @galvao at https://github.com/zendframework/zend-mail/issues/193#issuecomment-362932832

michalbundyra commented 4 years ago

Update: Using the second method (count + for loop) it's possible to catch the Exception, but still, every single message causes this Exception, making the task of reading these messages absolutely impossible. Since Custom Headers seem to be a common thing, I'd remove this exception entirely or at least modify Zend\Mail so the presence of such a header doesn't block the entire operation of fetching a message.


Originally posted by @galvao at https://github.com/zendframework/zend-mail/issues/193#issuecomment-369824682

puecher commented 3 years ago

What about using

const EOL = PHP_EOL;

const FOLDING = PHP_EOL . " ";

in https://github.com/laminas/laminas-mail/blob/2.13.x/src/Headers.php#L30