📄 mailbox.pas
字号:
begin
case Column of
0:
begin
case TMailbox(data).Id of
//gettext: basic mailbox name
-1:
CellText := _('New Mail');
//gettext: basic mailbox name
-2:
CellText := _('Inbox');
//gettext: basic mailbox name
-3:
CellText := _('Unsent');
//gettext: basic mailbox name
-4:
CellText := _('Unfinished');
//gettext: basic mailbox name
-5:
CellText := _('Sent Items');
//gettext: basic mailbox name
-6:
CellText := _('Trash');
//gettext: basic mailbox name
-7:
CellText := _('Junk Mail');
else
CellText := TMailbox(data).MailboxName;
end;
end;
1:
CellText := IntToStr(TMailbox(data).UnreadMessageCount);
2:
CellText := IntToStr(TMailbox(data).TotalMessageCount);
end;
end;
//cIDFolder:
end;
end;
end;
procedure TfrmMailbox.trMailboxGetNodeDataSize(Sender: TBaseVirtualTree;
var NodeDataSize: Integer);
begin
NodeDataSize := sizeOf(TTreeMailbox);
end;
function TfrmMailbox.addAccount(const account: TAccount): PVirtualNode;
begin
Result := trMailbox.AddChild(nil);
with PTreeMailbox(trMailbox.GetNodeData(Result))^ do begin
id := 0;
text := name;
end;
end;
function TfrmMailbox.addUser(const user: TUser): PVirtualNode;
begin
end;
//we build just user nodes here as parents
//all other data is read when necessary in OnInitNode
procedure TfrmMailbox.LoadUsers;
var i: Integer;
begin
Profiles := TUserList.Create(df.Profiles);
Profiles.LoadUserData;
if Profiles.Count = 0 then begin
FScheduleNewAccount := True;
Profile := nil;
end
else begin
i := Profiles.FindUser(xmlIni.ReadString('general', 'defaultProfile', ''));
if i < 0 then begin
MessageDlg(Format(_('Default Profile ''%s'' cannot be found.'),
[xmlIni.ReadString('general', 'defaultProfile', '')]), mtError, [mbOK], 0);
actUsersSwitch.Execute;
xmlIni.WriteString('general', 'defaultProfile', Profile.UserName);
end
else
SetProfile(i);
end;
end;
procedure TfrmMailbox.trMailboxInitNode(Sender: TBaseVirtualTree;
ParentNode, Node: PVirtualNode;
var InitialStates: TVirtualNodeInitStates);
var d, par: PTreeMailbox;
begin
if Profile = nil then Exit;
d := PTreeMailbox((Sender as TVirtualStringTree).GetNodeData(Node));
if ParentNode = nil then begin
if FShowProfileNode then begin
with d^ do begin
id := cIDUser;
data := Profile;
iconID := cIconUser;
text := '';
end;
InitialStates := [ivsHasChildren, ivsExpanded];
end
else begin
with d^ do begin
id := cIDAccount;
data := Profile.Accounts[Node.Index];
iconID := cIconAccount;
text := '';
end;
if Profile.Accounts[Node.Index].UnreadMessageCount > 0 then
InitialStates := [ivsHasChildren, ivsExpanded]
else
InitialStates := [ivsHasChildren];
//expand default account
if Profile.Accounts[Node.Index].AccountName = Profile.Config.ReadString('frmMailbox', 'defaultAccount', '') then begin
InitialStates := InitialStates + [ivsExpanded];
FSelectedAccount := Node.Index;
end;
//do not display node if we need to deliver data from that account to another one
if Profile.Accounts[Node.Index].AccountDeliverToAccount <> '' then
(Sender as TVirtualStringTree).IsVisible[Node] := False;
end;
end
else begin
par := PTreeMailbox((Sender as TVirtualStringTree).GetNodeData(ParentNode));
case par^.id of //if parent node is user then we need to initialize account data
cIDUser:
begin
with d^ do begin
id := cIDAccount;
data := Profile.Accounts[Node.Index];
iconID := cIconAccount;
text := '';
end;
if Profile.Accounts[Node.Index].UnreadMessageCount > 0 then
InitialStates := [ivsHasChildren, ivsExpanded]
else
InitialStates := [ivsHasChildren];
//expand default account
if Profile.Accounts[Node.Index].AccountName = Profile.Config.ReadString('frmMailbox', 'defaultAccount', '') then begin
InitialStates := InitialStates + [ivsExpanded];
FSelectedAccount := Node.Index;
end;
//do not display node if we need to deliver data from that account to another one
if Profile.Accounts[Node.Index].AccountDeliverToAccount <> '' then
(Sender as TVirtualStringTree).IsVisible[Node] := False;
end;
cIDAccount:
begin //if parent node is account then we need to initialize mailbox and folder data
with d^ do begin
id := cIDMailbox;
data := Profile.Accounts[Profile.Accounts.IndexOf(par^.data)].Mailboxes[Node.Index];
if TMailbox(data).id < 0 then iconID := 2 + Node.Index
else iconID := cIconMailbox;
text := '';
end;
//show inbox of default account
if FSelectedAccount >= 0 then begin
if not defaultExpanded then begin
if ParentNode.Index = FSelectedAccount then begin
if Profile.Accounts[Profile.Accounts.IndexOf(par^.data)].Mailboxes[Node.Index].Id = - Integer(mboxInbox) then begin
defaultExpanded := True;
InitialStates := InitialStates + [ivsSelected];
FSelectedMailbox := Node.Index;
frmMailList.ShowMailbox;
end;
end;
end;
end;
end;
//we need mailbox count
//cIDFolder:
end;
end;
end;
procedure TfrmMailbox.trMailboxInitChildren(Sender: TBaseVirtualTree;
Node: PVirtualNode; var ChildCount: Cardinal);
var d: PTreeMailbox;
begin
d := ((Sender as TVirtualStringTree).GetNodeData(Node));
case d.id of
//we need account count
cIDUser:
ChildCount := Profile.Accounts.Count;
//we need mailbox & folder count
cIDAccount:
begin
ChildCount := Profile.Accounts[Profile.Accounts.IndexOf(d^.data)].Mailboxes.Count;
end;
//we need mailbox count
//cIDFolder:
end;
end;
procedure TfrmMailbox.actMailboxNewExecute(Sender: TObject);
var tmpStr: String;
var d: PTreeMailbox;
var node: PVirtualNode;
begin
tmpStr := MyInputBox(_('Add mailbox'),
_('Please write name for new mailbox in the field below.'),
'', '', notAllowedInFileName);
Trim(tmpStr);
if tmpStr <> '' then begin
//find correct user,account id then add new mailbox
node := trMailbox.GetFirstSelected;
d := PTreeMailbox(trMailbox.GetNodeData(node));
case d.id of
cIDAccount:
begin
if Profile.Accounts[Profile.Accounts.IndexOf(d^.data)].Mailboxes.Find(tmpStr) = -1 then
//add mailbox
addMailbox(Profile.Accounts[Profile.Accounts.IndexOf(d^.data)].CreateNewMailbox(tmpStr), node)
//ups
else MessageDlg(Format(_('Mailbox ''%s'' already exists.'), [tmpStr]),
mtError, [mbOK], 0);
end;
cIDMailbox:
begin
d := PTreeMailbox(trMailbox.GetNodeData(node.Parent));
if Profile.Accounts[Profile.Accounts.IndexOf(d^.data)].Mailboxes.Find(tmpStr) = -1 then
//add mailbox
addMailbox(Profile.Accounts[Profile.Accounts.IndexOf(d^.data)].CreateNewMailbox(
tmpStr), node.Parent)
//ups
else MessageDlg(Format(_('Mailbox ''%s'' already exists.'), [tmpStr]),
mtError, [mbOK], 0);
end;
end;
end;
end;
procedure TfrmMailbox.actMailboxRenameExecute(Sender: TObject);
var tmpStr: String;
var mbox: TMailbox;
var node: PVirtualNode;
begin
node := trMailbox.GetFirstSelected;
mbox := getMailboxFromNode(node);
if mbox <> nil then begin
tmpStr := MyInputBox(_('Rename mailbox'),
Format(_('Please write new name for ''%s'' mailbox in the field below.'),
[mbox.MailboxName]), '', '', notAllowedInFileName);
Trim(tmpStr);
if tmpStr = '' then exit;
if Profile.Accounts[Profile.Accounts.IndexOf(PTreeMailbox(trMailbox.GetNodeData(node.Parent))^.data)].Mailboxes.Find(tmpStr) = -1 then begin
//rename mailbox
TAccount(PTreeMailbox(trMailbox.GetNodeData(node.Parent)).data).RenameMailbox(mbox, tmpStr);
trMailbox.RepaintNode(node);
end //ups
else MessageDlg(Format(_('Mailbox ''%s'' already exists.'), [tmpStr]),
mtError, [mbOK], 0);
end;
end;
procedure TfrmMailbox.actMailboxRenameUpdate(Sender: TObject);
var mbox: TMailbox;
begin
mbox := getMailboxFromNode(trMailbox.GetFirstSelected);
if mbox <> nil then begin
if mbox.id >= 0 then begin
actMailboxRename.Enabled := True;
end
else begin
actMailboxRename.Enabled := False;
end;
end
else begin //disable it
actMailboxRename.Enabled := False;
end;
end;
function TfrmMailbox.getMailboxFromNode(const node: PVirtualNode): TMailbox;
var d: PTreeMailbox;
begin
Result := nil;
if node <> nil then begin
d := PTreeMailbox(trMailbox.GetNodeData(node));
if d.id = cIDMailbox then begin
Result := TMailbox(d.data);
end;
end;
end;
function TfrmMailbox.getAccountFromNode(const node: PVirtualNode): TAccount;
var d: PTreeMailbox;
begin
Result := nil;
if node <> nil then begin
d := PTreeMailbox(trMailbox.GetNodeData(node));
if d.id = cIDAccount then begin
Result := TAccount(d.data);
end;
end;
end;
function TfrmMailbox.actMailboxDeleteF: Boolean;
var mbox: TMailbox;
var acc: TAccount;
var node, par: PVirtualNode;
begin
Result := False;
mbox := nil; acc := nil;
node := trMailbox.GetFirstSelected;
mbox := getMailboxFromNode(node);
acc := getAccountFromNode(node);
par := node.Parent;
if mbox <> nil then begin
if mbox.id < 0 then Exit;
if MessageDlg(Format(_('Are you sure you want to delete mailbox ''%s''?'),
[mbox.MailboxName]), mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
TAccount(PTreeMailbox(trMailbox.GetNodeData(node.Parent)).data).DeleteMailbox(mbox);
//if mbox shown in maillist is same as we are deleting then remove it from view
if frmMaillist.ShownMailbox = mbox then
frmMaillist.ClearMaillist;
trMailbox.DeleteNode(node);
end;
end
else if acc <> nil then begin
if MessageDlg(Format(_('Are you sure you want to delete account ''%s''?'),
[acc.AccountName]), mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
Profile.DeleteAccount(Profile.Accounts.IndexOf(acc));
//if mbox shown in maillist is from account we are deleting then remove it from view
if frmMaillist.MailboxFromAccount = FSelectedAccount then
frmMaillist.ClearMaillist;
DeleteCheckTimer(FSelectedAccount);
trMailbox.DeleteNode(node);
end;
end;
Result := True;
end;
procedure TfrmMailbox.actAccountNewExecute(Sender: TObject);
begin
frmNewAccountWizard.ShowModal;
if not frmNewAccountWizard.Cancled then begin
//this will update tree if new account was added
if FShowProfileNode then
trMailbox.ReinitNode(trMailbox.GetFirst, False)
else trMailbox.RootNodeCount := Profile.Accounts.Count;
CreateCheckTimer;
UpdateCheckTimer(Profile.Accounts.Count - 1);
trMailbox.Refresh;
end;
end;
procedure TfrmMailbox.actMailboxNewUpdate(Sender: TObject);
var mbox: TMailbox;
var acc: TAccount;
begin
mbox := getMailboxFromNode(trMailbox.GetFirstSelected);
//new mailbox menu can be enabled if account or mailboy is selected
if mbox = nil then acc := getAccountFromNode(trMailbox.GetFirstSelected);
if (mbox <> nil) or (acc <> nil) then
actMailboxNew.Enabled := True
else actMailboxNew.Enabled := False; //disable it
end;
procedure TfrmMailbox.trMailboxChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
var nd: PTreeMailbox;
begin
if Node = nil then exit;
if not (vsSelected in Node.States) then Exit;
nd := trMailbox.GetNodeData(Node);
case nd^.id of
cIDMailbox:
begin
FSelectedMailbox := findMailboxID(Node);
FSelectedAccount := findAccountID(Node);
frmMailList.ShowMailbox;
end;
cIDAccount:
begin
FSelectedAccount := findAccountID(Node);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -