Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

PowerBuilder Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(PowerBuilder) IMAP Download and Verify Signed MIME

Downloads the unmodified MIME of a digitally signed email, saves the .p7s signature (and other MIME parts), then loads the email into a Chilkat email object (which unwraps the S/MIME and verifies the signature) and then saves attachments (if the MIME parts were not already saved).

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_Imap
integer li_Success
oleobject loo_SbMime
oleobject loo_Mime
integer li_AlreadySavedParts
oleobject loo_Sa
integer li_NumFiles
integer i
oleobject loo_Email
oleobject loo_Cert

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loo_Imap = create oleobject
li_rc = loo_Imap.ConnectToNewObject("Chilkat_9_5_0.Imap")
if li_rc < 0 then
    destroy loo_Imap
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Connect to an IMAP server.
// Use TLS
loo_Imap.Ssl = 1
loo_Imap.Port = 993
li_Success = loo_Imap.Connect("imap.someMailServer.com")
if li_Success <> 1 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if

li_Success = loo_Imap.Login("myLogin","myPassword")
if li_Success <> 1 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if

// Select an IMAP mailbox
li_Success = loo_Imap.SelectMailbox("Inbox")
if li_Success <> 1 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if

// Download the 1st email (as MIME) in the Inbox by sequence number.
loo_SbMime = create oleobject
li_rc = loo_SbMime.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

li_Success = loo_Imap.FetchSingleAsMimeSb(1,0,loo_SbMime)
if li_Success <> 1 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    destroy loo_SbMime
    return
end if

// Load it into a MIME object and check to see if it is signed
loo_Mime = create oleobject
li_rc = loo_Mime.ConnectToNewObject("Chilkat_9_5_0.Mime")

loo_Mime.LoadMimeSb(loo_SbMime)
li_AlreadySavedParts = 0
if loo_Mime.ContainsSignedParts() = 1 then

    // This will save the .p7s and other parts...
    loo_Sa = loo_Mime.ExtractPartsToFiles("qa_output")
    if loo_Mime.LastMethodSuccess = 1 then
        li_NumFiles = loo_Sa.Count
        i = 0
        do while i < li_NumFiles
            Write-Debug "Created: " + loo_Sa.GetString(i)
            i = i + 1
        loop
        destroy loo_Sa
        li_AlreadySavedParts = 1
    end if

end if

// Load the MIME into an Email object.  This unwraps the security layers and verifies signatures.
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat_9_5_0.Email")

loo_Email.SetFromMimeSb(loo_SbMime)

if loo_Email.ReceivedSigned = 1 then

    Write-Debug "This email was signed."

    // Check to see if the signatures were verified.
    if loo_Email.SignaturesValid = 1 then
        Write-Debug "Digital signature(s) verified."

        Write-Debug "Signer: " + loo_Email.SignedBy

        // The certificate used for signing may be obtained
        // by calling email.GetSignedByCert.
        loo_Cert = loo_Email.GetSignedByCert()
        if loo_Email.LastMethodSuccess <> 1 then
            Write-Debug "Failed to get signing certificate object."
        else
            Write-Debug "Signing cert: " + loo_Cert.SubjectCN
            destroy loo_Cert
        end if

    end if

else
    Write-Debug "Digital signature verification failed."
end if

if li_AlreadySavedParts <> 1 then
    loo_Email.SaveAllAttachments("qa_output")
end if



destroy loo_Imap
destroy loo_SbMime
destroy loo_Mime
destroy loo_Email

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.