RemoveHeaders include

From 40tude Dialog Wiki

Remove any header (Include-File)

With this little script (done by Thomas Barghahn) you are able to delete any header and its content from your emails and/or postings. If you found bugs feel free to contact the autor Thomas Barghahn (Th.Barghahn@t-online.de).


Install & setup the script

Please note that this script is an include-file!. You have to copy the following script inside a new custom script (for example "RemoveAnyHeader_include") and safe it. Please don't compile this custom script! After that you have to add the following lines to your OnBeforeSending-Script:

{$I RemoveAnyHeader_include.ds}

and

Remove_Headers (Message, IsEmail );

This may look like this:

program OnBeforeSendingMessage;
{$I RemoveAnyHeader_include.ds}

function OnBeforeSendingMessage(var Message: TStringlist; Servername: string; IsEmail: boolean):boolean;
begin
  result:=true;

  Remove_Headers (Message, IsEmail );

  //possibly some other calls to scripts

end;

begin
end.

Just compile this OnBeforeSending-Script now to get your include-file to work. The setup of the script is shown inside the script. Please take a look at this to customize the script to your own fits. Please note that whenever you reconfigure the Remove Headers custom script, you have to recompile the OnBeforeSending-Script to apply the changes.


Setup in the script:
Change the following lines inside the script, to define you're own setup.

// set the header(s) you want to remove here, e.g. 'User-Agent: ,X-Scoring: '
Remove_Headers = 'X-Scoring: ,X-Scoring: ';

// remove header(s) from emails and/or postings set 'true' or 'false'
RemoveFromEmails = true;
RemoveFromNews   = true;

procedure Init_Remove_Headers ( var RemoveHeaders    : string;
                                var RemoveFromEmails : boolean;
                                var RemoveFromNews   : boolean
);

begin
//  ----------------------------------------------------
//  Configuration settings
//  ----------------------------------------------------

    // set the header(s) you want to remove here, e.g. 'User-Agent: ,X-Scoring: '
    RemoveHeaders := 'X-Scoring: ';

    // remove header(s) from emails and/or postings
    // set 'true' or 'false'
    RemoveFromEmails := true;
    RemoveFromNews := true;

   
//  ----------------------------------------------------
//  End of configuration settings
//  ---------------------------------------------------- 

end;

   // --------------------------------------------------------------- //
   // ----  No user maintainable parts below this line -------------- //
   // --------------------------------------------------------------- //
    

procedure Remove_Headers( Message : TStringlist; 
                          IsEmail : boolean 
);

var i                : integer;
    k                : integer;
    s                : string;
    CommaPos         : integer;
    RemoveHeaders    : string;
    DelHeader        : TStringlist;
    RemoveFromEmails : boolean;
    RemoveFromNews   : boolean;
    
begin
   i := 0;
   Init_Remove_Headers ( RemoveHeaders, RemoveFromEmails, RemoveFromNews );
   if ((IsEmail=true)  and (RemoveFromEmails=true)) or
      ((IsEmail=false) and (RemoveFromNews=true)) then begin
      If ( RemoveHeaders <> '' ) then begin
      try 
         DelHeader := TStringlist.Create;
         if ansipos ( ',', RemoveHeaders) = 0 then begin
            DelHeader.Add ( RemoveHeaders );
         end // if
         else begin
            CommaPos := 0;   
            for k := 1 to length ( RemoveHeaders ) do begin
               If RemoveHeaders[k] = ',' then begin
                  DelHeader.Add ( copy ( RemoveHeaders, CommaPos + 1, k - ( CommaPos + 1 )));
                  CommaPos := k;
               end; // if
               if k = length ( RemoveHeaders ) then
                  DelHeader.Add ( copy ( RemoveHeaders, CommaPos + 1, k - CommaPos ));                   
            end; // for  
         end; // else  
         s:=Message.text;
         while (Message.Strings[i]<>'') do begin
            k := 0;
            while k <= ( DelHeader.Count - 1 ) do begin 
               if pos( DelHeader[k], Message.Strings[i] ) = 1 then begin
                  delete ( s, pos(DelHeader[k], s ), length ( Message.Strings[i] ) + 2 );
                  i := i - 1;
                  k := DelHeader.Count - 1;
                  message.text := s;
               end; // if 
               k := k + 1;
            end; // while   
            i := i + 1;
         end; //while
         message.text:=s;
      finally
      DelHeader.Free;
      end; // try - finally 
      end; // if  
   end; // if
end; // Remove_Headers

>René Fischer