ddeboer / imap

Object-oriented, fully tested PHP IMAP library
MIT License
887 stars 253 forks source link

New "References:" formatting in headers processed by Exchange? #531

Open zax123 opened 2 years ago

zax123 commented 2 years ago
Q A
ddeboer/imap version 1.12.2
PHP version 7.4.3
IMAP provider outlook.office365.com

Summary

I use this imap library (which is fantastic by the way), to automatically parse/process email coming in to a specific email account in Office 365. Lately, I've noticed that the "References:" header (which I look at to know if I've already processed an email already) has references that are comma-separated as opposed to space separated and the snippet of code in this library explodes references by space. Perhaps we need to explode by both space and comma? I'm not sure if Outlook servers are adding the comma, or the email is arriving like that.

Current behavior

Currently, the library explodes the references header by space:

    /**
     * Get message References (from headers).
     *
     * @return string[]
     */
    final public function getReferences(): array
    {
        $references = $this->getHeaders()->get('references');
        \assert(null === $references || \is_string($references));

        return null !== $references ? \explode(' ', $references) : [];
    }

How to reproduce: code & error stack trace

An email with comma-separated references in the header will not parse correctly when using the getReferences() function.

Expected behavior

The references in the header would be exploded either by comma or space and result in a clean array of references.

Thanks!