File Coverage

blib/lib/Email/MIME.pm
Criterion Covered Total %
statement 343 351 97.7
branch 94 118 79.6
condition 53 76 69.7
subroutine 56 57 98.2
pod 29 36 80.5
total 575 638 90.1


line stmt bran cond sub pod time code
1 19     19   4263699 use v5.12.0;
  19         89  
2 19     19   107 use warnings;
  19         58  
  19         1625  
3             package Email::MIME 1.954;
4             # ABSTRACT: easy MIME message handling
5              
6 19     19   9320 use Email::Simple 2.212; # nth header value
  19         109164  
  19         682  
7 19     19   1764 use parent qw(Email::Simple);
  19         1238  
  19         133  
8              
9 19     19   1242 use Carp ();
  19         41  
  19         331  
10 19     19   8434 use Email::MessageID;
  19         28344  
  19         716  
11 19     19   6811 use Email::MIME::Creator;
  19         50  
  19         762  
12 19     19   9456 use Email::MIME::ContentType 1.023; # build_content_type
  19         192663  
  19         1516  
13 19     19   9824 use Email::MIME::Encode;
  19         60  
  19         814  
14 19     19   7434 use Email::MIME::Encodings 1.314;
  19         24648  
  19         640  
15 19     19   143 use Email::MIME::Header;
  19         28  
  19         525  
16 19     19   87 use Encode 1.9801 ();
  19         290  
  19         473  
17 19     19   82 use Scalar::Util qw(reftype weaken);
  19         32  
  19         56909  
