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

VERSION

9       version 2.218
10

SYNOPSIS

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

DESCRIPTION

41       The Email:: namespace was begun as a reaction against the increasing
42       complexity and bugginess of Perl's existing email modules.  "Email::*"
43       modules are meant to be simple to use and to maintain, pared to the
44       bone, fast, minimal in their external dependencies, and correct.
45

PERL VERSION

47       This library should run on perls released even a long time ago.  It
48       should work on any version of perl released in the last five years.
49
50       Although it may work on older versions of perl, no guarantee is made
51       that the minimum required version will not be increased.  The version
52       may be increased for any reason, and there is no promise that patches
53       will be accepted to lower the minimum required perl.
54

METHODS

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

CAVEATS

168       Email::Simple handles only RFC2822 formatted messages.  This means you
169       cannot expect it to cope well as the only parser between you and the
170       outside world, say for example when writing a mail filter for
171       invocation from a .forward file (for this we recommend you use
172       Email::Filter anyway).
173

AUTHORS

175       •   Simon Cozens
176
177       •   Casey West
178
179       •   Ricardo SIGNES <cpan@semiotic.systems>
180

CONTRIBUTORS

182       •   Brian Cassidy <bricas@cpan.org>
183
184       •   Christian Walde <walde.christian@googlemail.com>
185
186       •   Marc Bradshaw <marc@marcbradshaw.net>
187
188       •   Michael Stevens <mstevens@etla.org>
189
190       •   Pali <pali@cpan.org>
191
192       •   Ricardo Signes <rjbs@cpan.org>
193
194       •   Ricardo Signes <rjbs@semiotic.systems>
195
196       •   Ronald F. Guilmette <rfg@tristatelogic.com>
197
198       •   William Yardley <pep@veggiechinese.net>
199
201       This software is copyright (c) 2003 by Simon Cozens.
202
203       This is free software; you can redistribute it and/or modify it under
204       the same terms as the Perl 5 programming language system itself.
205
206
207
208perl v5.36.0                      2023-01-20                  Email::Simple(3)
Impressum