?? mbxsub1.pas
字號:
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Author: Fran鏾is PIETTE
Creation: Mar 20, 1999
Description: This program is used to scan an MBX file (Outlook Express) and
search for subscription messages to one of F. Piette mailing
lists. It extract EMail address from the subsject and add it
to a DBF file if not already there. DBF file is automatically
created if not found in same directory as exe file. You can
select MBX file using an entry in INI file.
I use this program to find new subscribers and send a message
to them asking for subscription postcard.
This program will not work with Delphi 1 because it uses
32 bits features such as splitter bar and long strings.
Version: 1.00
EMail: francois.piette@pophost.eunet.be
francois.piette@rtfm.be http://www.rtfm.be/fpiette
Support: Unsupported code.
Legal issues: Copyright (C) 1999 by Fran鏾is PIETTE
Rue de Grady 24, 4053 Embourg, Belgium. Fax: +32-4-365.74.56
<francois.piette@pophost.eunet.be>
This software is provided 'as-is', without any express or
implied warranty. In no event will the author be held liable
for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it
and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented,
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
4. You must register this software by sending a picture postcard
to the author. Use a nice stamp and mention your name, street
address, EMail address and any comment you like to say.
History:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
unit MbxSub1;
{$IFDEF VER80}
Bomb('Sorry, this program uses 32 bits features.');
{$ENDIF}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
IniFiles, StdCtrls, ExtCtrls, MbxFile, Db, DBTables, Bde, Grids, DBGrids,
DBCtrls, ComCtrls;
const
WM_APPSTARTUP = WM_USER + 1;
type
TAppBaseForm = class(TForm)
ToolsPanel: TPanel;
MbxHandler1: TMbxHandler;
ScanButton: TButton;
EMailTable: TTable;
PageControl1: TPageControl;
ScanTabSheet: TTabSheet;
DisplayMemo: TMemo;
EMailMemo: TMemo;
Splitter1: TSplitter;
ViewTabSheet: TTabSheet;
Panel1: TPanel;
EMailDBNavigator: TDBNavigator;
EMailDBGrid: TDBGrid;
EMailDataSource: TDataSource;
FindEdit: TEdit;
SortByDateRadioButton: TRadioButton;
SortByEmailRadioButton: TRadioButton;
OpenDialog1: TOpenDialog;
BrowseButton: TButton;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure ScanButtonClick(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
procedure FindEditChange(Sender: TObject);
procedure SortByDateRadioButtonClick(Sender: TObject);
procedure SortByEmailRadioButtonClick(Sender: TObject);
procedure BrowseButtonClick(Sender: TObject);
private
FIniFileName : String;
FInitialized : Boolean;
FDatabaseName : String;
FTableName : String;
function Extract(Item : String) : String;
procedure CreateDataTable;
procedure PackTable(aTable : TTable);
procedure WMAppStartup(var msg: TMessage); message WM_APPSTARTUP;
procedure SelectIndex;
public
procedure Display(Msg : String);
property IniFileName : String read FIniFileName write FIniFileName;
end;
function RenameToNumberedFile(From : String) : String;
function GetToken(pDelim : PCHar; Src : PChar; var Dst : String): PChar;
var
AppBaseForm: TAppBaseForm;
implementation
{$R *.DFM}
const
SectionWindow = 'Window'; // Must be unique for each window
KeyTop = 'Top';
KeyLeft = 'Left';
KeyWidth = 'Width';
KeyHeight = 'Height';
SectionData = 'Data';
KeyMbxFile = 'MbxFile';
KeySplitter = 'Splitter';
TempFileName = 'MbxSub.tmp';
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TAppBaseForm.FormCreate(Sender: TObject);
begin
FIniFileName := LowerCase(ExtractFileName(Application.ExeName));
FIniFileName := Copy(FIniFileName, 1, Length(FIniFileName) - 3) + 'ini';
FDatabaseName := LowerCase(ExtractFilePath(Application.ExeName));
FTableName := 'subscribe.dbf';
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TAppBaseForm.FormShow(Sender: TObject);
var
IniFile : TIniFile;
begin
if not FInitialized then begin
FInitialized := TRUE;
IniFile := TIniFile.Create(FIniFileName);
Width := IniFile.ReadInteger(SectionWindow, KeyWidth, Width);
Height := IniFile.ReadInteger(SectionWindow, KeyHeight, Height);
Top := IniFile.ReadInteger(SectionWindow, KeyTop,
(Screen.Height - Height) div 2);
Left := IniFile.ReadInteger(SectionWindow, KeyLeft,
(Screen.Width - Width) div 2);
DisplayMemo.Width := IniFile.ReadInteger(SectionData, KeySplitter, Width div 2);
MbxHandler1.FileName := IniFile.ReadString(SectionData, KeyMbxFile,
'c:\Windows\Application Data\Microsoft\Outlook Express\Mail\Dossier24.mbx');
IniFile.WriteString(SectionData, KeyMbxFile, MbxHandler1.FileName);
IniFile.Destroy;
DisplayMemo.Clear;
EMailMemo.Clear;
FindEdit.Clear;
SortByEmailRadioButton.Checked := TRUE;
PageControl1.ActivePage := ScanTabSheet;
Caption := 'MbxSub - ' + ExtractFileName(MbxHandler1.FileName);
PostMessage(Handle, WM_APPSTARTUP, 0, 0);
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TAppBaseForm.FormClose(Sender: TObject; var Action: TCloseAction);
var
IniFile : TIniFile;
begin
IniFile := TIniFile.Create(FIniFileName);
IniFile.WriteInteger(SectionWindow, KeyTop, Top);
IniFile.WriteInteger(SectionWindow, KeyLeft, Left);
IniFile.WriteInteger(SectionWindow, KeyWidth, Width);
IniFile.WriteInteger(SectionWindow, KeyHeight, Height);
IniFile.WriteInteger(SectionData, KeySplitter, DisplayMemo.Width);
IniFile.Destroy;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TAppBaseForm.WMAppStartup(var msg: TMessage);
var
I : Integer;
begin
Update;
EMailTable.DatabaseName := FDatabaseName;
EMailTable.TableName := FTableName;
try
EMailTable.Open;
except
on E:EDBEngineError do begin
if E.Errors[0].ErrorCode = DBIERR_NOSUCHTABLE then begin
Display('Missing datafile. Creating a new file.');
CreateDataTable;
EMailTable.Open;
end
else if E.Errors[0].ErrorCode = DBIERR_NOSUCHINDEX then begin
Display('Missing index file. Creating new index file.');
DeleteFile(FDatabaseName + TempFileName);
RenameFile(FDatabaseName + FTableName, FDatabaseName + TempFileName);
CreateDataTable;
DeleteFile(FDatabaseName + FTableName);
RenameFile(FDatabaseName + TempFileName, FDatabaseName + FTableName);
PackTable(EMailTable);
EMailTable.Open;
end
else if (E.Errors[0].Category = ERRCAT_DATACORRUPT) and
(E.ErrorCount > 1) and
(UpperCase(ExtractFileExt(E.Errors[1].Message)) = '.MDX') then begin
Display('Corrupt index file. Rebuilding index file.');
DeleteFile(FDatabaseName + TempFileName);
RenameFile(FDatabaseName + FTableName, FDatabaseName + TempFileName);
CreateDataTable;
DeleteFile(FDatabaseName + FTableName);
RenameFile(FDatabaseName + TempFileName, FDatabaseName + FTableName);
PackTable(EMailTable);
EMailTable.Open;
end
else if E.Errors[0].ErrorCode = DBIERR_HEADERCORRUPT then begin
Display('Corrupt data file.');
Display('Save corrupted file to: ''' +
RenameToNumberedFile(FDatabaseName +
FTableName) +
'''');
Display('Creating new data file.');
CreateDataTable;
EMailTable.Open;
end
else begin
Display(E.ClassName + ': ' + E.Message);
for I := 0 to E.ErrorCount - 1 do
Display(IntToStr(E.Errors[I].ErrorCode) + '/' +
IntToStr(E.Errors[I].Category) +
': ' + E.Errors[I].Message);
end;
end;
end;
EMailTable.Close;
end;
procedure TAppBaseForm.Display(Msg : String);
begin
DisplayMemo.Lines.BeginUpdate;
try
if DisplayMemo.Lines.Count > 200 then begin
while DisplayMemo.Lines.Count > 200 do
DisplayMemo.Lines.Delete(0);
end;
DisplayMemo.Lines.Add(Msg);
finally
DisplayMemo.Lines.EndUpdate;
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
//Fri, 19 Mar 1999 18:50:07 +0100
function ExtractDate(S : String) : TDateTime;
var
P : PChar;
Token : String;
Year, Month, Day : Word;
begin
P := PChar(S);
if P = nil then begin
Result := 0;
Exit;
end;
// Get day of week
P := GetToken(' ', P, Token);
Token := LowerCase(Copy(Trim(Token), 1, 3));
if not ((Token = 'mon') or (Token = 'tue') or
(Token = 'wed') or (Token = 'thu') or
(Token = 'fri') or (Token = 'sat') or (Token = 'sun')) then
raise Exception.Create('Invalid day name: ' + S);
// get day
P := GetToken(' ', P, Token);
Day := StrToInt(Trim(Token));
// get month
P := GetToken(' ', P, Token);
Token := LowerCase(Trim(Token));
if Token = 'jan' then
Month := 1
else if Token = 'feb' then
Month := 2
else if Token = 'mar' then
Month := 3
else if Token = 'apr' then
Month := 4
else if Token = 'may' then
Month := 5
else if Token = 'jun' then
Month := 6
else if Token = 'jul' then
Month := 7
else if Token = 'aug' then
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -