The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Email::Simple - Simple parsing of RFC2822 message format and headers

SYNOPSIS

    my $email = Email::Simple->new($text);

    my $from_header = $email->header("From");
    my @received = $email->header("Received");

    $email->header_set("From", 'Simon Cozens <simon@cpan.org>');

    my $old_body = $email->body;
    $email->body_set("Hello world\nSimon");

    print $email->as_string;

DESCRIPTION

Email::Simple is the first deliverable of the "Perl Email Project." The Email:: namespace is a reaction against the complexity and increasing bugginess of the Mail::* modules. In contrast, Email::* modules are meant to be simple to use and to maintain, pared to the bone, fast, minimal in their external dependencies, and correct.

METHODS

Methods are deliberately kept to a minimum. This is meant to be simple. No, I will not add method X. This is meant to be simple. Why doesn't it have feature Y? Because it's meant to be simple.

new

Parse an email from a scalar containing an RFC2822 formatted message, and return an object.

  my @values = $email->header($header_name);
  my $first  = $email->header($header_name);

In list context, this returns every value for the named header. In scalar context, it returns the first value for the named header.

header_set

    $email->header_set($field, $line1, $line2, ...);

Sets the header to contain the given data. If you pass multiple lines in, you get multiple headers, and order is retained.

header_names

    my @header_names = $email->header_names;

This method returns the list of header names currently in the email object. These names can be passed to the header method one-at-a-time to get header values. You are guaranteed to get a set of headers that are unique. You are not guaranteed to get the headers in any order at all.

For backwards compatibility, this method can also be called as headers.

header_pairs

  my @headers = $email->header_pairs;

body

Returns the body text of the mail.

body_set

Sets the body text of the mail.

as_string

Returns the mail as a string, reconstructing the headers.

If you've added new headers with header_set that weren't in the original mail, they'll be added to the end.

CAVEATS

Email::Simple handles only RFC2822 formatted messages. This means you cannot expect it to cope well as the only parser between you and the outside world, say for example when writing a mail filter for invocation from a .forward file (for this we recommend you use Email::Filter anyway). For more information on this issue please consult RT issue 2478, http://rt.cpan.org/NoAuth/Bug.html?id=2478 .

PERL EMAIL PROJECT

This module is maintained by the Perl Email Project

http://emailproject.perl.org/wiki/Email::Simple

COPYRIGHT AND LICENSE

Copyright 2004 by Casey West

Copyright 2003 by Simon Cozens

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.