Sample code for 30+ languages & platforms
PureBasic

Extract Files from MIME

See more MIME Examples

Extract files from a MIME message.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkStringTable.pb"
IncludeFile "CkMime.pb"

Procedure ChilkatExample()

    success.i = 0

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

    mime.i = CkMime::ckCreate()
    If mime.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; Load a MIME document from a file:
    ; (.mht and .eml files contain MIME).
    success = CkMime::ckLoadMimeFile(mime,"mst.mht")
    If success = 0
        Debug CkMime::ckLastErrorText(mime)
        CkMime::ckDispose(mime)
        ProcedureReturn
    EndIf

    st.i = CkStringTable::ckCreate()
    If st.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkMime::ckPartsToFiles(mime,"/temp/mimeParts",st)
    If success = 0
        Debug CkMime::ckLastErrorText(mime)
        CkMime::ckDispose(mime)
        CkStringTable::ckDispose(st)
        ProcedureReturn
    EndIf

    n.i = CkStringTable::ckCount(st)

    ; Display the paths of the files created:
    i.i = 0
    While i < n
        Debug CkStringTable::ckStringAt(st,i)
        i = i + 1
    Wend


    CkMime::ckDispose(mime)
    CkStringTable::ckDispose(st)


    ProcedureReturn
EndProcedure