Explode(3pm)
π NAME π
okay so bestie, gather round β this is MIME::Explode, a Perl extension for explode MIME messages. no cap, that's literally the whole vibe. π
πΈ SYNOPSIS πΈ
here's how you actually use it, copy-paste girlies rise:
use MIME::Explode;
my $explode = MIME::Explode->new(
output_dir => "tmp",
mkdir => 0755,
decode_subject => 1,
check_content_type => 1,
content_types => ["image/gif", "image/jpeg", "image/bmp"],
types_action => "exclude"
);
print "Number of messages: ", $explode->nmsgs, "\n";
open(MAIL, "<file.mbox") or
die("Couldn't open file.mbox for reading: $!\n");
open(OUTPUT, ">file.tmp")
or die("Couldn't open file.tmp for writing: $!\n");
my $headers = $explode->parse(\*MAIL, \*OUTPUT);
close(OUTPUT);
close(MAIL);
for my $part (sort{ $a cmp $b } keys(%{$headers})) {
for my $k (keys(%{$headers->{$part}})) {
if(ref($headers->{$part}->{$k}) eq "ARRAY") {
for my $i (0 .. $#{$headers->{$part}->{$k}}) {
print "$part => $k => $i => ", $headers->{$part}->{$k}->[$i], "\n";
}
} elsif(ref($headers->{$part}->{$k}) eq "HASH") {
for my $ks (keys(%{$headers->{$part}->{$k}})) {
if(ref($headers->{$part}->{$k}->{$ks}) eq "ARRAY") {
print "$part => $k => $ks => ", join(($ks eq "charset") ? " " : "", @{$headers->{$part}->{$k}->{$ks}}), "\n";
} else {
print "$part => $k => $ks => ", $headers->{$part}->{$k}->{$ks}, "\n";
}
print "$part => $k => $ks => ", $headers->{$part}->{$k}->{$ks}, "\n";
}
} else {
print "$part => $k => ", $headers->{$part}->{$k}, "\n";
}
}
}
if(my $e = $explode->clean_all()) {
print "Error: $e\n";
}
β¨ DESCRIPTION β¨
MIME::Explode is a perl module for parsing and decoding single or multipart MIME messages, and outputting its decoded components to a given directory. basically?? it's giving "extract the attached files out of a MIME encoded email messages or mailboxes" energy β that's the whole point of it, and the module is designed to allow users to do exactly that. π
π«Ά METHODS π«Ά
new([, OPTION ...])
this method create a new MIME::Explode object. slay. here are the keys you can pass, all of them, no skips:
output_dirβ Directory where the decoded files are placed πmkdir => octal_numberβ If the value is set to octal number then make theoutput_dirdirectory (example:mkdir => 0755). like it literally goes and makes the folder for you, iconic.check_content_type => 0 or 1β If the value is set to1the content-type of file is checked πdecode_subject => 0 or 1β If the value is set to1then the subject is decoded into a list. so you get:
$header->{'0.0'}->{subject}->{value} = [ARRAYREF];
$header->{'0.0'}->{subject}->{charset} = [ARRAYREF];
$subject = join("", @{$header->{'0.0'}->{subject}->{value}});
exclude_types => [ARRAYREF]β Not save files with specified content types (deprecated in next versions) β οΈ yeah bestie, deprecated, so don't get too attached.content_types => [ARRAYREF]β Array reference with content types for "include" or "exclude"types_action => "include" or "exclude"β If the action is a"include", all attached files with specified content types are saved but if the action is a"exclude", no files are saved except if its in the array of content types. If no array is specified, but the action is a"include", all attached files are saved, otherwise all files are removed if action is a"exclude". The default action is"include". π
parse(FILEHANDLE, FILEHANDLE)
this method parse the stream and splits it into its component entities. it return a hash reference with all parts. the FILEHANDLE should be a reference to a GLOB. the second argument is optional. yes queen, optional, you can just not. π
nmsgs
Returns the number of parsed messages. that's it, that's the whole method, we love a one-liner. π
clean_all
Cleans all files from the "output_dir" directory and then removes the directory. If an error happens returns it. so it's not just cleaning, it's deleting β she takes the whole folder with her. π§
π AUTHOR π
Henrique Dias <henrique.ribeiro.dias@gmail.com>
π CREDITS π
Thanks to Rui Castro for the revision. shoutout to the bestie who proofread, fr fr. π«Ά
π¦ SEE ALSO π¦
MIME::Tools, perl(1).
and that's the whole page, bestie!! this manual was brought to you by perl v5.42.3, dated 2026-08-19 β go forth and explode those MIME messages, you absolute main character π β¨πΈ
π¦ where this page comes from
- ubuntu stonking: libmime-explode-perl 0.39-4build6 Β· 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