MboxPa...::Body(3pm)
π MboxPa...::Body β the whole vibe π
okay bestie, so this page is from the User Contributed Perl Documentation for Mail::MboxParser::Mail::Body, and we're about to make it make sense. sit down, grab a strawberry drink π, and let's go.
β¨ NAME β¨
Mail::MboxParser::Mail::Body β it's a rudimentary mail-body object, no cap. it does the basics and it does them well π
π SYNOPSIS π
here's the whole little situation, copy it exactly or the vibes will be off:
use Mail::MboxParser;
[...]
# $msg is a Mail::MboxParser::Mail
my $body = $msg->body(0);
# or preferably
my $body = $msg->body($msg->find_body);
for my $line ($body->signature) { print $line, "\n" }
for my $url ($body->extract_urls(unique => 1)) {
print $url->{url}, "\n";
print $url->{context}, "\n";
}
see that $msg->body($msg->find_body) up there? that's the preferred way, bestie, don't fight it π
π¦ DESCRIPTION π¦
so this class represents the body of an email-message. sounds simple, right? WRONG, kind of π β because emails can have multiple MIME-parts and every single one of those parts has a body of its own. so likeβ¦ which part is actually holding the text of the message? (if there's any text at all, which, mood). that's the whole problem.
Mail::MboxParser::Mail::find_body is your bestie here β it'll help you out and suggest a part. π«Ά
π METHODS π
π as_string ([strip_sig => 1])
returns the textual representation of the body as one string, one single unit, slay.
decoding happens when the mailbox has been opened using the decode => 'BODY' | 'ALL' option β so like, that's when the magic kicks in β¨
and if 'strip_sig' is set to a true value, the signature gets stripped from the string. bye bye signature π¨
π as_lines ([strip_sig => 1])
same as as_string() except you get an array of lines, with newlines attached to each line. iconic.
NOTE: when the body is actually some encoded binary data (most commonly such a body is base64-encoded), you can still use this method. but then you won't really get proper lines, bestie. instead you get chunks of binary data that you should concatenate, like this:
my $binary = join "", $body->as_lines;
if 'strip_sig' is set to a true value, the signature is stripped from the string. yes, same as before. it's consistent, we love that for her π
π signature
returns the signature of a message as an array of lines. trailing newlines are already removed β she's tidy like that β¨
$body->error returns a string if no signature has been found. so if you get nothing, check the error, don't just sit there confused π
π extract_urls
π extract_urls (unique => 1)
returns an array of hash-refs. each hash-ref has two fields: 'url' and 'context', where context is the line in which the 'url' appeared. so you get the link AND the receipt of where it came from, we love context π
when you call it like $mail->extract_urls(unique => 1), duplicate URLs get filtered out regardless of the 'context'. that's genuinely useful if you just want a list of all the URLs hanging out in your mails, no dupes, no drama.
$body->error() will return a string if no URLs could be found within the body. again: check the error, bestie π₯
π quotes
returns a hash-ref of array-refs, where the hash-keys are the several levels of quotation. each array-element contains the paragraphs of this quotation-level as one string. okay example time:
my $quotes = $msg->body($msg->find_body)->quotes;
print $quotes->{1}->[0], "\n";
print $quotes->{0}->[0], "\n";
this should print the first paragraph of the mail-body that has been quoted once, and below that, the paragraph that supposedly is the reply to this paragraph. perhaps thus:
> I had been trying to work with the CGI module
> but I didn't yet fully understand it.
Ah, it is tricky. Have you read the CGI-FAQ that
comes with the module?
see what she did there? π
mark that empty lines will not be ignored and are part of the lines contained in the array of $quotes->{0}. she counts them. she sees them. nothing escapes her π
so below is a little code-snippet that should, in most cases, restore the first 5 paragraphs (containing quote-level 0 and 1) of an email:
for (0 .. 4) {
print $quotes->{0}->[$_];
print $quotes->{1}->[$_];
}
since quotes() considers an empty line between two quotes paragraphs as a paragraph in $quotes->{0}, the paragraphs with one quote and those with zero are balanced. that means:
scalar @{$quotes->{0}} - DIFF == scalar @{$quotes->{1}} where DIFF is element of {-1, 0, 1}.
fr fr, that's the math, that's the balance, that's the symmetry β¨
unfortunately,quotes()can up to now only deal with'>'as quotation-marks. that's the limit, bestie, she's doing her best π
πΈ VERSION πΈ
this is version 0.55.
π AUTHOR AND COPYRIGHT π
Tassilo von Parseval <tassilo.von.parseval@rwth-aachen.de> β the icon, the legend π
Copyright (c) 2001-2005 Tassilo von Parseval. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π« SEE ALSO π«
nothing listed here, bestie β the section's just vibing empty. no references, no cross-links, just space π¦
and that's the whole page, periodt π
this was perl v5.34.0 documentation dated 2022-06-15 β thanks for reading my ted talk, mwah π«Άπ
π¦ where this page comes from
- debian bookworm: libmail-mboxparser-perl 0.55-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmail-mboxparser-perl 0.55-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmail-mboxparser-perl 0.55-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmail-mboxparser-perl 0.55-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmail-mboxparser-perl 0.55-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms