PureBasic
PureBasic
Remove a Single Attached Message from an Email
See more Email Object Examples
Demonstrates the Chilkat Email.RemoveAttachedMessage method, which removes the Nth message/rfc822 sub-part (an attached email) from the message. Indexing begins at 0. This example attaches an email, removes it, and prints the attached-message count before and after.
Background: Attached messages (forwarded emails carried as
message/rfc822 parts) are counted and indexed separately from ordinary file attachments and related items. RemoveAttachedMessage targets just one nested email by index — useful, for example, when trimming a bundled digest or stripping a forwarded original before re-sending.Chilkat PureBasic Downloads
IncludeFile "CkEmail.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the RemoveAttachedMessage method, which removes the Nth message/rfc822
; sub-part (attached email) of the email. The index is zero-based.
; Build an inner email and attach it to an outer email.
innerEmail.i = CkEmail::ckCreate()
If innerEmail.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkEmail::setCkSubject(innerEmail, "Embedded message")
CkEmail::setCkFrom(innerEmail, "alice@example.com")
email.i = CkEmail::ckCreate()
If email.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkEmail::setCkSubject(email, "Has an attached message")
success = CkEmail::ckAttachEmail(email,innerEmail)
If success = 0
Debug CkEmail::ckLastErrorText(email)
CkEmail::ckDispose(innerEmail)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
Debug "NumAttachedMessages before = " + Str(CkEmail::ckNumAttachedMessages(email))
; Remove the first attached message (index 0).
CkEmail::ckRemoveAttachedMessage(email,0)
Debug "NumAttachedMessages after = " + Str(CkEmail::ckNumAttachedMessages(email))
CkEmail::ckDispose(innerEmail)
CkEmail::ckDispose(email)
ProcedureReturn
EndProcedure