DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoMht
Handle hoSbMht
Boolean iBLoaded
String sTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatMht)) To hoMht
If (Not(IsComObjectCreated(hoMht))) Begin
Send CreateComObject of hoMht
End
// 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.
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbMht
If (Not(IsComObjectCreated(hoSbMht))) Begin
Send CreateComObject of hoSbMht
End
Get ComLoadFile Of hoSbMht "qa_data/page.mht" "utf-8" To iBLoaded
If (iBLoaded <> True) Begin
Showln "Failed to load the MHT file."
Procedure_Return
End
// 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.
Get ComGetAsString Of hoSbMht To sTemp1
Get ComUnpackMHTString Of hoMht sTemp1 "qa_output/unpacked" "index.html" "parts" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMht To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "MHT unpacked."
End_Procedure