unit NewFold;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls,PXStuff,filectrl, PMTreeview,inifiles;

type
  TFrmNewFold = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Button2: TButton;
    Button3: TButton;
    Edit1: TEdit;
    Treeview1: TPMTreeview;
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
        Folder: string;
  public
    sName:string;
    procedure LoadFolderData(Data: PFolderData);
    procedure SaveFolderData(var Data: PFolderData);

    { Public declarations }
  end;

var
  FrmNewFold: TFrmNewFold;
  iNodeCount:integer;
implementation

uses Main;

{$R *.DFM}


procedure TFrmNewFold.Button2Click(Sender: TObject);
var
  S: string;
  I: Integer;
begin
  for I := 1 to Length(Edit1.Text) do
    if Edit1.Text[I] in ['\', '/', '<', '>', ':', '?', '*', '"', '|', #19] then
    begin
      MessageDlg(GetMessageString(44), mtWarning, [mbOK], 0);
      Exit;
    end;

 { S := GetParentFolder(Folder) + Edit1.Text + '\';
  if LowerCase(Folder) <> LowerCase(S) then
    if DirectoryExists(S) then begin
      MessageDlg(Format(GetMessageString(50), [Edit1.Text]), mtWarning,
        [mbOK], 0);
      Exit;
    end;}
  iNodeCount:=TreeView1.Selected.AbsoluteIndex;
  ModalResult := mrOK;
end;

procedure TFrmNewFold.FormCreate(Sender: TObject);
var
  SearchRec: TSearchRec;
  Found, Level: Integer;
  Node: TTreeNode;
  F: TINIFile;
  AccountData: PAccountData;
  I, iTask,j : Integer;  //AH09, ITask added
  FolderData: PFolderData;
  FNode,TempNode: TTreeNode;
  //dir:string;
begin
  TreeView1.Items.Clear;
  TreeView1.LoadFromFile(sAccountRootFolder+'Fold.st');

  Node:=TreeView1.Items.GetFirstNode;
  while Node<>nil do
  begin
    if Node.Level=0 then begin
      Node.ImageIndex := 7;
      Node.SelectedIndex := 7;
      Node.StateIndex := tnAccounts;
      AccountsNode := Node;
    end
    else if Node.Level=1 then
    begin
        dir:=sAccountRootFolder + Node.Text;
        F := TIniFile.Create(sAccountRootFolder + Node.Text +
          '\Account.ini');
        New(AccountData);
        AccountData^.Path := sAccountRootFolder + Node.Text + '\';
        AccountData^.Name := F.ReadString('Account', 'Name', 'Account Name');
        AccountData^.FromMail := F.ReadString('From', 'EMail', '');
        AccountData^.FromDesc := F.ReadString('From', 'Name', '');
        AccountData^.ReplyMail := F.ReadString('ReplyTo', 'EMail', '');
        AccountData^.ReplyDesc := F.ReadString('ReplyTo', 'Name', '');
        AccountData^.POPServer := F.ReadString('POP3', 'Server', '');
        AccountData^.POPPort := F.ReadString('POP3', 'Port', '110');
        AccountData^.POPUser := F.ReadString('POP3', 'User', '');
        AccountData^.POPPass := MHDecrypt(F.ReadString('POP3', 'Password', ''));
        AccountData^.SMTPServer := F.ReadString('SMTP', 'Server', '');
        AccountData^.SMTPPort := F.ReadString('SMTP', 'Port', '25');
        AccountData^.SMTPAuthenticate := F.ReadBool('SMTP', 'Authenticate',
          false);
        AccountData^.SMTPUserName := F.ReadString('SMTP', 'User', '');
        AccountData^.SMTPPassword := MHDecrypt(F.ReadString('SMTP', 'Password',
          ''));
        AccountData^.Organization := F.ReadString('From', 'Organization', '');
        AccountData^.PromptPassword := F.ReadInteger('POP3', 'PromptPassword',
          0);
        AccountData^.DoSMTP := F.ReadInteger('SMTP', 'DoSMTP', 1);
        AccountData^.DoSMTPAfterPOP := F.ReadInteger('SMTP', 'DoSMTPAfterPOP', 0);
        AccountData^.DoPOP := F.ReadInteger('POP3', 'DoPOP', 1);
        AccountData^.StandardDownload := F.ReadInteger('POP3',
          'StandardDownload', 0);
        AccountData^.KeepFilter := F.ReadString('Filter', 'Keep', '');
        AccountData^.DeleteFilter := F.ReadString('Filter', 'Delete', '');
        AccountData^.ShowDownload := F.ReadInteger('POP3', 'ShowDownload', 0);
        F.Free;
        Node.Data := AccountData;

        Node.StateIndex := tnAccount;
        //RecurseDirs(sAccountRootFolder + SearchRec.Name + '\');
    end
    else if Node.Level=2 then
    begin
      TempNode:=Node;
      ////////////////////inbox/////////////////
      if Node.Text=GetMessageString(5) then
      begin
      F := TINIFile.Create(dir + '\Account.ini');
      New(FolderData);
      FolderData^.Path := Dir;
      FolderData^.Name := GetMessageString(5);
      FolderData^.Outbox := F.ReadBool(GetMessageString(5), 'Outbox', False);
      FolderData^.Inbox := F.ReadBool(GetMessageString(5), 'Inbox', False);
      FolderData^.Drafts := F.ReadBool(GetMessageString(5), 'Drafts', False);
      FolderData^.Filter := F.ReadString(GetMessageString(5), 'TakeIn', '');
      F.Free;
//      while Node.Level <> (Level) do
 //       Node := Node.Parent;
      Node.Data := FolderData;
      Node.ImageIndex := 15;
      Node.SelectedIndex := 16;
      Node.StateIndex := tnFolder;
      end else
      ////////////////////inbox/////////////////


      ////////////////////outbox/////////////////
      if Node.Text=GetMessageString(4) then
      begin
      F := TINIFile.Create(Dir + '\Account.ini');
      New(FolderData);
      FolderData^.Path := Dir;
      FolderData^.Name := GetMessageString(4);
      FolderData^.Outbox := F.ReadBool(GetMessageString(4), 'Outbox', False);
      FolderData^.Inbox := F.ReadBool(GetMessageString(4), 'Inbox', False);
      FolderData^.Drafts := F.ReadBool(GetMessageString(4), 'Drafts', False);
      FolderData^.Filter := F.ReadString(GetMessageString(4), 'TakeIn', '');
      F.Free;
//      while Node.Level <> (Level) do
//        Node := Node.Parent;
      Node.Data := FolderData;
      Node.ImageIndex := 3;
      Node.SelectedIndex := 4;
      Node.StateIndex := tnFolder;
      end else
      ////////////////////outbox/////////////////

      ////////////////////Repositorybox/////////////////
      if Node.Text=GetMessageString(2) then
      begin
      Node.StateIndex := tnRepository;
      Node.ImageIndex := 8;
      Node.SelectedIndex := 8;
      RepositoryNode := Node;
      end else
      ////////////////////Repositorybox/////////////////

      ////////////////////Trashbox/////////////////
      if Node.Text=GetMessageString(1) then
      begin
      Node.StateIndex := tnThrashBag;
      Node.ImageIndex := 6;
      Node.SelectedIndex := 6;
      TrashNode := Node;
      end else
      ////////////////////Trashbox/////////////////




      ////////////////////draftbox/////////////////
      if Node.Text=GetMessageString(6) then
      begin
      F := TINIFile.Create(Dir + '\Account.ini');
      New(FolderData);
      FolderData^.Path := Dir;
      FolderData^.Name := GetMessageString(6);
      FolderData^.Outbox := F.ReadBool(GetMessageString(6), 'Outbox', False);
      FolderData^.Inbox := F.ReadBool(GetMessageString(6), 'Inbox', False);
      FolderData^.Drafts := F.ReadBool(GetMessageString(6), 'Drafts', False);
      FolderData^.Filter := F.ReadString(GetMessageString(6), 'TakeIn', '');
      F.Free;
//      while Node.Level <> (Level) do
//        Node := Node.Parent;
      Node.Data := FolderData;
      Node.ImageIndex := 17;
      Node.SelectedIndex := 18;
      Node.StateIndex := tnFolder;
      end else
      begin
      ////////////////////draftbox/////////////////
      New(FolderData);
      FolderData^.Path := Dir;
      FolderData^.Name := Node.Text;
      FolderData^.Outbox := False;
      FolderData^.Inbox := False;
      FolderData^.Drafts := False;
      FolderData^.Filter :='';

      Node.Data := FolderData;
      Node.ImageIndex := 17;
      Node.SelectedIndex := 18;
      Node.StateIndex := tnFolder;
      end;
    end else
    begin
      New(FolderData);
      FolderData^.Path := Dir;
      FolderData^.Name := Node.Text;
      FolderData^.Outbox := False;
      FolderData^.Inbox := False;
      FolderData^.Drafts := False;
      FolderData^.Filter :='';

      Node.Data := FolderData;
      Node.ImageIndex := 17;
      Node.SelectedIndex := 18;
      Node.StateIndex := tnFolder;

    end;
    Node:=Node.GetNext;
  end;
end;

procedure TFrmNewFold.LoadFolderData(Data: PFolderData);
begin
//  Folder := Data^.Path
end;

procedure TFrmNewFold.SaveFolderData(var Data: PFolderData);
var
  Node:TtreeNode;
begin
  Data^.Name := Edit1.Text;
  Data^.Filter := '过滤器只可能用在收件箱';
  Data^.OutBox := false;
  Data^.InBox := false;
  Data^.Drafts := false;


  Node:=Treeview1.Selected;
  if Node.StateIndex = tnFolder then
    Data^.Path := PFolderData(Node.Data)^.Path + '##@@  @@##\'
  else
    Data^.Path := PAccountData(Node.Data)^.Path + Data^.Name +
      '##@@  @@##\';
    Folder := Data^.Path;
    Data^.Path := GetParentFolder(Folder) + Edit1.Text + '\';
end;

procedure TFrmNewFold.FormShow(Sender: TObject);
var
  iCount,i:integer;
  Node:TtreeNode;
begin
  iCount:=MainForm.Treeview1.Selected.AbsoluteIndex;
  Treeview1.Items[iCount].Selected:=true;
end;

procedure TFrmNewFold.Button3Click(Sender: TObject);
begin
  close;
end;

end.
