protected function emailFromArray(array $arr)
    {
        if (isset($arr['address'])) {
            $arr['email'] = $arr['address'];
            unset($arr['address']);
        }

        if (!isset($arr['email'])) {
            throw new InvalidArgumentException(
                'The array must contain at least the "address" key.'
            );
        }

        $email = strval(filter_var($arr['email'], FILTER_SANITIZE_EMAIL));

        if (!isset($arr['name']) || $arr['name'] === '') {
            return $email;
        }

        $name = str_replace('"', '', filter_var($arr['name'], FILTER_SANITIZE_STRING));
        return sprintf('"%s" <%s>', $name, $email);
    }