Unicode C++
Unicode C++
Remove a Header Field from an Email
See more Email Object Examples
Demonstrates the Chilkat Email.RemoveHeaderField method, which removes by name all occurrences of a header field. Header-field names are case-insensitive, and every repeated occurrence with the given name is removed. This example adds a custom header, then removes it.
Background: Editing a message sometimes means deleting a header outright — stripping a tracking header, removing an
X- flag before forwarding, or clearing a stale field before re-sending. Because a field name can appear more than once (like Received), RemoveHeaderField removes all matching occurrences in one call rather than just the first.Chilkat Unicode C++ Downloads
#include <CkEmailW.h>
void ChilkatSample(void)
{
// Demonstrates the RemoveHeaderField method, which removes by name all occurrences of a
// header field. Header-field names are case-insensitive.
CkEmailW email;
email.put_Subject(L"Remove header field");
email.put_From(L"alice@example.com");
email.AddHeaderField(L"X-Custom-Header",L"some value");
// Use HasHeaderMatching to test for the header's presence. ("*" matches any value.)
bool hasBefore = email.HasHeaderMatching(L"X-Custom-Header",L"*",false);
wprintf(L"Has X-Custom-Header before: %d\n",hasBefore);
// Remove all occurrences of the header field.
email.RemoveHeaderField(L"X-Custom-Header");
bool hasAfter = email.HasHeaderMatching(L"X-Custom-Header",L"*",false);
wprintf(L"Has X-Custom-Header after: %d\n",hasAfter);
}