[ale] Easy way to cut body of email in perl

Alan Dobkin ALE at MaestroIT.com
Thu Jan 5 12:06:27 EST 2006


On 1/5/2006 8:46 AM, Christopher Fowler wrote:
> On Thu, 2006-01-05 at 08:37 -0500, fletch at phydeaux.org wrote:
>   
>>> It's been a while since i was manually deconstructing mail, but IIRC
>>> there's a blank line between headers and body ... and between messages.
>>>       
>> Sure.  Not that it's not trivial to separate the two.
>>
>>     

If all you need to do is separate the body from the headers, as you
indicated in your example, then this is extremely trivial, as Fletch
indicated.  Since you are not parsing the headers or processing an
entire mbox, only individual messages, then all you have to do is grab
everything after the first blank line as the body.  Per RFC822, this is
clearly defined:

> 3.1. GENERAL DESCRIPTION A message consists of header fields and,
> optionally, a body. The body is simply a sequence of lines containing
> ASCII characters. It is separated from the headers by a null line
> (i.e., a line with nothing preceding the CRLF). 

Of course, this does not take into account what you actually want to do
with the body once you have it, whether it includes attachments or not,
etc.  But you didn't ask about any of that stuff, so I assume you
already have it covered.  :-)

Alan



More information about the Ale mailing list