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

Tcl 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
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
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

 

 

 

(Tcl) Get IMAP UID from Email Header

Demonstrates how to get the IMAP UID from an email header. After fetching an email or header using IMAP, the UID is contained in the ckx-imap-uid header field.

Chilkat Tcl Extension Downloads

Chilkat Tcl Extension Downloads

load ./chilkat.dll

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

set imap [new_CkImap]

# Connect to an IMAP server.
# Use TLS
CkImap_put_Ssl $imap 1
CkImap_put_Port $imap 993
set success [CkImap_Connect $imap "imap.someMailServer.com"]
if {$success != 1} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

# Login
set success [CkImap_Login $imap "login" "password"]
if {$success != 1} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

# Select an IMAP mailbox
set success [CkImap_SelectMailbox $imap "Inbox"]
if {$success != 1} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

set fetchUids 1
# Get the message UIDs of all the emails in the mailbox
# messageSet is a CkMessageSet
set messageSet [CkImap_Search $imap "ALL" $fetchUids]
if {[CkImap_get_LastMethodSuccess $imap] != 1} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

# bundle is a CkEmailBundle
set bundle [CkImap_FetchHeaders $imap $messageSet]
if {[CkImap_get_LastMethodSuccess $imap] != 1} then {
    delete_CkMessageSet $messageSet

    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

# The UID of each fetched email header is available 
# in the ckx-imap-uid header field.
set i 0
set szBundle [CkEmailBundle_get_MessageCount $bundle]
set msOneMsg [new_CkMessageSet]

while {$i < $szBundle} {
    # email is a CkEmail
    set email [CkEmailBundle_GetEmail $bundle $i]

    # Build a message set containing one UID
    set uidStr [CkEmail_getHeaderField $email "ckx-imap-uid"]
    CkMessageSet_FromCompactString $msOneMsg $uidStr

    # Move this message to some other folder.
    set success [CkImap_MoveMessages $imap $msOneMsg "someOtherFolder"]
    if {$success != 1} then {
        puts [CkImap_lastErrorText $imap]
        # Exit the loop...
        set i $szBundle
    }

    delete_CkEmail $email

    set i [expr $i + 1]
}

# Disconnect from the IMAP server.
set success [CkImap_Disconnect $imap]

delete_CkMessageSet $messageSet

delete_CkEmailBundle $bundle


delete_CkImap $imap
delete_CkMessageSet $msOneMsg

 

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