1Email::Simple(3)      User Contributed Perl Documentation     Email::Simple(3)
2
3
4

NAME

6       Email::Simple - simple parsing of RFC2822 message format and headers
7

SYNOPSIS

9         my $email = Email::Simple->new($text);
10
11         my $from_header = $email->header("From");
12         my @received = $email->header("Received");
13
14         $email->header_set("From", 'Simon Cozens <simon@cpan.org>');
15
16         my $old_body = $email->body;
17         $email->body_set("Hello world\nSimon");
18
19         print $email->as_string;
20
21       ...or, to create a message from scratch...
22
23         my $email = Email::Simple->create(
24             header => [
25               From    => 'casey@geeknest.com',
26               To      => 'drain@example.com',
27               Subject => 'Message in a bottle',
28             ],
29             body => '...',
30         );
31
32         $email->header_set( 'X-Content-Container' => 'bottle/glass' );
33
34         print $email->as_string;
35

DESCRIPTION

37       "Email::Simple" is the first deliverable of the "Perl Email Project."
38       The Email:: namespace was begun as a reaction against the increasing
39       complexity and bugginess of Perl's existing email modules.  "Email::*"
40       modules are meant to be simple to use and to maintain, pared to the
41       bone, fast, minimal in their external dependencies, and correct.
42

METHODS

44   new
45         my $email = Email::Simple->new($message, \%arg);
46
47       This method parses an email from a scalar containing an RFC2822
48       formatted message, and return an object.  $message may be a reference
49       to a message string, in which case the string will be altered in place.
50       This can result in significant memory savings.
51
52       If you want to create a message from scratch, you should use the plugin
53       Email::Simple::Creator.
54
55       Valid arguments are:
56
57         header_class - the class used to create new header objects
58                        The named module is not 'require'-ed by Email::Simple!
59
60   create
61         my $email = Email::Simple->create(header => [ @headers ], body => '...');
62
63       This method is a constructor that creates an Email::Simple object from
64       a set of named parameters. The "header" parameter's value is a list
65       reference containing a set of headers to be created. The "body"
66       parameter's value is a scalar value holding the contents of the message
67       body.  Line endings in the body will normalized to CRLF.
68
69       If no "Date" header is specified, one will be provided for you based on
70       the "gmtime" of the local machine. This is because the "Date" field is
71       a required header and is a pain in the neck to create manually for
72       every message. The "From" field is also a required header, but it is
73       not provided for you.
74
75   header_obj
76         my $header = $email->header_obj;
77
78       This method returns the object representing the email's header.  For
79       the interface for this object, see Email::Simple::Header.
80
81   header_obj_set
82         $email->header_obj_set($new_header_obj);
83
84       This method substitutes the given new header object for the email's
85       existing header object.
86
87   header
88         my @values = $email->header($header_name);
89         my $first  = $email->header($header_name);
90
91       In list context, this returns every value for the named header.  In
92       scalar context, it returns the first value for the named header.
93
94   header_set
95           $email->header_set($field, $line1, $line2, ...);
96
97       Sets the header to contain the given data. If you pass multiple lines
98       in, you get multiple headers, and order is retained.  If no values are
99       given to set, the header will be removed from to the message entirely.
100
101   header_names
102           my @header_names = $email->header_names;
103
104       This method returns the list of header names currently in the email
105       object.  These names can be passed to the "header" method one-at-a-time
106       to get header values. You are guaranteed to get a set of headers that
107       are unique. You are not guaranteed to get the headers in any order at
108       all.
109
110       For backwards compatibility, this method can also be called as headers.
111
112   header_pairs
113         my @headers = $email->header_pairs;
114
115       This method returns a list of pairs describing the contents of the
116       header.  Every other value, starting with and including zeroth, is a
117       header name and the value following it is the header value.
118
119   body
120       Returns the body text of the mail.
121
122   body_set
123       Sets the body text of the mail.
124
125   as_string
126       Returns the mail as a string, reconstructing the headers.
127
128   crlf
129       This method returns the type of newline used in the email.  It is an
130       accessor only.
131
132   default_header_class
133       This returns the class used, by default, for header objects, and is
134       provided for subclassing.  The default default is
135       Email::Simple::Header.
136

CAVEATS

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

PERL EMAIL PROJECT

146       This module is maintained by the Perl Email Project
147
148       <http://emailproject.perl.org/wiki/Email::Simple>
149

AUTHORS

151       Simon Cozens originally wrote Email::Simple in 2003.  Casey West took
152       over maintenance in 2004, and Ricardo SIGNES took over maintenance in
153       2006.
154
156       Copyright 2004 by Casey West
157
158       Copyright 2003 by Simon Cozens
159
160       This library is free software; you can redistribute it and/or modify it
161       under the same terms as Perl itself.
162
163
164
165perl v5.12.1                      2009-11-04                  Email::Simple(3)
Impressum