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
(C) 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 <C_CkMime.h> #include <C_CkEmail.h> #include <C_CkStringArray.h> void ChilkatSample(void) { const char *emlPath; HCkMime mime; BOOL success; HCkEmail email; int i; int numAttach; int numRelated; int numAttachedMessages; HCkEmail em; int numReports; HCkStringArray sa; int numFinalRecipients; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. emlPath = "C:/AAWorkarea/beatrix/roesner.eml"; mime = CkMime_Create(); success = CkMime_LoadMimeFile(mime,emlPath); if (success != TRUE) { printf("%s\n",CkMime_lastErrorText(mime)); CkMime_Dispose(mime); return; } printf("---- MIME structure ----\n"); printf("%s\n",CkMime_getStructure(mime,"text")); printf("------------------------\n"); email = CkEmail_Create(); success = CkEmail_LoadEml(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. printf("Email was Signed: %d\n",CkEmail_getReceivedSigned(email)); printf("Email was Encrypted: %d\n",CkEmail_getReceivedEncrypted(email)); if (CkEmail_getReceivedSigned(email) == TRUE) { printf("Signature(s) valid = %d\n",CkEmail_getSignaturesValid(email)); } if (CkEmail_getReceivedEncrypted(email) == TRUE) { printf("Decrypted successfully = %d\n",CkEmail_getDecrypted(email)); } i = 0; numAttach = CkEmail_getNumAttachments(email); printf("Number of attachments = %d\n",numAttach); while (i < numAttach) { printf("---- Attachment %d\n",i); // Examine the filename (if any) printf("filename: %s\n",CkEmail_getAttachmentFilename(email,i)); // Examine the content-ID (if any) printf("Content-ID: %s\n",CkEmail_getAttachmentContentID(email,i)); // Examine the content-type printf("Content-Type: %s\n",CkEmail_getAttachmentContentType(email,i)); // Examine the content-disposition printf("Content-Disposition%s\n",CkEmail_getAttachmentHeader(email,i,"content-disposition")); // Examine the attachment size: printf("Size (in bytes) of the attachment: %d\n",CkEmail_GetAttachmentSize(email,i)); i = i + 1; } printf("--\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. numRelated = CkEmail_getNumRelatedItems(email); printf("Number of related items = %d\n",numRelated); i = 0; while (i < numRelated) { printf("---- Related Item %d\n",i); // Examine the filename (if any) printf("filename: %s\n",CkEmail_getRelatedFilename(email,i)); // Examine the content-ID (if any) printf("Content-ID: %s\n",CkEmail_getRelatedContentID(email,i)); // Examine the content-type printf("Content-Type: %s\n",CkEmail_getRelatedContentType(email,i)); // Examine the content-location (if any) printf("Content-Location%s\n",CkEmail_getRelatedContentLocation(email,i)); i = i + 1; } // The email could also have attached messages. // An attached message is another email that was attached to this email. numAttachedMessages = CkEmail_getNumAttachedMessages(email); printf("Number of attached messages = %d\n",numAttachedMessages); i = 0; while (i < numAttachedMessages) { printf("---- Attached message %d\n",i); // Examine the attached email em = CkEmail_GetAttachedMessage(email,i); printf("from: %s\n",CkEmail_ck_from(em)); printf("subject: %s\n",CkEmail_subject(em)); CkEmail_Dispose(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. numReports = CkEmail_getNumReports(email); i = 0; printf("Number of reports = %d\n",numReports); i = 0; while (i < numReports) { printf("---- Report %d\n",i); // Get the raw report data... printf("%s\n",CkEmail_getReport(email,i)); 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 (CkEmail_IsMultipartReport(email) == TRUE) { printf("--- Delivery Status Information:\n"); printf("Status: %s\n",CkEmail_getDeliveryStatusInfo(email,"Status")); printf("Action: %s\n",CkEmail_getDeliveryStatusInfo(email,"Action")); printf("Reporting-MTA: %s\n",CkEmail_getDeliveryStatusInfo(email,"Reporting-MTA")); sa = CkEmail_GetDsnFinalRecipients(email); numFinalRecipients = CkStringArray_getCount(sa); i = 0; while (i < numFinalRecipients) { printf("final recipient: %s\n",CkStringArray_getString(sa,i)); i = i + 1; } CkStringArray_Dispose(sa); } CkMime_Dispose(mime); CkEmail_Dispose(email); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.