Sample code for 30+ languages & platforms
PureBasic

Serialize MIME to a StringBuilder

See more MIME Examples

Demonstrates the Chilkat Mime.GetMimeSb method, which serializes the complete MIME entity and appends it to a StringBuilder. The only argument is the StringBuilder; existing content is preserved.

Background: Serializing into a StringBuilder avoids creating a new string and is convenient when you are accumulating output or building a larger document. Because it appends, you can assemble several pieces in one buffer. As with GetMime, use the BinData form for content with arbitrary binary bytes.

Chilkat PureBasic Downloads

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

Procedure ChilkatExample()

    success.i = 0

    ;  Demonstrates the Mime.GetMimeSb method, which serializes the complete MIME entity and appends
    ;  it to a StringBuilder.  The only argument is the StringBuilder.

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

    success = CkMime::ckSetBodyFromPlainText(mime,"Hello, this is the message body.")
    If success = 0
        Debug CkMime::ckLastErrorText(mime)
        CkMime::ckDispose(mime)
        ProcedureReturn
    EndIf

    ;  Append the serialized MIME to a StringBuilder.  Existing content is preserved.
    sb.i = CkStringBuilder::ckCreate()
    If sb.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

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

    Debug CkStringBuilder::ckGetAsString(sb)


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


    ProcedureReturn
EndProcedure