in reply to getting headers from essage

<UPDATE

NEVER MIND

Didn't see ikegami's explanation before, but it makes sense!

Tho I wouldn't be surprised if multiple "To:" headers were indeed allowed.

UPDATE>

> So iam trying to get to this array of arrays element I solved it with splitting the string and removing leading and trailing spaces, but it's not fantastic

What you are describing is not in line with the documentation of parse_header()

It returns a hash reference in which the keys are the header field names (without the colon) and the values are references to arrays of values.

So please show us a dumps of

$$hashref{To}

and

@{$$hashref{To}}

in order to tell what's going on here.

Maybe this module's documentation is faulty or the mail is malformed or ...

Anyway using hashslices inside a deref is begging for trouble. Please change your style.

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: getting headers from essage
by ikegami (Patriarch) on Dec 16, 2025 at 21:31 UTC

    It will have the form

    my $hashref = { From => [ 'Mark Smith <mark.smith@example.org>', ], To => [ join( ', ', '"Doe, John" <john.doe@example.org>', '"Roe, Jane" <jane.roe@example.org>', ), ], ... };
      Thanks, actually it can get much more complicated tho

      https://en.wikipedia.org/wiki/Email_address

      I think there should° be a module dedicated to parse a list of email addresses.

      Doing this manually smells like trying to parse HTML with a regex.

      UPDATE

      °) Yep, see Email::Address on CPAN (unexpected name ;-)

      my @addrs = Email::Address->parse( q[me@local, Casey <me@local>, "Casey" <me@local> (West)] );

      and from the description

      ACHTUNG! Email isn't easy (if even possible) to parse with a regex, at least if you're on a perl prior to 5.10.0. Providing regular expressions for use by other programs isn't a great idea,

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      see Wikisyntax for the Monastery