QuotedGuard

From 40tude Dialog Wiki

This procedure controls if there is not too much quoted lines kept in a followup post or if there are enough comments inside the kept quoted lines

program OnOutgoingMessageCheck;

{ Version 1 beta 1.1.3 2003/10/13 - 07:32
  compile and run with Dialog version 2.0.6.1
  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.
 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 can be adapted to your
 preferences

 **************************************************************}


CONST
   MaxKeptQuotedLineWithNoComment =16;


   FUNCTION QuotedGuard (var Message: TStringlist) : boolean;
   {This function avoid sending a post where too many quoted lines are foregoten}

   VAR
      NumberOfQuotedLinesWhithoutComment : INTEGER;
      MessageIndex : INTEGER;

   BEGIN
      MessageIndex := Message.count-1;
      NumberOfQuotedLinesWhithoutComment:=0;
      WHILE (MessageIndex > 0)
      AND (NumberOfQuotedLinesWhithoutComment < MaxKeptQuotedLineWithNoComment) DO
      BEGIN
         IF Trim(Message.Strings[MessageIndex]) <> '' THEN
         {empty and blank lines, skip}
            IF POS('>', Message.Strings[MessageIndex]) = 1 THEN
               NumberOfQuotedLinesWhithoutComment := NumberOfQuotedLinesWhithoutComment+1
            ELSE
               NumberOfQuotedLinesWhithoutComment := 0;
         MessageIndex := MessageIndex-1;
      END;
      Result := NumberOfQuotedLinesWhithoutComment < MaxKeptQuotedLineWithNoComment;
   END;

   procedure OnOutgoingMessageCheck(Message: TStringlist; var Warnings, Errors: TStringlist);
   begin
   //Your code goes here
      IF NOT QuotedGuard(Message) THEN
      BEGIN
         Warnings.Add('Too many quoted lines without comment');
         Errors.Add('Quoted line number check');
      END;
   end;

begin
end.