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
(PureBasic) 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.
IncludeFile "CkMime.pb" IncludeFile "CkEmail.pb" IncludeFile "CkStringArray.pb" Procedure ChilkatExample() ; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. emlPath.s = "C:/AAWorkarea/beatrix/roesner.eml" mime.i = CkMime::ckCreate() If mime.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i = CkMime::ckLoadMimeFile(mime,emlPath) If success <> 1 Debug CkMime::ckLastErrorText(mime) CkMime::ckDispose(mime) ProcedureReturn EndIf Debug "---- MIME structure ----" Debug CkMime::ckGetStructure(mime,"text") Debug "------------------------" email.i = CkEmail::ckCreate() If email.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkEmail::ckLoadEml(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. Debug "Email was Signed: " + Str(CkEmail::ckReceivedSigned(email)) Debug "Email was Encrypted: " + Str(CkEmail::ckReceivedEncrypted(email)) If CkEmail::ckReceivedSigned(email) = 1 Debug "Signature(s) valid = " + Str(CkEmail::ckSignaturesValid(email)) EndIf If CkEmail::ckReceivedEncrypted(email) = 1 Debug "Decrypted successfully = " + Str(CkEmail::ckDecrypted(email)) EndIf i.i = 0 numAttach.i = CkEmail::ckNumAttachments(email) Debug "Number of attachments = " + Str(numAttach) While i < numAttach Debug "---- Attachment " + Str(i) ; Examine the filename (if any) Debug "filename: " + CkEmail::ckGetAttachmentFilename(email,i) ; Examine the content-ID (if any) Debug "Content-ID: " + CkEmail::ckGetAttachmentContentID(email,i) ; Examine the content-type Debug "Content-Type: " + CkEmail::ckGetAttachmentContentType(email,i) ; Examine the content-disposition Debug "Content-Disposition" + CkEmail::ckGetAttachmentHeader(email,i,"content-disposition") ; Examine the attachment size: Debug "Size (in bytes) of the attachment: " + Str(CkEmail::ckGetAttachmentSize(email,i)) i = i + 1 Wend Debug "--" ; 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. numRelated.i = CkEmail::ckNumRelatedItems(email) Debug "Number of related items = " + Str(numRelated) i = 0 While i < numRelated Debug "---- Related Item " + Str(i) ; Examine the filename (if any) Debug "filename: " + CkEmail::ckGetRelatedFilename(email,i) ; Examine the content-ID (if any) Debug "Content-ID: " + CkEmail::ckGetRelatedContentID(email,i) ; Examine the content-type Debug "Content-Type: " + CkEmail::ckGetRelatedContentType(email,i) ; Examine the content-location (if any) Debug "Content-Location" + CkEmail::ckGetRelatedContentLocation(email,i) i = i + 1 Wend ; The email could also have attached messages. ; An attached message is another email that was attached to this email. numAttachedMessages.i = CkEmail::ckNumAttachedMessages(email) Debug "Number of attached messages = " + Str(numAttachedMessages) i = 0 While i < numAttachedMessages Debug "---- Attached message " + Str(i) ; Examine the attached email em.i = CkEmail::ckGetAttachedMessage(email,i) Debug "from: " + CkEmail::ckFrom(em) Debug "subject: " + CkEmail::ckSubject(em) CkEmail::ckDispose(em) i = i + 1 Wend ; An email could also be a multipart/report email. ; This is a DSN (Delivery Status Notification) ; The NumReports property indicates how many "reports" exist. numReports.i = CkEmail::ckNumReports(email) i = 0 Debug "Number of reports = " + Str(numReports) i = 0 While i < numReports Debug "---- Report " + Str(i) ; Get the raw report data... Debug CkEmail::ckGetReport(email,i) i = i + 1 Wend ; If the email is a multipart/report, then the information ; from the message/delivery-status part of the email can be retrieved: If CkEmail::ckIsMultipartReport(email) = 1 Debug "--- Delivery Status Information:" Debug "Status: " + CkEmail::ckGetDeliveryStatusInfo(email,"Status") Debug "Action: " + CkEmail::ckGetDeliveryStatusInfo(email,"Action") Debug "Reporting-MTA: " + CkEmail::ckGetDeliveryStatusInfo(email,"Reporting-MTA") sa.i = CkEmail::ckGetDsnFinalRecipients(email) numFinalRecipients.i = CkStringArray::ckCount(sa) i = 0 While i < numFinalRecipients Debug "final recipient: " + CkStringArray::ckGetString(sa,i) i = i + 1 Wend CkStringArray::ckDispose(sa) EndIf CkMime::ckDispose(mime) CkEmail::ckDispose(email) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.