Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Tcl Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
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
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(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 {[expr $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 {[expr [CkEmail_get_ReceivedSigned $email] == 1]} then {
    puts "Signature(s) valid = [CkEmail_get_SignaturesValid $email]"
}

if {[expr [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 {[expr $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.
set numRelated [CkEmail_get_NumRelatedItems $email]
puts "Number of related items = $numRelated"
set i 0
while {[expr $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 {[expr $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 {[expr $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 {[expr [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 {[expr $i < $numFinalRecipients]} {
        puts "final recipient: [CkStringArray_getString $sa $i]"
        set i [expr $i + 1]
    }
    delete_CkStringArray $sa

}


delete_CkMime $mime
delete_CkEmail $email

 

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