in reply to Re: Splitting folded MIME headers into indivual headers?
in thread Splitting folded MIME headers into indivual headers?

How would that work? A folded header line does contain one single \n, and then the next line begins with any whitespace. A newline (\n) followed by a non-whitespace is the beginning of a new header.

The whitespace a folded line begins with, may not neccessarly be a \n. In face \n would not be permitted, because a double \n (\n\n) would mark the start of body

Example of a non-folded header line, combined with a folded header line combined with a non-folded one:

Subject: Hi you are beutiful Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Return-Path: <example@example.org>
This should result in:
$fixedheaders[0] = "Subject: Hi you are beutiful"; $fixedheaders[1] = "Content-Type: text/plain;\tformat=flowed;\tcharset +=\"iso-8859-1\";\treply-type=original"; $fixedheaders[2] = "Return-Path: <example@example.org>";

Replies are listed 'Best First'.
Re^3: Splitting folded MIME headers into indivual headers?
by roboticus (Chancellor) on Mar 02, 2015 at 21:06 UTC

    sebastiannielsen2:

    In that case, I'd use:

    @fixedheaders = split /\n\b/, $fixedmsgheader;

    Update: checked my work with a test program:

    cat splitest.pl #!/usr/bin/env perl use strict; use warnings; my $t = q{ Subject: Hi there Content-Type: text/plain; format=flowed; charset="iso-1189-1"; Return-Path: <example@example.org> }; my @fields = split /\n\b/, $t; print join("\n***\n", @fields), "\n"; localadmins-MacBook-Pro-2:~ [mmason] $ perl splitest.pl *** Subject: Hi there *** Content-Type: text/plain; format=flowed; charset="iso-1189-1"; *** Return-Path: <example@example.org>

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re^3: Splitting folded MIME headers into indivual headers?
by sebastiannielsen2 (Novice) on Mar 02, 2015 at 21:02 UTC

    OOps the result was a Little bit wrong. It should be:

    $fixedheaders[0] = "Subject: Hi you are beutiful"; $fixedheaders[1] = "Content-Type: text/plain;\n\tformat=flowed;\n\tcha +rset +=\"iso-8859-1\";\n\treply-type=original"; $fixedheaders[2] = "Return-Path: <example@example.org>";

    Eg with newlines Before the tabs.