File: Construct.pod

package info (click to toggle)
libmail-box-perl 2.068-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,576 kB
  • ctags: 1,493
  • sloc: perl: 22,358; makefile: 49
file content (193 lines) | stat: -rw-r--r-- 5,127 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

=head1 NAME

Mail::Message::Body::Construct - adds functionality to Mail::Message::Body



=head1 SYNOPSIS



=head1 DESCRIPTION

This package adds complex functionality to the L<Mail::Message::Body|Mail::Message::Body>
class.  This functions less often used, so many programs will not
compile this package.



=head1 METHODS


=head2 Constructing a body


$obj-E<gt>B<attach>(MESSAGES, OPTIONS)

=over 4

Make a multipart containing this body and the specified MESSAGES. The
options are passed to the constructor of the multi-part body.  If you
need more control, create the multi-part body yourself.  At least
take a look at L<Mail::Message::Body::Multipart|Mail::Message::Body::Multipart>.

The message-parts will be coerced into a L<Mail::Message::Part|Mail::Message::Part>, so you
may attach Mail::Internet or MIME::Entity objects if you want --see
L<Mail::Message::coerce()|Mail::Message/"Internals">.  A new body with attached messages is
returned.

I<Example:> 

 my $pgpkey = Mail::Message::Body::File->new(file => 'a.pgp');
 my $msg    = Mail::Message->buildFromBody(
    $message->decoded->attach($pgpkey));

 # The last message of the $multi multiparted body becomes a coerced $entity.
 my $entity  = MIME::Entity->new;
 my $multi   = $msg->body->attach($entity);

 # Now create a new message
 my $msg     = Mail::Message->new(head => ..., body => $multi);

=back

$obj-E<gt>B<concatenate>(COMPONENTS)

=over 4

Concatenate a list of elements into one new body.  The encoding is defined by
the body where this method is called upon (and which does not need to be
included in the result).

Specify a list of COMPONENTS.  Each component can be
a message (L<Mail::Message|Mail::Message>, the body of the message is used),
a plain body (L<Mail::Message::Body|Mail::Message::Body>), 
C<undef> (which will be skipped),
a scalar (which is split into lines), or
an array of scalars (each providing one line).

I<Example:> 

 # all arguments are Mail::Message::Body's.
 my $sum = $body->concatenate($preamble, $body, $epilogue, "-- \n" , $sig);

=back

$obj-E<gt>B<foreachLine>(CODE)

=over 4

Create a new body by performing an action on each of its lines.  If none
of the lines change, the current body will be returned, otherwise a new
body is created of the same type as the current.

The CODE refers to a subroutine which is called, where C<$_> contains
body's original line.  DO NOT CHANGE C<$_>!!!  The result of the routine
is taken as new line.  When the routine returns C<undef>, the line will be
skipped.

I<Example:> 

 my $content  = $msg->decoded;
 my $reply    = $content->foreachLine( sub { '> '.$_ } );
 my $rev      = $content->foreachLine( sub {reverse} );

 sub filled() { length $_ > 1 ? $_ : undef }
 my $nonempty = $content->foreachLine( \&filled );

 my $wrong    = $content->foreachLine( sub {s/a/A/} );  # WRONG!!!
 my $right    = $content->foreachLine(
        sub {(my $x=$_) =~ s/a/A/; $x} );

=back

$obj-E<gt>B<stripSignature>(OPTIONS)

=over 4

Strip the signature from the body.  The body must already be decoded
otherwise the wrong lines may get stripped.  Returned is the stripped
version body, and in list context also the signature, encapsulated in
its own body object.  The signature separator is the first line of the
returned signature body.

The signature is added by the sender to tell about him- or herself.
It is superfluous in some situations, for instance if you want to create
a reply to the person's message you do not need to include that signature.

If the body had no signature, the original body object is returned,
and C<undef> for the signature body.

 Option     --Defined in     --Default
 max_lines                     10
 pattern                       qr/^--\s?$/
 result_type                   <same as current>

. max_lines INTEGER|undef

=over 4

The maximum number of lines which can be the length of a signature.
Specify C<undef> to remove the limit.

=back

. pattern REGEX|STRING|CODE

=over 4

Which pattern defines the line which indicates the separator between
the message and the signature.  In case of a STRING, this is matched
to the beginning of the line, and REGEX is a full regular expression.

In case of CODE, each line (from last to front) is passed to the
specified subroutine as first argument.  The subroutine must return
TRUE when the separator is found.

=back

. result_type CLASS

=over 4

The type of body to be created for the stripped body (and maybe also to
contain the stripped signature)

=back

I<Example:> 

 my $start = $message->decoded;
 my $start = $body->decoded;

 my $stripped = $start->stripSignature;

 my ($stripped, $sign) = $start->stripSignature
     (max_lines => 5, pattern => '-*-*-');

=back









=head1 REFERENCES

See the MailBox website at L<http://perl.overmeer.net/mailbox/> for more details.

=head1 COPYRIGHTS

Distribution version 2.068.
Written by Mark Overmeer (mark@overmeer.net).  See the ChangeLog for
other contributors.

Copyright (c) 2001-2006 by the author(s). All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.