Sample code for 30+ languages & platforms
DataFlex

MIME Content Part Descriptor Properties

See more MIME Examples

Demonstrates the properties that describe an individual MIME content part: Charset (the charset parameter of Content-Type), Encoding (the Content-Transfer-Encoding), Disposition (the Content-Disposition value), Filename (the filename parameter of Content-Disposition), and Name (the name parameter of Content-Type). Each is set and then read back, and the effect is visible in the serialized MIME header.

Background. These properties operate on the current MIME entity's header fields. Filename and Name are receiver-facing labels, not local filesystem paths, and Charset is meaningful for text parts.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoMime
    String sMimeStr
    String sTemp1
    Boolean bTemp1

    Move False To iSuccess

    Get Create (RefClass(cComChilkatMime)) To hoMime
    If (Not(IsComObjectCreated(hoMime))) Begin
        Send CreateComObject of hoMime
    End
    Get ComSetBodyFromPlainText Of hoMime "The quick brown fox." To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Charset is the charset parameter of the Content-Type header field (meaningful for text parts).
    Set ComCharset Of hoMime To "utf-8"

    //  Encoding is the Content-Transfer-Encoding for this part.
    Set ComEncoding Of hoMime To "quoted-printable"

    //  Disposition, Filename, and Name describe how a receiver should present the part.
    //  Filename is the filename parameter of Content-Disposition; Name is the name parameter of
    //  Content-Type.  Both are receiver-facing names, not local filesystem paths.
    Set ComDisposition Of hoMime To "attachment"
    Set ComFilename Of hoMime To "note.txt"
    Set ComName Of hoMime To "note.txt"

    //  Read the descriptors back.
    Get ComCharset Of hoMime To sTemp1
    Showln "Charset = " sTemp1
    Get ComEncoding Of hoMime To sTemp1
    Showln "Encoding = " sTemp1
    Get ComDisposition Of hoMime To sTemp1
    Showln "Disposition = " sTemp1
    Get ComFilename Of hoMime To sTemp1
    Showln "Filename = " sTemp1
    Get ComName Of hoMime To sTemp1
    Showln "Name = " sTemp1

    //  The descriptors appear in the serialized MIME header.
    Get ComGetMime Of hoMime To sMimeStr
    Get ComLastMethodSuccess Of hoMime To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln sMimeStr


End_Procedure