18              
19             our @CARP_NOT = qw(Email::MIME::ContentType);
20              
21             our $MAX_DEPTH = 10;
22              
23             our $CUR_PARTS = 0;
24             our $MAX_PARTS = 100;
25              
26             #pod =head1 SYNOPSIS
27             #pod
28             #pod B Before you read this, maybe you just need L, which is
29             #pod a much easier-to-use tool for building simple email messages that might have
30             #pod attachments or both plain text and HTML. If that doesn't do it for you, then
31             #pod by all means keep reading.
32             #pod
33             #pod use Email::MIME;
34             #pod my $parsed = Email::MIME->new($message);
35             #pod
36             #pod my @parts = $parsed->parts; # These will be Email::MIME objects, too.
37             #pod my $decoded = $parsed->body;
38             #pod my $non_decoded = $parsed->body_raw;
39             #pod
40             #pod my $content_type = $parsed->content_type;
41             #pod
42             #pod ...or...
43             #pod
44             #pod use Email::MIME;
45             #pod use IO::All;
46             #pod
47             #pod # multipart message
48             #pod my @parts = (
49             #pod Email::MIME->create(
50             #pod attributes => {
51             #pod filename => "report.pdf",
52             #pod content_type => "application/pdf",
53             #pod encoding => "quoted-printable",
54             #pod name => "2004-financials.pdf",
55             #pod },
56             #pod body => io( "2004-financials.pdf" )->binary->all,
57             #pod ),
58             #pod Email::MIME->create(
59             #pod attributes => {
60             #pod content_type => "text/plain",
61             #pod disposition => "attachment",
62             #pod charset => "US-ASCII",
63             #pod },
64             #pod body_str => "Hello there!",
65             #pod ),
66             #pod );
67             #pod
68             #pod my $email = Email::MIME->create(
69             #pod header_str => [
70             #pod From => 'casey@geeknest.com',
71             #pod To => [ 'user1@host.com', 'Name ' ],
72             #pod Cc => Email::Address::XS->new("Display Name \N{U+1F600}", 'user@example.com'),
73             #pod ],
74             #pod parts => [ @parts ],
75             #pod );
76             #pod
77             #pod # nesting parts
78             #pod $email->parts_set(
79             #pod [
80             #pod $email->parts,
81             #pod Email::MIME->create( parts => [ @parts ] ),
82             #pod ],
83             #pod );
84             #pod
85             #pod # standard modifications
86             #pod $email->header_str_set( 'X-PoweredBy' => 'RT v3.0' );
87             #pod $email->header_str_set( To => rcpts() );
88             #pod $email->header_str_set( Cc => aux_rcpts() );
89             #pod $email->header_str_set( Bcc => sekrit_rcpts() );
90             #pod
91             #pod # more advanced
92             #pod $_->encoding_set( 'base64' ) for $email->parts;
93             #pod
94             #pod # Quick multipart creation
95             #pod my $email = Email::MIME->create(
96             #pod header_str => [
97             #pod From => 'my@address',
98             #pod To => 'your@address',
99             #pod ],
100             #pod parts => [
101             #pod q[This is part one],
102             #pod q[This is part two],
103             #pod q[These could be binary too],
104             #pod ],
105             #pod );
106             #pod
107             #pod print $email->as_string;
108             #pod
109             #pod =head1 DESCRIPTION
110             #pod
111             #pod This is an extension of the L module, to handle MIME
112             #pod encoded messages. It takes a message as a string, splits it up into its
113             #pod constituent parts, and allows you access to various parts of the
114             #pod message. Headers are decoded from MIME encoding.
115             #pod
116             #pod =head1 METHODS
117             #pod
118             #pod Please see L for the base set of methods. It won't take
119             #pod very long. Added to that, you have:
120             #pod
121             #pod =cut
122              
123             our $CREATOR = 'Email::MIME::Creator';
124              
125             my $NO_ENCODE_RE = qr/
126             \A
127             (?:7bit|8bit|binary)\s*(?:;|$)
128             /ix;
129              
130             sub new {
131 82     82 1 831624 local $CUR_PARTS = 0;
132 82         325 my ($class, @rest) = @_;
133 82         304 $class->_new(@rest);
134             }
135              
136             sub _new {
137 164     164   478 my ($class, $text, $arg, @rest) = @_;
138 164   100     538 $arg ||= {};
139              
140             my $encode_check = exists $arg->{encode_check}
141             ? delete $arg->{encode_check}
142 164 100       478 : Encode::FB_CROAK;
143              
144 164         699 my $self = shift->SUPER::new($text, $arg, @rest);
145 164         2765 $self->encode_check_set($encode_check);
146 164         389 $self->{ct} = parse_content_type($self->content_type_raw);
147 164         27755 $self->parts;
148 164         517 return $self;
149             }
150              
151             #pod =method create
152             #pod
153             #pod my $single = Email::MIME->create(
154             #pod header_str => [ ... ],
155             #pod body_str => '...',
156             #pod attributes => { ... },
157             #pod );
158             #pod
159             #pod my $multi = Email::MIME->create(
160             #pod header_str => [ ... ],
161             #pod parts => [ ... ],
162             #pod attributes => { ... },
163             #pod );
164             #pod
165             #pod This method creates a new MIME part. The C parameter is a list of
166             #pod headers pairs to include in the message. The value for each pair is expected to
167             #pod be a text string that will be MIME-encoded as needed. Alternatively it can be
168             #pod an object with C method which implements conversion of that
169             #pod object to MIME-encoded string. That object method is called with two named
170             #pod input parameters: C and C. It should return
171             #pod MIME-encoded representation of the object. As of 2017-07-25, the
172             #pod header-value-as-object code is very young, and may yet change.
173             #pod
174             #pod In case header name is registered in C<%Email::MIME::Header::header_to_class_map>
175             #pod hash then registered class is used for conversion from Unicode string to 8bit
176             #pod MIME encoding. Value can be either string or array reference to strings.
177             #pod Object is constructed via method C with string value (or values
178             #pod in case of array reference) and converted to MIME-encoded string via
179             #pod C method.
180             #pod
181             #pod A similar C
parameter can be provided in addition to or instead of
182             #pod C. Its values will be used verbatim.
183             #pod
184             #pod C is a hash of MIME attributes to assign to the part, and may
185             #pod override portions of the header set in the C
parameter. The hash keys
186             #pod correspond directly to methods for modifying a message. The allowed keys are:
187             #pod content_type, charset, name, format, boundary, encoding, disposition, and
188             #pod filename. They will be mapped to C<"$attr\_set"> for message modification.
189             #pod
190             #pod The C parameter is a list reference containing C
191             #pod objects. Elements of the C list can also be a non-reference
192             #pod string of data. In that case, an C object will be created
193             #pod for you. Simple checks will determine if the part is binary or not, and
194             #pod all parts created in this fashion are encoded with C, just in case.
195             #pod
196             #pod If C is given instead of C, it specifies the body to be used for a
197             #pod flat (subpart-less) MIME message. It is assumed to be a sequence of octets.
198             #pod
199             #pod If C is given instead of C or C, it is assumed to be a
200             #pod character string to be used as the body. If you provide a C
201             #pod parameter, you B provide C and C attributes.
202             #pod
203             #pod =cut
204              
205             my %CT_SETTER = map {; $_ => 1 } qw(
206             content_type charset name format boundary
207             encoding
208             disposition filename
209             );
210              
211             sub create {
212 54     54 1 1283682 my ($class, %args) = @_;
213              
214 54         273 my $header = '';
215 54         157 my %headers;
216 54 100       213 if (exists $args{header}) {
217 8         15 my @headers = @{ $args{header} };
  8         26  
218 8 50       31 pop @headers if @headers % 2 == 1;
219 8         40 while (my ($key, $value) = splice @headers, 0, 2) {
220 16         454 $headers{$key} = 1;
221 16         132 $CREATOR->_add_to_header(\$header, $key, $value);
222             }
223             }
224              
225 54 100       501 if (exists $args{header_str}) {
226 11         18 my @headers = @{ $args{header_str} };
  11         34  
227 11 50       75 pop @headers if @headers % 2 == 1;
228 11         48 while (my ($key, $value) = splice @headers, 0, 2) {
229 23         883 $headers{$key} = 1;
230              
231 23         77 $value = Email::MIME::Encode::maybe_mime_encode_header(
232             $key, $value, 'UTF-8'
233             );
234 23         128 $CREATOR->_add_to_header(\$header, $key, $value);
235             }
236             }
237              
238             $CREATOR->_add_to_header(\$header, Date => $CREATOR->_date_header)
239 54 50       855 unless exists $headers{Date};
240 54         105033 $CREATOR->_add_to_header(\$header, 'MIME-Version' => '1.0',);
241              
242 54 100       1811 my %attrs = $args{attributes} ? %{ $args{attributes} } : ();
  31         176  
243              
244             # XXX: This is awful... but if we don't do this, then Email::MIME->new will
245             # end up calling parse_content_type($self->content_type) which will mean
246             # parse_content_type(undef) which, for some reason, returns the default.
247             # It's really sort of mind-boggling. Anyway, the default ends up being
248             # q{text/plain; charset="us-ascii"} so that if content_type is in the
249             # attributes, but not charset, then charset isn't changed and you up with
250             # something that's q{image/jpeg; charset="us-ascii"} and you look like a
251             # moron. -- rjbs, 2009-01-20
252 54 100       168 if (
253 270         612 grep { exists $attrs{$_} } qw(content_type charset name format boundary)
254             ) {
255 30         103 $CREATOR->_add_to_header(\$header, 'Content-Type' => 'text/plain',);
256             }
257              
258 54         1017 my %pass_on;
259              
260 54 100       167 if (exists $args{encode_check}) {
261 3         9 $pass_on{encode_check} = $args{encode_check};
262             }
263              
264 54         207 my $email = $class->new($header, \%pass_on);
265              
266 54         211 for my $key (sort keys %attrs) {
267 64         247 $email->content_type_attribute_set($key => $attrs{$key});
268             }
269              
270 54         655 my $body_args = grep { defined $args{$_} } qw(parts body body_str);
  162         375  
271 54 50       181 Carp::confess("only one of parts, body, or body_str may be given")
272             if $body_args > 1;
273              
274 54 100 66     237 if ($args{parts} && @{ $args{parts} }) {
  14 100       65  
    100          
275 14         24 foreach my $part (@{ $args{parts} }) {
  14         35  
276 25 100       108 $part = $CREATOR->_construct_part($part)
277             unless ref($part);
278             }
279 14         92 $email->parts_set($args{parts});
280             } elsif (defined $args{body}) {
281 33         88 $email->body_set($args{body});
282             } elsif (defined $args{body_str}) {
283             Carp::confess("body_str was given, but no charset is defined")
284 6 50       28 unless my $charset = $attrs{charset};
285              
286             Carp::confess("body_str was given, but no encoding is defined")
287 6 50       45 unless $attrs{encoding};
288              
289 6         23 my $body_octets = Encode::encode($attrs{charset}, $args{body_str}, $email->encode_check);
290 4         1526 $email->body_set($body_octets);
291             }
292              
293 52         1005 $email;
294             }
295              
296             sub as_string {
297 145     145 1 3447 my $self = shift;
298             return $self->__head->as_string
299 145   50     461 . ($self->{mycrlf} || "\n") # XXX: replace with ->crlf
300             . $self->body_raw;
301             }
302              
303             sub parts {
304 302     302 1 3862 my $self = shift;
305              
306 302 100       1022 $self->fill_parts unless $self->{parts};
307              
308 302         379 my @parts = @{ $self->{parts} };
  302         623  
309 302 100       785 @parts = $self unless @parts;
310 302         754 return @parts;
311             }
312              
313             sub subparts {
314 52     52 1 120 my ($self) = @_;
315              
316 52 50       132 $self->fill_parts unless $self->{parts};
317 52         77 my @parts = @{ $self->{parts} };
  52         127  
318 52         158 return @parts;
319             }
320              
321             sub fill_parts {
322 193     193 0 309 my $self = shift;
323              
324 193 100 66     1003 if (
325             $self->{ct}{type} eq "multipart"
326             or $self->{ct}{type} eq "message"
327             ) {
328 41         163 $self->parts_multipart;
329             } else {
330 152         393 $self->parts_single_part;
331             }
332              
333 193         311 return $self;
334             }
335              
336             sub body {
337 106     106 1 1206 my $self = shift;
338 106         327 my $body = $self->SUPER::body;
339 106   100     987 my $cte = $self->header("Content-Transfer-Encoding") || '';
340              
341 106         288 $cte =~ s/\A\s+//;
342 106         187 $cte =~ s/\s+\z//;
343 106         158 $cte =~ s/;.+//; # For S/MIME, etc.
344              
345 106 100       265 return $body unless $cte;
346              
347 55 100 66     152 if (!$self->force_decode_hook and $cte =~ $NO_ENCODE_RE) {
348 26         101 return $body;
349             }
350              
351 29 50       207 $body = $self->decode_hook($body) if $self->can("decode_hook");
352              
353 29         124 $body = Email::MIME::Encodings::decode($cte, $body, '7bit');
354 29         903 return $body;
355             }
356              
357             sub parts_single_part {
358 152     152 0 259 my $self = shift;
359 152         348 $self->{parts} = [];
360 152         412 return $self;
361             }
362              
363             sub body_raw {
364 237   66 237 1 12969 return $_[0]->{body_raw} || $_[0]->SUPER::body;
365             }
366              
367             sub body_str {
368 14     14 1 1329 my ($self) = @_;
369 14         40 my $encoding = $self->{ct}{attributes}{charset};
370              
371 14 100       48 unless ($encoding) {
372 2 50 33     14 if ($self->{ct}{type} eq 'text'
      66        
373             and
374             ($self->{ct}{subtype} eq 'plain' or $self->{ct}{subtype} eq 'html')
375             ) {
376              
377             # assume that plaintext or html without ANY charset is us-ascii
378 1         5 return $self->body;
379             }
380              
381 1         4 Carp::confess("can't get body as a string for " . $self->content_type);
382             }
383              
384 12         44 my $str = Encode::decode($encoding, $self->body, $self->encode_check);
385 10         1207 return $str;
386             }
387              
388             sub parts_multipart {
389 41     41 0 68 my $self = shift;
390 41         146 my $boundary = $self->{ct}->{attributes}->{boundary};
391              
392 41   100     203 our $DEPTH ||= 0;
393              
394 41 50 33     251 Carp::croak("attempted to parse a MIME message more than $MAX_DEPTH deep")
395             if $MAX_DEPTH && $DEPTH > $MAX_DEPTH;
396              
397             # Take a message, join all its lines together. Now try to Email::MIME->new
398             # it with 1.861 or earlier. Death! It tries to recurse endlessly on the
399             # body, because every time it splits on boundary it gets itself. Obviously
400             # that means it's a bogus message, but a mangled result (or exception) is
401             # better than endless recursion. -- rjbs, 2008-01-07
402 41 50 33     188 return $self->parts_single_part
403             unless length $boundary and $self->body_raw =~ /^--\Q$boundary\E\s*$/sm;
404              
405 41         191 $self->{body_raw} = $self->SUPER::body;
406              
407             # rfc1521 7.2.1
408 41         1220 my ($body, $epilogue) = split /^--\Q$boundary\E--\s*$/sm, $self->body_raw, 2;
409              
410 41   50     968 my @bits = split /^--\Q$boundary\E\s*$/sm, ($body || '');
411              
412 41         170 $self->SUPER::body_set(undef);
413              
414             # If there are no headers in the potential MIME part, it's just part of the
415             # body. This is a horrible hack, although it's debatable whether it was
416             # better or worse when it was $self->{body} = shift @bits ... -- rjbs,
417             # 2006-11-27
418 41 50 100     665 $self->SUPER::body_set(shift @bits) if index(($bits[0] || ''), ':') == -1;
419              
420 41         537 local $CUR_PARTS = $CUR_PARTS + @bits;
421 41 50 33     261 Carp::croak("attempted to parse a MIME message with more than $MAX_PARTS parts")
422             if $MAX_PARTS && $CUR_PARTS > $MAX_PARTS;
423              
424 41         66 my @parts;
425 41         92 for my $bit (@bits) {
426 82         499 $bit =~ s/\A[\n\r]+//smg;
427 82         1282 $bit =~ s/(?{mycrlf}\Z//sm;
428 82         191 local $DEPTH = $DEPTH + 1;
429 82         262 my $email = (ref $self)->_new($bit, { encode_check => $self->encode_check });
430 82         262 push @parts, $email;
431             }
432              
433 41         161 $self->{parts} = \@parts;
434              
435 41         66 return @{ $self->{parts} };
  41         123  
436             }
437              
438 55     55 0 579 sub force_decode_hook { 0 }
439 29     29 1 111 sub decode_hook { return $_[1] }
440 22     22 1 131 sub content_type { scalar shift->header("Content-type"); }
441 164     164 0 464 sub content_type_raw { scalar shift->header_raw("Content-type"); }
442              
443             sub debug_structure {
444 7     7 1 995 my ($self, $level) = @_;
445 7   100     58 $level ||= 0;
446 7         18 my $rv = " " x (5 * $level);
447 7   100     13 $rv .= "+ " . ($self->content_type || '') . "\n";
448 7         16 my @parts = $self->subparts;
449 7         42 $rv .= $_->debug_structure($level + 1) for @parts;
450 7         24 return $rv;
451             }
452              
453             my %gcache;
454              
455             sub filename {
456 5     5 1 3306 my ($self, $force) = @_;
457 5 100       19 return $gcache{$self} if exists $gcache{$self};
458              
459 4   100     11 my $dis = $self->header_raw("Content-Disposition") || '';
460 4         126 my $attrs = parse_content_disposition($dis)->{attributes};
461             my $name = $attrs->{filename}
462 4   100     453 || $self->{ct}{attributes}{name};
463 4 100 66     26 return $name if $name or !$force;
464             return $gcache{$self} = $self->invent_filename(
465 2         8 $self->{ct}->{type} . "/" . $self->{ct}->{subtype});
466             }
467              
468             my $gname = 0;
469              
470             sub invent_filename {
471 2     2 1 4 my ($self, $ct) = @_;
472 2         24 require MIME::Types;
473 2         13 my $type = MIME::Types->new->type($ct);
474 2   33     101 my $ext = $type && (($type->extensions)[0]);
475 2   50     28 $ext ||= "dat";
476 2         28 return "attachment-$$-" . $gname++ . ".$ext";
477             }
478              
479 164     164 1 11097 sub default_header_class { 'Email::MIME::Header' }
480              
481             sub header_str {
482 26     26 0 10927 my $self = shift;
483 26         69 $self->header_obj->header_str(@_);
484             }
485              
486             sub header_str_set {
487 20     20 1 12476 my $self = shift;
488 20         74 $self->header_obj->header_str_set(@_);
489             }
490              
491             sub header_str_pairs {
492 1     1 1 1682 my $self = shift;
493 1         3 $self->header_obj->header_str_pairs(@_);
494             }
495              
496             sub header_as_obj {
497 14     14 1 60 my $self = shift;
498 14         31 $self->header_obj->header_as_obj(@_);
499             }
500              
501             #pod =method content_type_set
502             #pod
503             #pod $email->content_type_set( 'text/html' );
504             #pod
505             #pod Change the content type. All C header attributes
506             #pod will remain intact.
507             #pod
508             #pod =cut
509              
510             sub content_type_set {
511 28     28 1 2198 my ($self, $ct) = @_;
512 28         89 my $ct_header = parse_content_type($self->header('Content-Type'));
513 28         2791 @{$ct_header}{qw[type subtype]} = split m[/], $ct;
  28         79  
514 28         100 $self->_compose_content_type($ct_header);
515 28         92 $self->_reset_cids;
516 28         167 return $ct;
517             }
518              
519             #pod =method charset_set
520             #pod
521             #pod =method name_set
522             #pod
523             #pod =method format_set
524             #pod
525             #pod =method boundary_set
526             #pod
527             #pod $email->charset_set( 'UTF-8' );
528             #pod $email->name_set( 'some_filename.txt' );
529             #pod $email->format_set( 'flowed' );
530             #pod $email->boundary_set( undef ); # remove the boundary
531             #pod
532             #pod These four methods modify common C attributes. If set to
533             #pod C, the attribute is removed. All other C header
534             #pod information is preserved when modifying an attribute.
535             #pod
536             #pod =cut
537              
538             BEGIN {
539 19     19   83 foreach my $attr (qw[charset name format]) {
540             my $code = sub {
541 16     16   6205 my ($self, $value) = @_;
542 16         66 my $ct_header = parse_content_type($self->header('Content-Type'));
543 16 100       2092 if ($value) {
544 15         49 $ct_header->{attributes}->{$attr} = $value;
545             } else {
546 1         3 delete $ct_header->{attributes}->{$attr};
547             }
548 16         85 $self->_compose_content_type($ct_header);
549 16         52 return $value;
550 57         273 };
551              
552 19     19   146 no strict 'refs'; ## no critic strict
  19         33  
  19         1243  
553 57         88 *{"$attr\_set"} = $code;
  57         41523  
554             }
555             }
556              
557             sub boundary_set {
558 1     1 1 3 my ($self, $value) = @_;
559 1         7 my $ct_header = parse_content_type($self->header('Content-Type'));
560              
561 1 50       223 if (length $value) {
562 1         4 $ct_header->{attributes}->{boundary} = $value;
563             } else {
564 0         0 delete $ct_header->{attributes}->{boundary};
565             }
566 1         5 $self->_compose_content_type($ct_header);
567              
568 1 50       5 $self->parts_set([ $self->parts ]) if $self->parts > 1;
569             }
570              
571             sub content_type_attribute_set {
572 65     65 0 1456 my ($self, $key, $value) = @_;
573 65         128 $key = lc $key;
574              
575 65 100       201 if ($CT_SETTER{$key}) {
576 62         140 my $method = "$key\_set";
577 62         237 return $self->$method($value);
578             }
579              
580 3         19 my $ct_header = parse_content_type($self->header('Content-Type'));
581 3         410 my $attrs = $ct_header->{attributes};
582              
583 3         9 for my $existing_key (keys %$attrs) {
584 3 50       11 delete $attrs->{$existing_key} if lc $existing_key eq $key;
585             }
586              
587 3 50       10 if ($value) {
588 3         8 $ct_header->{attributes}->{$key} = $value;
589             } else {
590 0         0 delete $ct_header->{attributes}->{$key};
591             }
592 3         10 $self->_compose_content_type($ct_header);
593             }
594              
595             #pod =method encode_check
596             #pod
597             #pod =method encode_check_set
598             #pod
599             #pod $email->encode_check;
600             #pod $email->encode_check_set(0);
601             #pod $email->encode_check_set(Encode::FB_DEFAULT);
602             #pod
603             #pod Gets/sets the current C setting (default: I).
604             #pod This is the parameter passed to L and L
605             #pod when C, C, and C are called.
606             #pod
607             #pod With the default setting, Email::MIME may crash if the claimed charset
608             #pod of a body does not match its contents (for example - utf8 data in a
609             #pod text/plain; charset=us-ascii message).
610             #pod
611             #pod With an C of 0, the unrecognized bytes will instead be
612             #pod replaced with the C (U+0FFFD), and may end up
613             #pod as either that or question marks (?).
614             #pod
615             #pod See L for more information.
616             #pod
617             #pod =cut
618              
619             sub encode_check {
620 102     102 1 222 my ($self) = @_;
621              
622 102         639 return $self->{encode_check};
623             }
624              
625             sub encode_check_set {
626 164     164 1 309 my ($self, $val) = @_;
627              
628 164         406 return $self->{encode_check} = $val;
629             }
630              
631             #pod =method encoding_set
632             #pod
633             #pod $email->encoding_set( 'base64' );
634             #pod $email->encoding_set( 'quoted-printable' );
635             #pod $email->encoding_set( '8bit' );
636             #pod
637             #pod Convert the message body and alter the C
638             #pod header using this method. Your message body, the output of the C
639             #pod method, will remain the same. The raw body, output with the C
640             #pod method, will be changed to reflect the new encoding.
641             #pod
642             #pod =cut
643              
644             sub encoding_set {
645 59     59 1 115 my ($self, $enc) = @_;
646 59   100     182 $enc ||= '7bit';
647 59         155 my $body = $self->body;
648 59         240 $self->header_raw_set('Content-Transfer-Encoding' => $enc);
649 59         2731 $self->body_set($body);
650             }
651              
652             #pod =method body_set
653             #pod
654             #pod $email->body_set( $unencoded_body_string );
655             #pod
656             #pod This method will encode the new body you send using the encoding
657             #pod specified in the C header, then set
658             #pod the body to the new encoded body.
659             #pod
660             #pod =cut
661              
662             sub body_set {
663 295     295 1 15942 my ($self, $body) = @_;
664 295         466 my $body_ref;
665              
666 295 100       601 if (ref $body) {
667 165 50       537 Carp::croak("provided body reference is not a scalar reference")
668             unless reftype($body) eq 'SCALAR';
669 165         247 $body_ref = $body;
670             } else {
671 130         204 $body_ref = \$body;
672             }
673 295         778 my $enc = $self->header('Content-Transfer-Encoding');
674              
675             # XXX: This is a disgusting hack and needs to be fixed, probably by a
676             # clearer definition and reengineering of Simple construction. The bug
677             # this fixes is an indirect result of the previous behavior in which all
678             # Simple subclasses were free to alter the guts of the Email::Simple
679             # object. -- rjbs, 2007-07-16
680 295 100 100     2033 unless (((caller(1))[3] || '') eq 'Email::Simple::new') {
681 131 100 100     1308 $$body_ref = Email::MIME::Encodings::encode($enc, $$body_ref)
682             unless !$enc || $enc =~ $NO_ENCODE_RE;
683             }
684              
685 295         2191 $self->{body_raw} = $$body_ref;
686 295         920 $self->SUPER::body_set($body_ref);
687             }
688              
689             #pod =method body_str_set
690             #pod
691             #pod $email->body_str_set($unicode_str);
692             #pod
693             #pod This method behaves like C, but assumes that the given value is a
694             #pod Unicode string that should be encoded into the message's charset
695             #pod before being set.
696             #pod
697             #pod The charset must already be set, either manually (via the C
698             #pod argument to C or C) or through the C of a
699             #pod parsed message. If the charset can't be determined, an exception is thrown.
700             #pod
701             #pod =cut
702              
703             sub body_str_set {
704 0     0 1 0 my ($self, $body_str) = @_;
705              
706 0         0 my $ct = parse_content_type($self->content_type);
707             Carp::confess("body_str was given, but no charset is defined")
708 0 0       0 unless my $charset = $ct->{attributes}{charset};
709              
710 0         0 my $body_octets = Encode::encode($charset, $body_str, $self->encode_check);
711 0         0 $self->body_set($body_octets);
712             }
713              
714             #pod =method disposition_set
715             #pod
716             #pod $email->disposition_set( 'attachment' );
717             #pod
718             #pod Alter the C of a message. All header attributes
719             #pod will remain intact.
720             #pod
721             #pod =cut
722              
723             sub disposition_set {
724 8     8 1 394 my ($self, $dis) = @_;
725 8   50     21 $dis ||= 'inline';
726 8         69 my $dis_header = $self->header('Content-Disposition');
727 8 100       70 $dis_header
728             ? ($dis_header =~ s/^([^;]+)/$dis/)
729             : ($dis_header = $dis);
730 8         26 $self->header_raw_set('Content-Disposition' => $dis_header);
731             }
732              
733             #pod =method filename_set
734             #pod
735             #pod $email->filename_set( 'boo.pdf' );
736             #pod
737             #pod Sets the filename attribute in the C header. All other
738             #pod header information is preserved when setting this attribute.
739             #pod
740             #pod =cut
741              
742             sub filename_set {
743 4     4 1 8 my ($self, $filename) = @_;
744 4         13 my $dis_header = $self->header('Content-Disposition');
745 4         8 my ($disposition, $attrs) = ('inline', {});
746 4 50       7 if ($dis_header) {
747 4         9 my $struct = parse_content_disposition($dis_header);
748 4         373 $disposition = $struct->{type};
749 4         8 $attrs = $struct->{attributes};
750             }
751 4 100       10 $filename ? $attrs->{filename} = $filename : delete $attrs->{filename};
752 4         9 my $dis = build_content_disposition({type => $disposition, attributes => $attrs});
753 4         1550 $self->header_raw_set('Content-Disposition' => $dis);
754             }
755              
756             #pod =method parts_set
757             #pod
758             #pod $email->parts_set( \@new_parts );
759             #pod
760             #pod Replaces the parts for an object. Accepts a reference to a list of
761             #pod C objects, representing the new parts. If this message was
762             #pod originally a single part, the C header will be changed to
763             #pod C, and given a new boundary attribute.
764             #pod
765             #pod =cut
766              
767             sub parts_set {
768 29     29 1 150 my ($self, $parts) = @_;
769 29         56 my $body = q{};
770              
771 29         102 my $ct_header = parse_content_type($self->header('Content-Type'));
772              
773 29 100 100     3939 if (@{$parts} > 1 or $ct_header->{type} eq 'multipart') {
  29 50       204  
774              
775             # setup multipart
776             $ct_header->{attributes}->{boundary} = Email::MessageID->new->user
777 25 100       160 unless length $ct_header->{attributes}->{boundary};
778 25         19699 my $bound = $ct_header->{attributes}->{boundary};
779 25         43 foreach my $part (@{$parts}) {
  25         63  
780 51         150 $body .= "$self->{mycrlf}--$bound$self->{mycrlf}";
781 51         121 $body .= $part->as_string;
782             }
783 25         78 $body .= "$self->{mycrlf}--$bound--$self->{mycrlf}";
784              
785 25 100       58 unless (grep { $ct_header->{type} eq $_ } qw[multipart message]) {
  50         179  
786 10 50       41 if (scalar $self->header('Content-Type')) {
787 0         0 Carp::carp("replacing non-multipart type ($ct_header->{type}/$ct_header->{subtype}) with multipart/mixed");
788             }
789 10         29 @{$ct_header}{qw[type subtype]} = qw[multipart mixed];
  10         31  
790             }
791              
792 25         90 $self->encoding_set('7bit');
793 25         391 delete $ct_header->{attributes}{charset};
794             } elsif (@$parts == 1) { # setup singlepart
795 4         17 $body .= $parts->[0]->body;
796              
797 4         16 my $from_ct = parse_content_type($parts->[0]->header('Content-Type'));
798 4         444 @{$ct_header}{qw[type subtype]} = @{ $from_ct }{qw[type subtype]};
  4         10  
  4         12  
799              
800 4 100       14 if (exists $from_ct->{attributes}{charset}) {
801 2         8 $ct_header->{attributes}{charset} = $from_ct->{attributes}{charset};
802             } else {
803 2         4 delete $ct_header->{attributes}{charset};
804             }
805              
806 4         51 $self->encoding_set($parts->[0]->header('Content-Transfer-Encoding'));
807 4         78 delete $ct_header->{attributes}->{boundary};
808             }
809              
810 29         100 $self->_compose_content_type($ct_header);
811 29         96 $self->body_set($body);
812 29         461 $self->fill_parts;
813 29         88 $self->_reset_cids;
814             }
815              
816             #pod =method parts_add
817             #pod
818             #pod $email->parts_add( \@more_parts );
819             #pod
820             #pod Adds MIME parts onto the current MIME part. This is a simple extension
821             #pod of C to make our lives easier. It accepts an array reference
822             #pod of additional parts.
823             #pod
824             #pod =cut
825              
826             sub parts_add {
827 3     3 1 1440 my ($self, $parts) = @_;
828 3         9 $self->parts_set([ $self->parts, @{$parts}, ]);
  3         8  
829             }
830              
831             #pod =method walk_parts
832             #pod
833             #pod $email->walk_parts(sub {
834             #pod my ($part) = @_;
835             #pod return if $part->subparts; # multipart
836             #pod
837             #pod if ( $part->content_type =~ m[text/html]i ) {
838             #pod my $body = $part->body;
839             #pod $body =~ s/]+>//; # simple filter example
840             #pod $part->body_set( $body );
841             #pod }
842             #pod });
843             #pod
844             #pod Walks through all the MIME parts in a message and applies a callback to
845             #pod each. Accepts a code reference as its only argument. The code reference
846             #pod will be passed a single argument, the current MIME part within the
847             #pod top-level MIME object. All changes will be applied in place.
848             #pod
849             #pod =cut
850              
851             sub walk_parts {
852 10     10 1 2697 my ($self, $callback) = @_;
853              
854 10         51 my %changed;
855              
856             my $walk_weak;
857             my $walk = sub {
858 40     40   73 my ($part) = @_;
859 40         119 $callback->($part);
860              
861 40 100       4745 if (my @orig_subparts = $part->subparts) {
862 14         26 my $differ;
863             my @subparts;
864              
865 14         29 for my $part (@orig_subparts) {
866 30         70 my $str = $part->as_string;
867 30 50       97 next unless my $new = $walk_weak->($part);
868 30 100       72 $differ = 1 if $str ne $new->as_string;
869 30         92 push @subparts, $new;
870             }
871              
872             $differ
873             ||= (@subparts != @orig_subparts)
874             || (grep { $subparts[$_] != $orig_subparts[$_] } (0 .. $#subparts))
875 14   33     150 || (grep { $changed{ 0+$subparts[$_] } } (0 .. $#subparts));
      66        
876              
877 14 100       43 if ($differ) {
878 6         26 $part->parts_set(\@subparts);
879 6         176 $changed{ 0+$part }++;
880             }
881             }
882              
883 40         220 return $part;
884 10         58 };
885              
886 10         20 $walk_weak = $walk;
887 10         22 weaken $walk_weak;
888              
889 10         36 my $rv = $walk->($self);
890              
891 10         131 undef $walk;
892              
893 10         56 return $rv;
894             }
895              
896             sub _compose_content_type {
897 77     77   144 my ($self, $ct_header) = @_;
898 77         466 my $ct = build_content_type({type => $ct_header->{type}, subtype => $ct_header->{subtype}, attributes => $ct_header->{attributes}});
899 77         13604 $self->header_raw_set('Content-Type' => $ct);
900 77         4013 $self->{ct} = $ct_header;
901             }
902              
903             sub _get_cid {
904 39     39   144 Email::MessageID->new->address;
905             }
906              
907             sub _reset_cids {
908 57     57   144 my ($self) = @_;
909              
910 57         157 my $ct_header = parse_content_type($self->header('Content-Type'));
911              
912 57 100       6613 if ($self->parts > 1) {
913 19 100       69 if ($ct_header->{subtype} eq 'alternative') {
914 4         11 my %cids;
915 4         16 for my $part ($self->parts) {
916 9   100     31 my $cid = $part->header('Content-ID') // q{};
917 9         70 $cids{$cid}++;
918             }
919 4 100       66 return if keys(%cids) == 1;
920              
921 1         49 my $cid = $self->_get_cid;
922 1         64 $_->header_raw_set('Content-ID' => "<$cid>") for $self->parts;
923             } else {
924 15         35 foreach ($self->parts) {
925 38         874 my $cid = $self->_get_cid;
926 38 100       1969 $_->header_raw_set('Content-ID' => "<$cid>")
927             unless $_->header('Content-ID');
928             }
929             }
930             }
931             }
932              
933             1;
934              
935             =pod
936              
937             =encoding UTF-8
938              
939             =head1 NAME
940              
941             Email::MIME - easy MIME message handling
942              
943             =head1 VERSION
944              
945             version 1.954
946              
947             =head1 SYNOPSIS
948              
949             B Before you read this, maybe you just need L, which is
950             a much easier-to-use tool for building simple email messages that might have
951             attachments or both plain text and HTML. If that doesn't do it for you, then
952             by all means keep reading.
953              
954             use Email::MIME;
955             my $parsed = Email::MIME->new($message);
956              
957             my @parts = $parsed->parts; # These will be Email::MIME objects, too.
958             my $decoded = $parsed->body;
959             my $non_decoded = $parsed->body_raw;
960              
961             my $content_type = $parsed->content_type;
962              
963             ...or...
964              
965             use Email::MIME;
966             use IO::All;
967              
968             # multipart message
969             my @parts = (
970             Email::MIME->create(
971             attributes => {
972             filename => "report.pdf",
973             content_type => "application/pdf",
974             encoding => "quoted-printable",
975             name => "2004-financials.pdf",
976             },
977             body => io( "2004-financials.pdf" )->binary->all,
978             ),
979             Email::MIME->create(
980             attributes => {
981             content_type => "text/plain",
982             disposition => "attachment",
983             charset => "US-ASCII",
984             },
985             body_str => "Hello there!",
986             ),
987             );
988              
989             my $email = Email::MIME->create(
990             header_str => [
991             From => 'casey@geeknest.com',
992             To => [ 'user1@host.com', 'Name ' ],
993             Cc => Email::Address::XS->new("Display Name \N{U+1F600}", 'user@example.com'),
994             ],
995             parts => [ @parts ],
996             );
997              
998             # nesting parts
999             $email->parts_set(
1000             [
1001             $email->parts,
1002             Email::MIME->create( parts => [ @parts ] ),
1003             ],
1004             );
1005              
1006             # standard modifications
1007             $email->header_str_set( 'X-PoweredBy' => 'RT v3.0' );
1008             $email->header_str_set( To => rcpts() );
1009             $email->header_str_set( Cc => aux_rcpts() );
1010             $email->header_str_set( Bcc => sekrit_rcpts() );
1011              
1012             # more advanced
1013             $_->encoding_set( 'base64' ) for $email->parts;
1014              
1015             # Quick multipart creation
1016             my $email = Email::MIME->create(
1017             header_str => [
1018             From => 'my@address',
1019             To => 'your@address',
1020             ],
1021             parts => [
1022             q[This is part one],
1023             q[This is part two],
1024             q[These could be binary too],
1025             ],
1026             );
1027              
1028             print $email->as_string;
1029              
1030             =head1 DESCRIPTION
1031              
1032             This is an extension of the L module, to handle MIME
1033             encoded messages. It takes a message as a string, splits it up into its
1034             constituent parts, and allows you access to various parts of the
1035             message. Headers are decoded from MIME encoding.
1036              
1037             =head1 PERL VERSION
1038              
1039             This library should run on perls released even a long time ago. It should
1040             work on any version of perl released in the last five years.
1041              
1042             Although it may work on older versions of perl, no guarantee is made that the
1043             minimum required version will not be increased. The version may be increased
1044             for any reason, and there is no promise that patches will be accepted to
1045             lower the minimum required perl.
1046              
1047             =head1 METHODS
1048              
1049             Please see L for the base set of methods. It won't take
1050             very long. Added to that, you have:
1051              
1052             =head2 create
1053              
1054             my $single = Email::MIME->create(
1055             header_str => [ ... ],
1056             body_str => '...',
1057             attributes => { ... },
1058             );
1059              
1060             my $multi = Email::MIME->create(
1061             header_str => [ ... ],
1062             parts => [ ... ],
1063             attributes => { ... },
1064             );
1065              
1066             This method creates a new MIME part. The C parameter is a list of
1067             headers pairs to include in the message. The value for each pair is expected to
1068             be a text string that will be MIME-encoded as needed. Alternatively it can be
1069             an object with C method which implements conversion of that
1070             object to MIME-encoded string. That object method is called with two named
1071             input parameters: C and C. It should return
1072             MIME-encoded representation of the object. As of 2017-07-25, the
1073             header-value-as-object code is very young, and may yet change.
1074              
1075             In case header name is registered in C<%Email::MIME::Header::header_to_class_map>
1076             hash then registered class is used for conversion from Unicode string to 8bit
1077             MIME encoding. Value can be either string or array reference to strings.
1078             Object is constructed via method C with string value (or values
1079             in case of array reference) and converted to MIME-encoded string via
1080             C method.
1081              
1082             A similar C
parameter can be provided in addition to or instead of
1083             C. Its values will be used verbatim.
1084              
1085             C is a hash of MIME attributes to assign to the part, and may
1086             override portions of the header set in the C
parameter. The hash keys
1087             correspond directly to methods for modifying a message. The allowed keys are:
1088             content_type, charset, name, format, boundary, encoding, disposition, and
1089             filename. They will be mapped to C<"$attr\_set"> for message modification.
1090              
1091             The C parameter is a list reference containing C
1092             objects. Elements of the C list can also be a non-reference
1093             string of data. In that case, an C object will be created
1094             for you. Simple checks will determine if the part is binary or not, and
1095             all parts created in this fashion are encoded with C, just in case.
1096              
1097             If C is given instead of C, it specifies the body to be used for a
1098             flat (subpart-less) MIME message. It is assumed to be a sequence of octets.
1099              
1100             If C is given instead of C or C, it is assumed to be a
1101             character string to be used as the body. If you provide a C
1102             parameter, you B provide C and C attributes.
1103              
1104             =head2 content_type_set
1105              
1106             $email->content_type_set( 'text/html' );
1107              
1108             Change the content type. All C header attributes
1109             will remain intact.
1110              
1111             =head2 charset_set
1112              
1113             =head2 name_set
1114              
1115             =head2 format_set
1116              
1117             =head2 boundary_set
1118              
1119             $email->charset_set( 'UTF-8' );
1120             $email->name_set( 'some_filename.txt' );
1121             $email->format_set( 'flowed' );
1122             $email->boundary_set( undef ); # remove the boundary
1123              
1124             These four methods modify common C attributes. If set to
1125             C, the attribute is removed. All other C header
1126             information is preserved when modifying an attribute.
1127              
1128             =head2 encode_check
1129              
1130             =head2 encode_check_set
1131              
1132             $email->encode_check;
1133             $email->encode_check_set(0);
1134             $email->encode_check_set(Encode::FB_DEFAULT);
1135              
1136             Gets/sets the current C setting (default: I).
1137             This is the parameter passed to L and L
1138             when C, C, and C are called.
1139              
1140             With the default setting, Email::MIME may crash if the claimed charset
1141             of a body does not match its contents (for example - utf8 data in a
1142             text/plain; charset=us-ascii message).
1143              
1144             With an C of 0, the unrecognized bytes will instead be
1145             replaced with the C (U+0FFFD), and may end up
1146             as either that or question marks (?).
1147              
1148             See L for more information.
1149              
1150             =head2 encoding_set
1151              
1152             $email->encoding_set( 'base64' );
1153             $email->encoding_set( 'quoted-printable' );
1154             $email->encoding_set( '8bit' );
1155              
1156             Convert the message body and alter the C
1157             header using this method. Your message body, the output of the C
1158             method, will remain the same. The raw body, output with the C
1159             method, will be changed to reflect the new encoding.
1160              
1161             =head2 body_set
1162              
1163             $email->body_set( $unencoded_body_string );
1164              
1165             This method will encode the new body you send using the encoding
1166             specified in the C header, then set
1167             the body to the new encoded body.
1168              
1169             =head2 body_str_set
1170              
1171             $email->body_str_set($unicode_str);
1172              
1173             This method behaves like C, but assumes that the given value is a
1174             Unicode string that should be encoded into the message's charset
1175             before being set.
1176              
1177             The charset must already be set, either manually (via the C
1178             argument to C or C) or through the C of a
1179             parsed message. If the charset can't be determined, an exception is thrown.
1180              
1181             =head2 disposition_set
1182              
1183             $email->disposition_set( 'attachment' );
1184              
1185             Alter the C of a message. All header attributes
1186             will remain intact.
1187              
1188             =head2 filename_set
1189              
1190             $email->filename_set( 'boo.pdf' );
1191              
1192             Sets the filename attribute in the C header. All other
1193             header information is preserved when setting this attribute.
1194              
1195             =head2 parts_set
1196              
1197             $email->parts_set( \@new_parts );
1198              
1199             Replaces the parts for an object. Accepts a reference to a list of
1200             C objects, representing the new parts. If this message was
1201             originally a single part, the C header will be changed to
1202             C, and given a new boundary attribute.
1203              
1204             =head2 parts_add
1205              
1206             $email->parts_add( \@more_parts );
1207              
1208             Adds MIME parts onto the current MIME part. This is a simple extension
1209             of C to make our lives easier. It accepts an array reference
1210             of additional parts.
1211              
1212             =head2 walk_parts
1213              
1214             $email->walk_parts(sub {
1215             my ($part) = @_;
1216             return if $part->subparts; # multipart
1217              
1218             if ( $part->content_type =~ m[text/html]i ) {
1219             my $body = $part->body;
1220             $body =~ s/]+>//; # simple filter example
1221             $part->body_set( $body );
1222             }
1223             });
1224              
1225             Walks through all the MIME parts in a message and applies a callback to
1226             each. Accepts a code reference as its only argument. The code reference
1227             will be passed a single argument, the current MIME part within the
1228             top-level MIME object. All changes will be applied in place.
1229              
1230             =head2 header
1231              
1232             B Beware this method! In Email::MIME, it means the same as
1233             C, but on an Email::Simple object, it means C. Unless
1234             you always know what kind of object you have, you could get one of two
1235             significantly different behaviors.
1236              
1237             Try to use either C or C as appropriate.
1238              
1239             =head2 header_str_set
1240              
1241             $email->header_str_set($header_name => @value_strings);
1242              
1243             This behaves like C, but expects Unicode (character) strings as
1244             the values to set, rather than pre-encoded byte strings. It will encode them
1245             as MIME encoded-words if they contain any control or 8-bit characters.
1246              
1247             Alternatively, values can be objects with C method. Same as in
1248             method C.
1249              
1250             =head2 header_str_pairs
1251              
1252             my @pairs = $email->header_str_pairs;
1253              
1254             This method behaves like C, returning a list of field
1255             name/value pairs, but the values have been decoded to character strings, when
1256             possible.
1257              
1258             =head2 header_as_obj
1259              
1260             my $first_obj = $email->header_as_obj($field);
1261             my $nth_obj = $email->header_as_obj($field, $index);
1262             my @all_objs = $email->header_as_obj($field);
1263              
1264             my $nth_obj_of_class = $email->header_as_obj($field, $index, $class);
1265             my @all_objs_of_class = $email->header_as_obj($field, undef, $class);
1266              
1267             This method returns an object representation of the header value. It instances
1268             new object via method C of specified class. Input argument
1269             for that class method is list of the raw MIME-encoded values. If class argument
1270             is not specified then class name is taken from the hash
1271             C<%Email::MIME::Header::header_to_class_map> via key field. Use class method
1272             C<< Email::MIME::Header->set_class_for_header($class, $field) >> for adding new
1273             mapping.
1274              
1275             =head2 parts
1276              
1277             This returns a list of C objects reflecting the parts of the
1278             message. If it's a single-part message, you get the original object back.
1279              
1280             In scalar context, this method returns the number of parts.
1281              
1282             This is a stupid method. Don't use it.
1283              
1284             =head2 subparts
1285              
1286             This returns a list of C objects reflecting the parts of the
1287             message. If it's a single-part message, this method returns an empty list.
1288              
1289             In scalar context, this method returns the number of subparts.
1290              
1291             =head2 body
1292              
1293             This decodes and returns the body of the object I. For
1294             top-level objects in multi-part messages, this is highly likely to be something
1295             like "This is a multi-part message in MIME format."
1296              
1297             =head2 body_str
1298              
1299             This decodes both the Content-Transfer-Encoding layer of the body (like the
1300             C method) as well as the charset encoding of the body (unlike the C
1301             method), returning a Unicode string.
1302              
1303             If the charset is known, it is used. If there is no charset but the content
1304             type is either C or C, us-ascii is assumed. Otherwise,
1305             an exception is thrown.
1306              
1307             =head2 body_raw
1308              
1309             This returns the body of the object, but doesn't decode the transfer encoding.
1310              
1311             =head2 decode_hook
1312              
1313             This method is called before the L C method, to
1314             decode the body of non-binary messages (or binary messages, if the
1315             C method returns true). By default, this method does
1316             nothing, but subclasses may define behavior.
1317              
1318             This method could be used to implement the decryption of content in secure
1319             email, for example.
1320              
1321             =head2 content_type
1322              
1323             This is a shortcut for access to the content type header.
1324              
1325             =head2 filename
1326              
1327             This provides the suggested filename for the attachment part. Normally
1328             it will return the filename from the headers, but if C is
1329             passed a true parameter, it will generate an appropriate "stable"
1330             filename if one is not found in the MIME headers.
1331              
1332             =head2 invent_filename
1333              
1334             my $filename = Email::MIME->invent_filename($content_type);
1335              
1336             This routine is used by C to generate filenames for attached files.
1337             It will attempt to choose a reasonable extension, falling back to F.
1338              
1339             =head2 debug_structure
1340              
1341             my $description = $email->debug_structure;
1342              
1343             This method returns a string that describes the structure of the MIME entity.
1344             For example:
1345              
1346             + multipart/alternative; boundary="=_NextPart_2"; charset="BIG-5"
1347             + text/plain
1348             + text/html
1349              
1350             =head1 CONFIGURATION
1351              
1352             The variable C<$Email::MIME::MAX_DEPTH> is the maximum depth of parts that will
1353             be processed. It defaults to 10, already higher than legitimate mail is ever
1354             likely to be. This value may go up over time as the parser is improved.
1355              
1356             The variable C<$Email::MIME::MAX_PARTS> is the maximum number of parts that
1357             will be processed. It defaults to 100, already higher than legitimate mail is
1358             ever likely to be. This value may go up over time as the parser is improved or
1359             as research suggests that our starting position was wrong.
1360              
1361             Increasing either of these variables risks significant consumption of memory.
1362             Test before changing things.
1363              
1364             =head1 SEE ALSO
1365              
1366             L
1367              
1368             =head1 THANKS
1369              
1370             This module was generously sponsored by Best Practical
1371             (http://www.bestpractical.com/), Pete Sergeant, and Pobox.com.
1372              
1373             =head1 AUTHORS
1374              
1375             =over 4
1376              
1377             =item *
1378              
1379             Ricardo SIGNES
1380              
1381             =item *
1382              
1383             Casey West
1384              
1385             =item *
1386              
1387             Simon Cozens
1388              
1389             =back
1390              
1391             =head1 CONTRIBUTORS
1392              
1393             =for stopwords Alex Vandiver Anirvan Chatterjee Arthur Axel 'fREW' Schmidt Brian Cassidy Damian Lukowski Dan Book David Steinbrunner Dotan Dimet dxdc Eric Wong Geraint Edwards ivulfson Jesse Luehrs Kurt Anderson Lance A. Brown Matthew Horsfall memememomo Michael McClimon Mishrakk Pali Ricardo Signes Shawn Sorichetti Tomohiro Hosaka
1394              
1395             =over 4
1396              
1397             =item *
1398              
1399             Alex Vandiver
1400              
1401             =item *
1402              
1403             Anirvan Chatterjee
1404              
1405             =item *
1406              
1407             Arthur Axel 'fREW' Schmidt
1408              
1409             =item *
1410              
1411             Brian Cassidy
1412              
1413             =item *
1414              
1415             Damian Lukowski
1416              
1417             =item *
1418              
1419             Dan Book
1420              
1421             =item *
1422              
1423             David Steinbrunner
1424              
1425             =item *
1426              
1427             Dotan Dimet
1428              
1429             =item *
1430              
1431             dxdc
1432              
1433             =item *
1434              
1435             Eric Wong
1436              
1437             =item *
1438              
1439             Geraint Edwards
1440              
1441             =item *
1442              
1443             ivulfson <9122139+ivulfson@users.noreply.github.com>
1444              
1445             =item *
1446              
1447             Jesse Luehrs
1448              
1449             =item *
1450              
1451             Kurt Anderson
1452              
1453             =item *
1454              
1455             Lance A. Brown
1456              
1457             =item *
1458              
1459             Matthew Horsfall
1460              
1461             =item *
1462              
1463             memememomo
1464              
1465             =item *
1466              
1467             Michael McClimon
1468              
1469             =item *
1470              
1471             Mishrakk <48946018+Mishrakk@users.noreply.github.com>
1472              
1473             =item *
1474              
1475             Pali
1476              
1477             =item *
1478              
1479             Ricardo Signes
1480              
1481             =item *
1482              
1483             Ricardo Signes
1484              
1485             =item *
1486              
1487             Shawn Sorichetti
1488              
1489             =item *
1490              
1491             Tomohiro Hosaka
1492              
1493             =back
1494              
1495             =head1 COPYRIGHT AND LICENSE
1496              
1497             This software is copyright (c) 2004 by Simon Cozens and Casey West.
1498              
1499             This is free software; you can redistribute it and/or modify it under
1500             the same terms as the Perl 5 programming language system itself.
1501              
1502             =cut
1503              
1504             __END__