Sample code for 30+ languages & platforms
DataFlex

MIME Header Q and B Encoding and Decoding

See more Encryption Examples

Demonstrates how to Q and B encode/decode.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoSb
2    Handle hoSb2
    String sTemp1

    Move False To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSb
    If (Not(IsComObjectCreated(hoSb))) Begin
        Send CreateComObject of hoSb
    End

    Get ComAppend Of hoSb "This is a test" To iSuccess

    Get ComGetEncoded Of hoSb "B" "utf-8" To sTemp1
    Showln sTemp1
    // output is:
    // =?utf-8?B?VGhpcyBpcyBhIHRlc3Q=?=

    Get ComGetEncoded Of hoSb "Q" "iso-8859-1" To sTemp1
    Showln sTemp1
    // output is:
    // =?utf-8?Q?This_is_a_test?=

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSb2
    If (Not(IsComObjectCreated(hoSb2))) Begin
        Send CreateComObject of hoSb2
    End

    Get ComAppend Of hoSb2 "=?utf-8?B?VGhpcyBpcyBhIHRlc3Q=?=" To iSuccess
    Get ComDecode Of hoSb2 "B" "utf-8" To iSuccess
    Get ComGetAsString Of hoSb2 To sTemp1
    Showln sTemp1

    // output is:
    // This is a test

    Send ComClear To hoSb2
    Get ComAppend Of hoSb2 "=?utf-8?Q?This_is_a_test?=" To iSuccess
    Get ComDecode Of hoSb2 "Q" "utf-8" To iSuccess
    Get ComGetAsString Of hoSb2 To sTemp1
    Showln sTemp1

    // output is:
    // This is a test

    // "B" or "Q" will decode both B and Q.
    Send ComClear To hoSb2
    Get ComAppend Of hoSb2 "=?utf-8?Q?This_is_a_test?= 123 =?utf-8?B?VGhpcyBpcyBhIHRlc3Q=?=" To iSuccess
    Get ComDecode Of hoSb2 "Q" "utf-8" To iSuccess
    Get ComGetAsString Of hoSb2 To sTemp1
    Showln sTemp1

    // output is:
    // This is a test 123 This is a test


End_Procedure