Perl Diver 2.33
Main Environment Variables Perl Default Values Perl Config - Summary Perl Config - Full Installed Modules List Directory uptime Docs

Module Documentation
Details and documentation about a specific module, including version and documentation (if available). Note that while links to perldoc.com and search.cpan.org are provided, the module may be part of a larger distribution. If you reach a File Not Found page on either site, please try the parent module.

MIME::Explode

Name MIME::Explode
Version 0.39
Located at /usr/lib/x86_64-linux-gnu/perl5/5.34
File /usr/lib/x86_64-linux-gnu/perl5/5.34/MIME/Explode.pm
Is Core No
Search CPAN for this module MIME::Explode
Documentation MIME::Explode
Module Details MIME::Explode

NAME

MIME::Explode - Perl extension for explode MIME messages


SYNOPSIS

  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 perl module for parsing and decoding single or multipart MIME messages, and outputting its decoded components to a given directory ie, this module is designed to allows users to extract the attached files out of a MIME encoded email messages or mailboxes.


METHODS

new([, OPTION ...])

This method create a new MIME::Explode object. The following keys are available:

output_dir
Directory where the decoded files are placed

mkdir => octal_number
If the value is set to octal number then make the output_dir directory (example: mkdir => 0755).

check_content_type => 0 or 1
If the value is set to 1 the content-type of file is checked

decode_subject => 0 or 1
If the value is set to 1 then the subject is decoded into a list.
  $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)

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. This method return a hash reference with all parts. The FILEHANDLE should be a reference to a GLOB. The second argument is optional.

nmsgs

Returns the number of parsed messages.

clean_all

Cleans all files from the ``output_dir'' directory and then removes the directory. If an error happens returns it.


AUTHOR

Henrique Dias <henrique.ribeiro.dias@gmail.com>


CREDITS

Thanks to Rui Castro for the revision.


SEE ALSO

MIME::Tools, perl(1).

Perl Diver brought to you by ScriptSolutions.com © 1997- 2026