Tcl
Tcl
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 Tcl Downloads
load ./chilkat.dll
set success 0
# 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.
set innerEmail [new_CkEmail]
CkEmail_put_Subject $innerEmail "Embedded message"
CkEmail_put_From $innerEmail "alice@example.com"
CkEmail_put_Body $innerEmail "This is the embedded message."
set email [new_CkEmail]
CkEmail_put_Subject $email "Has an attached message"
set success [CkEmail_AttachEmail $email $innerEmail]
if {$success == 0} then {
puts [CkEmail_lastErrorText $email]
delete_CkEmail $innerEmail
delete_CkEmail $email
exit
}
# Copy the first embedded message (index 0) into its own Email object.
set attached [new_CkEmail]
set success [CkEmail_GetAttachedEmail $email 0 $attached]
if {$success == 0} then {
puts [CkEmail_lastErrorText $email]
delete_CkEmail $innerEmail
delete_CkEmail $email
delete_CkEmail $attached
exit
}
puts "Attached email subject: [CkEmail_subject $attached]"
puts "Attached email from: [CkEmail_from $attached]"
delete_CkEmail $innerEmail
delete_CkEmail $email
delete_CkEmail $attached