🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #181680

Re: [Dialog] Split header into multiple line?

#181680
From: Korbinian Abenthum
Date: Mon, 13 Mar 2006 00:39
106 lines
5273 bytes
Eggs Zachtly wrote:
> Korbinian Abenthum said:
>> Eggs Zachtly wrote:

>>> Rather, if I wanted to insert some "X-" header, and force it to wrap in
>>> certain places, could this be done?

>> If you want an X-Header to use multiple lines, you can fold it:

>>| X-My-Header: I can span
>>|  multiple lines

> Yes! That's just what I want it to do. However, I can't seem to duplicate
> what you've done. :(  Did Hamster have anything to do with your results?

Yes, I modified the article manually in hamster's outbox.

But you can use the following script to do that for you. I didn't test it that
thoroughly, so there may be mistakes left in it. Please take the time to test
it before you use it. I took the setup  description from the wiki, but
didn't put it there since I don't really think there'll be a lot of demand.
If anyone thinks otherwise, feel free to put it up.

To use it, just write your X-Header and insert "%n" (by default) where you
want the header to fold.

== Setup ==
/Please note that this script is realized as an include-file!/ To make it
work, you have to copy&paste the script into a new custom script (e.g.
"INCLUDE_FoldHeader").
The script is configured in the first few lines, please adjust it there to
fit your needs. Then safe it. After that, add the following lines to your
OnBeforeSending-Script:

| {$I INCLUDE_FoldHeader.ds}

and

| result := result AND FoldHeader(Message, Servername, IsEmail);

It could look like this:

----8<--------------------------------
program OnBeforeSendingMessage;

{$I INCLUDE_FoldHeader.ds}

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

  //possibly some calls to scripts

  result := result AND FoldHeader(Message, Servername, IsEmail);
end;

begin
end.
----8<--------------------------------

Now compile this OnBeforeSending-Script to get your include-file to work.
Please note that whenever you reconfigure the FoldHeader custom script, you
have to recompile the OnBeforeSending-Script to apply the changes. 

== Scriptcode, to be put in the custom script called "INCLUDE_FoldHeader" ==

const FH_HEADER = 'X-test: '; //Case sensitive! The name of the header to fold
const FH_FOLDING_WHITEPACE = '	'; //Text at the beginning of every folded line. Has to start with either a space or a tab.
const FH_LINEBREAK_TAG = '%n'; //Case sensitive! And this part may not be a substring of the header to fold (including the space).

const FH_MAXINT = 2147483647;

function FoldHeader(var Message: TStringlist; Servername: string; IsEmail: boolean):boolean;
var i, index : integer;
    header : string;
begin
  if (AnsiPos(FH_LINEBREAK_TAG, FH_HEADER)>0) then begin result:=false; exit; end; //Misconfiguration.
  if ((Copy(FH_FOLDING_WHITEPACE, 1, 1)<>chr(32)) AND (Copy(FH_FOLDING_WHITEPACE, 1, 1)<>chr(9))) then begin result:=false; exit; end; //Misconfiguration.

  result:=true; //We cannot fail ;)
  
  //For all lines of the article
  for i:=0 to Message.count-1 do begin

    //look for the header to fold
      if AnsiPos(FH_HEADER, message.strings[i])=1 then begin
        header := message.strings[i] + FH_LINEBREAK_TAG;
        message.delete( i );

        while (header<>FH_FOLDING_WHITEPACE) do begin
              index := AnsiPos(FH_LINEBREAK_TAG, header);
              message.Insert(i, Copy(header, 1, index-1));
              header := FH_FOLDING_WHITEPACE+Copy(header, index+Length(FH_LINEBREAK_TAG), FH_MAXINT);
              i := i + 1;
        end;

        break; //We're finished.
      end;

    if message.strings[i]='' then break; //No references found in the header => we're done
  end; //for
end;


-- 
"Our knees do not bend easily." - Arthur Dayne
Technical Details
Message-ID: <130306.013930.nsr.102@news.abenthum.de>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeedt0.toon.t-online.de!62.153.159.134.MISMATCH!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail
References: <44koior92p7o$.dlg@sneupie.eingang.org> <120306.153602.nsr.97@news.abenthum.de> <78arkip1czzw$.dlg@sneupie.eingang.org>

Show Full Headers
Complete Article Headers
Message-ID: <130306.013930.nsr.102@news.abenthum.de>
Subject: Re: [Dialog] Split header into multiple line?
Date: Mon, 13 Mar 2006 01:39:30 +0100
From: Korbinian Abenthum <korbinian@gmx.de>
References: <44koior92p7o$.dlg@sneupie.eingang.org> <120306.153602.nsr.97@news.abenthum.de> <78arkip1czzw$.dlg@sneupie.eingang.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeedt0.toon.t-online.de!62.153.159.134.MISMATCH!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail
Newsgroups: news.software.readers
Organization: T-Online
Lines: 106
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: news.t-online.com 1142210981 01 17763 UA3BvRovaOvWRXL 060313 00:49:41
X-Complaints-To: usenet-abuse@t-online.de
X-ID: ZGSq7TZCQeXSYGGrrqXfWHbsZSTNAolR7cXjEDXyVsinOgcSWVWzZp
X-Now-Playing: Ennio Morricone - sacco and vanzetti
User-Agent: 40tude_Dialog/2.0.15.35 Hamster/2.1.0.5
X-Face: &[gF$*:|'M7pwKut]{LOz!&65BT96:Wn\M"V6Qa#q%~9^z8XhJfmh?.)VB{,
 p]Z`6q@e()!g1ghrG7.atG.DXfzulkKE%u~|D7?e6^-yN4GvZJuvz%$LZBA6`dJTo,
 MYUO%I*0us[.v/AT,
X-test: Gee,
 I
 hope
 this
 works.