{
    "mode": "perldoc",
    "parameter": "MIME::Explode",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/MIME%3A%3AExplode/json",
    "generated": "2026-06-11T18:09:12Z",
    "synopsis": "use MIME::Explode;\nmy $explode = MIME::Explode->new(\noutputdir         => \"tmp\",\nmkdir              => 0755,\ndecodesubject     => 1,\ncheckcontenttype => 1,\ncontenttypes      => [\"image/gif\", \"image/jpeg\", \"image/bmp\"],\ntypesaction       => \"exclude\"\n);\nprint \"Number of messages: \", $explode->nmsgs, \"\\n\";\nopen(MAIL, \"<file.mbox\") or\ndie(\"Couldn't open file.mbox for reading: $!\\n\");\nopen(OUTPUT, \">file.tmp\")\nor die(\"Couldn't open file.tmp for writing: $!\\n\");\nmy $headers = $explode->parse(\\*MAIL, \\*OUTPUT);\nclose(OUTPUT);\nclose(MAIL);\nfor my $part (sort{ $a cmp $b } keys(%{$headers})) {\nfor my $k (keys(%{$headers->{$part}})) {\nif(ref($headers->{$part}->{$k}) eq \"ARRAY\") {\nfor my $i (0 .. $#{$headers->{$part}->{$k}}) {\nprint \"$part => $k => $i => \", $headers->{$part}->{$k}->[$i], \"\\n\";\n}\n} elsif(ref($headers->{$part}->{$k}) eq \"HASH\") {\nfor my $ks (keys(%{$headers->{$part}->{$k}})) {\nif(ref($headers->{$part}->{$k}->{$ks}) eq \"ARRAY\") {\nprint \"$part => $k => $ks => \", join(($ks eq \"charset\") ? \" \" : \"\", @{$headers->{$part}->{$k}->{$ks}}), \"\\n\";\n} else {\nprint \"$part => $k => $ks => \", $headers->{$part}->{$k}->{$ks}, \"\\n\";\n}\nprint \"$part => $k => $ks => \", $headers->{$part}->{$k}->{$ks}, \"\\n\";\n}\n} else {\nprint \"$part => $k => \", $headers->{$part}->{$k}, \"\\n\";\n}\n}\n}\nif(my $e = $explode->cleanall()) {\nprint \"Error: $e\\n\";\n}",
    "sections": {
        "NAME": {
            "content": "MIME::Explode - Perl extension for explode MIME messages\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use MIME::Explode;\n\nmy $explode = MIME::Explode->new(\noutputdir         => \"tmp\",\nmkdir              => 0755,\ndecodesubject     => 1,\ncheckcontenttype => 1,\ncontenttypes      => [\"image/gif\", \"image/jpeg\", \"image/bmp\"],\ntypesaction       => \"exclude\"\n);\n\nprint \"Number of messages: \", $explode->nmsgs, \"\\n\";\n\nopen(MAIL, \"<file.mbox\") or\ndie(\"Couldn't open file.mbox for reading: $!\\n\");\nopen(OUTPUT, \">file.tmp\")\nor die(\"Couldn't open file.tmp for writing: $!\\n\");\nmy $headers = $explode->parse(\\*MAIL, \\*OUTPUT);\nclose(OUTPUT);\nclose(MAIL);\n\nfor my $part (sort{ $a cmp $b } keys(%{$headers})) {\nfor my $k (keys(%{$headers->{$part}})) {\nif(ref($headers->{$part}->{$k}) eq \"ARRAY\") {\nfor my $i (0 .. $#{$headers->{$part}->{$k}}) {\nprint \"$part => $k => $i => \", $headers->{$part}->{$k}->[$i], \"\\n\";\n}\n} elsif(ref($headers->{$part}->{$k}) eq \"HASH\") {\nfor my $ks (keys(%{$headers->{$part}->{$k}})) {\nif(ref($headers->{$part}->{$k}->{$ks}) eq \"ARRAY\") {\nprint \"$part => $k => $ks => \", join(($ks eq \"charset\") ? \" \" : \"\", @{$headers->{$part}->{$k}->{$ks}}), \"\\n\";\n} else {\nprint \"$part => $k => $ks => \", $headers->{$part}->{$k}->{$ks}, \"\\n\";\n}\nprint \"$part => $k => $ks => \", $headers->{$part}->{$k}->{$ks}, \"\\n\";\n}\n} else {\nprint \"$part => $k => \", $headers->{$part}->{$k}, \"\\n\";\n}\n}\n}\n\nif(my $e = $explode->cleanall()) {\nprint \"Error: $e\\n\";\n}\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "MIME::Explode is perl module for parsing and decoding single or multipart MIME messages, and\noutputting its decoded components to a given directory ie, this module is designed to allows\nusers to extract the attached files out of a MIME encoded email messages or mailboxes.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "new([, OPTION ...])\nThis method create a new MIME::Explode object. The following keys are available:\n\noutputdir\nDirectory where the decoded files are placed\n\nmkdir => octalnumber\nIf the value is set to octal number then make the outputdir directory (example: mkdir =>\n0755).\n\ncheckcontenttype => 0 or 1\nIf the value is set to 1 the content-type of file is checked\n\ndecodesubject => 0 or 1\nIf the value is set to 1 then the subject is decoded into a list.\n\n$header->{'0.0'}->{subject}->{value} = [ARRAYREF];\n$header->{'0.0'}->{subject}->{charset} = [ARRAYREF];\n$subject = join(\"\", @{$header->{'0.0'}->{subject}->{value}});\n\nexcludetypes => [ARRAYREF]\nNot save files with specified content types (deprecated in next versions)\n\ncontenttypes => [ARRAYREF]\nArray reference with content types for \"include\" or \"exclude\"\n\ntypesaction => \"include\" or \"exclude\"\nIf the action is a \"include\", all attached files with specified content types are saved\nbut if the action is a \"exclude\", no files are saved except if its in the array of\ncontent types. If no array is specified, but the action is a \"include\", all attached\nfiles are saved, otherwise all files are removed if action is a \"exclude\". The default\naction is \"include\".\n\nparse(FILEHANDLE, FILEHANDLE)\nThis method parse the stream and splits it into its component entities. This method return a\nhash reference with all parts. The FILEHANDLE should be a reference to a GLOB. The second\nargument is optional.\n\nnmsgs\nReturns the number of parsed messages.\n\ncleanall\nCleans all files from the \"outputdir\" directory and then removes the directory. If an error\nhappens returns it.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Henrique Dias <henrique.ribeiro.dias@gmail.com>\n",
            "subsections": []
        },
        "CREDITS": {
            "content": "Thanks to Rui Castro for the revision.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "MIME::Tools, perl(1).\n",
            "subsections": []
        }
    },
    "summary": "MIME::Explode - Perl extension for explode MIME messages",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "perl",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/perl/1/json"
        }
    ]
}