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
Secrets
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) Load .eml and Examine the Structure, Attachments, and Related Items

Demonstrates how to load examine the MIME structure of a .eml, and also examine the attachment and related item filenames, attached messages, and multipart/report and DSN information.

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 emlPath "C:/AAWorkarea/beatrix/roesner.eml"

set mime [new_CkMime]

set success [CkMime_LoadMimeFile $mime $emlPath]
if {$success != 1} then {
    puts [CkMime_lastErrorText $mime]
    delete_CkMime $mime
    exit
}

puts "---- MIME structure ----"
puts [CkMime_getStructure $mime text]
puts "------------------------"

set email [new_CkEmail]

set success [CkEmail_LoadEml $email $emlPath]

# Was this a signed and/or encrypted email?
# If so, then loading the .eml automatically unwraps
# (i.e. verifies signatures and decrypts) and the resultant
# email is what existed prior to signing/encrypting.
puts "Email was Signed: [CkEmail_get_ReceivedSigned $email]"
puts "Email was Encrypted: [CkEmail_get_ReceivedEncrypted $email]"
if {[CkEmail_get_ReceivedSigned $email] == 1} then {
    puts "Signature(s) valid = [CkEmail_get_SignaturesValid $email]"
}

if {[CkEmail_get_ReceivedEncrypted $email] == 1} then {
    puts "Decrypted successfully = [CkEmail_get_Decrypted $email]"
}

set i 0
set numAttach [CkEmail_get_NumAttachments $email]
puts "Number of attachments = $numAttach"

while {$i < $numAttach} {
    puts "---- Attachment $i"

    # Examine the filename (if any)
    puts "filename: [CkEmail_getAttachmentFilename $email $i]"
    # Examine the content-ID (if any)
    puts "Content-ID: [CkEmail_getAttachmentContentID $email $i]"
    # Examine the content-type
    puts "Content-Type: [CkEmail_getAttachmentContentType $email $i]"
    # Examine the content-disposition
    puts "Content-Disposition[CkEmail_getAttachmentHeader $email $i content-disposition]"
    # Examine the attachment size:
    puts "Size (in bytes) of the attachment: [CkEmail_GetAttachmentSize $email $i]"

    set i [expr $i + 1]
}
puts "--"

# Now for the related items.

# Note: A MIME sub-part can potentially be both a related item AND an attachment.
# The typical case is when the item is contained under the multipart/related enclosure and 
# the item also has a "Content-Disposition" header indicating "attachment".
# The location within multipart/related makes it a "related item", yet the Content-Disposition can also make it semantically an attachment.
# Related items and attachments are not necessarily mutually exclusive.

set numRelated [CkEmail_get_NumRelatedItems $email]
puts "Number of related items = $numRelated"
set i 0
while {$i < $numRelated} {
    puts "---- Related Item $i"

    # Examine the filename (if any)
    puts "filename: [CkEmail_getRelatedFilename $email $i]"
    # Examine the content-ID (if any)
    puts "Content-ID: [CkEmail_getRelatedContentID $email $i]"
    # Examine the content-type
    puts "Content-Type: [CkEmail_getRelatedContentType $email $i]"
    # Examine the content-location (if any)
    puts "Content-Location[CkEmail_getRelatedContentLocation $email $i]"

    set i [expr $i + 1]
}

# The email could also have attached messages.
# An attached message is another email that was attached to this email.
set numAttachedMessages [CkEmail_get_NumAttachedMessages $email]
puts "Number of attached messages = $numAttachedMessages"
set i 0
while {$i < $numAttachedMessages} {
    puts "---- Attached message $i"

    # Examine the attached email
    # em is a CkEmail
    set em [CkEmail_GetAttachedMessage $email $i]
    puts "from: [CkEmail_from $em]"
    puts "subject: [CkEmail_subject $em]"
    delete_CkEmail $em

    set i [expr $i + 1]
}

# An email could also be a multipart/report email. 
# This is a DSN (Delivery Status Notification)
# The NumReports property indicates how many "reports" exist.
set numReports [CkEmail_get_NumReports $email]
set i 0
puts "Number of reports = $numReports"
set i 0
while {$i < $numReports} {
    puts "---- Report $i"
    # Get the raw report data...
    puts [CkEmail_getReport $email $i]
    set i [expr $i + 1]
}

# If the email is a multipart/report, then the information
# from the message/delivery-status part of the email can be retrieved:
if {[CkEmail_IsMultipartReport $email] == 1} then {

    puts "--- Delivery Status Information:"
    puts "Status: [CkEmail_getDeliveryStatusInfo $email Status]"
    puts "Action: [CkEmail_getDeliveryStatusInfo $email Action]"
    puts "Reporting-MTA: [CkEmail_getDeliveryStatusInfo $email Reporting-MTA]"

    # sa is a CkStringArray
    set sa [CkEmail_GetDsnFinalRecipients $email]
    set numFinalRecipients [CkStringArray_get_Count $sa]
    set i 0
    while {$i < $numFinalRecipients} {
        puts "final recipient: [CkStringArray_getString $sa $i]"
        set i [expr $i + 1]
    }
    delete_CkStringArray $sa

}


delete_CkMime $mime
delete_CkEmail $email

 

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