Sample code for 30+ languages & platforms
Tcl

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 Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  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.

set mime [new_CkMime]

CkMime_put_ContentType $mime "text/plain"

#  The body is provided already Base64-encoded; Chilkat stores it without re-encoding.
set base64Body "SGVsbG8sIHRoaXMgaXMgdGhlIGJvZHku"
set success [CkMime_SetBodyFromEncoded $mime "base64" $base64Body]
if {$success == 0} then {
    puts [CkMime_lastErrorText $mime]
    delete_CkMime $mime
    exit
}

#  The decoded body is the original text.
set decoded [CkMime_getBodyDecoded $mime]
if {[CkMime_get_LastMethodSuccess $mime] == 0} then {
    puts [CkMime_lastErrorText $mime]
    delete_CkMime $mime
    exit
}

puts "$decoded"

delete_CkMime $mime