1Mail::Message::Body::CoUnssetrruCcotn(t3r)ibuted Perl DoMcauimle:n:tMaetsisoange::Body::Construct(3)
2
3
4
6 Mail::Message::Body::Construct - adds functionality to
7 Mail::Message::Body
8
11 This package adds complex functionality to the Mail::Message::Body
12 class. This functions less often used, so many programs will not
13 compile this package.
14
16 Constructing a body
17 $obj->attach($messages, %options)
18 Make a multipart containing this body and the specified $messages.
19 The options are passed to the constructor of the multi-part body.
20 If you need more control, create the multi-part body yourself. At
21 least take a look at Mail::Message::Body::Multipart.
22
23 The message-parts will be coerced into a Mail::Message::Part, so
24 you may attach Mail::Internet or MIME::Entity objects if you want
25 --see Mail::Message::coerce(). A new body with attached messages
26 is returned.
27
28 example:
29
30 my $pgpkey = Mail::Message::Body::File->new(file => 'a.pgp');
31 my $msg = Mail::Message->buildFromBody(
32 $message->decoded->attach($pgpkey));
33
34 # The last message of the $multi multiparted body becomes a coerced $entity.
35 my $entity = MIME::Entity->new;
36 my $multi = $msg->body->attach($entity);
37
38 # Now create a new message
39 my $msg = Mail::Message->new(head => ..., body => $multi);
40
41 $obj->concatenate($components)
42 Concatenate a list of elements into one new body.
43
44 Specify a list of text $components. Each component can be a
45 message (Mail::Message, the body of the message is used), a plain
46 body (Mail::Message::Body), "undef" (which will be skipped), a
47 scalar (which is split into lines), or an array of scalars (each
48 providing one line).
49
50 example:
51
52 # all arguments are Mail::Message::Body's.
53 my $sum = $body->concatenate($preamble, $body, $epilogue, "-- \n" , $sig);
54
55 $obj->foreachLine(CODE)
56 Create a new body by performing an action on each of its lines. If
57 none of the lines change, the current body will be returned,
58 otherwise a new body is created of the same type as the current.
59
60 The CODE refers to a subroutine which is called, where $_ contains
61 body's original line. DO NOT CHANGE $_!!! The result of the
62 routine is taken as new line. When the routine returns "undef",
63 the line will be skipped.
64
65 example:
66
67 my $content = $msg->decoded;
68 my $reply = $content->foreachLine( sub { '> '.$_ } );
69 my $rev = $content->foreachLine( sub {reverse} );
70
71 sub filled() { length $_ > 1 ? $_ : undef }
72 my $nonempty = $content->foreachLine( \&filled );
73
74 my $wrong = $content->foreachLine( sub {s/a/A/} ); # WRONG!!!
75 my $right = $content->foreachLine(
76 sub {(my $x=$_) =~ s/a/A/; $x} );
77
78 $obj->stripSignature(%options)
79 Strip the signature from the body. The body must already be
80 decoded otherwise the wrong lines may get stripped. Returned is
81 the stripped version body, and in list context also the signature,
82 encapsulated in its own body object. The signature separator is
83 the first line of the returned signature body.
84
85 The signature is added by the sender to tell about him- or herself.
86 It is superfluous in some situations, for instance if you want to
87 create a reply to the person's message you do not need to include
88 that signature.
89
90 If the body had no signature, the original body object is returned,
91 and "undef" for the signature body.
92
93 -Option --Default
94 max_lines 10
95 pattern qr/^--\s?$/
96 result_type <same as current>
97
98 max_lines => INTEGER|undef
99 The maximum number of lines which can be the length of a
100 signature. Specify "undef" to remove the limit.
101
102 pattern => REGEX|STRING|CODE
103 Which pattern defines the line which indicates the separator
104 between the message and the signature. In case of a STRING, this
105 is matched to the beginning of the line, and REGEX is a full
106 regular expression.
107
108 In case of CODE, each line (from last to front) is passed to the
109 specified subroutine as first argument. The subroutine must
110 return TRUE when the separator is found.
111
112 result_type => CLASS
113 The type of body to be created for the stripped body (and maybe
114 also to contain the stripped signature)
115
116 example:
117
118 my $start = $message->decoded;
119 my $start = $body->decoded;
120
121 my $stripped = $start->stripSignature;
122
123 my ($stripped, $sign) = $start->stripSignature
124 (max_lines => 5, pattern => '-*-*-');
125
127 This module is part of Mail-Message distribution version 3.013, built
128 on June 24, 2023. Website: http://perl.overmeer.net/CPAN/
129
131 Copyrights 2001-2023 by [Mark Overmeer <markov@cpan.org>]. For other
132 contributors see ChangeLog.
133
134 This program is free software; you can redistribute it and/or modify it
135 under the same terms as Perl itself. See http://dev.perl.org/licenses/
136
137
138
139perl v5.38.0 2023-07-20 Mail::Message::Body::Construct(3)