Sample code for 30+ languages & platforms
DataFlex

Unpack an MHT Archive into Files

See more MHT / HTML Email Examples

Demonstrates Mht.UnpackMHT, which extracts an MHT archive into its constituent parts: the HTML document and its referenced resources.

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. The source may be an MHT file path or the literal MHT MIME text. The HTML is written under the chosen filename, and the referenced parts (images, style sheets, etc.) are written into a sub-directory.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoMht
    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.

    //  Unpack an MHT file into its constituent parts.  The 1st argument may be an MHT file path or the
    //  literal MHT MIME text.  The 2nd argument is the directory to unpack into, the 3rd is the filename
    //  for the extracted HTML, and the 4th is the sub-directory (relative to the unpack directory) for the
    //  referenced parts such as images and style sheets.
    Get ComUnpackMHT Of hoMht "qa_data/page.mht" "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