home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 11
/
Freelog011.iso
/
BestOf
/
PhoenixMail
/
Source
/
phoenix
/
PXStuff.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1999-02-20
|
31KB
|
875 lines
{*****************************************************************************
*
* PXStuff.pas - Phoenix common routines (22-July-1998)
*
* Copyright (c) 1998-99 Michael Haller
*
* Author: Michael Haller
* E-mail: michael@discountdrive.com
* Homepage: http://www.discountdrive.com/sunrise
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
*----------------------------------------------------------------------------
*
* Revision history:
*
* DATE REV DESCRIPTION
* ----------- --- ----------------------------------------------------------
*
*****************************************************************************}
unit PXStuff;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, FileCtrl, Base64sup, Registry, ShellAPI, ActiveX, ShlObj,
IniFiles, MMSystem, MailParser, Buttons;
type
PAccountData = ^TAccountData;
TAccountData = record
Path, Name: String;
FromMail, FromDesc, ReplyMail, ReplyDesc: String;
POPServer, POPPort, POPUser, POPPass: String;
SMTPServer, SMTPPort, KeepFilter, DeleteFilter: String;
Organization: String;
DoSMTP, DoPOP, StandardDownload, PromptPassword: Byte;
end;
PFolderData = ^TFolderData;
TFolderData = record
Path, Name: String;
Filter: String;
Outbox, Inbox: Boolean;
end;
const
StandardMsgType: TMsgType = mtText;
crHandCursor = 5;
sRegKey = 'Software\Michael Haller\Phoenix Mail';
sMailerVer1 = '0.92.08 Standard Edition';
sMailerVer2 = '0.92.08 Developer Edition';
sInfoVersion = 'Version 0.92.08';
sVersion = '0.92';
sAppTitle = 'Phoenix Mail 0.92';
sMHHomepage = 'http://www.discountdrive.com/sunrise/';
sOfficeFontName = 'Tahoma';
WM_TASKICON = WM_USER + 521;
WM_PREVINSTRUN = WM_USER + 522;
WM_GETFORMHANDLES = WM_USER + 523;
WM_SPELLCHECKFINISHED = WM_USER + 524;
var
CurrentEMail: TEMail;
sTemporaryFolder: String;
sTempMessageFile: String;
sAccountRootFolder: String;
sSignatureFolder: String;
sRepositoryFolder: String;
sTrashFolder: String;
sProtocolFile: String;
sAddressBookFolder: String;
sLanguageFolder: String;
sTempLanguageFile: String;
sTempNewMessageFile: String;
sTempSpellCheckFile: String;
sSpellCheckerFile: String;
sSettingsFile: String;
sBannerDLLFileName: String;
sStandardAccountDataFile: String;
sWriteNewMessage1, sWriteNewMessage2: String;
sWinTempFolder: String;
sVirusProg, sVirusParams, sLastFolder, sMessageFont: String;
bVirusMin, bSmallToolbarButtons: Boolean;
bMakeProtocol, bShowTips, bAskToGoOffline: Boolean;
bAskForDelFromServer, bFriendlyPrinter: Boolean;
bAskForLanguage, bGoOnlineAtStart, bStartAtWindowsStart: Boolean;
bScheduleC1, bScheduleC2, bScheduleC3, bScheduleC4, bScheduleC5: Boolean;
bCheckForStdEMail, bListMailsAtDownload, bOfficeFonts, bFlatButtons: Boolean;
sScheduleS2, sScheduleS3: String;
sLastAttSaveDir, sLastAttOpenDir, sLanguage, sCustAddressBook: String;
iActualTip, iFontSize, iFontColor, iMarkAsReadSec, iFontCharSet: Integer;
sDUNConnection, sDUNUsername, sDUNPassword, sToolbarBKBitmap: String;
bDUNAskForPassword, bDUNAutoQuit, bViewStatusAtEnd, bDUNNormalQuit: Boolean;
iDUNAutoQuitTime, sScheduleS1: Integer;
sSoundFile1, sSoundFile2, sSoundFile3, sToolbarButtons: String;
sAccountsCaption, sTrashBagCaption, sRepositoryCaption: String;
bShowCntInBrackets, bHideAnimations: Boolean;
bLanguageLoaded: Boolean;
SaveMessage: Boolean;
sXMailer, sHomepage: String;
ColorScheme, LowColor, bDrawBK: Boolean;
iColorDepth: Integer;
// general
function BolToInt(B: Boolean): Byte;
function BrowseForFolder(Title: String; StartMenu: Boolean): String;
function FormatByteText(I: Integer): String;
function FileCopy(Progress: TProgressBar; SourceName, DestName: String): String;
procedure MoveTreeViewNode(const TreeView: TTreeView; Source, Target: TTreeNode);
function MakeValidDirName(Dir: String): String;
procedure CreateFolder(Dir: String);
procedure MoveFolder(OldDir, NewDir: String);
function GetParentFolder(Dir: String): String;
procedure DeleteFolder(Dir, TrashFileFolder: String);
function SetFileAttr(Filename: String; faReadOnly, faArchive, faHidden, faSystem: Boolean): Boolean;
function HexToInt(S: String): Integer;
function MHEncrypt(S: String): String;
function MHDecrypt(S: String): String;
procedure ClearFolder(S: String);
function GetFileSize(Filename: String): Integer;
procedure Set3DButtons(ThreeD: Boolean; Owner: TForm);
procedure PlaySound(Filename: String);
// more concrete
function CheckVersion: Boolean;
function CheckForPrevInstance: Boolean;
procedure ClearUpCheckForPrevInstance;
function CheckColorDepth: Boolean;
function CheckCDROMStart: Boolean;
procedure CheckForStandardEMailProgram;
procedure InitializePX;
procedure ClearUpPX;
implementation
{$R PXStuff.res}
uses
LangSup, FMLanguage, Main, FMStdMail, ParserSup;
var
Mutex: THandle;
TextFile: Text;
function GetFileSize(Filename: String): Integer;
var
H: HFile;
begin
Result := 0;
try
H := CreateFile(PChar(Filename), GENERIC_READ, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, 0);
if H <> 0 then begin
Result := Windows.GetFileSize(H, nil);
CloseHandle(H);
end;
if Result < 0 then Result := 0;
except end;
end;
function BolToInt(B: Boolean): Byte;
begin
if B then Result := 1 else Result := 0;
end;
function FormatByteText(I: Integer): String;
var
R: Real;
begin
Result := 'n.a.';
try
R := I / 1024;
if I = 0 then
Result := '0 Byte'
else
if I < 1048576 then
Result := FloatToStrF(R, ffNumber, 18, 1)+' KB'
else
if I < 1073741824 then begin
R := R / 1024;
I := Round(R);
if I < 10 then
Result := FloatToStrF(R, ffNumber, 18, 1)+' MB'
else
Result := IntToStr(I)+' MB';
end else begin
I := Round(R / 1024 / 1024);
Result := IntToStr(I)+' GB';
end;
if (Result[Length(Result)-3] = '0') and (Result[Length(Result)-4] = ',') then
Delete(Result, Length(Result)-4, 2);
except end;
end;
function BrowseForFolder(Title: String; StartMenu: Boolean): String;
var
BrowseInfo: TBrowseInfo;
pszName: array [0..MAX_PATH] of Char;
IDL: PITEMIDLIST;
begin
Result := '';
try
if SHGetSpecialFolderLocation(Application.Handle, CSIDL_PROGRAMS, IDL)<> NOERROR then IDL := nil;
if not StartMenu then IDL := nil;
with BrowseInfo do begin
hwndOwner := Application.Handle;
pidlRoot := IDL;
pszDisplayName := @pszName;
lpszTitle := PChar(Title);
ulFlags := BIF_RETURNONLYFSDIRS;
lpfn := nil;
end;
IDL := SHBrowseForFolder(BrowseInfo);
if IDL <> nil then
if SHGetPathFromIDList(IDL, @pszName) then Result := MakeValidDirName(pszName);
except end;
end;
function FileCopy(Progress: TProgressBar; SourceName, DestName: String): String;
var
S, D: File;
Buffer: array[1..4096] of Byte;
Counter: Integer;
OrgFileMode: Byte;
Attributes: Cardinal;
begin
Result := '';
Attributes := GetFileAttributes(PChar(SourceName));
try
OrgFileMode := FileMode;
FileMode := 0;
try
AssignFile(S, SourceName);
Reset(S, 1);
AssignFile(D, DestName);
Rewrite(D, 1);
while not EoF(S) do begin
BlockRead(S, Buffer, SizeOf(Buffer), Counter);
BlockWrite(D, Buffer, Counter);
if Assigned(Progress) then Progress.StepIt;
Application.ProcessMessages;
end;
finally
FileMode := OrgFileMode;
try
CloseFile(S);
CloseFile(D);
except end;
end;
SetFileAttributes(PChar(DestName), Attributes);
except
Result := 'An error occured while trying to copy '+SourceName+' to '+DestName+'!';
end;
end;
procedure MoveTreeViewNode(const TreeView: TTreeView; Source, Target: TTreeNode);
var
Data: PFolderData;
Node: TTreeNode;
procedure CopySubNotes(Source, Target: TTreeNode);
var
I: Integer;
Node: TTreeNode;
begin
for I := 0 to Source.Count-1 do begin
Node := TreeView.Items.AddChild(Target, GetPXTreeNodeName(Source.Item[I]));
New(Data);
Data^.Path := PFolderData(Target.Data)^.Path+GetPXTreeNodeName(Source.Item[I])+'\';
//Data^.Path := PFolderData(Source.Item[I].Data)^.Path;
Data^.Name := PFolderData(Source.Item[I].Data)^.Name;
Data^.Filter := PFolderData(Source.Item[I].Data)^.Filter;
Data^.Inbox := PFolderData(Source.Item[I].Data)^.Inbox;
Data^.Outbox := PFolderData(Source.Item[I].Data)^.Outbox;
Node.Data := Data;
Node.ImageIndex := Source.Item[I].ImageIndex;
Node.StateIndex := Source.Item[I].StateIndex;
Node.SelectedIndex := Source.Item[I].SelectedIndex;
if Source.Count > 0 then CopySubNotes(Source.Item[I], Node);
end;
end;
begin
//TreeView1.Selected.MoveTo(Node, naAddChildFirst);
Node := TreeView.Items.AddChild(Target, GetPXTreeNodeName(Source));
New(Data);
Data^.Path := PFolderData(Source.Data)^.Path;
Data^.Name := PFolderData(Source.Data)^.Name;
Data^.Filter := PFolderData(Source.Data)^.Filter;
Data^.Inbox := PFolderData(Source.Data)^.Inbox;
Data^.Outbox := PFolderData(Source.Data)^.Outbox;
Node.Data := Data;
Node.ImageIndex := Source.ImageIndex;
Node.StateIndex := Source.StateIndex;
Node.SelectedIndex := Source.SelectedIndex;
CopySubNotes(Source, Node);
Source.Delete;
Node.Expand(True);
Node.Selected := True;
TreeView.AlphaSort;
end;
function HexToInt(S: String): Integer;
var
I, E, F, G: Integer;
function DigitValue(C: Char): Integer;
begin
Result := 0;
try
case C of
'A': Result := 10;
'B': Result := 11;
'C': Result := 12;
'D': Result := 13;
'E': Result := 14;
'F': Result := 15;
else
Result := StrToInt(C);
end;
except end;
end;
begin
S := UpperCase(S);
if S[1] = '$' then Delete(S, 1, 1);
if S[2] = 'X' then Delete(S, 1, 2);
E := -1; Result := 0;
for I := Length(S) downto 1 do begin
G := 1; for F := 0 to E do G := G*16;
Result := Result+(DigitValue(S[I])*G);
Inc(E);
end;
end;
function MHEncrypt(S: String): String;
var
I: Integer;
T: String;
begin
Result := '';
if S = '' then Exit;
T := IntToHex(Random(15)+1, 1);
T := T + IntToHex(Length(S), 2);
for I := 1 to Length(S) do
T := T + IntToHex(Ord(S[I]), 2);
for I := 1 to Random(8)+2 do
T := T + IntToHex(Random(256), 2);
T := T + IntToHex(Random(15)+1, 1);
S := '';
for I := 1 to (Length(T) div 2) do
S := S + Chr(HexToInt(T[I*2-1]+T[I*2]));
S := Chr(Random(26)+65) + StringToBase64(S);
Result := '';
for I := Length(S) downto 1 do
Result := Result + S[I];
end;
function MHDecrypt(S: String): String;
var
I, E: Integer;
T: String;
begin
Result := '';
if S = '' then Exit;
T := '';
for I := Length(S) downto 1 do
T := T + S[I];
Delete(T, 1, 1);
S := Base64ToString(T);
T := '';
for I := 1 to Length(S) do
T := T + IntToHex(Ord(S[I]), 2);
E := HexToInt(T[2]+T[3]);
Delete(T, 1, 3);
S := '';
for I := 1 to E do
S := S + Chr(HexToInt(T[I*2-1]+T[I*2]));
Result := S;
end;
function MakeValidDirName(Dir: String): String;
begin
if Dir[Length(Dir)] <> '\' then Dir := Dir+'\';
Result := Dir;
end;
procedure CreateFolder(Dir: String);
begin
ForceDirectories(Dir);
if DirectoryExists(Dir) = False then begin
ShowMessage('Error creating folder '+Dir);
Halt;
end;
end;
procedure MoveFolder(OldDir, NewDir: String);
begin
if OldDir[Length(OldDir)] = '\' then Delete(OldDir, Length(OldDir), 1);
if NewDir[Length(NewDir)] = '\' then Delete(NewDir, Length(NewDir), 1);
RenameFile(OldDir, NewDir);
end;
function GetParentFolder(Dir: String): String;
var
I: Integer;
begin
if Dir[Length(Dir)] = '\' then Delete(Dir, Length(Dir), 1);
I := Length(Dir);
while Dir[I] <> '\' do Dec(I);
Delete(Dir, I+1, Length(Dir)-I);
if Pos('\', Dir) = 0 then Dir := Dir+'\';
Result := Dir;
end;
procedure DeleteFolder(Dir, TrashFileFolder: String);
var
SL: TStringList;
I: Integer;
procedure DeleteAllFiles(Dir: String);
var
SearchRec: TSearchRec;
Found: Integer;
begin
Found := FindFirst(Dir+'*.*', faAnyFile, SearchRec);
while Found = 0 do begin
SetFileAttr(Dir+SearchRec.Name, False, True, False, False);
if TrashFileFolder <> '' then
CopyFile(PChar(Dir+SearchRec.Name), PChar(TrashFileFolder+SearchRec.Name), False);
DeleteFile(Dir+SearchRec.Name);
Found := FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
procedure RecurseDirs(Dir: String);
var
SearchRec: TSearchRec;
Found: Integer;
begin
Found := FindFirst(Dir+'*.*', $37, SearchRec);
while Found = 0 do begin
if (SearchRec.Attr and $10 = $10) and (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then begin
SL.Add(Dir+SearchRec.Name+'\');
DeleteAllFiles(Dir+SearchRec.Name+'\');
RecurseDirs(Dir+SearchRec.Name+'\');
end;
Found := FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
begin
SL := TStringList.Create;
SL.Add(Dir);
DeleteAllFiles(Dir);
RecurseDirs(Dir);
for I := SL.Count-1 downto 0 do
RemoveDir(SL.Strings[I]);
SL.Free;
end;
function SetFileAttr(Filename: String; faReadOnly, faArchive, faHidden, faSystem: Boolean): Boolean;
var
I: Integer;
begin
I := 0;
if faReadOnly then I := I or FILE_ATTRIBUTE_READONLY;
if faArchive then I := I or FILE_ATTRIBUTE_ARCHIVE;
if faHidden then I := I or FILE_ATTRIBUTE_HIDDEN;
if faSystem then I := I or FILE_ATTRIBUTE_SYSTEM;
Result := SetFileAttributes(PChar(Filename), I);
end;
procedure ClearFolder(S: String);
var
Found: Integer;
SearchRec: TSearchRec;
begin
Found := FindFirst(S+'*.*', faAnyFile, SearchRec);
while Found = 0 do begin
SetFileAttr(S+SearchRec.Name, False, True, False, False);
DeleteFile(S+SearchRec.Name);
Found := FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
procedure Set3DButtons(ThreeD: Boolean; Owner: TForm);
procedure ControlRecursive(Component: TComponent);
var
I: Integer;
begin
for I := 0 to Component.ComponentCount-1 do begin
if Component.Components[I] is TSpeedButton then
TSpeedButton(Component.Components[I]).Flat := ThreeD;
if Component.Components[I].ComponentCount > 0 then
ControlRecursive(Component.Components[I]);
end;
end;
begin
ControlRecursive(TComponent(Owner));
end;
procedure PlaySound(Filename: String);
begin
if FileExists(Filename) then
SndPlaySound(PChar(Filename), SND_ASYNC or SND_NODEFAULT);
end;
function CheckVersion: Boolean;
var
Reg: TRegIniFile;
begin
Result := True;
{if Reg.ReadString('', 'Version', sVersion) <> sVersion then begin
if MessageDlg('There is already another version of Phoenix Mail on this system!'+#13+
'Continue?', mtWarning, [mbYes, mbNo], 0) = mrNo then
Result := False;
end;}
Reg := TRegIniFile.Create(sRegKey);
if Result = True then Reg.WriteString('', 'Version', sVersion);
Reg.WriteString('', 'Path', MakeValidDirName(ExtractFilePath(Application.ExeName)));
Reg.Free;
end;
function CheckForPrevInstance: Boolean;
var
S: String;
H: HWnd;
I: Integer;
begin
Result := False;
sTempNewMessageFile := MakeValidDirName(ExtractFilePath(Application.ExeName)) + '\tmpmsgad.tmp';
sWriteNewMessage1 := '';
sWriteNewMessage2 := '';
if (ParamCount >= 2) and (ParamStr(1) = '-newmail') then begin
S := ParamStr(2);
if Pos('mailto:', LowerCase(S)) > 0 then Delete(S, 1, 7);
for I := 1 to Length(S) do begin
if S[I] <> '?' then
sWriteNewMessage1 := sWriteNewMessage1 + S[I]
else begin
Delete(S, 1, I);
if Pos('subject=', LowerCase(S)) > 0 then Delete(S, 1, 8);
sWriteNewMessage2 := S;
Break;
end;
end;
end;
S := 'Phoenix Mail Previous Instance';
Mutex := CreateMutex(nil, True, PChar(S));
if (Mutex <> 0) and (GetLastError = 0) then begin
Result := True;
end else begin
H := FindWindow(nil, PChar(sAppTitle));
if H <> 0 then begin
if sWriteNewMessage1 = '' then
SendMessage(H, WM_PREVINSTRUN, 0, 0)
else begin
try
AssignFile(TextFile, sTempNewMessageFile);
Rewrite(TextFile);
WriteLn(TextFile, sWriteNewMessage1);
WriteLn(TextFile, sWriteNewMessage2);
CloseFile(TextFile);
except end;
sWriteNewMessage1 := '';
sWriteNewMessage2 := '';
SendMessage(H, WM_PREVINSTRUN, 1, 0);
end;
end;
end;
end;
procedure ClearUpCheckForPrevInstance;
begin
if Mutex <> 0 then CloseHandle(Mutex);
Mutex := 0;
end;
function CheckColorDepth: Boolean;
var
DC: HDC;
begin
Result := True;
DC := GetDC(GetDesktopWindow);
iColorDepth := GetDeviceCaps(DC, BITSPIXEL) * GetDeviceCaps(DC, PLANES);
if iColorDepth < 8 then LowColor := True else LowColor := False;
if ColorToRGB(clBtnFace) = clSilver then ColorScheme := False else ColorScheme := True;
end;
procedure CheckForStandardEMailProgram;
const
DummyArray: array[1..4] of Byte = (2, 0, 0, 0);
var
NativeReg: TRegistry;
S: String;
begin
if bCheckForStdEMail = False then Exit;
S := '"'+Application.ExeName+'" -newmail "%1"';
NativeReg := TRegistry.Create;
NativeReg.RootKey := HKEY_CLASSES_ROOT;
NativeReg.OpenKey('mailto\shell\open\command', True);
if NativeReg.ReadString('') <> S then begin
StdMailForm := TStdMailForm.Create(Application);
if StdMailForm.ShowModal = mrYes then begin
NativeReg.WriteString('', S);
NativeReg.CloseKey;
NativeReg.OpenKey('mailto\DefaultIcon', True);
NativeReg.WriteString('', '"'+Application.ExeName+'",0');
NativeReg.CloseKey;
NativeReg.RootKey := HKEY_LOCAL_MACHINE;
NativeReg.OpenKey('SOFTWARE\Clients\Mail', True);
NativeReg.WriteString('', 'Phoenix Mail');
NativeReg.CloseKey;
NativeReg.OpenKey('SOFTWARE\Clients\Mail\Phoenix Mail', True);
NativeReg.WriteString('', 'Phoenix Mail');
NativeReg.CloseKey;
NativeReg.OpenKey('SOFTWARE\Clients\Mail\Phoenix Mail\Protocols\mailto', True);
NativeReg.WriteString('', 'URL:MailTo Protocol');
NativeReg.WriteBinaryData('Edit Flags', DummyArray, 4);
NativeReg.WriteString('URL Protocol', '');
NativeReg.CloseKey;
NativeReg.OpenKey('SOFTWARE\Clients\Mail\Phoenix Mail\Protocols\mailto\DefaultIcon', True);
NativeReg.WriteString('', '"'+Application.ExeName+'",0');
NativeReg.CloseKey;
NativeReg.OpenKey('SOFTWARE\Clients\Mail\Phoenix Mail\Protocols\mailto\shell\open\command', True);
NativeReg.WriteString('', S);
NativeReg.CloseKey;
NativeReg.OpenKey('SOFTWARE\Clients\Mail\Phoenix Mail\shell\open\command', True);
NativeReg.WriteString('', '"'+Application.ExeName+'"');
end;
StdMailForm.Free;
end;
NativeReg.CloseKey;
NativeReg.Free;
Application.ProcessMessages;
end;
function CheckCDROMStart: Boolean;
begin
Result := True;
if GetDriveType(PChar(Application.ExeName[1]+':\')) = DRIVE_CDROM then begin
MessageDlg(MainForm.ListBox1.Items[77], mtError, [mbOK], 0);
Result := False;
end;
end;
procedure InitializePX;
var
S: String;
NativeReg: TRegistry;
IniFile: TIniFile;
A: array[0..MAX_PATH] of Char;
begin
Application.Title := sAppTitle;
Randomize;
PrepareBase64Support;
// Folders and Files
S := LowerCase(MakeValidDirName(ExtractFilePath(Application.ExeName)));
sTemporaryFolder := S+'Temp\';
CreateFolder(sTemporaryFolder);
sTempMessageFile := sTemporaryFolder+'PXMsg598.rtf';
sTempLanguageFile := S+'templang.tmp';
sAddressBookFolder := S+'Address\';
CreateFolder(sAddressBookFolder);
sSpellCheckerFile := S+'pxspell.exe';
sTempSpellCheckFile := S+'tmpspell.tmp';
if FileExists(sSpellCheckerFile) = False then sSpellCheckerFile := '';
sAccountRootFolder := S+'Accounts\';
CreateFolder(sAccountRootFolder);
sTrashFolder := S+'Trash\';
CreateFolder(sTrashFolder);
sLanguageFolder := S+'Lang\';
CreateFolder(sLanguageFolder);
sRepositoryFolder := S+'Reposit\';
CreateFolder(sRepositoryFolder);
sSignatureFolder := S+'Signat\';
CreateFolder(sSignatureFolder);
sBannerDLLFileName := S+'pxadvert.dll';
sProtocolFile := S+'Protocol.txt';
sSettingsFile := S+'Settings.ini';
Application.HelpFile := S+'Phoenix.hlp';
sStandardAccountDataFile := S+'Default.ini';
GetTempPath(MAX_PATH, A);
sWinTempFolder := A;
sWinTempFolder := MakeValidDirName(sWinTempFolder);
// Registry
IniFile := TIniFile.Create(sSettingsFile);
bMakeProtocol := IniFile.ReadBool('Settings', 'Protocol', True);
bShowTips := IniFile.ReadBool('Settings', 'ShowTipsOnStartUp', True);
iActualTip := IniFile.ReadInteger('Settings', 'ActualTip', 0);
iFontCharSet := IniFile.ReadInteger('Settings', 'FontCharSet', 0);
bAskToGoOffline := IniFile.ReadBool('Settings', 'AskToGoOffline', False);
sVirusProg := IniFile.ReadString('Settings', 'VirusScanner', '');
sVirusParams := IniFile.ReadString('Settings', 'ScannerParameter', '');
sCustAddressBook := IniFile.ReadString('Settings', 'CustAddressBook', '');
if DirectoryExists(sCustAddressBook) then sAddressBookFolder := sCustAddressBook else sCustAddressBook := '';
bVirusMin := IniFile.ReadBool('Settings', 'RunScannerMinimized', True);
sLastFolder := IniFile.ReadString('Settings', 'LastFolder', '');
bAskForDelFromServer := IniFile.ReadBool('Settings', 'AskForDelFromServer', False);
bGoOnlineAtStart := IniFile.ReadBool('Settings', 'GoOnlineAtStart', False);
sMessageFont := IniFile.ReadString('Settings', 'MessageFont', 'Courier New');
iFontSize := IniFile.ReadInteger('Settings', 'FontSize', 9);
iFontColor := IniFile.ReadInteger('Settings', 'FontColor', clWindowText);
iMarkAsReadSec := IniFile.ReadInteger('Settings', 'MarkAsReadSec', 3);
sLastAttSaveDir := IniFile.ReadString('Settings', 'LastAttSaveDir', '');
sLastAttOpenDir := IniFile.ReadString('Settings', 'LastAttOpenDir', '');
bFriendlyPrinter := IniFile.ReadBool('Settings', 'FriendlyPrinter', True);
bListMailsAtDownload := IniFile.ReadBool('Settings', 'ListMailsAtDownload', True);
bCheckForStdEMail := IniFile.ReadBool('Settings', 'CheckForStdEMail', True);
sLanguage := IniFile.ReadString('Settings', 'Language', '');
bAskForLanguage := IniFile.ReadBool('Settings', 'AskForLanguage', False);
bScheduleC1 := IniFile.ReadBool('Settings', 'ScheduleC1', False);
bScheduleC2 := IniFile.ReadBool('Settings', 'ScheduleC2', False);
bScheduleC3 := IniFile.ReadBool('Settings', 'ScheduleC3', False);
bScheduleC4 := IniFile.ReadBool('Settings', 'ScheduleC4', False);
bScheduleC5 := IniFile.ReadBool('Settings', 'ScheduleC5', False);
sScheduleS1 := IniFile.ReadInteger('Settings', 'ScheduleS1', 60);
sScheduleS2 := IniFile.ReadString('Settings', 'ScheduleS2', '03:20');
sScheduleS3 := IniFile.ReadString('Settings', 'ScheduleS3', '24:00');
iDUNAutoQuitTime := IniFile.ReadInteger('DUN', 'AutoQuitTime', 15);
bDUNAutoQuit := IniFile.ReadBool('DUN', 'AutoQuit', False);
sDUNConnection := IniFile.ReadString('DUN', 'Connection', '');
sDUNUsername := IniFile.ReadString('DUN', 'Username', '');
sDUNPassword := MHDecrypt(IniFile.ReadString('DUN', 'Password', ''));
bDUNAskForPassword := IniFile.ReadBool('DUN', 'AskForPassword', False);
bDUNNormalQuit := IniFile.ReadBool('DUN', 'DUNNormalQuit', False);
bViewStatusAtEnd := IniFile.ReadBool('Settings', 'ViewStatusAtEnd', True);
sSoundFile1 := IniFile.ReadString('Sound', 'SoundFile1', S+'newmail.wav');
sSoundFile2 := IniFile.ReadString('Sound', 'SoundFile2', S+'error.wav');
sSoundFile3 := IniFile.ReadString('Sound', 'SoundFile3', S+'status.wav');
sToolbarButtons := IniFile.ReadString('Style', 'ToolbarButtons', '1, 0, 2, 3, 0, 4, 5, 6, 7, 8, 0, 9, 10');
sToolbarBKBitmap := IniFile.ReadString('Style', 'Background', '');
bFlatButtons := IniFile.ReadBool('Style', 'FlatButtons', True);
bOfficeFonts := IniFile.ReadBool('Style', 'UseOfficeFonts', False);
bSmallToolbarButtons := IniFile.ReadBool('Style', 'SmallToolbarButtons', False);
bShowCntInBrackets := IniFile.ReadBool('Settings', 'ShowCountInBrackets', False);
bHideAnimations := IniFile.ReadBool('Style', 'HideAnimations', False);
IniFile.Free;
//Stuff
Screen.Cursors[crHandCursor] := LoadCursor(hInstance, 'PX400');
NativeReg := TRegistry.Create;
NativeReg.RootKey := HKEY_LOCAL_MACHINE;
NativeReg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run', True);
bStartAtWindowsStart := NativeReg.ValueExists('PhoenixMail');
NativeReg.CloseKey;
NativeReg.Free;
sHomepage := sMHHomepage;
//TEMail
CurrentEMail := TEMail.Create;
// Language
if (sLanguage <> 'English') or (bAskForLanguage) then begin
S := sLanguageFolder+sLanguage+'.lng';
if (bAskForLanguage) or (FileExists(S)= False) then begin
LanguageForm := TLanguageForm.Create(Application);
if LanguageForm.Filename = '' then LanguageForm.ShowModal;
Application.ProcessMessages;
S := LanguageForm.Filename;
sLanguage := Copy(ExtractFileName(S), 1, Length(ExtractFileName(S))-4);
LanguageForm.Free;
end;
if FileExists(S) then begin
LoadLanguageFile(S);
bLanguageLoaded := True;
end;
end;
SaveMessage := False;
end;
procedure ClearUpPX;
var
NativeReg: TRegistry;
IniFile: TIniFile;
begin
IniFile := TIniFile.Create(sSettingsFile);
IniFile.WriteBool('Settings', 'Protocol', bMakeProtocol);
IniFile.WriteBool('Settings', 'ShowTipsOnStartUp', bShowTips);
IniFile.WriteInteger('Settings', 'ActualTip', iActualTip);
IniFile.WriteBool('Settings', 'AskToGoOffline', bAskToGoOffline);
IniFile.WriteString('Settings', 'VirusScanner', sVirusProg);
IniFile.WriteString('Settings', 'ScannerParameter', sVirusParams);
IniFile.WriteString('Settings', 'LastFolder', sLastFolder);
IniFile.WriteBool('Settings', 'RunScannerMinimized', bVirusMin);
IniFile.WriteBool('Settings', 'AskForDelFromServer', bAskForDelFromServer);
IniFile.WriteBool('Settings', 'CheckForStdEMail', bCheckForStdEMail);
IniFile.WriteBool('Settings', 'ListMailsAtDownload', bListMailsAtDownload);
IniFile.WriteString('Settings', 'MessageFont', sMessageFont);
IniFile.WriteInteger('Settings', 'FontSize', iFontSize);
IniFile.WriteInteger('Settings', 'FontColor', iFontColor);
IniFile.WriteInteger('Settings', 'MarkAsReadSec', iMarkAsReadSec);
IniFile.WriteString('Settings', 'LastAttSaveDir', sLastAttSaveDir);
IniFile.WriteString('Settings', 'LastAttOpenDir', sLastAttOpenDir);
IniFile.WriteString('Settings', 'CustAddressBook', sCustAddressBook);
IniFile.WriteBool('Settings', 'FriendlyPrinter', bFriendlyPrinter);
IniFile.WriteBool('Settings', 'AskForLanguage', bAskForLanguage);
IniFile.WriteString('Settings', 'Language', sLanguage);
IniFile.WriteBool('Settings', 'GoOnlineAtStart', bGoOnlineAtStart);
IniFile.WriteBool('Settings', 'ScheduleC1', bScheduleC1);
IniFile.WriteBool('Settings', 'ScheduleC2', bScheduleC2);
IniFile.WriteBool('Settings', 'ScheduleC3', bScheduleC3);
IniFile.WriteBool('Settings', 'ScheduleC4', bScheduleC4);
IniFile.WriteBool('Settings', 'ScheduleC5', bScheduleC5);
IniFile.WriteInteger('Settings', 'ScheduleS1', sScheduleS1);
IniFile.WriteString('Settings', 'ScheduleS2', sScheduleS2);
IniFile.WriteString('Settings', 'ScheduleS3', sScheduleS3);
IniFile.WriteInteger('Settings', 'FontCharSet', iFontCharSet);
IniFile.WriteInteger('DUN', 'AutoQuitTime', iDUNAutoQuitTime);
IniFile.WriteBool('DUN', 'AutoQuit', bDUNAutoQuit);
IniFile.WriteString('DUN', 'Connection', sDUNConnection);
IniFile.WriteString('DUN', 'Username', sDUNUsername);
IniFile.WriteString('DUN', 'Password', MHEncrypt(sDUNPassword));
IniFile.WriteBool('DUN', 'AskForPassword', bDUNAskForPassword);
IniFile.WriteBool('Settings', 'ViewStatusAtEnd', bViewStatusAtEnd);
IniFile.WriteString('Sound', 'SoundFile1', sSoundFile1);
IniFile.WriteString('Sound', 'SoundFile2', sSoundFile2);
IniFile.WriteString('Sound', 'SoundFile3', sSoundFile3);
IniFile.WriteBool('DUN', 'DUNNormalQuit', bDUNNormalQuit);
IniFile.WriteString('Captions', 'Accounts', sAccountsCaption);
IniFile.WriteString('Captions', 'TrashBag', sTrashBagCaption);
IniFile.WriteString('Captions', 'Repository', sRepositoryCaption);
IniFile.WriteString('Style', 'ToolbarButtons', sToolbarButtons);
IniFile.WriteString('Style', 'Background', sToolbarBKBitmap);
IniFile.WriteBool('Style', 'FlatButtons', bFlatButtons);
IniFile.WriteBool('Style', 'UseOfficeFonts', bOfficeFonts);
IniFile.WriteBool('Style', 'SmallToolbarButtons', bSmallToolbarButtons);
IniFile.WriteBool('Settings', 'ShowCountInBrackets', bShowCntInBrackets);
IniFile.WriteBool('Style', 'HideAnimations', bHideAnimations);
IniFile.Free;
NativeReg := TRegistry.Create;
NativeReg.RootKey := HKEY_LOCAL_MACHINE;
NativeReg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run', True);
if bStartAtWindowsStart then begin
NativeReg.WriteString('PhoenixMail', '"'+Application.ExeName+'" -min');
end else begin
NativeReg.DeleteValue('PhoenixMail');
end;
NativeReg.CloseKey;
NativeReg.Free;
CurrentEMail.Free;
ClearUpLangFile;
ClearFolder(sTemporaryFolder);
ClearUpCheckForPrevInstance;
end;
end.