📄 account.pas
字号:
m_IsChanged := false;
if m_lstAccount = nil then
exit;
if lstAccount.Items.Count > 0 then
exit;
//
// 遍历 m_lstAccount 所有账号
//
for i := 0 to m_lstAccount.Count - 1 do
begin
pAccount := m_lstAccount.Items[i];
//
// 更新账号显示列表框的显示
//
item := lstAccount.Items.Add();
with pAccount^ do
begin
item.Caption := m_Account;
item.SubItems.Clear();
item.SubItems.Add(m_Server);
item.SubItems.Add(m_User);
item.SubItems.Add(m_Mobile);
end;
end;
end;
//
// 列表框单击处理事件
//
procedure TfrmAccount.lstAccountClick(Sender: TObject);
var
pAccount : ^TAccountInfo;
begin
if lstAccount.Selected = nil then
exit;
//
// 获取 m_lstAccount 中对应的pAccount,并删除之
//
pAccount := m_lstAccount.Items[lstAccount.Selected.index];
//
// 更新账号显示列表框的显示
//
with pAccount^ do
begin
edtAccount.Text := m_Account;
edtServer.Text := m_Server;
edtPort.Text := m_Port;
edtUser.Text := m_User;
edtPwd.Text := m_Pwd;
edtMobile.Text := m_Mobile;
chkSendSMS.Checked := m_SendToMobile;
end;
end;
//
// 读取配置文件中的账号和邮件信息
//
procedure TfrmAccount.ReadAccountInfo;
var
Configini: TIniFile;
Account_num : integer;
i : integer;
stream : TStringStream;
FilePath : string;
pAccount : ^TAccountInfo;
pEmail : ^TEmailInfo;
DataFile : File of TEmailInfo;
begin
FilePath := ExtractFilePath(ParamStr(0));
if not FileExists(FilePath + 'MailConfig.ini') then
exit;
ConfigIni := TIniFile.Create(FilePath + 'MailConfig.ini');
with Configini do
begin
//
// 账号数据
//
Account_num := ReadInteger('Account', 'Account Number', 0);
for i := 0 to Account_num - 1 do
begin
Stream := TStringStream.Create('');
ReadBinaryStream('Account' + IntToStr(i), 'Id', Stream);
new(pAccount);
pAccount^.m_Pwd := Stream.DataString;
pAccount^.m_Account := ReadString('Account' + IntToStr(i), 'Account', 'account');
pAccount^.m_Server := ReadString('Account' + IntToStr(i), 'Server', 'server');
pAccount^.m_Port := ReadString('Account' + IntToStr(i),'Port', '110');
pAccount^.m_User := ReadString('Account' + IntToStr(i), 'User', 'User');
pAccount^.m_Mobile := ReadString('Account' + IntToStr(i),'Mobile', '');
pAccount^.m_SendToMobile := ReadBool('Account' + IntToStr(i), 'SendToMobile', True);
pAccount^.m_lstEmail := TList.Create();
if m_lstAccount = nil then
m_lstAccount := TList.Create();
m_lstAccount.Add(pAccount);
//
// 读取邮件信息
//
if not FileExists(FilePath + pAccount^.m_Account + '.emi') then
continue;
AssignFile(DataFile, FilePath + pAccount^.m_Account + '.emi');
Reset(DataFile);
try
while not Eof(DataFile) do
begin
new(pEmail);
Read(DataFile, pEmail^);
pAccount^.m_lstEmail.Add(pEmail);
end;
Finally
CloseFile(DataFile);
end;
end; // end of for ...
end; // end of with Configini
ConfigIni.Free;
end;
//
// 将当前的账号和邮件信息保存到配置文件中
//
procedure TfrmAccount.SaveAccountInfo;
var
Configini: TIniFile;
stream : TStringStream;
i : integer;
pAccount : ^TAccountInfo;
FilePath : string;
pEmail : ^TEmailInfo;
DataFile : File of TEmailInfo;
mail_index : integer;
begin
if m_lstAccount = nil then
begin
exit;
end;
FilePath := ExtractFilePath(ParamStr(0));
ConfigIni :=TIniFile.Create(FilePath + 'MailConfig.ini');
with Configini do
begin
//
// 账号数据
//
WriteInteger('Account', 'Account Number', m_lstAccount.Count);
for i:= 0 to m_lstAccount.Count - 1 do
begin
pAccount := m_lstAccount.Items[i];
stream := TStringStream.Create(pAccount^.m_Pwd);
WriteBinaryStream('Account' + IntToStr(i), 'Id', stream);
WriteString('Account' + IntToStr(i), 'Account', pAccount^.m_Account);
WriteString('Account' + IntToStr(i), 'Password', '@@@@@@@@@');
WriteString('Account' + IntToStr(i), 'Server', pAccount^.m_Server);
WriteString('Account' + IntToStr(i), 'Port', pAccount^.m_Port);
WriteString('Account' + IntToStr(i), 'User', pAccount^.m_User);
WriteString('Account' + IntToStr(i), 'Mobile', pAccount^.m_Mobile);
WriteBool('Account' + IntToStr(i), 'SendToMobile', pAccount^.m_SendToMobile);
//
// 存储邮件信息
//
if pAccount^.m_lstEmail = nil then
continue;
AssignFile(DataFile, FilePath + pAccount^.m_Account + '.emi');
Rewrite(DataFile);
try
for mail_index := 0 to pAccount^.m_lstEmail.Count - 1 do
begin
pEmail := pAccount^.m_lstEmail.Items[mail_index];
write(DataFile, pEmail^);
end;
finally
CloseFile(DataFile);
end;
end; // end of for...
end; // end of with configini
ConfigIni.Free;
end;
//
// 窗体创建时触发此事件
//
procedure TfrmAccount.FormCreate(Sender: TObject);
begin
ReadAccountInfo();
end;
//
// 窗体销毁时触发此事件
//
procedure TfrmAccount.FormDestroy(Sender: TObject);
begin
//
// 保存账号信息
//
SaveAccountInfo();
//
// 释放内存
//
ReleaseAll();
end;
//
// 释放内存
//
procedure TfrmAccount.ReleaseAll;
var
i, j : integer;
pAccount : ^TAccountInfo;
pEmail : ^TEmailInfo;
begin
if m_lstAccount = nil then
exit;
//
// 释放m_lstAccount链表
//
for i := 0 to m_lstAccount.Count - 1 do
begin
pAccount := m_lstAccount.Items[i];
//
// 释放m_lstEmail链表
//
if pAccount^.m_lstEmail <> nil then
begin
for j := 0 to pAccount^.m_lstEmail.Count - 1 do
begin
pEmail := pAccount^.m_lstEmail.Items[j];
Dispose(pEmail);
end;
pAccount^.m_lstEmail.Free;
end;
Dispose(pAccount);
end;
m_lstAccount.Free();
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -