Settings_SmtpServerAccessControl.pas
上传用户:dh8233980
上传日期:2014-10-16
资源大小:1015k
文件大小:8k
源码类别:

Email服务器

开发平台:

Delphi

  1. unit Settings_SmtpServerAccessControl;
  2. (******************************************************************************)
  3. (*                                                                            *)
  4. (* Hermes Smtp Server Settings Access Banning Dialog Box                      *)
  5. (* Part of Hermes SMTP/POP3 Server.                                           *)
  6. (* Copyright(C) 2000 by Alexander J. Fanti, All Rights Reserver Worldwide.    *)
  7. (*                                                                            *)
  8. (* Created February 13, 2000 by Alexander J. Fanti.  See License.txt          *)
  9. (*                                                                            *)
  10. (* Used by: Settings_SmtpServer                                               *)
  11. (* Uses: DataU1                                                               *)
  12. (*                                                                            *)
  13. (* Description: This Modal dialog window allows the user to change Smtp       *)
  14. (*              server access settings.                                       *)
  15. (*                                                                            *)
  16. (* Revisions: 2/13/2000  AJF  Commented                                       *)
  17. (*                                                                            *)
  18. (******************************************************************************)
  19. interface
  20. uses
  21.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  22.   Menus, StdCtrls, Spin, Buttons;
  23. type
  24.   TfrmSettings_SmtpServerAccessControl = class(TForm)
  25.     cbxBannedDomains: TCheckBox;
  26.     lstBannedDomains: TListBox;
  27.     cbxBannedMailboxes: TCheckBox;
  28.     lstBannedMailboxes: TListBox;
  29.     cbxRejectToCount: TCheckBox;
  30.     speRejectToCount: TSpinEdit;
  31.     popupBannedDomains: TPopupMenu;
  32.     pu_BannedDomains_Add: TMenuItem;
  33.     pu_BannedDomains_Delete: TMenuItem;
  34.     popupBannedMailboxes: TPopupMenu;
  35.     pu_BannedMailboxes_Add: TMenuItem;
  36.     pu_BannedMailboxes_Delete: TMenuItem;
  37.     popupBannedAddresses: TPopupMenu;
  38.     pu_BannedAddresses_Add: TMenuItem;
  39.     pu_BannedAddresses_Delete: TMenuItem;
  40.     btnOK: TBitBtn;
  41.     btnCancel: TBitBtn;
  42.     cbxBannedAddresses: TCheckBox;
  43.     lstBannedAddresses: TListBox;
  44.     Label8: TLabel;
  45.     Label1: TLabel;
  46.     procedure btnOKClick(Sender: TObject);
  47.     procedure FormShow(Sender: TObject);
  48.     procedure popupBannedDomainsPopup(Sender: TObject);
  49.     procedure popupBannedMailboxesPopup(Sender: TObject);
  50.     procedure popupBannedAddressesPopup(Sender: TObject);
  51.     procedure pu_BannedDomains_AddClick(Sender: TObject);
  52.     procedure pu_BannedDomains_DeleteClick(Sender: TObject);
  53.     procedure pu_BannedMailboxes_AddClick(Sender: TObject);
  54.     procedure pu_BannedMailboxes_DeleteClick(Sender: TObject);
  55.     procedure pu_BannedAddresses_AddClick(Sender: TObject);
  56.     procedure pu_BannedAddresses_DeleteClick(Sender: TObject);
  57.   private
  58.     { Private declarations }
  59.   public
  60.     { Public declarations }
  61.   end;
  62. var
  63.   frmSettings_SmtpServerAccessControl: TfrmSettings_SmtpServerAccessControl;
  64. implementation
  65. {$R *.DFM}
  66. uses DataU1;
  67. procedure TfrmSettings_SmtpServerAccessControl.FormShow(Sender: TObject);
  68. var
  69.   x : longint;
  70. begin
  71.   // Populate dialog with data
  72.   lstBannedDomains.Clear;
  73.   for x := 0 to INI.Smtp_Access_BannedDomains.Count -1 do
  74.     lstBannedDomains.Items.Add(INI.Smtp_Access_BannedDomains[x]);
  75.   lstBannedMailboxes.Clear;
  76.   for x := 0 to INI.Smtp_Access_BannedMailboxes.Count -1 do
  77.     lstBannedMailboxes.Items.Add(INI.Smtp_Access_BannedMailboxes[x]);
  78.   lstBannedAddresses.Clear;
  79.   for x := 0 to INI.Smtp_Access_BannedAddresses.Count -1 do
  80.     lstBannedAddresses.Items.Add(INI.Smtp_Access_BannedAddresses[x]);
  81.   cbxBannedDomains.Checked := INI.Smtp_Access_BanDomains;
  82.   cbxBannedMailboxes.Checked := INI.Smtp_Access_BanMailboxes;
  83.   cbxBannedAddresses.Checked := INI.Smtp_Access_BanAddresses;
  84.   cbxRejectToCount.Checked := INI.Smtp_Access_OnlyForUnderXUsers;
  85.   speRejectToCount.Value := INI.Smtp_Access_OnlyForUsersCount;
  86. end;
  87. procedure TfrmSettings_SmtpServerAccessControl.btnOKClick(Sender: TObject);
  88. begin
  89.   // Save Access Control
  90.   INI.SetSmtp_Access_BannedDomains(lstBannedDomains.Items);
  91.   INI.SetSmtp_Access_BannedMailboxes(lstBannedMailboxes.Items);
  92.   INI.SetSmtp_Access_BannedAddresses(lstBannedAddresses.Items);
  93.   INI.Smtp_Access_BanDomains := cbxBannedDomains.Checked;
  94.   INI.Smtp_Access_BanMailboxes := cbxBannedMailboxes.Checked;
  95.   INI.Smtp_Access_BanAddresses := cbxBannedAddresses.Checked;
  96.   INI.Smtp_Access_OnlyForUnderXUsers := cbxRejectToCount.Checked;
  97.   INI.Smtp_Access_OnlyForUsersCount := speRejectToCount.Value;
  98. end;
  99. procedure TfrmSettings_SmtpServerAccessControl.popupBannedDomainsPopup(Sender: TObject);
  100. begin
  101.   // Enable Domain list popum menu items
  102.   pu_BannedDomains_Delete.Enabled := lstBannedDomains.SelCount > 0;
  103. end;
  104. procedure TfrmSettings_SmtpServerAccessControl.pu_BannedDomains_AddClick(Sender: TObject);
  105. var
  106.   NewDomain : String;
  107.   x : Longint;
  108.   Found : Boolean;
  109. begin
  110.   // Add a new domain to the Domains list
  111.   NewDomain := Trim(InputBox('Add Banned Domain', 'Domain', ''));
  112.   if NewDomain <> '' then begin
  113.     Found := False;
  114.     for x := 0 to lstBannedDomains.Items.Count -1 do
  115.       if LowerCase(NewDomain) = LowerCase(lstBannedDomains.Items[x]) then
  116.         Found := True;
  117.     if not Found then lstBannedDomains.Items.Add(NewDomain);
  118.   end;
  119. end;
  120. procedure TfrmSettings_SmtpServerAccessControl.pu_BannedDomains_DeleteClick(Sender: TObject);
  121. var
  122.   x : Longint;
  123. begin
  124.   // remove domains from the domain list
  125.   for x := lstBannedDomains.Items.Count -1 downto 0 do
  126.     if lstBannedDomains.Selected[x] then lstBannedDomains.Items.Delete(x);
  127. end;
  128. procedure TfrmSettings_SmtpServerAccessControl.popupBannedMailboxesPopup(
  129.   Sender: TObject);
  130. begin
  131.   // Enable Domain list popum menu items
  132.   pu_BannedMailboxes_Delete.Enabled := lstBannedMailboxes.SelCount > 0;
  133. end;
  134. procedure TfrmSettings_SmtpServerAccessControl.pu_BannedMailboxes_AddClick(Sender: TObject);
  135. var
  136.   NewMailbox : String;
  137.   x : Longint;
  138.   Found : Boolean;
  139. begin
  140.   // Add a new mailbox to the mailboxes list
  141.   NewMailbox := Trim(InputBox('Add Banned Mailbox', 'Mailbox', ''));
  142.   if NewMailbox <> '' then begin
  143.     Found := False;
  144.     for x := 0 to lstBannedMailboxes.Items.Count -1 do
  145.       if LowerCase(NewMailbox) = LowerCase(lstBannedMailboxes.Items[x]) then
  146.         Found := True;
  147.     if not Found then lstBannedMailboxes.Items.Add(NewMailbox);
  148.   end;
  149. end;
  150. procedure TfrmSettings_SmtpServerAccessControl.pu_BannedMailboxes_DeleteClick(
  151.   Sender: TObject);
  152. var
  153.   x : Longint;
  154. begin
  155.   // remove mailboxes from the mailbox list
  156.   for x := lstBannedMailboxes.Items.Count -1 downto 0 do
  157.     if lstBannedMailboxes.Selected[x] then lstBannedMailboxes.Items.Delete(x);
  158. end;
  159. procedure TfrmSettings_SmtpServerAccessControl.popupBannedAddressesPopup(
  160.   Sender: TObject);
  161. begin
  162.   // Enable Domain list popum menu items
  163.   pu_BannedAddresses_Delete.Enabled := lstBannedAddresses.SelCount > 0;
  164. end;
  165. procedure TfrmSettings_SmtpServerAccessControl.pu_BannedAddresses_AddClick(
  166.   Sender: TObject);
  167. var
  168.   NewAddress : String;
  169.   x : Longint;
  170.   Found : Boolean;
  171. begin
  172.   // Add a new domain to the Domains list
  173.   NewAddress := Trim(InputBox('Add Banned Address', 'Address', ''));
  174.   if NewAddress <> '' then begin
  175.     Found := False;
  176.     for x := 0 to lstBannedAddresses.Items.Count -1 do
  177.       if LowerCase(NewAddress) = LowerCase(lstBannedAddresses.Items[x]) then
  178.         Found := True;
  179.     if not Found then lstBannedAddresses.Items.Add(NewAddress);
  180.   end;
  181. end;
  182. procedure TfrmSettings_SmtpServerAccessControl.pu_BannedAddresses_DeleteClick(
  183.   Sender: TObject);
  184. var
  185.   x : Longint;
  186. begin
  187.   // remove domains from the domain list
  188.   for x := lstBannedAddresses.Items.Count -1 downto 0 do
  189.     if lstBannedAddresses.Selected[x] then lstBannedAddresses.Items.Delete(x);
  190. end;
  191. end.