You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RnQ/RnQ/Prefs/antispam_fr.pas

603 lines
17 KiB
Plaintext

{
This file is part of R&Q.
Under same license
}
unit antispam_fr;
{$I RnQConfig.inc}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, StdCtrls, ExtCtrls, ComCtrls,
VirtualTrees, Menus, RnQButtons, RnQSpin, RDGlobal, RnQPrefsLib, RnQProtocol, System.UITypes;
{$I NoRTTI.inc}
type
TantispamFr = class(TPrefFrame)
plBg: TPanel;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
IgnoreAuthNILChk: TCheckBox;
ignorepagersChk: TCheckBox;
ignorenilChk: TCheckBox;
warnChk: TCheckBox;
gb: TGroupBox;
notnilChk: TCheckBox;
badwordsChk: TCheckBox;
notemptyChk: TCheckBox;
multisendChk: TCheckBox;
uingtChk: TCheckBox;
badwordsBox: TMemo;
uingSpin: TRnQSpinEdit;
UseBotChk: TCheckBox;
SpamFileChk: TCheckBox;
QuestBox: TComboBox;
QstGrp: TGroupBox;
QuestAddBtn: TRnQSpeedButton;
QuestDelBtn: TRnQSpeedButton;
QuestMemo: TMemo;
qstLbl: TLabel;
TrCntBox: TComboBox;
Label1: TLabel;
AnsMemo: TMemo;
Label2: TLabel;
IgnoreSht: TTabSheet;
IgnoreTree: TVirtualDrawTree;
AddIgnBtn: TRnQButton;
AddIgnSrvBtn: TRnQButton;
RmvIgnSrvBtn: TRnQButton;
RmvIgnBtn: TRnQButton;
UseIgnChk: TCheckBox;
BotInInvisChk: TCheckBox;
AddSpamToHistChk: TCheckBox;
procedure QuestBoxChange(Sender: TObject);
procedure QuestAddBtnClick(Sender: TObject);
procedure QuestDelBtnClick(Sender: TObject);
procedure IgnoreTreeFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure IgnoreTreeDrawNode(Sender: TBaseVirtualTree; const PaintInfo: TVTPaintInfo);
procedure RmvIgnBtnClick(Sender: TObject);
procedure AddIgnBtnClick(Sender: TObject);
procedure AddIgnSrvBtnClick(Sender: TObject);
procedure SpamFileChkClick(Sender: TObject);
private
{ Private declarations }
lastqst: Integer;
qst: array of record
q: String;
a: array of String;
end;
menu: TPopupMenu;
procedure LoadQuests;
procedure SaveQuests;
procedure fillIgnoreList;
procedure AddToIgnoreAction(Sender: TObject);
// procedure addBtnClick(Sender: TObject);
procedure Sendmessage1Click(Sender: TObject);
procedure Viewinfo1Click(Sender: TObject);
function current: TRnQcontact;
procedure MenuPopup(Sender: TObject);
public
{ Public declarations }
procedure applyPage; Override;
procedure resetPage;Override;
procedure initPage; Override;
procedure updateVisPage; Override;
end;
implementation
{$R *.dfm}
uses
StrUtils, utilLib, RDUtils, RnQLangs, Math,
RQThemes, RnQPics, themesLib,
globalLib, selectcontactsDlg,
// menusUnit,
RnQMenu,
chatDlg;
type
PIgnItem = ^TIgnItem;
TIgnItem = record
// s : array[0..1] of string;
s0: string;
s1: TUID;
isSrv: Boolean;
// Pl : T;
end;
procedure TantispamFr.updateVisPage;
begin
QstGrp.Visible := SpamFileChk.Checked;
SpamFileChk.Width := GetWidth(SpamFileChk);
{$IFDEF UseNotSSI}
AddIgnSrvBtn.Enabled := useSSI2;
{$ELSE UseNotSSI}
AddIgnSrvBtn.Enabled := True;
{$ENDIF UseNotSSI}
end;
procedure TantispamFr.fillIgnoreList;
var
// i:integer;
PlItem: PIgnItem;
n: PVirtualNode;
cnt: TRnQcontact;
// pl:Tplugin;
begin
IgnoreTree.Clear;
// if prefPages[thisPrefIdx].frame = NIL then exit;
IgnoreTree.BeginUpdate;
ignoreList.resetEnumeration;
while ignoreList.hasMore do
begin
cnt := ignoreList.getNext;
n := IgnoreTree.AddChild(nil);
PlItem := IgnoreTree.GetNodeData(n);
PlItem.s0 := cnt.displayed;
if PlItem.s0 <> cnt.UID then
PlItem.s0 := PlItem.s0 + '(' + cnt.UID + ')'
else
PlItem.s0 := cnt.UID;
PlItem.s1 := cnt.UID;
PlItem.isSrv := Account.AccProto.isInList(LT_SPAM, cnt);
// PlItem.Pl := pl;
// n.CheckType := ctCheckBox;
{ if 0=pos(pl.filename, disabledPlugins) then
n.CheckState := csCheckedNormal
else
n.CheckState := csUncheckedNormal;
{ with list do
begin
if pl.screenname='' then
items.add('('+getTranslation('Filename')+') '+pl.filename)
else
items.add(pl.screenName);
items.objects[items.count-1]:=Tobject(pl);
checked[items.count-1]:= 0=pos(pl.filename, disabledPlugins);
end; }
end;
IgnoreTree.EndUpdate;
end;
procedure TantispamFr.IgnoreTreeDrawNode(Sender: TBaseVirtualTree; const PaintInfo: TVTPaintInfo);
var
PItem: PIgnItem;
x, OldMode: Integer;
OldColor: TColor;
begin
// if PaintInfo.Column in [0..1] then
begin
PaintInfo.canvas.Font.Color := clWindowText;
if vsSelected in PaintInfo.Node.States then
begin
OldColor := PaintInfo.canvas.Brush.Color;
PaintInfo.canvas.Brush.Color := clSilver;
PaintInfo.canvas.FrameRect(PaintInfo.canvas.ClipRect);
PaintInfo.canvas.Brush.Color := OldColor;
end;
x := PaintInfo.ContentRect.Left;
// y := 0;
PItem := PIgnItem(Sender.GetNodeData(PaintInfo.Node));
if PItem.isSrv then
inc(x, theme.drawPic(PaintInfo.canvas.Handle, x, 1, PIC_SPECIAL).cx + 2);
OldMode := SetBKMode(PaintInfo.canvas.Handle, TRANSPARENT);
// paintinfo.canvas.textout(x, 2, PItem.s[PaintInfo.Column]);
PaintInfo.canvas.textout(x, 2, PItem.s0);
SetBKMode(PaintInfo.canvas.Handle, OldMode);
end;
end;
procedure TantispamFr.IgnoreTreeFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
begin
with TIgnItem(Sender.GetNodeData(Node)^) do
// with PPlItem(Sender.getnodedata(Node)) do
begin
s0 := '';
s1 := '';
end;
end;
// fillPluginsGrid
function TantispamFr.current: TRnQcontact;
begin
result := NIL;
if IgnoreTree.FocusedNode = NIL then
exit;
// if TIgnItem(PListItem(IgnoreTree.getnodedata(IgnoreTree.FocusedNode))^).kind = LI_group then
// result := NIL
// else
result := Account.AccProto.getContact(TIgnItem(PIgnItem(IgnoreTree.GetNodeData(IgnoreTree.FocusedNode))^).s1);
end;
procedure TantispamFr.MenuPopup(Sender: TObject);
var
C: TRnQcontact;
// i : Integer;
it: TMenuItem;
begin
C := current;
if Sender is TPopupMenu then
// with TPopupMenu(sender) do
for it in TPopupMenu(Sender).Items do
// for i := 0 to TPopupMenu(sender).Items.Count -1 do
it.Enabled := C <> NIL;
// TPopupMenu(sender).Items[i].Enabled := C <> NIL;
end;
procedure TantispamFr.Viewinfo1Click(Sender: TObject);
var
cnt: TRnQcontact;
begin
cnt := current;
if Assigned(cnt) then
cnt.ViewInfo;
end;
procedure TantispamFr.Sendmessage1Click(Sender: TObject);
begin
chatFrm.openOn(current)
end;
procedure TantispamFr.SpamFileChkClick(Sender: TObject);
begin
updateVisPage;
end;
procedure TantispamFr.initPage;
begin
badwordsBox.Width := gb.Width - GAP_SIZE2;
badwordsBox.Left := GAP_SIZE;;
uingSpin.Left := GAP_SIZE + 150;
uingSpin.Width := gb.Width - GAP_SIZE2 - 150;
IgnoreTree.NodeDataSize := SizeOf(TIgnItem);
menu := TPopupMenu.Create(self);
AddToMenu(menu.Items, 'View info', PIC_INFO, True, Viewinfo1Click);
AddToMenu(menu.Items, 'Send message', PIC_MSG, False, Sendmessage1Click);
IgnoreTree.PopupMenu := menu;
menu.OnPopup := MenuPopup;
end;
procedure TantispamFr.AddIgnBtnClick(Sender: TObject);
var
cntcts: TselectCntsFrm;
begin
// cntcts := TselectContactsFrm.Create(Self);
cntcts := TselectCntsFrm.doAll(self, 'Select contacts to ignore', 'Select', Account.AccProto,
notInList.clone.add(Account.AccProto.readList(LT_ROSTER)), AddToIgnoreAction, [sco_groups], @cntcts);
end;
procedure TantispamFr.AddIgnSrvBtnClick(Sender: TObject);
var
n: PVirtualNode;
cnt: TRnQcontact;
begin
n := IgnoreTree.FocusedNode;
if (n = NIL)
{$IFDEF UseNotSSI}
or not useSSI2
{$ENDIF UseNotSSI}
then
exit;
if not OnlFeature(Account.AccProto) then
exit;
cnt := Account.AccProto.getContact(PIgnItem(IgnoreTree.GetNodeData(n)).s1);
// if useSSI then
if Assigned(cnt) and Assigned(Account.AccProto) and Account.AccProto.isOnline
{$IFDEF UseNotSSI}
and useSSI2
{$ENDIF UseNotSSI}
then
begin
Account.AccProto.AddToList(LT_SPAM, cnt);
PIgnItem(IgnoreTree.GetNodeData(n)).isSrv := True;
end;
end;
procedure TantispamFr.AddToIgnoreAction(Sender: TObject);
var
wnd: TselectCntsFrm;
cntct: TRnQcontact;
// histFile : String;
// rslt : String;
// fn : String;
PlItem: PIgnItem;
n: PVirtualNode;
begin
if (not(Sender is Tcontrol)) or (not((Sender as Tcontrol).parent is TselectCntsFrm)) then
exit;
wnd := (Sender as Tcontrol).parent as TselectCntsFrm;
cntct := wnd.current;
if cntct = NIL then
// msgDlg('You must select contact', mtInformation)
else
begin
addToIgnorelist(cntct, True);
n := IgnoreTree.AddChild(nil);
PlItem := IgnoreTree.GetNodeData(n);
PlItem.s0 := cntct.displayed;
if PlItem.s0 <> cntct.UID then
PlItem.s0 := PlItem.s0 + '(' + cntct.uin2Show + ')'
else
PlItem.s0 := cntct.UID;
PlItem.s1 := cntct.UID;
// PlItem.isSrv := usessi and ICQ.isOnline;
// PlItem.isSrv := usessi and ICQ.isOnline;
PlItem.isSrv := Account.AccProto.isInList(LT_SPAM, cntct);
end;
wnd.Close;
self.SetFocus;
end;
procedure TantispamFr.applyPage;
begin
enableIgnorelist := UseIgnChk.Checked;
spamfilter.warn := warnChk.Checked;
spamfilter.addToHist := AddSpamToHistChk.Checked;
spamfilter.ignoreNIL := ignorenilChk.Checked;
spamfilter.ignorepagers := ignorepagersChk.Checked;
// spamfilter.
spamfilter.ignoreauthNIL := IgnoreAuthNILChk.Checked;
spamfilter.multisend := multisendChk.Checked;
spamfilter.notnil := notnilChk.Checked;
spamfilter.notEmpty := notemptyChk.Checked;
spamfilter.noBadwords := badwordsChk.Checked;
spamfilter.badwords := AnsiReplaceStr(badwordsBox.text, CRLF, ';');
if TrCntBox.ItemIndex in [0 .. 4] then
spamfilter.BotTryesCount := TrCntBox.ItemIndex + 2;
if uingtChk.Checked then
spamfilter.uingt := round(uingSpin.value)
else
spamfilter.uingt := 0;
// Bot
spamfilter.useBot := UseBotChk.Checked;
spamfilter.useBotInInvis := BotInInvisChk.Checked;
spamfilter.UseBotFromFile := SpamFileChk.Checked;
SaveQuests;
end;
procedure TantispamFr.resetPage;
begin
UseIgnChk.Checked := enableIgnorelist;
ignorenilChk.Checked := spamfilter.ignoreNIL;
ignorepagersChk.Checked := spamfilter.ignorepagers;
warnChk.Checked := spamfilter.warn;
AddSpamToHistChk.Checked := spamfilter.addToHist;
IgnoreAuthNILChk.Checked := spamfilter.ignoreauthNIL;
notnilChk.Checked := spamfilter.notnil;
notemptyChk.Checked := spamfilter.notEmpty;
multisendChk.Checked := spamfilter.multisend;
badwordsChk.Checked := spamfilter.noBadwords;
badwordsBox.lines.text := AnsiReplaceStr(spamfilter.badwords, ';', CRLF);
uingtChk.Checked := spamfilter.uingt > 0;
if spamfilter.uingt = 0 then
uingSpin.value := 150000000
else
uingSpin.value := spamfilter.uingt;
// Bot
UseBotChk.Checked := spamfilter.useBot;
BotInInvisChk.Checked := spamfilter.useBotInInvis;
SpamFileChk.Checked := spamfilter.UseBotFromFile;
TrCntBox.ItemIndex := bound(spamfilter.BotTryesCount - 2, 0, 4);
LoadQuests;
lastqst := -1;
if QuestBox.Items.Count > 0 then
QuestBox.ItemIndex := 0;
QuestBoxChange(QuestBox);
{ QuestBox.ItemIndex := QuestBox.Items.Count-1;
lastqst := QuestBox.ItemIndex;
QuestEdit.Text := qst[lastqst].q;
AnsEdit.Text := qst[lastqst].a; }
fillIgnoreList;
end;
procedure TantispamFr.RmvIgnBtnClick(Sender: TObject);
var
n: PVirtualNode;
cnt: TRnQcontact;
begin
n := IgnoreTree.FocusedNode;
if n = NIL then
exit;
cnt := ignoreList.get(Account.AccProto.getContactClass, PIgnItem(IgnoreTree.GetNodeData(n)).s1);
// if icq.readSpamList.exists(PIgnItem(IgnoreTree.GetNodeData(n)).s[1]) then
removeFromIgnorelist(cnt);
IgnoreTree.FocusedNode := IgnoreTree.GetPrevious(n);
if IgnoreTree.FocusedNode = NIL then
IgnoreTree.FocusedNode := IgnoreTree.getNext(n);
if IgnoreTree.FocusedNode <> NIL then
IgnoreTree.Selected[IgnoreTree.FocusedNode] := True;
IgnoreTree.DeleteNode(n);
// if n <> NIL then
// PPlItem(IgnoreTree.GetNodeData(n)).Pl.cast_preferences;
end;
procedure Answers0(var ans: array of string);
var
I: Integer;
begin
for I := Low(ans) to High(ans) do
SetLength(ans[I], 0);
// SetLength(ans, 0);
end;
procedure TantispamFr.LoadQuests;
var
// cfg, l, h : string;
I, j: Integer;
// function yesno:boolean;
// begin result:=comparetext(l,'yes')=0 end;
begin
SetLength(qst, Length(spamfilter.quests));
QuestBox.Items.Clear;
for I := 0 to Length(spamfilter.quests) - 1 do
begin
qst[I].q := spamfilter.quests[I].q;
Answers0(qst[I].a);
SetLength(qst[I].a, Length(spamfilter.quests[I].ans));
for j := 0 to Length(spamfilter.quests[I].ans) - 1 do
qst[I].a[j] := spamfilter.quests[I].ans[j];
QuestBox.Items.add(getTranslation('Question') + IntToStr(I + 1));
end;
end;
procedure TantispamFr.SaveQuests;
var
// cfg : string;
I, j: Integer;
begin
if QuestBox.ItemIndex >= 0 then
with qst[QuestBox.ItemIndex] do
begin
q := QuestMemo.text;
Answers0(a);
SetLength(a, 0);
for I := 0 to AnsMemo.lines.Count - 1 do
if Trim(AnsMemo.lines.Strings[I]) > '' then
begin
SetLength(a, Length(a) + 1);
a[Length(a) - 1] := Trim(AnsMemo.lines.Strings[I]);
end;
end;
SetLength(spamfilter.quests, Length(qst));
// QuestBox.Items.Clear;
for I := 0 to Length(qst) - 1 do
begin
spamfilter.quests[I].q := qst[I].q;
// spamfilter.quests[i].a := qst[i].a;
Answers0(spamfilter.quests[I].ans);
SetLength(spamfilter.quests[I].ans, 0);
for j := 0 to Length(qst[I].a) - 1 do
begin
SetLength(spamfilter.quests[I].ans, Length(spamfilter.quests[I].ans) + 1);
spamfilter.quests[I].ans[Length(spamfilter.quests[I].ans) - 1] := qst[I].a[j];
end;
// QuestBox.Items.Add('Question' + IntToStr(i+1));
end;
saveListsDelayed := True;
// SaveSpamQuests;
end;
procedure TantispamFr.QuestAddBtnClick(Sender: TObject);
var
I: Integer;
begin
I := Length(qst);
SetLength(qst, I + 1);
QuestBox.Items.add(getTranslation('Question') + IntToStr(I + 1));
with qst[I] do
begin
q := '';
Answers0(a);
SetLength(a, 0);
end;
QuestBox.ItemIndex := I;
QuestBoxChange(QuestBox);
end;
procedure TantispamFr.QuestBoxChange(Sender: TObject);
var
I: Integer;
begin
if lastqst <> QuestBox.ItemIndex then
begin
if (lastqst >= Low(qst)) and (lastqst <= High(qst)) then
with qst[lastqst] do
begin
q := QuestMemo.text;
// a := AnsEdit.Text;
Answers0(a);
SetLength(a, 0);
for I := 0 to AnsMemo.lines.Count - 1 do
if Trim(AnsMemo.lines.Strings[I]) > '' then
begin
SetLength(a, Length(a) + 1);
a[Length(a) - 1] := Trim(AnsMemo.lines.Strings[I]);
end;
end;
if QuestBox.ItemIndex = -1 then
begin
lastqst := QuestBox.ItemIndex;
QuestMemo.text := '';
AnsMemo.text := '';
QuestMemo.Enabled := False;
AnsMemo.Enabled := False;
end
else
begin
lastqst := QuestBox.ItemIndex;
QuestMemo.text := qst[lastqst].q;
AnsMemo.text := '';
for I := 0 to Length(qst[lastqst].a) - 1 do
AnsMemo.lines.add(qst[lastqst].a[I]);
QuestMemo.Enabled := True;
AnsMemo.Enabled := True;
end;
end;
// resetProxy;
end;
procedure TantispamFr.QuestDelBtnClick(Sender: TObject);
var
I, j, k: Integer;
pr: array of record q: String;
a: array of String;
end;
begin
I := QuestBox.ItemIndex;
if (QuestBox.Items.Count <= 0) or (I = -1) then
exit;
if Length(qst) = I + 1 then
begin
SetLength(qst, Length(qst) - 1);
QuestBox.Items.Delete(I);
QuestBox.ItemIndex := I - 1;
QuestBoxChange(QuestBox);
QuestBox.Repaint;
end
else
begin
SetLength(pr, Length(qst) - I - 1);
for j := I + 1 to Length(qst) - 1 do
begin
pr[j - I - 1].q := qst[j].q;
// pr[j-i-1].a := qst[j].a;
Answers0(pr[j - I - 1].a);
SetLength(pr[j - I - 1].a, Length(qst[j].a));
for k := 0 to Length(qst[j].a) - 1 do
pr[j - I - 1].a[k] := qst[j].a[k];
end;
SetLength(qst, Length(qst) - 1);
for j := I to Length(qst) - 1 do
begin
qst[j].q := pr[j - I].q;
// qst[j].a := pr[j-i].a;
Answers0(qst[j].a);
SetLength(qst[j].a, Length(pr[j - I].a));
for k := 0 to Length(pr[j - I].a) - 1 do
qst[j].a[k] := pr[j - I].a[k];
end;
lastqst := -1;
QuestBox.Items.Delete(I);
QuestBox.ItemIndex := I;
QuestBoxChange(QuestBox);
end;
end;
end.