Skip to content

mimeDecode issue #1325

Description

@nixnutnz

[24-Jul-2026 04:45:43 Pacific/Auckland] PHP Warning: Uninitialized string offset 0 in /home/serv/public_html/mailwatch/mailscanner/lib/pear/Mail/mimeDecode.php on line 483

the fix

function _parseHeaders($input)
    {
        $return = [];

        if ($input !== '') {
            // Unfold the input
            $input = preg_replace("/\r?\n/", "\r\n", $input);
            $input = preg_replace("/=\r\n(\t| )+/", '=', $input);
            $input = preg_replace("/\r\n(\t| )+/", ' ', $input);

            $headers = explode("\r\n", trim($input));
            $got_start = false;

            foreach ($headers as $value) {
                if (!$got_start) {
                    // munge headers for mbox style from
                    if (!empty($value) && $value[0] == '>') {
                        $value = substr($value, 1); // remove mbox >
                    }
                    if (substr($value, 0, 5) == 'From ') {
                        $value = 'Return-Path: ' . substr($value, 5);
                    } else {
                        $got_start = true;
                    }
                }

                $pos = strpos($value, ':');
                if ($pos !== false) {
                    $hdr_name  = substr($value, 0, $pos);
                    $hdr_value = substr($value, $pos + 1);

                    if (!empty($hdr_value) && $hdr_value[0] == ' ') {
                        $hdr_value = substr($hdr_value, 1);
                    }

                    $return[] = [
                        'name'  => $hdr_name,
                        'value' => $hdr_value,
                    ];
                }
            }
        }

        return $return;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions