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
(Lianja) 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.
// This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. lcEmlPath = "C:/AAWorkarea/beatrix/roesner.eml" loMime = createobject("CkMime") llSuccess = loMime.LoadMimeFile(lcEmlPath) if (llSuccess <> .T.) then ? loMime.LastErrorText release loMime return endif ? "---- MIME structure ----" ? loMime.GetStructure("text") ? "------------------------" loEmail = createobject("CkEmail") llSuccess = 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 = .T.) then ? "Signature(s) valid = " + str(loEmail.SignaturesValid) endif if (loEmail.ReceivedEncrypted = .T.) 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 i = 0 ? "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() = .T.) 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.