PowerBuilder
PowerBuilder
Unpack MHT MIME Text into Files
See more MHT / HTML Email Examples
Demonstrates Mht.UnpackMHTString, which extracts MHT data into its constituent parts: the HTML document and its referenced resources. The source is MHT MIME text supplied as a string.
The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background. Despite the method name, the source may be either literal MHT MIME text or a local MHT file path; Chilkat distinguishes the two by detecting MIME headers. The HTML is written under the chosen filename, and referenced parts are written into a sub-directory.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Mht
oleobject loo_SbMht
integer li_BLoaded
li_Success = 0
loo_Mht = create oleobject
li_rc = loo_Mht.ConnectToNewObject("Chilkat.Mht")
if li_rc < 0 then
destroy loo_Mht
MessageBox("Error","Connecting to COM object failed")
return
end if
// The file paths are relative to the application's current working directory. Absolute paths may
// also be used. Supply the paths appropriate to your own environment.
// Load the MHT MIME text into a string.
loo_SbMht = create oleobject
li_rc = loo_SbMht.ConnectToNewObject("Chilkat.StringBuilder")
li_BLoaded = loo_SbMht.LoadFile("qa_data/page.mht","utf-8")
if li_BLoaded <> 1 then
Write-Debug "Failed to load the MHT file."
destroy loo_Mht
destroy loo_SbMht
return
end if
// Unpack the MHT MIME text into its constituent parts. The 1st argument may be MHT MIME text or a
// file path; the 2nd is the unpack directory, the 3rd is the main HTML filename, and the 4th is the
// sub-directory (relative to the unpack directory) for the referenced parts such as images and style
// sheets.
li_Success = loo_Mht.UnpackMHTString(loo_SbMht.GetAsString(),"qa_output/unpacked","index.html","parts")
if li_Success = 0 then
Write-Debug loo_Mht.LastErrorText
destroy loo_Mht
destroy loo_SbMht
return
end if
Write-Debug "MHT unpacked."
destroy loo_Mht
destroy loo_SbMht