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

PureBasic 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

 

 

 

(PureBasic) Using IMAP IDLE to Wait for Updates

This example demonstrates how to use the IMAP IDLE functionality in Chilkat.

Chilkat PureBasic Module Download

Chilkat PureBasic Module

IncludeFile "CkImap.pb"

Procedure ChilkatExample()

    imap.i = CkImap::ckCreate()
    If imap.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ; ....
    ; ....
    ; ....

    ; Select an IMAP mailbox
    success = CkImap::ckSelectMailbox(imap,"INBOX")
    If success <> 1
        Debug CkImap::ckLastErrorText(imap)
        CkImap::ckDispose(imap)
        ProcedureReturn
    EndIf

    ; After a mailbox has been selected, IDLE may begin.
    ; Idling tells the IMAP server to push unsolicited updates for the selected
    ; mailbox to the connected client (which is your application).
    success = CkImap::ckIdleStart(imap)
    If success <> 1
        Debug CkImap::ckLastErrorText(imap)
        CkImap::ckDispose(imap)
        ProcedureReturn
    EndIf

    ; Once idling has started, your code still has to periodically check to see
    ; if any updates have arrived.  However, this is significantly different
    ; then what normally occurs when checking email.  The IdleCheck does NOT
    ; send a message to the IMAP server.  It simply checks the connection to see
    ; if any data has arrived.  If so, it can be consumed and the client (your app)
    ; can react appropriately.  

    ; Note: It is recommended that idling only run for a max of 20 minutes before stopping and
    ; re-starting the IDLE.  This is to maintain a minimum low level of activity so that 
    ; the IMAP server does not disconnect (which it may do if it considers the connection to 
    ; be truly inactive, i.e. forgotten).

    ; To check the connection for IDLE updates, call IdleCheck.  The 1st argument indicates how
    ; long we're willing to wait. We'll wait 1 millisecond:
    idleResultXml.s
    idleResultXml = CkImap::ckIdleCheck(imap,1)
    If CkImap::ckLastMethodSuccess(imap) <> 1
        Debug CkImap::ckLastErrorText(imap)
        CkImap::ckDispose(imap)
        ProcedureReturn
    EndIf

    ; See the online reference documentation for details regarding the XML that is returned.
    ; Your application code would parse the XML to determine what action to take.
    ; If the XML contains "<idle></idle>", then no updates are available and your application
    ; would call IdleCheck again at some point in the future.

    ; If updates are available, the IDLE must be terminated by calling IdleDone, like this:
    success = CkImap::ckIdleDone(imap)
    If success <> 1
        Debug CkImap::ckLastErrorText(imap)
        CkImap::ckDispose(imap)
        ProcedureReturn
    EndIf

    ; Once the IDLE is terminated, your application can make calls to fetch email, etc.
    ; Any attempt to communicate with the IMAP server prior to terminating the IDLE will
    ; result in failure.

    ; IMPORTANT: Please realize that your application code will be structured differently than shown here.
    ; The call to IdleCheck will likely be in a function/procedure that is periodically called
    ; after the IdleStart has been called from some other location in your app


    CkImap::ckDispose(imap)


    ProcedureReturn
EndProcedure

 

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