#include #include #include #include #include Global $__g_sLicenceKey = "30-day trial" Global $_sPOP3_Server = _INI_SETUP('POP3_Server') Global $_sPOP3_UserName = _INI_SETUP('POP3_UserName') Global $_sPOP3_Password = _INI_SETUP('POP3_Password') ;~ http://www.chilkatsoft.com/downloads_ActiveX.asp #CS http://www.chilkatsoft.com/support.asp Success/Failure Return Values Methods that return a boolean always return True for success and False for failure. (ActiveX methods return 1 for success, 0 for failure. Objective-C methods return YES for success and NO for failure.) If a method returns a new instance of a Chilkat object, a NULL (or nil, null, 0, etc. depending on the programming language) is returned upon failure. LastErrorText The LastErrorText property is common to all Chilkat classes/objects in all programming languages. It provides detailed information about the last method call on an object instance. The LastErrorText is the first place to get more information about why a method failed or behaved unexpectedly. The LastErrorText will contain information even when a method call is successful. More information about LastErrorText. http://www.cknotes.com/category/lasterrortext/ #CE ;~ http://www.chilkatsoft.com/default.asp ;~ http://www.chilkatsoft.com/refdoc/activex.asp ;~ http://www.chilkatsoft.com/refdoc/xChilkatCertStoreRef.html ;~ http://www.chilkatsoft.com/refdoc/xChilkatCertChainRef.html ;~ Email ActiveX Reference Documentation ;~ http://www.chilkatsoft.com/refdoc/xChilkatEmailRef.html ;~ http://www.example-code.com/vbscript/emailObj.asp ;~ http://www.example-code.com/vbscript/pop3.asp ;~ _Example_01_Version() ;~ _Example_02_Get_number_of_mesages() ;~ _Example_03_Retrieve_UIDLs_from_POP3_Server() ;~ _Example_04_Save_Email_Attachments_to_Filesystem() ;~ _Example_05_Unpack_HTML_Email_to_Files() ;~ _Example_06_EMAIL_html_Viewer() ;~ _Example_07_HTTP_POST_JSON__TODO() ;~ _Example_08_HTTP_SOAP_1_2__TODO() ;~ _Example_09_htmlToText_simple() ;~ _Example_10_htmlToXml_simple() ;~ _Example_11_htmlToMHT() _Example_12_JsonObject_PrettyPrint() _Example_13_JsonObject_IterateMembers() _Example_14_JsonObject_CreateDocument() Func _Example_01_Version() Local $oCrypt2 = ObjCreate("Chilkat_9_5_0.Crypt2") MsgBox(0, '', $oCrypt2.Version) EndFunc ;==>_Example_01_Version Func _Example_02_Get_number_of_mesages() ; http://www.example-code.com/vbscript/pop3_mailboxCount.asp ; The mailman object is used for receiving (POP3) ; and sending (SMTP) email. ; This ObjCreate statement uses the new single-DLL ActiveX for v9.5.0 Local $oMailMan = ObjCreate("Chilkat_9_5_0.MailMan") ; Any string argument automatically begins the 30-day trial. $success = $oMailMan.UnlockComponent($__g_sLicenceKey) If ($success <> 1) Then MsgBox(0, 'UnlockComponent', $oMailMan.LastErrorText) Return EndIf ; Set the POP3 server's hostname $oMailMan.MailHost = $_sPOP3_Server ; Set the POP3 login/password. $oMailMan.PopUsername = $_sPOP3_UserName $oMailMan.PopPassword = $_sPOP3_Password ; Get the number of messages in the mailbox. Local $iNumMessages = $oMailMan.GetMailboxCount() MsgBox(0, '', $iNumMessages) EndFunc ;==>_Example_02_Get_number_of_mesages Func _Example_03_Retrieve_UIDLs_from_POP3_Server() ; Retrieve UIDL's from POP3 Server ; http://www.example-code.com/vbscript/pop3_getUidls.asp ; The mailman object is used for receiving (POP3) ; and sending (SMTP) email. ; This ObjCreate statement uses the new single-DLL ActiveX for v9.5.0 Local $oMailMan = ObjCreate("Chilkat_9_5_0.MailMan") ; Any string argument automatically begins the 30-day trial. $success = $oMailMan.UnlockComponent($__g_sLicenceKey) If ($success <> 1) Then MsgBox(0, 'UnlockComponent', $oMailMan.LastErrorText) Return EndIf ; Set the POP3 server's hostname $oMailMan.MailHost = $_sPOP3_Server ; Set the POP3 login/password. $oMailMan.PopUsername = $_sPOP3_UserName $oMailMan.PopPassword = $_sPOP3_Password ; sa is a Chilkat_9_5_0.StringArray Local $oSA = $oMailMan.GetUidls() Local $iCount = $oSA.Count For $i = 0 To $iCount - 1 ConsoleWrite($oSA.GetString($i) & @CRLF) Next EndFunc ;==>_Example_03_Retrieve_UIDLs_from_POP3_Server Func _Example_04_Save_Email_Attachments_to_Filesystem() ; Save Email Attachments to Filesystem ; http://www.example-code.com/vbscript/emailObject_saveAttachments.asp Local $oEmail = ObjCreate("Chilkat_9_5_0.Email") ; Load an email object containing attachments. ; This .eml can be downloaded from: ; http://www.example-code.com/testData/HtmlEmail.eml Local $sEML_FileFullPath = FileOpenDialog('Choose EML File', @ScriptDir, 'EML file (*.eml)', $FD_FILEMUSTEXIST) If @error Then ; Display the error message. MsgBox($MB_SYSTEMMODAL, "", "No file(s) were selected.") Return 0 EndIf Local $iSuccess = $oEmail.LoadEml($sEML_FileFullPath) If ($iSuccess <> 1) Then ConsoleWrite($oEmail.LastErrorText & @CRLF) Return 0 EndIf ; If OverwriteExisting is turned on, files with the same ; name are overwritten. If turned off, new/unique filenames ; are automatically generated. The filenames actually saved ; are accessible via the GetAttachmentFilename method. $oEmail.OverwriteExisting = 1 ; Save all attachments to the "myAttachments" subdirectory ; found under the calling process;s current working directory. ; This directory is automatically created if it does not already ; exist. $iSuccess = $oEmail.SaveAllAttachments("myAttachments") If ($iSuccess <> 1) Then ConsoleWrite($oEmail.LastErrorText & @CRLF) Return 0 EndIf ; List the attachment filenames: For $i = 0 To $oEmail.NumAttachments - 1 ConsoleWrite($oEmail.GetAttachmentFilename($i) & @CRLF) Next EndFunc ;==>_Example_04_Save_Email_Attachments_to_Filesystem Func _Example_05_Unpack_HTML_Email_to_Files($sHTMLFilename = "thisEmail.html") ; Unpack HTML Email to Files ; http://www.example-code.com/vbscript/email_unpackHtml.asp ; This CreateObject statement uses the new single-DLL ActiveX for v9.5.0 Local $oEmail = ObjCreate("Chilkat_9_5_0.Email") ; Select EML File containing HTML content with images. Local $sEML_FileFullPath = FileOpenDialog('Choose EML File', @ScriptDir, 'EML file (*.eml)', $FD_FILEMUSTEXIST) If @error Then ; Display the error message. MsgBox($MB_SYSTEMMODAL, "", "No file(s) were selected.") Return 0 EndIf ; Load an email object containing HTML content with images. Local $iSuccess = $oEmail.LoadEml($sEML_FileFullPath) If ($iSuccess <> 1) Then ConsoleWrite($oEmail.LastErrorText & @CRLF) Return 0 EndIf ; Is this an HTML email? If ($oEmail.HasHtmlBody() = 1) Then ; Unpack the HTML to files. The image and css URLs ; in the HTML are modified to point to the files extracted to disk. Local $sUnpackDir = @ScriptDir & "\ExtractedHTML" Local $sHTMLFileFullPath = $sUnpackDir & '\' & $sHTMLFilename Local $sPartsSubdir = "images" $iSuccess = $oEmail.UnpackHtml($sUnpackDir, $sHTMLFilename, $sPartsSubdir) If ($iSuccess <> 1) Then ConsoleWrite($oEmail.LastErrorText & @CRLF) Return 0 EndIf ; If the UnpackHtml method was successful, the ; HTML is written to /temp/thisEmail.html and ; the image files are located in /temp/images Return $sHTMLFileFullPath EndIf EndFunc ;==>_Example_05_Unpack_HTML_Email_to_Files Func _Example_06_EMAIL_html_Viewer($sHTMLFileFullPath = @ScriptDir & "\ExtractedHTML\thisEmail.html") If Not FileExists($sHTMLFileFullPath) Then Return SetError(1, 0, 0) Local $oIE = _IECreateEmbedded() GUICreate("Embedded Web control Test", 640, 580, _ (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _ $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) GUICtrlCreateObj($oIE, 10, 40, 600, 360) GUISetState(@SW_SHOW) ;Show GUI Local $sUnpackDir = StringRegExp($sHTMLFileFullPath, '(?i)(.+)\\.+?', 3)[0] Local $hFileOpen = FileOpen($sHTMLFileFullPath, $FO_READ) Local $sHTML = FileRead($hFileOpen) FileClose($hFileOpen) _html_imgSrcToLocalPath($sHTML, $sUnpackDir) _IENavigate($oIE, "about:blank") _IEDocWriteHTML($oIE, $sHTML) ;~ _IEAction($oIE, "refresh") ; Waiting for user to close the window While 1 Local $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd GUIDelete() EndFunc ;==>_Example_06_EMAIL_html_Viewer Func _Example_07_HTTP_POST_JSON__TODO() Return ; not finished yet ; Demonstrates how to send a JSON POST and get the JSON response. ; http://www.example-code.com/vbscript/http_post_json.asp ; !!! TODO EndFunc ;==>_Example_07_HTTP_POST_JSON__TODO Func _Example_08_HTTP_SOAP_1_2__TODO() Return ; not finished yet ; HTTP SOAP 1.2 Request and Response using POST ; http://www.example-code.com/vbscript/http_soapPost12.asp ; !!! TODO EndFunc ;==>_Example_08_HTTP_SOAP_1_2__TODO Func _Example_09_htmlToText_simple() ;~ http://www.example-code.com/vbscript/htmlToText_simple.asp Local $oHtmlToText = ObjCreate("Chilkat_9_5_0.HtmlToText") Local $iSuccess = $oHtmlToText.UnlockComponent($__g_sLicenceKey) If ($iSuccess <> 1) Then MsgBox(0, '$oHtmlToText.LastErrorText', $oHtmlToText.LastErrorText) Else Local $sHtml_Content = FileRead("........html") ClipPut($oHtmlToText.ToText($sHtml_Content)) MsgBox(0, '$oHtmlToText.ToText', $oHtmlToText.ToText($sHtml_Content)) EndIf EndFunc ;==>_Example_09_htmlToText_simple Func _Example_10_htmlToXml_simple() ;~ http://www.example-code.com/vbscript/htmlToText_simple.asp Local $oHtmlToXml = ObjCreate("Chilkat_9_5_0.HtmlToXml") Local $iSuccess = $oHtmlToXml.UnlockComponent($__g_sLicenceKey) If ($iSuccess <> 1) Then MsgBox(0, '$oHtmlToXml.LastErrorText', $oHtmlToXml.LastErrorText) Else ; Indicate the charset of the output XML we'll want. $oHtmlToXml.XmlCharset = "utf-8" ConsoleWrite($oHtmlToXml.LastErrorText & @CRLF) ConsoleWrite("! @ScriptLineNumber=" & @ScriptLineNumber & @CRLF) Local $sHTML_FileFullPath = ".........html" Local $sXML_FileFullPath = $sHTML_FileFullPath & '.xml' ; Set the HTML: Local $sHtml_Content = FileRead($sHTML_FileFullPath) $oHtmlToXml.Html = $sHtml_Content ConsoleWrite($oHtmlToXml.LastErrorText & @CRLF) ; Get the XML: ClipPut($oHtmlToXml.ToXML()) ConsoleWrite($oHtmlToXml.LastErrorText & @CRLF) ;~ MsgBox(0, '$oHtmlToXml.ToXml', $oHtmlToXml.ToXml()) Local $hFileOpen = FileOpen($sXML_FileFullPath, $FO_OVERWRITE + $FO_UTF8) Local $sHTML = FileWrite($hFileOpen, $oHtmlToXml.ToXml()) FileClose($hFileOpen) EndIf EndFunc ;==>_Example_10_htmlToXml_simple Func _Example_11_htmlToMHT() Local $oMht = ObjCreate("Chilkat_9_5_0.Mht") Local $iSuccess = $oMht.UnlockComponent($__g_sLicenceKey) If ($iSuccess <> 1) Then MsgBox(0, '$oMht.LastErrorText', $oMht.LastErrorText) Else $oMht.BaseUrl('.....') ConsoleWrite($oMht.LastErrorText & @CRLF) MsgBox(0, '', 1) $oMht.DebugLogFilePath('.....') ConsoleWrite($oMht.LastErrorText & @CRLF) $oMht.NumCacheLevels = 0 ConsoleWrite($oMht.LastErrorText & @CRLF) $oMht.FetchFromCache = 1 ConsoleWrite($oMht.LastErrorText & @CRLF) $oMht.AddCacheRoot('.....') ConsoleWrite($oMht.LastErrorText & @CRLF) Local $sHTMLContent = FileRead('......htm') $oMht.HtmlToMHTFile($sHTMLContent, '.....') ConsoleWrite($oMht.LastErrorText & @CRLF) EndIf EndFunc ;==>_Example_11_htmlToMHT Func _Example_12_JsonObject_PrettyPrint() _Log_Chilkat('_Example_12_JsonObject_PrettyPrint') ; https://www.example-code.com/vbscript/json_pretty_print.asp Local $oJSON = ObjCreate("Chilkat_9_5_0.JsonObject") $sJSON_String = "{""name"": ""donut"",""image"":{""fname"": ""donut.jpg"",""w"": 200,""h"": 200},""thumbnail"":{""fname"": ""donutThumb.jpg"",""w"": 32,""h"": 32}}" $iSuccess = $oJSON.Load($sJSON_String) If ($iSuccess <> 1) Then ConsoleWrite($oJSON.LastErrorText & @CRLF) Return EndIf ; To pretty-print, set the EmitCompact property equal to 0 $oJSON.EmitCompact = 0 ; If bare-LF line endings are desired, turn off EmitCrLf ; Otherwise CRLF line endings are emitted. $oJSON.EmitCrLf = 0 ; Emit the formatted JSON: ConsoleWrite($oJSON.Emit() & @CRLF) EndFunc ;==>_Example_12_JsonObject_PrettyPrint Func _Example_13_JsonObject_IterateMembers() _Log_Chilkat('_Example_13_JsonObject_IterateMembers') ; https://www.example-code.com/vbscript/json_iterate_members.asp Local $oJSON = ObjCreate("Chilkat_9_5_0.JsonObject") $sJSON_String = "{ ""id"": 1, ""name"": ""A green door"", ""tags"": [""home"", ""green""], ""price"": 125 }" $iSuccess = $oJSON.Load($sJSON_String) If ($iSuccess <> 1) Then ConsoleWrite($oJSON.LastErrorText & @CRLF) Return EndIf $iNumMembers = $oJSON.Size For $iMember_idx = 0 To $iNumMembers - 1 $sName = $oJSON.NameAt($iMember_idx) $sValue = $oJSON.StringAt($iMember_idx) ConsoleWrite($sName & ": " & $sValue & @CRLF) $iValue = $oJSON.IntAt($iMember_idx) ConsoleWrite($sName & " as integer: " & $iValue & @CRLF) Next EndFunc ;==>_Example_13_JsonObject_IterateMembers Func _Example_14_JsonObject_CreateDocument() _Log_Chilkat('_Example_14_JsonObject_CreateDocument') ; https://www.example-code.com/vbscript/create_json.asp Local $oJSON = ObjCreate("Chilkat_9_5_0.JsonObject") Local $iSuccess $iSuccess = $oJSON.AddStringAt(-1,"Title","Pan's Labyrinth") $iSuccess = $oJSON.AddStringAt(-1,"Director","Guillermo del Toro") $iSuccess = $oJSON.AddStringAt(-1,"Original_Title","El laberinto del fauno") $iSuccess = $oJSON.AddIntAt(-1,"Year_Released",2006) $oJSON.EmitCompact = 0 ConsoleWrite($oJSON.Emit() & @CRLF) EndFunc ;==>_Example_13_JsonObject_IterateMembers ; #FUNCTION# ==================================================================================================================== ; Name ..........: _html_imgSrcToLocalPath ; Description ...: Change relative Path to direct local path in HTML source ; Syntax ........: _html_imgSrcToLocalPath(Byref $sHTML[, $sPath = @ScriptDir]) ; Parameters ....: $sHTML - [in/out] a string value. ; $sPath - [optional] a string value. Default is @ScriptDir. ; Return values .: None ; Author ........: SmOke_N ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/167535-iedocwritehtml-extractedhtml/#entry1225920 ; Example .......: No ; =============================================================================================================================== Func _html_imgSrcToLocalPath(ByRef $sHTML, $sPath = @ScriptDir) Local $aImgFiles = StringRegExp($sHTML, "(?is)(<\s*img\s+src=[""'](.+?)[""'])", 3) If @error Then ; no img files Return SetError(1, 0, 0) EndIf $sPath = StringReplace(StringRegExpReplace($sPath, "[\\/]+$", ""), "\", "/", 0, 1) Local $sRepl For $i = 0 To UBound($aImgFiles) - 1 Step 2 If StringRegExp($aImgFiles[$i + 1], "^(?i)\s*(http|s?ftp|file:///)") Then ContinueLoop $sRepl = StringReplace($aImgFiles[$i], $aImgFiles[$i + 1], _ "file:///" & $sPath & "/" & $aImgFiles[$i + 1]) $sHTML = StringReplace($sHTML, $aImgFiles[$i], $sRepl, 1, 0) Next Return 1 EndFunc ;==>_html_imgSrcToLocalPath Func _INI_SETUP($sKey) Local $sINIFileFullPath = @ScriptFullPath & '.INI' Local $sINI_Value = IniRead($sINIFileFullPath, "POP3", $sKey, 'Default') If $sINI_Value = 'Default' Or $sINI_Value = '' Then $sINI_Value = InputBox('INI Setup for Key: ' & $sKey, 'Enter value for ini Key: ' & $sKey & '=', '') IniWrite($sINIFileFullPath, "POP3", $sKey, IniRead($sINIFileFullPath, "POP3", $sKey, Default)) EndIf Return $sINI_Value EndFunc ;==>_INI_SETUP Func _Log_Chilkat($sData) ConsoleWrite('>+ ' & $sData & @CRLF) EndFunc