private function getLoggingEmails($mail, $parts)
    {
        $emailAddresses = $this->flattenEmailAddresses(
            $this->getAllEmailAddresses($parts)
        );

        $messageIds = [];
        $headers    = $mail->getHeaders();
        if (!empty($headers) && $headers->has('message-id')) {
            $messageId = $headers->get('message-id');
            if ($messageId instanceof ArrayIterator) {
                foreach ($messageId as $header) {
                    /** @var $header HeaderInterface */
                    $messageIds[] = $header->getFieldValue();
                }
            } elseif ($messageId instanceof HeaderInterface) {
                $messageIds = [$messageId->getFieldValue()];
            }
        }

        /*
         * Also strip < and > from message id to only return the email-like id
         */
        $messageIds = array_map(function ($messageId) {
            return trim($messageId, " \t\n\r\0\x0B<>");
        }, $messageIds);

        return array_merge($emailAddresses, $messageIds);
    }