Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex 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
Regular Expressions
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

 

 

 

(DataFlex) 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

Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoMailman
    String sSeenUidlsPath
    Variant vSbXml
    Handle hoSbXml
    Handle hoHtSeenUidls
    Handle hoFac
    Variant vStUidls
    Handle hoStUidls
    Handle hoStUnseenUidls
    String sUidl
    Integer i
    Integer iCount
    Variant vEmail
    Handle hoEmail
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    Move False To iSuccess

    // 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.
    Get Create (RefClass(cComChilkatMailMan)) To hoMailman
    If (Not(IsComObjectCreated(hoMailman))) Begin
        Send CreateComObject of hoMailman
    End

    // Set the POP3 server's hostname
    Set ComMailHost Of hoMailman To "pop.example.com"

    // Set the POP3 login/password.
    Set ComPopUsername Of hoMailman To "***"
    Set ComPopPassword Of hoMailman To "***"

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

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbXml
    If (Not(IsComObjectCreated(hoSbXml))) Begin
        Send CreateComObject of hoSbXml
    End
    Get Create (RefClass(cComChilkatHashtable)) To hoHtSeenUidls
    If (Not(IsComObjectCreated(hoHtSeenUidls))) Begin
        Send CreateComObject of hoHtSeenUidls
    End
    Get Create (RefClass(cComCkFileAccess)) To hoFac
    If (Not(IsComObjectCreated(hoFac))) Begin
        Send CreateComObject of hoFac
    End
    Get ComFileExists Of hoFac sSeenUidlsPath To bTemp1
    If (bTemp1 = True) Begin
        Get ComLoadFile Of hoSbXml sSeenUidlsPath "utf-8" To iSuccess
        If (iSuccess = False) Begin
            Get ComLastErrorText Of hoSbXml To sTemp1
            Showln sTemp1
            Procedure_Return
        End

        Get pvComObject of hoSbXml to vSbXml
        Get ComAddFromXmlSb Of hoHtSeenUidls vSbXml To iSuccess
    End

    // Get the complete list of UIDLs on the mail server.
    Get Create (RefClass(cComChilkatStringTable)) To hoStUidls
    If (Not(IsComObjectCreated(hoStUidls))) Begin
        Send CreateComObject of hoStUidls
    End
    Get pvComObject of hoStUidls to vStUidls
    Get ComFetchUidls Of hoMailman vStUidls To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMailman To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Build a list of unseen UIDLs
    Get Create (RefClass(cComChilkatStringTable)) To hoStUnseenUidls
    If (Not(IsComObjectCreated(hoStUnseenUidls))) Begin
        Send CreateComObject of hoStUnseenUidls
    End

    Move 0 To i
    Get ComCount Of hoStUidls To iCount
    While (i < iCount)
        Get ComStringAt Of hoStUidls i To sUidl
        Get ComContains Of hoHtSeenUidls sUidl To bTemp1
        If (bTemp1 <> True) Begin
            Get ComAppend Of hoStUnseenUidls sUidl To iSuccess
        End

        Move (i + 1) To i
    Loop

    Get ComCount Of hoStUnseenUidls To iTemp1
    If (iTemp1 = 0) Begin
        Showln "No unseen emails!"
        Procedure_Return
    End

    // Download the unseen emails, adding each UIDL to the "seen" hash table.
    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End

    Get ComCount Of hoStUnseenUidls To iCount
    Move 0 To i
    While (i < iCount)
        // Download the full email.
        Get ComStringAt Of hoStUnseenUidls i To sUidl
        Get pvComObject of hoEmail to vEmail
        Get ComFetchByUidl Of hoMailman sUidl False 0 vEmail To iSuccess
        If (iSuccess = False) Begin
            Get ComLastErrorText Of hoMailman To sTemp1
            Showln sTemp1
            Procedure_Return
        End

        Showln i
        Get ComFrom Of hoEmail To sTemp1
        Showln "From: " sTemp1
        Get ComSubject Of hoEmail To sTemp1
        Showln "Subject: " sTemp1

        // Add this UIDL to the "seen" hash table.
        Get ComAddStr Of hoHtSeenUidls sUidl "" To iSuccess

        Move (i + 1) To i
    Loop

    Get ComPop3EndSession Of hoMailman To iSuccess

    // Update the "seen" UIDLs file.
    Send ComClear To hoSbXml
    Get pvComObject of hoSbXml to vSbXml
    Get ComToXmlSb Of hoHtSeenUidls vSbXml To iSuccess
    Get ComWriteFile Of hoSbXml sSeenUidlsPath "utf-8" False To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoSbXml To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Success."


End_Procedure

 

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