⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 account.pas

📁 siMail, siMail, siMail, siMail
💻 PAS
📖 第 1 页 / 共 5 页
字号:
begin
  Result := -1;
  ForceDirectories(FPath + userName);
  usr := TUser.Create(FPath + userName + '\', userName);
  Result := (inherited Add(usr));
end;

procedure TUserList.Clear;
var i: Integer;
begin
  for i := 0 to Count - 1 do begin
    Users[i].Free;
  end;
end;

function TUserList.Count: Integer;
begin
  Result := inherited Count;
end;

constructor TUserList.Create(Path: String);
begin
  inherited Create;

  FfileFound := TEasyFileSearch.Create(nil);
  FfileFound.OnFileFound := findfileFound;
  FfileFound.SearchOptions := [okLookForDirectory];
  FfileFound.RootPath := Path;
  FFileFound.ExcludedFiles.Text := 'Address Book';

  FPath := Path;
end;

procedure TUserList.Delete(Index: Integer);
begin
  Users[Index].Free;
  inherited Delete(Index);
end;

function TUserList.DeleteUser(Index: Integer): Boolean;
var i: Integer;
var path: String;
begin
//delete all user files
  if users[Index].Accounts.Count = 0 then
    Result := True
  else
    Result := False;

  for i := users[Index].Accounts.Count - 1 downto 0 do begin
    Result := users[Index].DeleteAccount(i);
  end;

    //delete user directory
  if Result then begin
    path := users[Index].FUserDirPath;
    Delete(Index);
    DelTree(path);
    Result := not DirectoryExists(path);
  end;

end;

destructor TUserList.Destroy;
begin
  FfileFound.Free;
  inherited Destroy;
end;

procedure TUserList.findFileFound(FileFound: TFileInformations);
begin
  Add(FileFound.Name);
end;

function TUserList.FindUser(userName: String): Integer;
var i, c: Integer;
begin
  Result := -1;
  c := Count - 1;
  for i := 0 to c do begin
    if AnsiStrIComp(PChar(userName), PChar(Users[i].UserName)) = 0 then begin
      Result := i;
      Break;
    end;
  end;
end;

function TUserList.GetUser(Index: Integer): TUser;
begin
  Result := (inherited Items[Index]);
end;

function TUserList.IndexOf(user: TUser): Integer;
begin
  Result := inherited IndexOf(user);
end;

procedure TUserList.Insert(Index: Integer; Item: TUser; ID: Integer);
begin
  inherited Insert(Index, Item);
end;

procedure TUserList.LoadUserData;
begin
  FfileFound.Search;
end;

procedure TUserList.PutUser(Index: Integer; const Value: TUser);
begin
  inherited Put(index, Value);
end;

function TUserList.Remove(Item: TUser): Integer;
begin
  Users[inherited IndexOf(Item)].Free;
  Result := inherited Remove(Item);
end;

{ TAccountList }

function TAccountList.Add(accnt: TAccount): Integer;
begin
  Result := inherited Add(accnt);
end;

procedure TAccountList.Clear;
var i: Integer;
begin
  for i := 0 to Count - 1 do begin
    Items[i].Free;
  end;

  inherited Clear;
end;

function TAccountList.Count: Integer;
begin
  Result := inherited Count;
end;

constructor TAccountList.Create;
begin
  inherited Create;

end;

procedure TAccountList.Delete(Index: Integer);
begin
  Items[Index].Free;
  inherited Delete(Index);
end;

destructor TAccountList.Destroy;
begin
   //Clear; we do not have to call this here it is called by Destroy
  inherited Destroy;
end;

function TAccountList.GetAccount(Index: Integer): TAccount;
begin
  Result := (inherited Items[Index]);
end;

function TAccountList.IndexOf(account: TAccount): Integer;
begin
  Result := inherited IndexOf(account);
end;

procedure TAccountList.Insert(Index: Integer; Item: TAccount);
begin
  inherited Insert(Index, Item);
end;

procedure TAccountList.PutAccount(Index: Integer; const Value: TAccount);
begin
  inherited Put(index, Value);
end;

function TAccountList.Remove(Item: TAccount): Integer;
begin
  Items[inherited IndexOf(Item)].Free;
  Result := inherited Remove(Item);
end;

{ TUser }

constructor TUser.Create(UserDirPath, UserName: String);
begin
  inherited Create;

  FUserDirPath := UserDirPath;
  FUserName := UserName;
  FAccountList := TAccountList.Create;
  FfileFound := TEasyFileSearch.Create(nil);
  FfileFound.OnFileFound := findfileFound;
  FfileFound.SearchOptions := [okLookForDirectory];
  if not DirectoryExists(UserDirPath + 'Address Book\') then
    ForceDirectories(UserDirPath + 'Address Book\');

  LoadAccounts;
  FSignatures := TSignatures.Create(FUserDirPath + 'signatures.xml');
  FConfig := TxmlConf.Create(FUserDirPath + 'config.xml');
  FAddressBook := TAddressBooks.Create(FUserDirPath + 'Address Book\address book.xml');
  FAddressBook.Load;
  FUnlocked := Unlock('');
end;

function TUser.CreateNewAccount(accountName: String): Integer;
var acc: TAccount;
var i: Integer;
begin

  ForceDirectories(FUserDirPath + accountName + '\');
  ForceDirectories(FUserDirPath + accountName + '\Attachments\');
  acc := TAccount.Create(FUserDirPath + accountName + '\', accountName);
  i := FAccountList.Count;
  FAccountList.Add(acc);
  if i < FAccountList.Count then Result := FAccountList.Count - 1
  else Result := -1;

end;

function TUser.DeleteAccount(accountID: Integer): Boolean;
begin
  if accountID >= 0 then begin
    Result := FAccountList.Items[accountID].DeleteFiles;
    FAccountList.Delete(accountID);
  end;
end;

destructor TUser.Destroy;
begin
  FAccountList.Free;
  FSignatures.Free;
  FConfig.Free;
  FAddressBook.Free;
  FfileFound.Free;
  inherited Destroy;
end;

procedure TUser.findFileFound(FileFound: TFileInformations);
var acc: TAccount;
begin
  acc := TAccount.Create(FileFound.Path + FileFound.Name + '\', FileFound.Name);
  Accounts.Add(acc);
end;

function TUser.GetPassword: String;
begin
  Result := DoPassword(Base64Decode(Config.ReadString('general', 'password', '')));
end;

procedure TUser.LoadAccounts;
begin
  FfileFound.RootPath := FUserDirPath;
  FFileFound.ExcludedFiles.Text := 'Address Book';
  FfileFound.Search;
end;

function TUser.Rename(NewUserName: String): Boolean;
var tmpStr: String;
begin
  Result := False;
  FAccountList.Clear;
  FSignatures.Free;
  FConfig.Free;
  FAddressBook.Free;
  tmpStr := Copy(FUserDirPath, 1, Length(FUserDirPath) - Length(FUserName) - 1) +
    NewUserName + '\';
  Result := RenameFile(FUserDirPath, tmpStr);
  if Result then begin
    FUserName := NewUserName;
    FUserDirPath := tmpStr;
  end;
  LoadAccounts;
  FSignatures := TSignatures.Create(FUserDirPath + 'signatures.xml');
  FConfig := TxmlConf.Create(FUserDirPath + 'config.xml');
  FAddressBook := TAddressBooks.Create(FUserDirPath + 'Address Book\address book.xml');
  FAddressBook.Load;
end;

procedure TAccount.SetYourName(const Value: String);
begin
  FaccConf.WriteString('user', 'name', Value);
end;

function TAccount.GetYourName: String;
begin
  Result := FaccConf.ReadString('user', 'name', '');
end;

function TAccount.GetAccountPath: String;
begin
  Result := FaccConf.ReadString('account', 'folder', '');
  if Result = '' then
    Result := FAccountPath;
end;

function TAccount.GetDefaultSignature: String;
begin
  Result := FaccConf.ReadString('user', 'defaultSignature', '');
end;

function TAccount.GetAccountDeliverToAccount: String;
begin
  Result := FaccConf.ReadString('account', 'deliverToAccount', '');
end;

function TAccount.GetEMail: String;
begin
  Result := FaccConf.ReadString('user', 'eMail', '');
end;

function TAccount.GetLastSignature: String;
begin
  Result := FaccConf.ReadString('user', 'lastSignature', '');
end;

function TAccount.GetOrganization: String;
begin
  Result := FaccConf.ReadString('user', 'organization', '');
end;

function TAccount.GetReplyEMail: String;
begin
  Result := FaccConf.ReadString('user', 'replyTo', '');
end;

function TAccount.GeTAccountType: TAccountType;
begin
  Result := TAccountType(FaccConf.ReadInteger('account', 'type', 0));
end;

procedure TAccount.SetAccountPath(const Value: String);
begin
  FaccConf.WriteString('account', 'folder', Value);
end;

procedure TAccount.SetDefaultSignature(const Value: String);
begin
  FaccConf.WriteString('user', 'defaultSignature', Value);
end;

procedure TAccount.SetAccountDeliverToAccount(const Value: String);
begin
  FaccConf.WriteString('account', 'deliverToAccount', Value);
end;

procedure TAccount.SetEMail(const Value: String);
begin
  FaccConf.WriteString('user', 'eMail', Value);
end;

procedure TAccount.SetLastSignature(const Value: String);
begin
  FaccConf.WriteString('user', 'lastSignature', Value);
end;

procedure TAccount.SetOrganization(const Value: String);
begin
  FaccConf.WriteString('user', 'organization', Value);
end;

procedure TAccount.SetReplyEMail(const Value: String);
begin
  FaccConf.WriteString('user', 'replyTo', Value);
end;

procedure TAccount.SeTAccountType(const Value: TAccountType);
begin
  FaccConf.WriteInteger('account', 'type', Integer(Value));
end;

function TAccount.GetPOP3Password: String;
begin
  Result := DoPassword(Base64Decode(FaccConf.ReadString('pop3', 'password', '')));
end;

function TAccount.GetPOP3Port: Integer;
begin
  Result := FaccConf.Re

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -