DataFlex
DataFlex
Get the Decoded MIME Body Bytes (BinData)
See more MIME Examples
Demonstrates the Chilkat Mime.GetBodyBd method, which replaces the contents of a BinData with the decoded body bytes of the current part. The only argument is the BinData. Base64 and quoted-printable are decoded; headers and boundaries are not included.
Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background: This is how you extract a part's actual content as bytes — the decoded payload of an attachment or an image, ready to hash, re-save, or hand to another API. Because it works in raw bytes it is the correct choice for binary parts, where a text decode would be wrong. Note it replaces the
BinData contents rather than appending.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoMime
Variant vBd
Handle hoBd
String sTemp1
Integer iTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatMime)) To hoMime
If (Not(IsComObjectCreated(hoMime))) Begin
Send CreateComObject of hoMime
End
Get ComLoadMimeFile Of hoMime "qa_data/message.eml" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMime To sTemp1
Showln sTemp1
Procedure_Return
End
// Replace the contents of a BinData with the decoded body bytes of the current part. Base64 and
// quoted-printable are decoded; MIME headers and multipart boundaries are not included.
Get Create (RefClass(cComChilkatBinData)) To hoBd
If (Not(IsComObjectCreated(hoBd))) Begin
Send CreateComObject of hoBd
End
Get pvComObject of hoBd to vBd
Get ComGetBodyBd Of hoMime vBd To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMime To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComNumBytes Of hoBd To iTemp1
Showln "Decoded body: " iTemp1 " bytes."
End_Procedure