RFC-822 header processing in perl

Eric Messick eric at parallax.com
Tue Jan 5 01:01:56 PST 1993

I've written a perl script to parse RFC-822 style headers.  It was a
good deal harder than I had thought it would be.  Since it's over 300
lines (with comments) I won't post it, but will mail it to anyone who
wants to play with it.  It has the following features:

Doesn't touch anything unless you ask it to.  Leaves the ordering and
whitespace/folding of header lines unchanged.

Allows you to replace any header line (which appears only once) with
an arbitrary value, which is appropriatly folded on output.

Allows you to delete any header line, or add a header line to the end
of the header.  These are special cases of replacing a header line.

Allows you to access the value (stuff after the :) of any header line.

Given a list of addresses, returns an array of canonicalized addresses.

The last item is the hard part.  It correctly parses the sample
addresses in the RFC-822 paper, as well as some really gnarly looking
junk that I threw at it.  It correctly handles the various types of
quoted strings, and backslash quoting, not splitting addresses at
quoted commas.  It removes nested comments from addresses.  It deletes
the group name from a list of addresses without screwing up quoted

It should be useful as a first step in alias processing.  That's what
I'll be adding next, when I figure out exactly how I want to do it.

-- eric messick
eric at toad.com

More information about the cypherpunks-legacy mailing list