MboxPa...::Body(3pm)

πŸ“¦
version 0.55 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’Œ 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.


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