{--------------------------------------------------------------------------}
{ UsenetBounce                                                             }
{                                                                          }
{ Deze routine kijkt of het adres of domain in Msg.XqtTo_U in de ROUTE.TDB }
{ file geconfigureerd is. Zoja, dan worden alle berichten daar naartoe     }
{ gebounced.                                                               }
{                                                                          }
FUNCTION UsenetBounce : BOOLEAN;

VAR Tmp : BouncePtr;

    FUNCTION IsMatch (Address : STRING) : BOOLEAN;

    VAR P : BYTE;

    BEGIN
         P:=Pos (Tmp^.EMailAddress,Address);

         IsMatch:=(P = 1) OR
                  ((Tmp^.WildMatch) AND (P > 1)) OR
                  ((P > 1) AND (Address[P-1] IN [' ','<']));
    END;

VAR UpTo_U,
    UpFromUser_U,
    UpSender_U,
    UpReplyTo_U  : STRING;

BEGIN
     UpTo_U:=UpCaseString (Msg.XqtTo_U);
     UpFromUser_U:=UpCaseString (Msg.FromUser_U);
     UpSender_U:=UpCaseString (Msg.Sender_U);
     UpReplyTo_U:=UpCaseString (Msg.ReplyTo_U);

     Tmp:=BounceList.GetFirstItem;

     WHILE (Tmp <> NIL) DO
     BEGIN
          IF (NOT Tmp^.FromBounce) THEN
          BEGIN
               IF IsMatch (UpTo_U) THEN
               BEGIN
                    UpTo_U:=' for '+Msg.XqtTo_U;
                    Break;
               END;
          END ELSE
          BEGIN
               IF IsMatch (UpFromUser_U) THEN
               BEGIN
                    UpTo_U:='FROM for '+Msg.FromUser_U;
                    Break;
               END;

               IF IsMatch (UpSender_U) THEN
               BEGIN
                    UpTo_U:='FROM for '+Msg.Sender_U;
                    Break;
               END;

               IF IsMatch (UpReplyTo_U) THEN
               BEGIN
                    UpTo_U:='FROM for '+Msg.ReplyTo_U;
                    Break;
               END;
          END;

          Tmp:=BounceList.GetNextItem;
     END;

     IF (Tmp = NIL) THEN
     BEGIN
          UsenetBounce:=FALSE; { gewoon verder verwerken }
          Exit; { niet gevonden }
     END;

     LogMessage ('Mail BOUNCE'+UpTo_U);

     {$IFDEF WtrTest}
     LogMessage ('Target: Mail bounce ('+Tmp^.Reason+')');
     Exit;
     {$ENDIF}

     UsenetBounceMail (Tmp^.Reason);

     UsenetBounce:=TRUE; { niet verder verwerken }
END;
