CustomizeUserAgent include

From 40tude Dialog Wiki

Customize User-Agent (Include)

A little script done by Thomas Barghahn. With this script you are able to change any header and add a trailing text at the end of the Header (IMHO its only reasonable for the User-Agent string). If you found bugs feel free to contact the autor Thomas Barghahn (Th.Barghahn@t-online.de).


Example with User-Agent-Header:

"User-Agent: 40tude_Dialog/2.0.12.1de (1693fe98.335.147) (Simply the best usenet experience)"

If you like to add you're text at the end of the user-agent, please attend of the following abstract from draft-ietf-usefor-usefor-01.

User-Agent

The User-Agent header contains information about the user agent (typically a newsreader) generating the article for statistical purposes and tracing of standards violations to specific software needing correction. Although not one of the mandatory headers, posting agents SHOULD normally include it. It is also intended that this header be suitable for use in Email.

user-agent      =  "User-Agent:" SP 1*product CRLF
product         =  [CFWS] token [CFWS] [ "/" product-version ]
product-version =  [CFWS] token [CFWS]

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 "ChangeAnyHeader_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 ChangeAnyHeader_include.ds}

and

ChangeAnyHeader ( Message, IsEmail );

This may look like this:

program OnBeforeSendingMessage;
{$I ChangeAnyHeader_include.ds}

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

  ChangeAnyHeader ( 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 Customize User-Agent 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 you want to change here, e.g. 'User-Agent'
    ChangeHeader = 'User-Agent:';
    AddOnChangeHeader = ' (Simply the best usenet experience)';

// change header in emails and/or postings
// set 'true' or 'false'
    ChangeInEmails=true;
    ChangeInNews=true;

// Date: 2004/10/22

procedure Init_ChangeAnyHeader ( var ChangeHeader      : String;
                                 var AddOnChangeHeader : String;
                                 var ChangeInEmails    : Boolean;
                                 var ChangeInNews      : Boolean
);

begin

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

    // set the header you want to change here, e.g. 'User-Agent'
    ChangeHeader := 'User-Agent:';
    AddOnChangeHeader := ' (Simply the best usenet experience)';

    // change header in emails and/or postings
    // set 'true' or 'false'
    ChangeInEmails := true;
    ChangeInNews := true;
    
//  ----------------------------------------------------
//  End of configuration settings
//  ---------------------------------------------------- 

end;

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

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

var i                 : integer;
    s                 : String;
    ChangeHeader      : String;
    AddOnChangeHeader : String;
    ChangeInEmails    : Boolean;
    ChangeInNews      : Boolean;
    
begin
   Init_ChangeAnyHeader ( ChangeHeader, AddOnChangeHeader, ChangeInEmails, ChangeInNews );
   if ((IsEmail=true)  and (ChangeInEmails=true)) or
      ((IsEmail=false) and (ChangeInNews=true)) then begin
         s := Message.text;
         i := 1;
         while (Message.Strings[i]<>'') do begin
            if pos(ChangeHeader,Message.Strings[i]) = 1 then begin
               Message.Strings[i] := Message.Strings[i] + AddOnChangeHeader;
               s := Message.text; 
            end;
            i := i + 1;
         end; {end of while}
      message.text := s;
   end;
end;

René Fischer