ufrmEmailBoxProperty.pas
上传用户:yjb1804
上传日期:2021-01-30
资源大小:3105k
文件大小:12k
源码类别:

Email服务器

开发平台:

Delphi

  1. unit ufrmEmailBoxProperty;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, RzTabs, cxTextEdit, cxControls, cxContainer, cxEdit, cxLabel,
  6.   cxMaskEdit, cxButtonEdit, Menus, cxLookAndFeelPainters, StdCtrls,
  7.   cxButtons, ExtCtrls, cxListBox, cxRadioGroup, cxCheckBox, cxGraphics,
  8.   cxDropDownEdit, cxImageComboBox, cxSpinEdit, RzShellDialogs, uMyXml,IniFiles,
  9.   ActnList;
  10. type
  11.   TfrmEmailBoxProperty = class(TForm)
  12.     RzPageControl1: TRzPageControl;
  13.     TabSheet2: TRzTabSheet;
  14.     TabSheet3: TRzTabSheet;
  15.     cxLabel4: TcxLabel;
  16.     pnl1: TPanel;
  17.     btnOk: TcxButton;
  18.     btnCancel: TcxButton;
  19.     lblEmailRecvCount: TLabel;
  20.     btnRecvClear: TcxButton;
  21.     lblBoxName: TLabel;
  22.     rztbshtTabSheet4: TRzTabSheet;
  23.     lstBlack: TcxListBox;
  24.     lstWhite: TcxListBox;
  25.     cxLabel11: TcxLabel;
  26.     cxLabel12: TcxLabel;
  27.     btnAddBlack: TcxButton;
  28.     btnDeleteBlack: TcxButton;
  29.     edtRecvPlaySound: TcxButtonEdit;
  30.     edtRecvRunExe: TcxButtonEdit;
  31.     cxLabel13: TcxLabel;
  32.     cxLabel14: TcxLabel;
  33.     rbAtuoDetect: TcxRadioButton;
  34.     rbMinDetect: TcxRadioButton;
  35.     rbRunDetect: TcxRadioButton;
  36.     rbNeverDetect: TcxRadioButton;
  37.     btnAddWhite: TcxButton;
  38.     btnDeleteWhite: TcxButton;
  39.     btnRuleSet: TcxButton;
  40.     chkReDownload: TcxCheckBox;
  41.     rztbshtTabSheet5: TRzTabSheet;
  42.     cbServerType: TcxImageComboBox;
  43.     cxLabel5: TcxLabel;
  44.     cxLabel8: TcxLabel;
  45.     edtUserName: TcxTextEdit;
  46.     cxLabel9: TcxLabel;
  47.     edtPass: TcxTextEdit;
  48.     edtServerRecv: TcxTextEdit;
  49.     cxlbl1: TcxLabel;
  50.     cxlbl2: TcxLabel;
  51.     edtServerSend: TcxTextEdit;
  52.     cxlbl3: TcxLabel;
  53.     lblEmailSendCount: TcxLabel;
  54.     btnSendClear: TcxButton;
  55.     edtRecvSaveTo: TcxButtonEdit;
  56.     cxlbl5: TcxLabel;
  57.     edtSendSaveTo: TcxButtonEdit;
  58.     chkSendLog: TcxCheckBox;
  59.     chkRecvLog: TcxCheckBox;
  60.     cxlbl6: TcxLabel;
  61.     edtDisplayName: TcxTextEdit;
  62.     lbl1: TcxLabel;
  63.     lbl2: TcxLabel;
  64.     edRecvPort: TcxSpinEdit;
  65.     edSendPort: TcxSpinEdit;
  66.     dlgSave: TRzSaveDialog;
  67.     dlgOpen: TRzOpenDialog;
  68.     lbl3: TcxLabel;
  69.     edt1: TcxButtonEdit;
  70.     actlst1: TActionList;
  71.     actWriteCheckEmailOption: TAction;
  72.     procedure btnRuleSetClick(Sender: TObject);
  73.     procedure btnCancelClick(Sender: TObject);
  74.     procedure edt1PropertiesButtonClick(Sender: TObject;
  75.       AButtonIndex: Integer);
  76.     procedure chkReDownloadClick(Sender: TObject);
  77.     procedure edtRecvPlaySoundPropertiesButtonClick(Sender: TObject;
  78.       AButtonIndex: Integer);
  79.     procedure edtRecvRunExePropertiesButtonClick(Sender: TObject;
  80.       AButtonIndex: Integer);
  81.     procedure btnSendClearClick(Sender: TObject);
  82.     procedure btnRecvClearClick(Sender: TObject);
  83.     procedure btnAddBlackClick(Sender: TObject);
  84.     procedure btnDeleteBlackClick(Sender: TObject);
  85.     procedure btnAddWhiteClick(Sender: TObject);
  86.     procedure btnDeleteWhiteClick(Sender: TObject);
  87.     procedure btnOkClick(Sender: TObject);
  88.     procedure FormCreate(Sender: TObject);
  89.     procedure FormDestroy(Sender: TObject);
  90.     procedure actWriteCheckEmailOptionExecute(Sender: TObject);
  91.     procedure edtRecvSaveToPropertiesButtonClick(Sender: TObject;
  92.       AButtonIndex: Integer);
  93.   private
  94.     { Private declarations }
  95.     FEmailAddr:string;
  96.     FMyxml:TMyXml;
  97.     FAddBlack,
  98.     FDelBlack,
  99.     FAddWhite,
  100.     FDelWhite:TStrings;
  101.     //procedure WriteCheckEmailOption(Option:Integer); 
  102.   public
  103.     { Public declarations }
  104.     procedure LoadDefault(EMailAddr:string);
  105.     procedure ShowPage(index:Integer=0);
  106.   end;
  107. var
  108.   frmEmailBoxProperty: TfrmEmailBoxProperty;
  109. implementation
  110. uses ufrmRule, ufrmMain, uCommon, NativeXml,{$WARNINGS OFF} FileCtrl {$WARNINGS ON} ;
  111. {$R *.dfm}
  112. procedure TfrmEmailBoxProperty.btnRuleSetClick(Sender: TObject);
  113. begin
  114.   with TfrmRule.Create(Application) do
  115.   try
  116.     if ShowModal=mrOk then ufrmMain.frmMain.LoadRules;
  117.   finally
  118.     free;
  119.   end;
  120. end;
  121. procedure TfrmEmailBoxProperty.LoadDefault(EMailAddr:string);
  122. var
  123.   MyXml:TMyXml;
  124.   L:TStringList;
  125.   Node:TXmlNode;
  126.   Str:string;
  127. begin
  128.   FEmailAddr:=EMailAddr;
  129.   myxml:=TMyXml.Create(AppPath+'EmailServers.xml');
  130.   try
  131.     L:=TStringList.Create;
  132.     MyXml.GetAllEmail(FEmailAddr,L,nil,nil);
  133.     lblEmailRecvCount.Caption:=Format('共有%D封邮件',[L.Count]);
  134.     L.Clear;
  135.     MyXml.GetAllSentEmail(FEmailAddr,L);
  136.     lblEmailSendCount.Caption:=Format('共有%D封邮件',[L.Count]);
  137.     L.Free;
  138.     
  139.     Node:=MyXml.FindPop3(FEmailAddr);
  140.     if Node<>nil then
  141.     begin
  142.       chkRecvLog.Checked:=StrToBoolDef(Node.AttributeByName['RecvLog'],True);
  143.       chkSendLog.Checked:=StrToBoolDef(Node.AttributeByName['SendLog'],True);
  144.       chkReDownload.Checked:=StrToBoolDef(Node.AttributeByName['ReDownload'],True);
  145.       case  StrToIntDef(Node.AttributeByName['Detect'],0)  of
  146.         0: rbAtuoDetect.Checked:=True;
  147.         1: rbMinDetect.Checked:=True;
  148.         2: rbRunDetect.Checked:=True;
  149.         3: rbNeverDetect.Checked:=True;
  150.         else ;
  151.       end;
  152.       edtRecvPlaySound.Text:=Node.AttributeByName['newemailwav'];
  153.       edtRecvRunExe.Text:=Node.AttributeByName['newemailexe'];
  154.       edtRecvSaveTo.Text:=Node.AttributeByName['SrcEmailSaveTo'];
  155.       edtSendSaveTo.Text:=Node.AttributeByName['SendEmailSaveTo'];
  156.     end;
  157.              
  158.     Str:=Node.ReadString('pop3server','');
  159.     if CompareText('pop',Copy(Str,1,3))=0 then cbServerType.ItemIndex:=0;
  160.     //add more
  161.     edtUserName.Text:=FEmailAddr;
  162.                        
  163.     edtServerRecv.Text:=Node.ReadString('pop3server','');
  164.     edtServerSend.Text:=TEMailAddress.SMTPEmailSever(FEmailAddr);
  165.     edtPass.Text:=Node.ReadString('pwd','');
  166.     edtDisplayName.Text:=Node.ReadString('displayname','');
  167.     edRecvPort.Value:=StrToInt(Node.ReadString('popPort','110')) ;
  168.     edSendPort.Value:=StrToInt(Node.ReadString('SMTPPort','25')) ;
  169.   finally
  170.     MyXml.Free;
  171.   end;
  172.   //LoadRules;
  173. end;
  174. procedure TfrmEmailBoxProperty.btnCancelClick(Sender: TObject);
  175. begin
  176.   ModalResult:=mrCancel;
  177. end;
  178. procedure TfrmEmailBoxProperty.edt1PropertiesButtonClick(Sender: TObject;
  179.   AButtonIndex: Integer);
  180. begin
  181.   dlgSave.Filter:='XML文件|*.xml';
  182.   dlgSave.Options:=dlgSave.Options-[osoFilesCanBeFolders];
  183.   if dlgSave.Execute then
  184.   begin
  185.     FMyxml:=TMyXml.Create(AppPath+'EmailServers.xml');
  186.     try
  187.       FMyXml.Root.FindNode('Rules').AttributeByName['RulesSaveTo']:=dlgSave.FileName;
  188.     finally
  189.       FMyxml.Free;
  190.     end;
  191.     frmMain.FRuleSaveTo:=dlgSave.FileName;
  192.   end;
  193. end;
  194. procedure TfrmEmailBoxProperty.chkReDownloadClick(Sender: TObject);
  195. begin
  196.   frmMain.FRetryAgain:=chkReDownload.Checked;
  197. end;
  198. procedure TfrmEmailBoxProperty.edtRecvPlaySoundPropertiesButtonClick(
  199.   Sender: TObject; AButtonIndex: Integer);
  200. var
  201.   FMyXml:TMyXml;
  202. begin
  203.   dlgOpen.Filter:='声音文件|*.mp3;*.mp4;*.rm;*.rmvb;*.wav;*.avi;|所有文件|*.*';
  204.   if dlgOpen.Execute then
  205.   begin
  206.     FMyxml:=TMyXml.Create(AppPath+'EmailServers.xml');
  207.     try
  208.       if FMyXml.FindPop3(FEmailAddr)<>nil then
  209.         FMyXml.FindPop3(FEmailAddr).AttributeByName['newemailwav']  :=dlgSave.FileName;
  210.     finally
  211.       FMyxml.Free;
  212.     end;
  213.     frmMain.FEmailArrivedPlaySound:=dlgOpen.FileName;
  214.   end;
  215. end;
  216. procedure TfrmEmailBoxProperty.edtRecvRunExePropertiesButtonClick(
  217.   Sender: TObject; AButtonIndex: Integer);
  218. var
  219.   FMyXml:TMyXml;
  220. begin
  221.   dlgOpen.Filter:='可执行文件|*.exe;*.Bat';
  222.   if dlgOpen.Execute then
  223.   begin
  224.     FMyxml:=TMyXml.Create(AppPath+'EmailServers.xml');
  225.     try
  226.       if FMyXml.FindPop3(FEmailAddr)<>nil then
  227.         FMyXml.FindPop3(FEmailAddr).AttributeByName['newemailexe']:=dlgSave.FileName;
  228.     finally
  229.       FMyxml.Free;
  230.     end;
  231.     frmMain.FEmailArrivedPlaySound:=dlgOpen.FileName;
  232.   end;
  233. end;
  234. procedure TfrmEmailBoxProperty.btnSendClearClick(Sender: TObject);  //清空发件箱
  235. var
  236.   L:TStrings;
  237.   I:Integer;
  238. begin
  239.   FMyxml:=TMyXml.Create(AppPath+'EmailServers.xml');
  240.   try
  241.     L:=TStringList.Create;
  242.     try
  243.       FMyxml.GetAllSentEmail(FEmailAddr,L);
  244.       for i:=0 to L.Count-1 do
  245.         if FileExists(L[I]) then DeleteFile(L[I]);
  246.       FMyxml.DeleteAllSentEmail(FEmailAddr);
  247.     finally
  248.       L.Free;
  249.     end;
  250.   finally
  251.     FMyxml.free;
  252.   end;
  253. end;
  254. procedure TfrmEmailBoxProperty.btnRecvClearClick(Sender: TObject); //清空收件箱
  255. var
  256.   L:TStrings;
  257.   I:Integer;
  258. begin
  259.   FMyxml:=TMyXml.Create(AppPath+'EmailServers.xml');
  260.   try
  261.     L:=TStringList.Create;
  262.     try
  263.       FMyxml.GetAllEmail(FEmailAddr,L,nil,nil);
  264.       for i:=0 to L.Count-1 do
  265.         if FileExists(L[I]) then DeleteFile(L[I]);
  266.       FMyxml.DeleteAllEmail(FEmailAddr);
  267.     finally
  268.       L.Free;
  269.     end;
  270.   finally
  271.     FMyxml.free;
  272.   end;
  273. end;
  274. procedure TfrmEmailBoxProperty.btnAddBlackClick(Sender: TObject);
  275. var
  276.   account:string;
  277. begin
  278.   account:=Dialogs.InputBox('添加黑名单','请输入黑名单成员的Email账号:','');
  279.   //if  trim(account)='' then Exit;
  280.   if not TEMailAddress.IsEmail(account) then
  281.   begin
  282.     MsgBoxError('Email账号不合法.合法的账号格式是:username@server');
  283.     Exit;
  284.   end;
  285.   lstBlack.Items.Add(Trim(account));
  286.   FAddBlack.Add(account);
  287. end;
  288. procedure TfrmEmailBoxProperty.btnDeleteBlackClick(Sender: TObject);
  289. begin
  290.   FDelBlack.Add(lstBlack.Items[lstBlack.ItemIndex])   ;
  291.   lstBlack.Items.Delete(lstBlack.ItemIndex);
  292. end;
  293. procedure TfrmEmailBoxProperty.btnAddWhiteClick(Sender: TObject);
  294. var
  295.   account:string;
  296. begin
  297.   account:=Dialogs.InputBox('添加白名单','请输入白名单成员的Email账号:','');
  298.   //if  trim(account)='' then Exit;
  299.   if not TEMailAddress.IsEmail(account) then
  300.   begin
  301.     MsgBoxError('Email账号不合法.合法的账号格式是:username@server');
  302.     Exit;
  303.   end;
  304.   lstWhite.Items.Add(Trim(account));
  305.   FAddWhite.Add(account);
  306. end;
  307. procedure TfrmEmailBoxProperty.btnDeleteWhiteClick(Sender: TObject);
  308. begin
  309.   FDelWhite.Add(lstWhite.Items[lstWhite.ItemIndex]);
  310.   lstWhite.Items.Delete(lstWhite.ItemIndex);
  311. end;
  312. procedure TfrmEmailBoxProperty.btnOkClick(Sender: TObject);
  313. var
  314.   MyXml:TMyXml;
  315. begin
  316.   MyXml:=TMyXml.Create(AppPath+'EmailServers.xml');
  317.   try
  318.     MyXml.AddBlackList(FAddBlack);
  319.     MyXml.AddWhiteList(FAddWhite);
  320.     MyXml.DeleteBlackList(FDelBlack);
  321.     MyXml.DeleteWhiteList(FDelWhite);
  322.     frmMain.FBlackList.Assign(lstBlack.Items);
  323.     frmMain.FWhiteList.Assign(lstWhite.Items);
  324.   finally
  325.     MyXml.Free;
  326.   end;
  327.   ModalResult:=mrOk;
  328. end;
  329. procedure TfrmEmailBoxProperty.FormCreate(Sender: TObject);
  330. var
  331.   MyXml:TMyXml;
  332. begin
  333.   FAddBlack:=THashedStringList.Create;
  334.   FDelBlack:=THashedStringList.Create;
  335.   FAddWhite:=THashedStringList.Create;
  336.   FDelWhite:=THashedStringList.Create;
  337.   MyXml:=TMyXml.Create(AppPath+'EmailServers.xml');
  338.   try
  339.     MyXml.GetBlackList(lstBlack.Items);
  340.     MyXml.GetWhiteList(lstWhite.Items);
  341.   finally
  342.     MyXml.Free;
  343.   end;
  344. end;
  345. procedure TfrmEmailBoxProperty.FormDestroy(Sender: TObject);
  346. begin
  347.   FAddBlack.Free;
  348.   FDelBlack.Free;
  349.   FAddWhite.Free;
  350.   FDelWhite.Free;
  351. end;
  352. procedure TfrmEmailBoxProperty.ShowPage(index: Integer);
  353. begin
  354.   RzPageControl1.TabIndex:=index;
  355. end;
  356. procedure TfrmEmailBoxProperty.actWriteCheckEmailOptionExecute(
  357.   Sender: TObject);
  358. var
  359.   myXml:TMyXml;
  360. begin
  361.   MyXml:=TMyXml.Create(AppPath+'EmailServers.xml');
  362.   try
  363.     MyXml.WriteEmailDetect(FEmailAddr,TcxRadioButton(sender).Tag);
  364.   finally
  365.     MyXml.Free;
  366.   end;
  367. end;
  368. procedure TfrmEmailBoxProperty.edtRecvSaveToPropertiesButtonClick(
  369.   Sender: TObject; AButtonIndex: Integer);
  370. var
  371.   Dir:String;
  372.   Xml:TAppXml;
  373. begin
  374.   if SelectDirectory('',AppPath,Dir) then
  375.   begin
  376.     Xml:=TAppXml.Create;
  377.     try
  378.       Xml.SetEmailSavePath(Dir);
  379.     finally
  380.       Xml.free;
  381.     end;
  382.   end;
  383. end;
  384. end.