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