baltimoregaq.blogg.se

Perl simple email parser
Perl simple email parser




Mail::Message objects are usually constructed by Mail::Box as part of reading in an email folder, but can also be generated from an email using the read method: $obj = Mail::Message->read($rfc2822) Mail::Message is extremely featureful and comprehensive, but that is not always meant as a compliment. If Mail::Internet and MIME::Entity don’t cut it for you, you can try Mark Overmeer’s own Mail::Message, part of the impressive Mail::Box suite. Thankfully, MIME::Entity is a MIME-aware subclass of Mail::Internet it allows you to read individual parts of a MIME message: my $num_parts = $obj->parts Mail::Internet is reasonably handy for simple tasks, but it doesn’t handle MIME at all. $obj->body("Wasn't worth reading anyway.") Reading and editing the body is done through the body method: my $old_body = $obj->body $obj->head->replace("Subject", "New subject") You can get and set individual headers through this object: my $subject = $obj->head->get("Subject") Mail::Internet splits a message into a header object in the Mail::Header class, plus a body. Throughout these examples, we’ll use the variable $rfc2822 to represent a mail message as a string. This module offers a constructor that takes either an array of lines or a filehandle, reads a message, and returns a Mail::Internet object representing the message.

perl simple email parser

The granddaddy of these modules is Mail::Internet, originally created by Graham Barr and now maintained by Mark Overmeer. We’ll begin with those modules that represent an individual message, giving you access to the headers and body, and usually allowing you to modify these. We’ll also concentrate on an effort started by myself, Richard Clamp, Simon Wistow, and others, called the Perl Email Project, to produce simple, efficient and accurate mail handling modules. There are many modules on the CPAN for slicing and dicing email, and we’re going to take a whistlestop tour of the major ones.

perl simple email parser

I spend the vast majority of my time at a computer working with email, whether it’s working through the ones I send and receive each day, or working on my interest in analyzing, indexing, organizing, and mining email content.






Perl simple email parser