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
(DataFlex) 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.
Use ChilkatAx-win32.pkg Procedure Test String sEmlPath Handle hoMime Boolean iSuccess Handle hoEmail Integer i Integer iNumAttach Integer iNumRelated Integer iNumAttachedMessages Variant vEm Handle hoEm Integer iNumReports Variant vSa Handle hoSa Integer iNumFinalRecipients String sTemp1 Integer iTemp1 Boolean bTemp1 // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Move "C:/AAWorkarea/beatrix/roesner.eml" To sEmlPath Get Create (RefClass(cComChilkatMime)) To hoMime If (Not(IsComObjectCreated(hoMime))) Begin Send CreateComObject of hoMime End Get ComLoadMimeFile Of hoMime sEmlPath To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoMime To sTemp1 Showln sTemp1 Procedure_Return End Showln "---- MIME structure ----" Get ComGetStructure Of hoMime "text" To sTemp1 Showln sTemp1 Showln "------------------------" Get Create (RefClass(cComChilkatEmail)) To hoEmail If (Not(IsComObjectCreated(hoEmail))) Begin Send CreateComObject of hoEmail End Get ComLoadEml Of hoEmail sEmlPath To iSuccess // 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. Get ComReceivedSigned Of hoEmail To bTemp1 Showln "Email was Signed: " bTemp1 Get ComReceivedEncrypted Of hoEmail To bTemp1 Showln "Email was Encrypted: " bTemp1 Get ComReceivedSigned Of hoEmail To bTemp1 If (bTemp1 = True) Begin Get ComSignaturesValid Of hoEmail To bTemp1 Showln "Signature(s) valid = " bTemp1 End Get ComReceivedEncrypted Of hoEmail To bTemp1 If (bTemp1 = True) Begin Get ComDecrypted Of hoEmail To bTemp1 Showln "Decrypted successfully = " bTemp1 End Move 0 To i Get ComNumAttachments Of hoEmail To iNumAttach Showln "Number of attachments = " iNumAttach While (i < iNumAttach) Showln "---- Attachment " i // Examine the filename (if any) Get ComGetAttachmentFilename Of hoEmail i To sTemp1 Showln "filename: " sTemp1 // Examine the content-ID (if any) Get ComGetAttachmentContentID Of hoEmail i To sTemp1 Showln "Content-ID: " sTemp1 // Examine the content-type Get ComGetAttachmentContentType Of hoEmail i To sTemp1 Showln "Content-Type: " sTemp1 // Examine the content-disposition Get ComGetAttachmentHeader Of hoEmail i "content-disposition" To sTemp1 Showln "Content-Disposition" sTemp1 // Examine the attachment size: Get ComGetAttachmentSize Of hoEmail i To iTemp1 Showln "Size (in bytes) of the attachment: " iTemp1 Move (i + 1) To i Loop Showln "--" // 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. Get ComNumRelatedItems Of hoEmail To iNumRelated Showln "Number of related items = " iNumRelated Move 0 To i While (i < iNumRelated) Showln "---- Related Item " i // Examine the filename (if any) Get ComGetRelatedFilename Of hoEmail i To sTemp1 Showln "filename: " sTemp1 // Examine the content-ID (if any) Get ComGetRelatedContentID Of hoEmail i To sTemp1 Showln "Content-ID: " sTemp1 // Examine the content-type Get ComGetRelatedContentType Of hoEmail i To sTemp1 Showln "Content-Type: " sTemp1 // Examine the content-location (if any) Get ComGetRelatedContentLocation Of hoEmail i To sTemp1 Showln "Content-Location" sTemp1 Move (i + 1) To i Loop // The email could also have attached messages. // An attached message is another email that was attached to this email. Get ComNumAttachedMessages Of hoEmail To iNumAttachedMessages Showln "Number of attached messages = " iNumAttachedMessages Move 0 To i While (i < iNumAttachedMessages) Showln "---- Attached message " i // Examine the attached email Get ComGetAttachedMessage Of hoEmail i To vEm If (IsComObject(vEm)) Begin Get Create (RefClass(cComChilkatEmail)) To hoEm Set pvComObject Of hoEm To vEm End Get ComFrom Of hoEm To sTemp1 Showln "from: " sTemp1 Get ComSubject Of hoEm To sTemp1 Showln "subject: " sTemp1 Send Destroy of hoEm Move (i + 1) To i Loop // An email could also be a multipart/report email. // This is a DSN (Delivery Status Notification) // The NumReports property indicates how many "reports" exist. Get ComNumReports Of hoEmail To iNumReports Showln "Number of reports = " iNumReports Move 0 To i While (i < iNumReports) Showln "---- Report " i // Get the raw report data... Get ComGetReport Of hoEmail i To sTemp1 Showln sTemp1 Move (i + 1) To i Loop // If the email is a multipart/report, then the information // from the message/delivery-status part of the email can be retrieved: Get ComIsMultipartReport Of hoEmail To bTemp1 If (bTemp1 = True) Begin Showln "--- Delivery Status Information:" Get ComGetDeliveryStatusInfo Of hoEmail "Status" To sTemp1 Showln "Status: " sTemp1 Get ComGetDeliveryStatusInfo Of hoEmail "Action" To sTemp1 Showln "Action: " sTemp1 Get ComGetDeliveryStatusInfo Of hoEmail "Reporting-MTA" To sTemp1 Showln "Reporting-MTA: " sTemp1 Get ComGetDsnFinalRecipients Of hoEmail To vSa If (IsComObject(vSa)) Begin Get Create (RefClass(cComCkStringArray)) To hoSa Set pvComObject Of hoSa To vSa End Get ComCount Of hoSa To iNumFinalRecipients Move 0 To i While (i < iNumFinalRecipients) Get ComGetString Of hoSa i To sTemp1 Showln "final recipient: " sTemp1 Move (i + 1) To i Loop Send Destroy of hoSa End End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.