Sample code for 30+ languages & platforms
PureBasic

Load MIME from a StringBuilder

See more MIME Examples

Demonstrates the Chilkat Mime.LoadMimeSb method, which parses complete MIME text from a StringBuilder and replaces the current MIME. The only argument is the StringBuilder.

Note: 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: When the MIME text already lives in a StringBuilder — assembled in memory, or read and lightly edited — this loads it directly without an intermediate string copy. Its parsing behavior matches LoadMime; the difference is purely the source. For content that might include arbitrary binary bytes, use the BinData loader instead.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkMime.pb"

Procedure ChilkatExample()

    success.i = 0

    ;  Demonstrates the Mime.LoadMimeSb method, which parses complete MIME text from a StringBuilder
    ;  and replaces the current MIME.  The only argument is the StringBuilder.

    ;  Put the MIME text into a StringBuilder (here loaded from a file, but it could come from
    ;  anywhere).
    sb.i = CkStringBuilder::ckCreate()
    If sb.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkStringBuilder::ckLoadFile(sb,"qa_data/message.eml","utf-8")
    If success = 0
        Debug CkStringBuilder::ckLastErrorText(sb)
        CkStringBuilder::ckDispose(sb)
        ProcedureReturn
    EndIf

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

    success = CkMime::ckLoadMimeSb(mime,sb)
    If success = 0
        Debug CkMime::ckLastErrorText(mime)
        CkStringBuilder::ckDispose(sb)
        CkMime::ckDispose(mime)
        ProcedureReturn
    EndIf

    Debug "Content-Type: " + CkMime::ckContentType(mime)


    CkStringBuilder::ckDispose(sb)
    CkMime::ckDispose(mime)


    ProcedureReturn
EndProcedure