Search the Community
Showing results for tags 'quoted-printable'.
-
Yeasterday I found this: https://stackoverflow.com/questions/496751/base64-encode-string-in-vbscript https://www.motobit.com/tips/detpg_quoted-printable-encode/ https://www.motobit.com/tips/detpg_quoted-printable-decode/ Here is AutoIt Version: #Region - QuotedPrintableEncode_Binary ;~ https://www.motobit.com/tips/detpg_quoted-printable-encode/ ; This article contains a short function for quoted printable encoding, using CDO.Message object. ; You can use this function in ASP or .VBS files (wsh - windows scripting host files), or directly in VBA (visual basic 5, 6, Word, Excel, Access and Outlook scripting). ; A source data of this function is a String variable and charset parameter of destination data. ; The source string (16bit VBScript BSTR variable) is first converted to a destination charset, using ADODB.Stream (GetDecodedContentStream). ; If the destination charset is not specified, the ADODB.Stream uses "iso-8859-1" by default. ; The EncodedContentStream then converts the binary data to a Quoted-Printable output string. ; VBScript QuotedPrintable encoding ; 2005 Antonin Foller http://www.motobit.com ; $s_SourceString - string variable with source data, BSTR type ; $s_CharSet - $s_CharSet of the destination data Func _QuotedPrintable_Encode($s_SourceString, $s_CharSet) ;Create CDO.$oCDOMessage object For the encoding. Local $oCDOMessage = ObjCreate("CDO.Message") ; Set the encoding $oCDOMessage.BodyPart.ContentTransferEncoding = "quoted-printable" ; Get the data $oStream To write source string data ; As ADODB.$oStream Local $oStream = $oCDOMessage.BodyPart.GetDecodedContentStream ; Set the $s_CharSet For the destination data, If required If StringLen($s_CharSet) > 0 Then $oStream.CharSet = $s_CharSet ; Write the VBScript string To the $oStream. $oStream.WriteText($s_SourceString) ; Store the data To the $oCDOMessage BodyPart $oStream.Flush ; Get an encoded $oStream $oStream = $oCDOMessage.BodyPart.GetEncodedContentStream ; read the encoded data As a string Return $oStream.ReadText ; You can use Read method To get a binary data. ; $oStream.Type = 1 ; Return $oStream.Read EndFunc ;==>QuotedPrintableEncode ; Next is a binary variant of the function, with bytearray (VT_UI1 VT_ARRAY) as input and output. ; You can simply modify these two functions for combination of binary and string input and output parameters. ; This Func is used on Quoted-printable encoder online sample page. ; VBScript QuotedPrintableEncode_Binary encoding ; 2005 Antonin Foller http://www.motobit.com Func _QuotedPrintable_Encode_Binary($dSourceBinary) ; Create CDO.$oCDOMessage object For the encoding. Local $oCDOMessage = ObjCreate("CDO.Message") ; Set the encoding $oCDOMessage.BodyPart.ContentTransferEncoding = "quoted-printable" ; Get the data $oStream To write source string data ; As ADODB.$oStream Local $oStream = $oCDOMessage.BodyPart.GetDecodedContentStream ; Set the type of the $oStream To adTypeBinary. $oStream.Type = 1 ; Write the VBScript string To the $oStream. $oStream.Write($dSourceBinary) ; Store the data To the $oCDOMessage BodyPart $oStream.Flush ; Get an encoded $oStream $oStream = $oCDOMessage.BodyPart.GetEncodedContentStream ; Set the type of the $oStream To adTypeBinary. $oStream.Type = 1 ; You can use Read method To get a binary data. Return $oStream.Read EndFunc ;==>QuotedPrintableEncode_Binary #EndRegion - _QuotedPrintable_Encode_Binary #Region - _QuotedPrintable_Decode_Binary ;~ https://www.motobit.com/tips/detpg_quoted-printable-decode/ ; This article contains a short Func for quoted printable decoding, using CDO.Message object. ; You can use this Func in ASP or .VBS files (wsh - windows scripting host files), or directly in VBA (visual basic 5, 6, Word, Excel, Access and Outlook scripting). ; VBScript QuotedPrintableDecode decoding Function ; 2005 Antonin Foller http://www.motobit.com Func _QuotedPrintable_Decode($s_SourceData, $s_CharSet) ; Create CDO.Message object For the encoding. Local $oCDO_Message = ObjCreate("CDO.Message") ; Set the encoding $oCDO_Message.BodyPart.ContentTransferEncoding = "quoted-printable" ; Get the data $oStream To write source string data ; As ADODB.$oStream Local $oStream = $oCDO_Message.BodyPart.GetEncodedContentStream If VarGetType($s_SourceData) = 'String' Then ; Set $s_CharSet To base windows $s_CharSet $oStream.CharSet = "windows-1250" ; Write the VBScript string To the $oStream. $oStream.WriteText($s_SourceData) Else ; Set the type of the $oStream To adTypeBinary. $oStream.Type = 1 ; Write the source binary data To the $oStream. $oStream.Write($s_SourceData) EndIf ; Store the data To the $oCDO_Message BodyPart $oStream.Flush ; Get an encoded $oStream $oStream = $oCDO_Message.BodyPart.GetDecodedContentStream ; Set the type of the $oStream To adTypeBinary. $oStream.CharSet = $s_CharSet ; You can use Read method To get a binary data. Return $oStream.ReadText EndFunc ;==>_QuotedPrintable_Decode ; Next is a binary variant of the function, with bytearray (VT_UI1 VT_ARRAY) as output. ; The _QuotedPrintable_Decode_Binary then converts the binary data to a Quoted-Printable output string. ; Output of this Func are binary decoded data (you can use it, for example, as a data parameter of Response. ; BinaryWrite method) You can simply modify these two functions for combination of binary and string input and output parameters. ; This Func is used on Quoted-printable decoder online sample page. ; VBScript _QuotedPrintable_Decode_Binary decoding Function ; 2005 Antonin Foller http://www.motobit.com Func _QuotedPrintable_Decode_Binary($s_SourceData) ; Create CDO.Message object For the encoding. Local $oCDO_Message = ObjCreate("CDO.Message") ; Set the encoding $oCDO_Message.BodyPart.ContentTransferEncoding = "quoted-printable" ; Get the data $oStream To write source string data ; As ADODB.$oStream Local $oStream = $oCDO_Message.BodyPart.GetEncodedContentStream If VarGetType($s_SourceData) = 'String' Then ; Write the VBScript string To the $oStream. $oStream.Write($s_SourceData) Else ; Set the type of the $oStream To adTypeBinary. $oStream.Type = 1 ; Write the source binary data To the $oStream. $oStream.Write($s_SourceData) EndIf ; Store the data To the $oCDO_Message BodyPart $oStream.Flush ; Get an encoded $oStream $oStream = $oCDO_Message.BodyPart.GetDecodedContentStream ; Set the type of the $oStream To adTypeBinary. $oStream.Type = 1 ; You can use Read method To get a binary data. Return $oStream.Read EndFunc ;==>_QuotedPrintable_Decode_Binary #EndRegion - _QuotedPrintable_Decode_Binary REMARK: License note from: https://www.motobit.com/tips/detpg_quoted-printable-decode/ and https://www.motobit.com/tips/detpg_quoted-printable-encode/: