1Email::Simple(3) User Contributed Perl Documentation Email::Simple(3)
2
3
4
6 Email::Simple - simple parsing of RFC2822 message format and headers
7
9 version 2.216
10
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
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
47 new
48 my $email = Email::Simple->new($message, \%arg);
49
50 This method parses an email from a scalar containing an RFC2822
51 formatted message and returns an object. $message may be a reference
52 to a message string, in which case the string will be altered in place.
53 This can result in significant memory savings.
54
55 If you want to create a message from scratch, you should use the
56 "create" method.
57
58 Valid arguments are:
59
60 header_class - the class used to create new header objects
61 The named module is not 'require'-ed by Email::Simple!
62
63 create
64 my $email = Email::Simple->create(header => [ @headers ], body => '...');
65
66 This method is a constructor that creates an Email::Simple object from
67 a set of named parameters. The "header" parameter's value is a list
68 reference containing a set of headers to be created. The "body"
69 parameter's value is a scalar value holding the contents of the message
70 body. Line endings in the body will normalized to CRLF.
71
72 If no "Date" header is specified, one will be provided for you based on
73 the "gmtime" of the local machine. This is because the "Date" field is
74 a required header and is a pain in the neck to create manually for
75 every message. The "From" field is also a required header, but it is
76 not provided for you.
77
78 header_obj
79 my $header = $email->header_obj;
80
81 This method returns the object representing the email's header. For
82 the interface for this object, see Email::Simple::Header.
83
84 header_obj_set
85 $email->header_obj_set($new_header_obj);
86
87 This method substitutes the given new header object for the email's
88 existing header object.
89
90 header
91 my @values = $email->header($header_name);
92 my $first = $email->header($header_name);
93 my $value = $email->header($header_name, $index);
94
95 In list context, this returns every value for the named header. In
96 scalar context, it returns the first value for the named header. If
97 second parameter is specified then instead first value it returns value
98 at position $index (negative $index is from the end).
99
100 header_set
101 $email->header_set($field, $line1, $line2, ...);
102
103 Sets the header to contain the given data. If you pass multiple lines
104 in, you get multiple headers, and order is retained. If no values are
105 given to set, the header will be removed from to the message entirely.
106
107 header_raw
108 This is another name (and the preferred one) for "header".
109
110 header_raw_set
111 This is another name (and the preferred one) for "header_set".
112
113 header_raw_prepend
114 $email->header_raw_prepend($field => $value);
115
116 This method adds a new instance of the name field as the first field in
117 the header.
118
119 header_names
120 my @header_names = $email->header_names;
121
122 This method returns the list of header names currently in the email
123 object. These names can be passed to the "header" method one-at-a-time
124 to get header values. You are guaranteed to get a set of headers that
125 are unique. You are not guaranteed to get the headers in any order at
126 all.
127
128 For backwards compatibility, this method can also be called as headers.
129
130 header_pairs
131 my @headers = $email->header_pairs;
132
133 This method returns a list of pairs describing the contents of the
134 header. Every other value, starting with and including zeroth, is a
135 header name and the value following it is the header value.
136
137 header_raw_pairs
138 This is another name (and the preferred one) for "header_pairs".
139
140 body
141 Returns the body text of the mail.
142
143 body_set
144 Sets the body text of the mail.
145
146 as_string
147 Returns the mail as a string, reconstructing the headers.
148
149 crlf
150 This method returns the type of newline used in the email. It is an
151 accessor only.
152
153 default_header_class
154 This returns the class used, by default, for header objects, and is
155 provided for subclassing. The default default is
156 Email::Simple::Header.
157
159 Email::Simple handles only RFC2822 formatted messages. This means you
160 cannot expect it to cope well as the only parser between you and the
161 outside world, say for example when writing a mail filter for
162 invocation from a .forward file (for this we recommend you use
163 Email::Filter anyway).
164
166 · Simon Cozens
167
168 · Casey West
169
170 · Ricardo SIGNES
171
173 · Brian Cassidy <bricas@cpan.org>
174
175 · Christian Walde <walde.christian@googlemail.com>
176
177 · Marc Bradshaw <marc@marcbradshaw.net>
178
179 · Michael Stevens <mstevens@etla.org>
180
181 · Pali <pali@cpan.org>
182
183 · Ricardo SIGNES <rjbs@cpan.org>
184
185 · Ronald F. Guilmette <rfg@tristatelogic.com>
186
187 · William Yardley <pep@veggiechinese.net>
188
190 This software is copyright (c) 2003 by Simon Cozens.
191
192 This is free software; you can redistribute it and/or modify it under
193 the same terms as the Perl 5 programming language system itself.
194
195
196
197perl v5.30.1 2020-01-29 Email::Simple(3)