Sample code for 30+ languages & platforms
Perl

Extract Files from MIME

See more MIME Examples

Extract files from a MIME message.

Chilkat Perl Downloads

Perl
use chilkat();

$success = 0;

# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

$mime = chilkat::CkMime->new();

# Load a MIME document from a file:
# (.mht and .eml files contain MIME).
$success = $mime->LoadMimeFile("mst.mht");
if ($success == 0) {
    print $mime->lastErrorText() . "\r\n";
    exit;
}

$st = chilkat::CkStringTable->new();
$success = $mime->PartsToFiles("/temp/mimeParts",$st);
if ($success == 0) {
    print $mime->lastErrorText() . "\r\n";
    exit;
}

$n = $st->get_Count();

# Display the paths of the files created:
$i = 0;
while ($i < $n) {
    print $st->stringAt($i) . "\r\n";
    $i = $i + 1;
}