Unicode C
Unicode C
Get an Attached Message as an Email Object
See more Email Object Examples
Demonstrates the Chilkat Email.GetAttachedEmail method, which copies the Nth embedded message/rfc822 MIME part into another Email object. The index is zero-based (valid values run from 0 through NumAttachedMessages - 1). This example attaches an email and then extracts it back into its own object.
Background: When a message forwards another email as an attachment, that nested message is a complete email in its own right.
GetAttachedEmail turns it back into a fully navigable Email object so you can read its subject, sender, body, and even its own attachments — essential for processing forwarded mail, or for tools that unpack reported spam/phishing to examine the original.Chilkat Unicode C Downloads
#include <C_CkEmailW.h>
void ChilkatSample(void)
{
BOOL success;
HCkEmailW innerEmail;
HCkEmailW email;
HCkEmailW attached;
success = FALSE;
// Demonstrates the GetAttachedEmail method, which copies the Nth embedded message/rfc822
// MIME part into another Email object. The index is zero-based.
// Build an inner email and attach it to an outer email.
innerEmail = CkEmailW_Create();
CkEmailW_putSubject(innerEmail,L"Embedded message");
CkEmailW_putFrom(innerEmail,L"alice@example.com");
CkEmailW_putBody(innerEmail,L"This is the embedded message.");
email = CkEmailW_Create();
CkEmailW_putSubject(email,L"Has an attached message");
success = CkEmailW_AttachEmail(email,innerEmail);
if (success == FALSE) {
wprintf(L"%s\n",CkEmailW_lastErrorText(email));
CkEmailW_Dispose(innerEmail);
CkEmailW_Dispose(email);
return true;
}
// Copy the first embedded message (index 0) into its own Email object.
attached = CkEmailW_Create();
success = CkEmailW_GetAttachedEmail(email,0,attached);
if (success == FALSE) {
wprintf(L"%s\n",CkEmailW_lastErrorText(email));
CkEmailW_Dispose(innerEmail);
CkEmailW_Dispose(email);
CkEmailW_Dispose(attached);
return true;
}
wprintf(L"Attached email subject: %s\n",CkEmailW_subject(attached));
wprintf(L"Attached email from: %s\n",CkEmailW_ck_from(attached));
CkEmailW_Dispose(innerEmail);
CkEmailW_Dispose(email);
CkEmailW_Dispose(attached);
}