Jump to content

Recommended Posts

Posted (edited)

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/:

Quote
The source code on this page and other samples at https://www.motobit.com/tips/ are a free code, you can use it as you want: copy it, modify it, use it in your products, ...
If you use this code, please:
1. Leave the author note in the source.
or
2. Link this sample from you page.

<A
 Href="https://www.motobit.com/tips/detpg_quoted-printable-decode/"
 Title="This article contains a short function
	for quoted printable decoding, using
	CDO.Message object."
>Quoted-printable decode VBScript function.</A>

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

  • mLipok changed the title to quoted-printable.au3 UDF
Posted

I get errors with this script.

"D:\AutoIt\Scripts\Temporary & Arrange\Au3Script_16-01-2021,11;01;37.au3"(24,70) : warning: $oStream: possibly used before declaration.
    Local $oStream = $oCDOMessage.BodyPart.GetDecodedContent($oStream)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
D:\AutoIt\Scripts\Temporary & Arrange\Au3Script_16-01-2021,11;01;37.au3 (78,12) : error: syntax error
    Return =
~~~~~~~~~~~^
D:\AutoIt\Scripts\Temporary & Arrange\Au3Script_16-01-2021,11;01;37.au3 (160,9) : error: Statement cannot be just an expression.
    Set $oStream
~~~~~~~~^
D:\AutoIt\Scripts\Temporary & Arrange\Au3Script_16-01-2021,11;01;37.au3 (24,70) : error: $oStream: undeclared global variable.
    Local $oStream = $oCDOMessage.BodyPart.GetDecodedContent($oStream)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
D:\AutoIt\Scripts\Temporary & Arrange\Au3Script_16-01-2021,11;01;37.au3 (160,9) : error: Set(): undefined function.
    Set $oStream
~~~~~~~~^
D:\AutoIt\Scripts\Temporary & Arrange\Au3Script_16-01-2021,11;01;37.au3 - 4 error(s), 1 warning(s)
>Exit code: 2    Time: 0.07674

I use this to decode quoted-printable:

ConsoleWrite(_Encoding_QuotedPrintableDecode('=C0=F3=F2=EE=E8=F2') & @CRLF)

Func _Encoding_QuotedPrintableDecode($sString)
    Local $iSymbolFound = 2, $sRet = ''
    
    $sString = StringRegExpReplace($sString, '=\r\n', '')
    
    For $i = 1 To StringLen($sString)
        If StringRegExp(StringMid($sString, $i, 3), '=[A-Fa-f0-9]{2}') Then
            $iSymbolFound = 0
            $sRet &= BinaryToString('0x' & StringMid($sString, $i + 1, 2))
        Else
            $iSymbolFound += 1
            
            If $iSymbolFound = 3 Then
                $iSymbolFound = 2
                $sRet &= StringMid($sString, $i, 1)
            EndIf
        EndIf
    Next
    
    If $sRet = '' Then
        Return SetError(1, 0, '')
    EndIf
    
    Return $sRet
EndFunc

 

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted
On 1/16/2021 at 10:17 AM, MrCreatoR said:

I get errors with this script.

Fixed in OP.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...