Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode 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
Box
CAdES
CSR
CSV
Cert Store
Certificates
Cloud Signature CSC
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
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
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
X
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(PowerBuilder) Reading Unread POP3 Email

The POP3 protocol cannot determine which emails are "unread," and pure POP3 servers do not store this information. Servers like Exchange Server, offering both POP3 and IMAP interfaces, do contain read/unread data, but it's only accessible through IMAP. Email clients like Outlook and Thunderbird store read/unread statuses on the client side. The example demonstrates using UIDLs to track and manage "unread" emails.

Note: This example requires Chilkat v11.0.0 or greater.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
integer li_Success
oleobject loo_Mailman
string ls_SeenUidlsPath
oleobject loo_SbXml
oleobject loo_HtSeenUidls
oleobject loo_Fac
oleobject loo_StUidls
oleobject loo_StUnseenUidls
string ls_Uidl
integer i
integer li_Count
oleobject loo_Email

li_Success = 0

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

// The mailman object is used for receiving (POP3) 
// and sending (SMTP) email.
loo_Mailman = create oleobject
li_rc = loo_Mailman.ConnectToNewObject("Chilkat.MailMan")
if li_rc < 0 then
    destroy loo_Mailman
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Set the POP3 server's hostname
loo_Mailman.MailHost = "pop.example.com"

// Set the POP3 login/password.
loo_Mailman.PopUsername = "***"
loo_Mailman.PopPassword = "***"

// Keep a records of already-seen UIDLs in hash table serialized to an XML file.
ls_SeenUidlsPath = "c:/temp/seenUidls.xml"

loo_SbXml = create oleobject
li_rc = loo_SbXml.ConnectToNewObject("Chilkat.StringBuilder")

loo_HtSeenUidls = create oleobject
li_rc = loo_HtSeenUidls.ConnectToNewObject("Chilkat.Hashtable")

loo_Fac = create oleobject
li_rc = loo_Fac.ConnectToNewObject("Chilkat.FileAccess")

if loo_Fac.FileExists(ls_SeenUidlsPath) = 1 then
    li_Success = loo_SbXml.LoadFile(ls_SeenUidlsPath,"utf-8")
    if li_Success = 0 then
        Write-Debug loo_SbXml.LastErrorText
        destroy loo_Mailman
        destroy loo_SbXml
        destroy loo_HtSeenUidls
        destroy loo_Fac
        return
    end if

    loo_HtSeenUidls.AddFromXmlSb(loo_SbXml)
end if

// Get the complete list of UIDLs on the mail server.
loo_StUidls = create oleobject
li_rc = loo_StUidls.ConnectToNewObject("Chilkat.StringTable")

li_Success = loo_Mailman.FetchUidls(loo_StUidls)
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    destroy loo_SbXml
    destroy loo_HtSeenUidls
    destroy loo_Fac
    destroy loo_StUidls
    return
end if

// Build a list of unseen UIDLs
loo_StUnseenUidls = create oleobject
li_rc = loo_StUnseenUidls.ConnectToNewObject("Chilkat.StringTable")

i = 0
li_Count = loo_StUidls.Count
do while i < li_Count
    ls_Uidl = loo_StUidls.StringAt(i)
    if loo_HtSeenUidls.Contains(ls_Uidl) <> 1 then
        loo_StUnseenUidls.Append(ls_Uidl)
    end if

    i = i + 1
loop

if loo_StUnseenUidls.Count = 0 then
    Write-Debug "No unseen emails!"
    destroy loo_Mailman
    destroy loo_SbXml
    destroy loo_HtSeenUidls
    destroy loo_Fac
    destroy loo_StUidls
    destroy loo_StUnseenUidls
    return
end if

// Download the unseen emails, adding each UIDL to the "seen" hash table.
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")

li_Count = loo_StUnseenUidls.Count
i = 0
do while i < li_Count
    // Download the full email.
    ls_Uidl = loo_StUnseenUidls.StringAt(i)
    li_Success = loo_Mailman.FetchByUidl(ls_Uidl,0,0,loo_Email)
    if li_Success = 0 then
        Write-Debug loo_Mailman.LastErrorText
        destroy loo_Mailman
        destroy loo_SbXml
        destroy loo_HtSeenUidls
        destroy loo_Fac
        destroy loo_StUidls
        destroy loo_StUnseenUidls
        destroy loo_Email
        return
    end if

    Write-Debug string(i)
    Write-Debug "From: " + loo_Email.From
    Write-Debug "Subject: " + loo_Email.Subject

    // Add this UIDL to the "seen" hash table.
    loo_HtSeenUidls.AddStr(ls_Uidl,"")

    i = i + 1
loop

loo_Mailman.Pop3EndSession()

// Update the "seen" UIDLs file.
loo_SbXml.Clear()
loo_HtSeenUidls.ToXmlSb(loo_SbXml)
li_Success = loo_SbXml.WriteFile(ls_SeenUidlsPath,"utf-8",0)
if li_Success = 0 then
    Write-Debug loo_SbXml.LastErrorText
    destroy loo_Mailman
    destroy loo_SbXml
    destroy loo_HtSeenUidls
    destroy loo_Fac
    destroy loo_StUidls
    destroy loo_StUnseenUidls
    destroy loo_Email
    return
end if

Write-Debug "Success."


destroy loo_Mailman
destroy loo_SbXml
destroy loo_HtSeenUidls
destroy loo_Fac
destroy loo_StUidls
destroy loo_StUnseenUidls
destroy loo_Email

 

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