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

Email服务器

开发平台:

Delphi

  1. unit ManageAliases;
  2. (******************************************************************************)
  3. (*                                                                            *)
  4. (* Hermes Manage Aliases Dialog Box                                           *)
  5. (* Part of Hermes SMTP/POP3 Server.                                           *)
  6. (* Copyright(C) 2000 by Alexander J. Fanti, All Rights Reserver Worldwide.    *)
  7. (*                                                                            *)
  8. (* Created January 13, 2000 by Alexander J. Fanti.  See License.txt           *)
  9. (*                                                                            *)
  10. (* Used by: Main                                                              *)
  11. (* Uses: DataU1, AddEditAlias                                                 *)
  12. (*                                                                            *)
  13. (* Description: This Modal dialog window allows the user to Add, Edit, Delete *)
  14. (*              and Rename user aliases                                       *)
  15. (*                                                                            *)
  16. (* Revisions: 1/21/2000  AJF  Commented                                       *)
  17. (*                                                                            *)
  18. (******************************************************************************)
  19. interface
  20. uses
  21.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  22.   StdCtrls, Menus, Buttons;
  23. type
  24.   TfrmManageAliases = class(TForm)
  25.     lstList: TListBox;
  26.     btnDelete: TBitBtn;
  27.     btnAdd: TBitBtn;
  28.     btnEdit: TBitBtn;
  29.     btnImport: TBitBtn;
  30.     btnClose: TBitBtn;
  31.     btnRename: TBitBtn;
  32.     btnExport: TBitBtn;
  33.     popupMenu: TPopupMenu;
  34.     puAdd: TMenuItem;
  35.     puEdit: TMenuItem;
  36.     puDelete: TMenuItem;
  37.     puRename: TMenuItem;
  38.     N1: TMenuItem;
  39.     puImport: TMenuItem;
  40.     puExport: TMenuItem;
  41.     procedure FormShow(Sender: TObject);
  42.     procedure popupMenuPopup(Sender: TObject);
  43.     procedure lstListClick(Sender: TObject);
  44.     procedure btnAddClick(Sender: TObject);
  45.     procedure btnEditClick(Sender: TObject);
  46.     procedure btnDeleteClick(Sender: TObject);
  47.     procedure btnRenameClick(Sender: TObject);
  48.     procedure btnImportClick(Sender: TObject);
  49.     procedure btnExportClick(Sender: TObject);
  50.     procedure btnCloseClick(Sender: TObject);
  51.     procedure lstListDblClick(Sender: TObject);
  52.   private
  53.     { Private declarations }
  54.     procedure Add;      // Add Alias
  55.     procedure Edit;     // Edit Alias
  56.     procedure Delete;   // Delete Alias
  57.     procedure Rename;   // Rename Alias
  58.     procedure Import;   // Import Alias
  59.     procedure DoExport; // Export Alias
  60.     procedure EnableUI; // Enable buttons and popum menus based on selections
  61.   public
  62.     { Public declarations }
  63.   end;
  64. var
  65.   frmManageAliases: TfrmManageAliases;
  66. implementation
  67. uses DataU1, AddEditAlias;
  68. {$R *.DFM}
  69. procedure TfrmManageAliases.FormShow(Sender: TObject);
  70. begin
  71.   // Populate list with aliases
  72.   INI.Alias_GetList(lstList.Items);
  73.   // Enable buttons based on list selection
  74.   EnableUI;
  75. end;
  76. procedure TfrmManageAliases.Add;
  77. begin
  78.   // if they added an alias through the AddEditAlias Dialog...
  79.   // then refresh the list of aliases
  80.   if frmAddEditAlias.Add then INI.Alias_GetList(lstList.Items);
  81. end;
  82. procedure TfrmManageAliases.Edit;
  83. begin
  84.   // if there's a selected alias, then let them edit it
  85.   // through the AddEditAlias Dialog...
  86.   // then refresh the list of aliases
  87.   if lstList.ItemIndex > -1 then
  88.     if frmAddEditAlias.Edit(lstList.Items[lstList.ItemIndex]) then
  89.       INI.Alias_GetList(lstList.Items);
  90. end;
  91. procedure TfrmManageAliases.Delete;
  92. var
  93.   x : Integer;
  94. begin
  95.   // Ask if they really want to delete, cause it can't be un-done
  96.   x := MessageDlg('Deleting alias(es) cannot be undone.  Proceed?',
  97.                   mtConfirmation, [mbYes, mbNo], 0);
  98.   if x = mrYes then begin
  99.     // they really want to do it... for each selected alias...
  100.     // call the delete function and refresh the alias list
  101.     for x := 0 to lstList.Items.Count -1 do
  102.       if lstList.Selected[x] then INI.Alias_Delete(lstList.Items[x]);
  103.     INI.Alias_GetList(lstList.Items);
  104.   end;
  105. end;
  106. procedure TfrmManageAliases.Rename;
  107. var
  108.   OldAliasID, AliasUser, NewAliasID : String;
  109. begin
  110.   // if there's an alias selected...
  111.   if lstList.ItemIndex > -1 then
  112.     INI.Alias_Parse(lstList.Items[lstList.ItemIndex], OldAliasID, AliasUser);
  113.   NewAliasID := InputBox('Rename Alias', 'Enter New Alias Name', OldAliasID);
  114.   if Pos(ALIASSEPERATOR, NewAliasID) = 0 then begin
  115.     // and the new alias isn't the same as the old one...
  116.     // then rename the alias and refresh the display
  117.     if LowerCase(NewAliasID) <> LowerCase(OldAliasID) then begin
  118.       if not INI.Alias_Rename(OldAliasID, NewAliasID) then
  119.         ShowMessage('Error: Cound not re-name.' + #13 + #10 +
  120.                     'Aliases must have a unique Name.')
  121.       else
  122.         INI.Alias_GetList(lstList.Items);
  123.     end;
  124.   end else begin
  125.     ShowMessage('Alias cannot contain "' + ALIASSEPERATOR + '".');
  126.   end;
  127. end;
  128. procedure TfrmManageAliases.Import;
  129. begin // Import Aliases
  130.   ShowMessage('Feature not implemented yet...');
  131.   // DEBUG
  132.   // How should I import Aliases?
  133. end;
  134. procedure TfrmManageAliases.DoExport;
  135. begin // Export aliases
  136.   ShowMessage('Feature not implemented yet...');
  137.   // DEBUG
  138.   // How should I export aliases?
  139. end;
  140. procedure TfrmManageAliases.EnableUI;
  141. begin
  142.   // Enable buttons and menus based on list selection
  143.   btnEdit.Enabled   := lstList.SelCount = 1;
  144.   btnDelete.Enabled := lstList.SelCount > 0;
  145.   btnRename.Enabled := lstList.SelCount = 1;
  146.   btnExport.Enabled := lstList.Items.Count > 0;
  147.   puEdit.Enabled   := lstList.SelCount = 1;
  148.   puDelete.Enabled := lstList.SelCount > 0;
  149.   puRename.Enabled := lstList.SelCount = 1;
  150.   puExport.Enabled := lstList.Items.Count > 0;
  151. end;
  152. // Hook Buttond and menus up with functions for performing actions
  153. procedure TfrmManageAliases.btnAddClick(Sender: TObject);
  154. begin  Add;                                    end;
  155. procedure TfrmManageAliases.btnEditClick(Sender: TObject);
  156. begin  Edit;                                   end;
  157. procedure TfrmManageAliases.btnDeleteClick(Sender: TObject);
  158. begin  Delete;                                 end;
  159. procedure TfrmManageAliases.btnRenameClick(Sender: TObject);
  160. begin  Rename;                                 end;
  161. procedure TfrmManageAliases.btnImportClick(Sender: TObject);
  162. begin  Import;                                 end;
  163. procedure TfrmManageAliases.btnExportClick(Sender: TObject);
  164. begin  DoExport;                               end;
  165. procedure TfrmManageAliases.lstListClick(Sender: TObject);
  166. begin  EnableUI;                               end;
  167. procedure TfrmManageAliases.lstListDblClick(Sender: TObject);
  168. begin  Edit;                                   end;
  169. procedure TfrmManageAliases.popupMenuPopup(Sender: TObject);
  170. begin  EnableUI;                               end;
  171. procedure TfrmManageAliases.btnCloseClick(Sender: TObject);
  172. begin  Close;                                  end;
  173. end.