Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(MFC) 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.
#include <CkMime.h> #include <CkEmail.h> #include <CkStringArray.h> void ChilkatSample(void) { CkString strOut; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. const char *emlPath = "C:/AAWorkarea/beatrix/roesner.eml"; CkMime mime; bool success = mime.LoadMimeFile(emlPath); if (success != true) { strOut.append(mime.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } strOut.append("---- MIME structure ----"); strOut.append("\r\n"); strOut.append(mime.getStructure("text")); strOut.append("\r\n"); strOut.append("------------------------"); strOut.append("\r\n"); CkEmail email; success = email.LoadEml(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. strOut.append("Email was Signed: "); strOut.appendInt(email.get_ReceivedSigned()); strOut.append("\r\n"); strOut.append("Email was Encrypted: "); strOut.appendInt(email.get_ReceivedEncrypted()); strOut.append("\r\n"); if (email.get_ReceivedSigned() == true) { strOut.append("Signature(s) valid = "); strOut.appendInt(email.get_SignaturesValid()); strOut.append("\r\n"); } if (email.get_ReceivedEncrypted() == true) { strOut.append("Decrypted successfully = "); strOut.appendInt(email.get_Decrypted()); strOut.append("\r\n"); } int i = 0; int numAttach = email.get_NumAttachments(); strOut.append("Number of attachments = "); strOut.appendInt(numAttach); strOut.append("\r\n"); while (i < numAttach) { strOut.append("---- Attachment "); strOut.appendInt(i); strOut.append("\r\n"); // Examine the filename (if any) strOut.append("filename: "); strOut.append(email.getAttachmentFilename(i)); strOut.append("\r\n"); // Examine the content-ID (if any) strOut.append("Content-ID: "); strOut.append(email.getAttachmentContentID(i)); strOut.append("\r\n"); // Examine the content-type strOut.append("Content-Type: "); strOut.append(email.getAttachmentContentType(i)); strOut.append("\r\n"); // Examine the content-disposition strOut.append("Content-Disposition"); strOut.append(email.getAttachmentHeader(i,"content-disposition")); strOut.append("\r\n"); // Examine the attachment size: strOut.append("Size (in bytes) of the attachment: "); strOut.appendInt(email.GetAttachmentSize(i)); strOut.append("\r\n"); i = i + 1; } strOut.append("--"); strOut.append("\r\n"); // 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. int numRelated = email.get_NumRelatedItems(); strOut.append("Number of related items = "); strOut.appendInt(numRelated); strOut.append("\r\n"); i = 0; while (i < numRelated) { strOut.append("---- Related Item "); strOut.appendInt(i); strOut.append("\r\n"); // Examine the filename (if any) strOut.append("filename: "); strOut.append(email.getRelatedFilename(i)); strOut.append("\r\n"); // Examine the content-ID (if any) strOut.append("Content-ID: "); strOut.append(email.getRelatedContentID(i)); strOut.append("\r\n"); // Examine the content-type strOut.append("Content-Type: "); strOut.append(email.getRelatedContentType(i)); strOut.append("\r\n"); // Examine the content-location (if any) strOut.append("Content-Location"); strOut.append(email.getRelatedContentLocation(i)); strOut.append("\r\n"); i = i + 1; } // The email could also have attached messages. // An attached message is another email that was attached to this email. int numAttachedMessages = email.get_NumAttachedMessages(); strOut.append("Number of attached messages = "); strOut.appendInt(numAttachedMessages); strOut.append("\r\n"); i = 0; while (i < numAttachedMessages) { strOut.append("---- Attached message "); strOut.appendInt(i); strOut.append("\r\n"); // Examine the attached email CkEmail *em = email.GetAttachedMessage(i); strOut.append("from: "); strOut.append(em->ck_from()); strOut.append("\r\n"); strOut.append("subject: "); strOut.append(em->subject()); strOut.append("\r\n"); delete em; i = 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. int numReports = email.get_NumReports(); i = 0; strOut.append("Number of reports = "); strOut.appendInt(numReports); strOut.append("\r\n"); i = 0; while (i < numReports) { strOut.append("---- Report "); strOut.appendInt(i); strOut.append("\r\n"); // Get the raw report data... strOut.append(email.getReport(i)); strOut.append("\r\n"); i = 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 (email.IsMultipartReport() == true) { strOut.append("--- Delivery Status Information:"); strOut.append("\r\n"); strOut.append("Status: "); strOut.append(email.getDeliveryStatusInfo("Status")); strOut.append("\r\n"); strOut.append("Action: "); strOut.append(email.getDeliveryStatusInfo("Action")); strOut.append("\r\n"); strOut.append("Reporting-MTA: "); strOut.append(email.getDeliveryStatusInfo("Reporting-MTA")); strOut.append("\r\n"); CkStringArray *sa = email.GetDsnFinalRecipients(); int numFinalRecipients = sa->get_Count(); i = 0; while (i < numFinalRecipients) { strOut.append("final recipient: "); strOut.append(sa->getString(i)); strOut.append("\r\n"); i = i + 1; } delete sa; } SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.