Sample code for 30+ languages & platforms
SQL Server

Remove a MIME Header Field

See more MIME Examples

Demonstrates the Chilkat Mime.RemoveHeaderField method, which removes header fields whose name matches case-insensitively. The first argument is the field name and the second (bAllOccurrences) selects whether to remove all matches or only the first. It is a void method.

Note: The file path is relative to the application's current working directory. Absolute paths may also be used. Supply the path to your own file.

Background: Stripping headers is common when reprocessing a message — removing spam-scoring X- headers, clearing an old Content-Length before re-serializing, or deleting routing headers before forwarding. The all-occurrences flag matters for headers that can repeat: pass true to purge every instance, or false to drop just the first.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    DECLARE @mime int
    EXEC @hr = sp_OACreate 'Chilkat.Mime', @mime OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @mime, 'LoadMimeFile', @success OUT, 'qa_data/message.eml'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mime
        RETURN
      END

    --  Remove header fields whose name matches (case-insensitively).  The 1st argument is the field
    --  name and the 2nd (bAllOccurrences) selects whether to remove all matches or only the first.
    --  RemoveHeaderField is a void method.

    --  Remove every X-Spam-Status header.
    DECLARE @bAllOccurrences int
    SELECT @bAllOccurrences = 1
    EXEC sp_OAMethod @mime, 'RemoveHeaderField', NULL, 'X-Spam-Status', @bAllOccurrences


    PRINT 'Removed the header field(s).'

    EXEC @hr = sp_OADestroy @mime


END
GO