Sample code for 30+ languages & platforms
JavaScript

Extract Files from MIME

See more MIME Examples

Extract files from a MIME message.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
var success = false;

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

var mime = new CkMime();

// Load a MIME document from a file:
// (.mht and .eml files contain MIME).
success = mime.LoadMimeFile("mst.mht");
if (success == false) {
    console.log(mime.LastErrorText);
    return;
}

var st = new CkStringTable();
success = mime.PartsToFiles("/temp/mimeParts",st);
if (success == false) {
    console.log(mime.LastErrorText);
    return;
}

var n = st.Count;

// Display the paths of the files created:
var i = 0;
while (i < n) {
    console.log(st.StringAt(i));
    i = i+1;
}