From 40tude Dialog Wiki

This procedure is based on QuotedLineGuard in OnOutgoingMessageCheck Version 1 beta 1.1.3 one.

This procedure checks the number of quoted lines that are not followed by a comment, the percentual number of quoted lines and the length of blank lines block. It also checks the length of the signature.

In this second version the value MaxPercentKeptQuotedLine is an integer (while in the first was a number lesser than one). Added the control on blanck lines block. The name has changed.

The text for the warnings are in italian (because I'm italian). The english versions of the warnings are written in the lower line as comment.

Works with version:;

{ Version 1.1 2004/03/22 - 15:14 by Stefano
  compile and run with Dialog version (beta 33)
  Check the source code or save your data before use.}


 This procedure check the number of quoted lines that are not
 followed by a comment, the percentual number of quoted 
 lines and the length of blank lines blok. It also check for 
 the lengh of the signature.
 It is a guard again bad practices like sending a followup post
 without deleting the useless lines in the original or letting
 two many lines without comment.

 MaxKeptQuotedLineWithNoComment, MaxPercentKeptQuotedLine and
 MaxKeptBlankLinesBlock can be adapted to your preferences. 
 MaxSignLines should not be changed until the standar changes!

  MaxPercentKeptQuotedLine = 50;
  MaxKeptQuotedLineWithNoComment = 15;
  MaxKeptBlankLinesBlock = 3;
  MaxSignLines = 5; //4 for the standard plus one for the delimiter

  function FormatControl(var Message: TStringlist): Byte;
  {This function avoid sending a post where too many quoted lines are foregoten.
   It also check the number of lines in the signature.}
    i, BodyStart, NumberOfBlankLines, BlankLinesBlock, SignLines: Integer;
    NumberOfQuotedLines, NumberOfQuotedLinesWhithoutComment: Integer;
    HighNumberOfBlankLinesBlock, HighNumberOfQuotedLinesWhithoutComment: Integer;
    PercentKeptQuotedLine: Double;
    {initialize variables}
    BodyStart := 0;  
    NumberOfBlankLines := 0;
    BlankLinesBlock := 0;
    NumberOfQuotedLines := 0;
    NumberOfQuotedLinesWhithoutComment := 0;
    HighNumberOfQuotedLinesWhithoutComment := 0;         
    HighNumberOfBlankLinesBlock := 0;
    SignLines := 0;       
    {skips the headers}
    while (Trim(Message.Strings[BodyStart]) <> '') do BodyStart := BodyStart+1;
    BodyStart := BodyStart+1;
    {checks the body}
    for i := BodyStart to (Message.count-1) do
      {check for empty and blank lines}
      if (Trim(Message.Strings[i]) = '') then  
        BlankLinesBlock := BlankLinesBlock+1
        NumberOfBlankLines := NumberOfBlankLines+BlankLinesBlock;
        if (HighNumberOfBlankLinesBlock < BlankLinesBlock) then
          HighNumberOfBlankLinesBlock := BlankLinesBlock;
        BlankLinesBlock := 0;
        {check for quoted lines}
        if (Pos('>', Message.Strings[i]) = 1) then
          NumberOfQuotedLinesWhithoutComment := NumberOfQuotedLinesWhithoutComment+1
          {check for signature lines}
          if (Trim(Message.Strings[i]) = '--') then
            SignLines := Message.Count-i;
            NumberOfQuotedLines := NumberOfQuotedLines+NumberOfQuotedLinesWhithoutComment;
            if (HighNumberOfQuotedLinesWhithoutComment < NumberOfQuotedLinesWhithoutComment) then
              HighNumberOfQuotedLinesWhithoutComment := NumberOfQuotedLinesWhithoutComment;
            NumberOfQuotedLinesWhithoutComment := 0;
    PercentKeptQuotedLine := Int(NumberOfQuotedLines/(Message.Count-BodyStart-NumberOfBlankLines-SignLines)*100);
    Result := 0;
    if (SignLines > MaxSignLines) then
      Result := Result or 1;
    if (HighNumberOfQuotedLinesWhithoutComment > MaxKeptQuotedLineWithNoComment) then
      Result := Result or 2;
    if (PercentKeptQuotedLine > MaxPercentKeptQuotedLine) then
      Result := Result or 4;
    if (HighNumberOfBlankLinesBlock > MaxKeptBlankLinesBlock) then
      Result := Result or 8;

  procedure OnOutgoingMessageCheck(Message: TStringlist; var Warnings, Errors: TStringlist);
    PostOK: Byte;
    PostOK := FormatControl(Message);
    if ((PostOK and 1) > 0) then
      Warnings.Add('Firma troppo lunga (max. '+IntToStr(MaxSignLines-1)+')');
      //Warnings.Add('Signature too long (max. '+IntToStr(MaxSignLines-1)+')');
    if ((PostOK and 2) > 0) then
      Warnings.Add('Troppe righe quotate senza commento (max. '+IntToStr(MaxKeptQuotedLineWithNoComment)+')');
      //Warnings.Add('Too many quoted lines without comment (max. '+IntToStr(MaxKeptQuotedLineWithNoComment)+')');
    if ((PostOK and 4) > 0) then
      Warnings.Add('Troppe righe quotate rispetto al numero totale di righe (max. '+IntToStr(MaxPercentKeptQuotedLine)+'%)');
      //Warnings.Add('Too many quoted lines with respect to the total numer of lines (max. '+IntToStr(MaxPercentKeptQuotedLine)+'%)');
    if ((PostOK and 8) > 0) then
      Warnings.Add('Troppe righe vuote consecutive (max. '+IntToStr(MaxKeptBlankLinesBlock)+')');
      //Warnings.Add('Too many consecutive blank lines (max. '+IntToStr(MaxKeptBlankLinesBlock)+')');
    if (PostOK > 0) then
      Errors.Add('Controllo formattazione post fallita');
      //Errors.Add('Format Control check');