spiritway has asked for the wisdom of the Perl Monks concerning the following question:
Beloved Brethren and Sistren:
I am stymied over what I would think is a simple matter. I am working on an e-mail program, using the Net::POP3 module. This module returns a pointer to an array of text that contains the entire message, both headers and body of the message. I am trying to figure out a way to get rid of the header information and preserve the body of the text.
I checked the documentation of Net::POP3, and it doesn't appear to have a way that I can simply ask for just the body text. I checked RFC 1939 and RFC 2822, and found that headers have the form <HeaderID> : <Header Text>. This is a big help, but not enough. Headers can span more than one line. When they do this, the subsequent lines begin with a whitespace.
I was trying to reconstruct the headers that were split into more than one line by finding newline/whitespace combinations, and replacing them with a space. This turned out to be quite difficult for me. First I tried:
$line =~ s/\n\s+/ /mg;
That doesn't work. I think the problem is that each line ends with a newline. There are no lines that contain a newline followed by another character.
I then reasoned that, since the newline is followed by whitespace, I might be able to search for lines that begin with whitespace (and simply remove those lines) using
$line =~ s/^\s+.*/ /g;Unfortunately, this finds any such lines, including those contained in the body text. I want to preserve all of the text, and simply remove (or at least identify) the header lines.
So the question is, how can I reconstruct the headers that span more than one line? Or, equally useful, how can I distinguish headers from body text?
UPDATE: Thanks to all of you who have commented. You've given me some great ideas to try. I appreciate it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Removing Headers from E-mail Messages.
by ysth (Canon) on Jan 29, 2006 at 10:55 UTC | |
|
Re: Removing Headers from E-mail Messages.
by atcroft (Abbot) on Jan 29, 2006 at 10:57 UTC | |
|
Re: Removing Headers from E-mail Messages.
by g0n (Priest) on Jan 29, 2006 at 10:57 UTC |