Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Tcl) Load .eml and Examine the Structure, Attachments, and Related ItemsDemonstrates 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.
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.