1MboxParser::Mail::Body(U3s)er Contributed Perl DocumentatMiboonxParser::Mail::Body(3)
2
3
4

NAME

6       Mail::MboxParser::Mail::Body - rudimentary mail-body object
7

SYNOPSIS

9           use Mail::MboxParser;
10
11           [...]
12
13           # $msg is a Mail::MboxParser::Mail
14           my $body = $msg->body(0);
15
16           # or preferably
17
18           my $body = $msg->body($msg->find_body);
19
20           for my $line ($body->signature) { print $line, "\n" }
21           for my $url ($body->extract_urls(unique => 1)) {
22               print $url->{url}, "\n";
23               print $url->{context}, "\n";
24           }
25

DESCRIPTION

27       This class represents the body of an email-message.  Since emails can
28       have multiple MIME-parts and each of these parts has a body it is not
29       always easy to say which part actually holds the text of the message
30       (if there is any at all).  Mail::MboxParser::Mail::find_body will help
31       and suggest a part.
32

METHODS

34       as_string ([strip_sig => 1])
35           Returns the textual representation of the body as one string.
36           Decoding takes place when the mailbox has been opened using the
37           decode => 'BODY' | 'ALL' option.
38
39           If 'strip_sig' is set to a true value, the signature is stripped
40           from the string.
41
42       as_lines ([strip_sig => 1])
43           Sames as as_string() just that you get an array of lines with
44           newlines attached to each line.
45
46           NOTE: When the body is actually some encoded binary data (most
47           commonly such a body is base64-encoded), you can still use this
48           method. Then you wont really get proper lines. Instead you get
49           chunks of binary data that you should concatenate as in
50
51               my $binary = join "", $body->as_lines;
52
53           If 'strip_sig' is set to a true value, the signature is stripped
54           from the string.
55
56       signature
57           Returns the signature of a message as an array of lines. Trailing
58           newlines are already removed.
59
60           $body->error returns a string if no signature has been found.
61
62       extract_urls
63       extract_urls (unique => 1)
64           Returns an array of hash-refs. Each hash-ref has two fields: 'url'
65           and 'context' where context is the line in which the 'url'
66           appeared.
67
68           When calling it like $mail->extract_urls(unique => 1), duplicate
69           URLs will be filtered out regardless of the 'context'. That's
70           useful if you just want a list of all URLs that can be found in
71           your mails.
72
73           $body->error() will return a string if no URLs could be found
74           within the body.
75
76       quotes
77           Returns a hash-ref of array-refs where the hash-keys are the
78           several levels of quotation. Each array-element contains the
79           paragraphs of this quotation-level as one string. Example:
80
81                   my $quotes = $msg->body($msg->find_body)->quotes;
82                   print $quotes->{1}->[0], "\n";
83                   print $quotes->{0}->[0], "\n";
84
85           This should print the first paragraph of the mail-body that has
86           been quoted once and below that the paragraph that supposedly is
87           the reply to this paragraph. Perhaps thus:
88
89                   > I had been trying to work with the CGI module
90                   > but I didn't yet fully understand it.
91
92                   Ah, it is tricky. Have you read the CGI-FAQ that
93                   comes with the module?
94
95           Mark that empty lines will not be ignored and are part of the lines
96           contained in the array of $quotes->{0}.
97
98           So below is a little code-snippet that should, in most cases,
99           restore the first 5 paragraphs (containing quote-level 0 and 1) of
100           an email:
101
102                   for (0 .. 4) {
103                           print $quotes->{0}->[$_];
104                           print $quotes->{1}->[$_];
105                   }
106
107           Since quotes() considers an empty line between two quotes
108           paragraphs as a paragraph in $quotes->{0}, the paragraphs with one
109           quote and those with zero are balanced. That means:
110
111           scalar @{$quotes->{0}} - DIFF == scalar @{$quotes->{1}} where DIFF
112           is element of {-1, 0, 1}.
113
114           Unfortunately, quotes() can up to now only deal with '>' as
115           quotation-marks.
116

VERSION

118       This is version 0.55.
119
121       Tassilo von Parseval <tassilo.von.parseval@rwth-aachen.de>
122
123       Copyright (c)  2001-2005 Tassilo von Parseval.  This program is free
124       software; you can redistribute it and/or modify it under the same terms
125       as Perl itself.
126

SEE ALSO

128perl v5.32.0                      2020-07-28         MboxParser::Mail::Body(3)
Impressum