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
(Visual FoxPro) 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.
LOCAL lcEmlPath LOCAL loMime LOCAL lnSuccess LOCAL loEmail LOCAL i LOCAL lnNumAttach LOCAL lnNumRelated LOCAL lnNumAttachedMessages LOCAL loEm LOCAL lnNumReports LOCAL loSa LOCAL lnNumFinalRecipients * This example requires the Chilkat API to have been previously unlocked. * See Global Unlock Sample for sample code. lcEmlPath = "C:/AAWorkarea/beatrix/roesner.eml" * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Mime') loMime = CreateObject('Chilkat.Mime') lnSuccess = loMime.LoadMimeFile(lcEmlPath) IF (lnSuccess <> 1) THEN ? loMime.LastErrorText RELEASE loMime CANCEL ENDIF ? "---- MIME structure ----" ? loMime.GetStructure("text") ? "------------------------" * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Email') loEmail = CreateObject('Chilkat.Email') lnSuccess = loEmail.LoadEml(lcEmlPath) * 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. ? "Email was Signed: " + STR(loEmail.ReceivedSigned) ? "Email was Encrypted: " + STR(loEmail.ReceivedEncrypted) IF (loEmail.ReceivedSigned = 1) THEN ? "Signature(s) valid = " + STR(loEmail.SignaturesValid) ENDIF IF (loEmail.ReceivedEncrypted = 1) THEN ? "Decrypted successfully = " + STR(loEmail.Decrypted) ENDIF i = 0 lnNumAttach = loEmail.NumAttachments ? "Number of attachments = " + STR(lnNumAttach) DO WHILE i < lnNumAttach ? "---- Attachment " + STR(i) * Examine the filename (if any) ? "filename: " + loEmail.GetAttachmentFilename(i) * Examine the content-ID (if any) ? "Content-ID: " + loEmail.GetAttachmentContentID(i) * Examine the content-type ? "Content-Type: " + loEmail.GetAttachmentContentType(i) * Examine the content-disposition ? "Content-Disposition" + loEmail.GetAttachmentHeader(i,"content-disposition") * Examine the attachment size: ? "Size (in bytes) of the attachment: " + STR(loEmail.GetAttachmentSize(i)) i = i + 1 ENDDO ? "--" * 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. lnNumRelated = loEmail.NumRelatedItems ? "Number of related items = " + STR(lnNumRelated) i = 0 DO WHILE i < lnNumRelated ? "---- Related Item " + STR(i) * Examine the filename (if any) ? "filename: " + loEmail.GetRelatedFilename(i) * Examine the content-ID (if any) ? "Content-ID: " + loEmail.GetRelatedContentID(i) * Examine the content-type ? "Content-Type: " + loEmail.GetRelatedContentType(i) * Examine the content-location (if any) ? "Content-Location" + loEmail.GetRelatedContentLocation(i) i = i + 1 ENDDO * The email could also have attached messages. * An attached message is another email that was attached to this email. lnNumAttachedMessages = loEmail.NumAttachedMessages ? "Number of attached messages = " + STR(lnNumAttachedMessages) i = 0 DO WHILE i < lnNumAttachedMessages ? "---- Attached message " + STR(i) * Examine the attached email loEm = loEmail.GetAttachedMessage(i) ? "from: " + loEm.From ? "subject: " + loEm.Subject RELEASE loEm i = i + 1 ENDDO * An email could also be a multipart/report email. * This is a DSN (Delivery Status Notification) * The NumReports property indicates how many "reports" exist. lnNumReports = loEmail.NumReports ? "Number of reports = " + STR(lnNumReports) i = 0 DO WHILE i < lnNumReports ? "---- Report " + STR(i) * Get the raw report data... ? loEmail.GetReport(i) i = i + 1 ENDDO * If the email is a multipart/report, then the information * from the message/delivery-status part of the email can be retrieved: IF (loEmail.IsMultipartReport() = 1) THEN ? "--- Delivery Status Information:" ? "Status: " + loEmail.GetDeliveryStatusInfo("Status") ? "Action: " + loEmail.GetDeliveryStatusInfo("Action") ? "Reporting-MTA: " + loEmail.GetDeliveryStatusInfo("Reporting-MTA") loSa = loEmail.GetDsnFinalRecipients() lnNumFinalRecipients = loSa.Count i = 0 DO WHILE i < lnNumFinalRecipients ? "final recipient: " + loSa.GetString(i) i = i + 1 ENDDO RELEASE loSa ENDIF RELEASE loMime RELEASE loEmail |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.