DataFlex
DataFlex
Set a MIME Body from Transfer-Encoded Text
See more MIME Examples
Demonstrates the Chilkat Mime.SetBodyFromEncoded method, which sets the body from already transfer-encoded text. The first argument is the encoding (base64 or quoted-printable) and the second is the encoded text.
Background: Sometimes you already hold content in its encoded form — a Base64 string from a database or another API — and re-decoding just to have Chilkat re-encode it is wasteful. This method stores the encoded text as-is and records the matching transfer encoding, so the body is correct without a needless round trip. Only the standard reversible encodings, Base64 and quoted-printable, are accepted.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoMime
String sBase64Body
String sDecoded
String sTemp1
Boolean bTemp1
Move False To iSuccess
// Demonstrates the Mime.SetBodyFromEncoded method, which sets the body from already transfer-
// encoded text. The 1st argument is the encoding ("base64" or "quoted-printable") and the 2nd is
// the encoded text.
Get Create (RefClass(cComChilkatMime)) To hoMime
If (Not(IsComObjectCreated(hoMime))) Begin
Send CreateComObject of hoMime
End
Set ComContentType Of hoMime To "text/plain"
// The body is provided already Base64-encoded; Chilkat stores it without re-encoding.
Move "SGVsbG8sIHRoaXMgaXMgdGhlIGJvZHku" To sBase64Body
Get ComSetBodyFromEncoded Of hoMime "base64" sBase64Body To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMime To sTemp1
Showln sTemp1
Procedure_Return
End
// The decoded body is the original text.
Get ComGetBodyDecoded Of hoMime To sDecoded
Get ComLastMethodSuccess Of hoMime To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoMime To sTemp1
Showln sTemp1
Procedure_Return
End
Showln sDecoded
End_Procedure