ufrmMain.pas
上传用户:yjb1804
上传日期:2021-01-30
资源大小:3105k
文件大小:71k
- unit ufrmMain;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs,uSendMail, Menus, ExtCtrls, ComCtrls,
- ImgList,dxBarExtItems, dxBar, cxClasses, cxControls, cxSplitter,
- cxContainer, cxTreeView, msxmldom, JvExControls,
- JvNavigationPane, JvExExtCtrls, Mail2000, cxGraphics,
- cxCustomData, cxStyles, cxTL, cxInplaceContainer,uRecvEmail,
- cxTextEdit, cxCheckBox, OleServer,
- ActnList, cxDataStorage, cxEdit, cxGridCustomTableView,
- cxGridTableView, cxGridCustomView, DB, cxGridLevel, cxGrid,
- cxDBData, cxGridDBTableView, OleCtrls, OALib_TLB, JvComponentBase,
- JvCipher, RzTray, cxGroupBox, CommCtrl, cxLabel, cxCalendar, SHDocVw, IniFiles,
- cxImage,uRulerMgr,idSMTP, uCheckEmail, cxFilter, cxData, uHtmlEdit,
- dxStatusBar, dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinCaramel,
- dxSkinCoffee, {dxSkinDarkRoom,} dxSkinDarkSide, {dxSkinFoggy,}
- dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
- dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
- dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
- dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinPumpkin, {dxSkinSeven,}
- {dxSkinSharp,} dxSkinSilver, {dxSkinSpringTime,} dxSkinStardust,
- dxSkinSummer2008, dxSkinsDefaultPainters, dxSkinValentine,
- dxSkinXmas2008Blue, {cxTLdxBarBuiltInMenu,} dxSkinscxPCPainter,
- cxLookAndFeelPainters, dxSkinsdxBarPainter, OutlookXP;
- type
- TfrmMain = class(TForm)
- dxBarManager1: TdxBarManager;
- dxBarManager1Bar1: TdxBar;
- dxBarManager1Bar2: TdxBar;
- dxBarManager1Bar5: TdxBar;
- dxBarSubItem1: TdxBarSubItem;
- dxBarSubItem2: TdxBarSubItem;
- dxBarSubItem3: TdxBarSubItem;
- dxBarSubItem4: TdxBarSubItem;
- dxBarSubItem5: TdxBarSubItem;
- dxBarSubItem6: TdxBarSubItem;
- dxBarButton1: TdxBarLargeButton;
- dxBarButton3: TdxBarLargeButton;
- dxBarButton4: TdxBarLargeButton;
- dxBarButton5: TdxBarLargeButton;
- dxBarButton6: TdxBarLargeButton;
- dxBarButton7: TdxBarLargeButton;
- dxBarButton8: TdxBarLargeButton;
- dxBarButton9: TdxBarLargeButton;
- dxBarButton10: TdxBarLargeButton;
- dxBarButton11: TdxBarLargeButton;
- dxBarLargeButton1: TdxBarLargeButton;
- btnSendAll: TdxBarLargeButton;
- dxBarLargeButton3: TdxBarLargeButton;
- dxBarLargeButton4: TdxBarLargeButton;
- btnRecp: TdxBarLargeButton;
- dxBarLargeButton6: TdxBarLargeButton;
- dxBarLargeButton7: TdxBarLargeButton;
- dxBarButton15: TdxBarButton;
- dxBarColorCombo1: TdxBarColorCombo;
- dxBarFontNameCombo1: TdxBarFontNameCombo;
- dxBarDateCombo1: TdxBarDateCombo;
- dxBarSpinEdit1: TdxBarSpinEdit;
- BarProgress: TdxBarProgressItem;
- lblProgress: TdxBarStatic;
- dxBarLargeButton9: TdxBarLargeButton;
- dxBarLargeButton10: TdxBarLargeButton;
- btnNewWindow: TdxBarLargeButton;
- btnArrangeAll: TdxBarLargeButton;
- btnSplit: TdxBarLargeButton;
- btnNew: TdxBarLargeButton;
- btnOpen: TdxBarLargeButton;
- btnSendAndRecv: TdxBarLargeButton;
- btnClose: TdxBarLargeButton;
- btnPrint: TdxBarLargeButton;
- btnSaveAs: TdxBarLargeButton;
- btnSaveAll: TdxBarLargeButton;
- dxBarSubItem7: TdxBarSubItem;
- dxBarLargeButton8: TdxBarLargeButton;
- dxBarButton2: TdxBarButton;
- dxBarButton12: TdxBarButton;
- dxbrbtn1: TdxBarButton;
- dxbrbtn2: TdxBarButton;
- Panel1: TPanel;
- cxSplitter1: TcxSplitter;
- Panel2: TPanel;
- Panel3: TPanel;
- PnlAddr: TPanel;
- il1: TImageList;
- JvNavPaneToolPanel1: TJvNavPaneToolPanel;
- JvNavPaneToolPanel3: TJvNavPaneToolPanel;
- Panel4: TPanel;
- Panel5: TPanel;
- cxSplitter2: TcxSplitter;
- cxSplitter3: TcxSplitter;
- lblMsgProgress: TdxBarStatic;
- BarProgressMsg: TdxBarProgressItem;
- lblError: TdxBarStatic;
- cxStyleRepository1: TcxStyleRepository;
- cxStyle1: TcxStyle;
- dxBarButton13: TdxBarButton;
- pm1: TdxBarPopupMenu;
- dxBarSubItem8: TdxBarSubItem;
- dxBarButton14: TdxBarButton;
- dxBarButton16: TdxBarButton;
- dxBarButton17: TdxBarButton;
- dxBarButton18: TdxBarButton;
- dxBarButton19: TdxBarButton;
- dxbrbtn3: TdxBarButton;
- dxbrbtn4: TdxBarButton;
- dxbrbtn5: TdxBarButton;
- dxbrbtn6: TdxBarButton;
- dxbrbtn7: TdxBarButton;
- dxbrbtn8: TdxBarButton;
- dxbrbtn9: TdxBarButton;
- dxbrbtn10: TdxBarButton;
- dxbrbtn11: TdxBarButton;
- dxBarSpinEdit2: TdxBarSpinEdit;
- dxBarToolbarsListItem1: TdxBarToolbarsListItem;
- dxbrtlbrslstm1: TdxBarToolbarsListItem;
- dxbrtlbrslstm2: TdxBarToolbarsListItem;
- dxbrtlbrslstm3: TdxBarToolbarsListItem;
- ActionList1: TActionList;
- actRecvCur: TAction;
- actRecvAll: TAction;
- actRecvThenDelete: TAction;
- dxBarToolbarsListItem2: TdxBarToolbarsListItem;
- dxBarControlContainerItem1: TdxBarControlContainerItem;
- dxbrbtn12: TdxBarButton;
- dxbrlrgbtn1: TdxBarLargeButton;
- dxBarButton20: TdxBarButton;
- btnRecpOne: TdxBarButton;
- dxbrbtn14: TdxBarButton;
- dxBarButton21: TdxBarButton;
- lblTotal: TdxBarStatic;
- cxGrid1Level1: TcxGridLevel;
- cxGrid1: TcxGrid;
- tvTableView: TcxGridTableView;
- gtvColReaded: TcxGridColumn;
- gtvColSender: TcxGridColumn;
- gtvColSubject: TcxGridColumn;
- gtvColDate: TcxGridColumn;
- gtvColSize: TcxGridColumn;
- gtvColAttch: TcxGridColumn;
- actNewEmail: TAction;
- actAddrBook: TAction;
- ltAddr: TcxTreeList;
- cxtrlstclmnAddrcxTreeListColumn1: TcxTreeListColumn;
- cxtrlstclmnAddrcxTreeListColumn2: TcxTreeListColumn;
- cxtrlstclmnAddrcxTreeListColumn3: TcxTreeListColumn;
- tvEMail: TcxTreeView;
- dxbrbtn15: TdxBarButton;
- actSuspend: TAction;
- actStop: TAction;
- dxbrbtn16: TdxBarButton;
- TrayIcon: TRzTrayIcon;
- cxgrpbx1: TcxGroupBox;
- pnlAttch: TPanel;
- gtvColContentFilename: TcxGridColumn;
- lv1: TListView;
- gtvColUIDL: TcxGridColumn;
- gtvColMyAddr: TcxGridColumn;
- gtvColAttchFullName: TcxGridColumn;
- btnTurn: TdxBarLargeButton;
- btnDeleteEmail: TdxBarLargeButton;
- dxbrlrgbtn4: TdxBarLargeButton;
- dxbrlrgbtn5: TdxBarLargeButton;
- pm2: TdxBarPopupMenu;
- dxbrbtn17: TdxBarButton;
- dxbrbtn18: TdxBarButton;
- btnUnRead: TdxBarButton;
- actReply: TAction;
- actResend: TAction;
- actDeleteCurEmail: TAction;
- dxbrbtn21: TdxBarButton;
- dxbrbtn22: TdxBarButton;
- dxbrbtn23: TdxBarButton;
- actSendPendingEmail: TAction;
- actRename: TAction;
- actDeletePop: TAction;
- dxbrbtn24: TdxBarButton;
- dxbrbtn25: TdxBarButton;
- dxbrbtn26: TdxBarButton;
- dxbrbtn27: TdxBarButton;
- dxbrbtn28: TdxBarButton;
- actProperty: TAction;
- dxbrbtn29: TdxBarButton;
- actNewAccunt: TAction;
- cxstyl1: TcxStyle;
- cxstyl2: TcxStyle;
- cxstyl3: TcxStyle;
- cxstyl4: TcxStyle;
- cxstyl5: TcxStyle;
- imgFlag: TImage;
- imgRecyle: TImage;
- imgBoxNotOpen: TImage;
- imgBoxOpen: TImage;
- imgAttch: TImage;
- gtvColUnUsed: TcxGridColumn;
- tmrAttamp: TTimer;
- btn1: TdxBarLargeButton;
- btn2: TdxBarLargeButton;
- pmLeft: TdxBarPopupMenu;
- pmRight: TdxBarPopupMenu;
- dxbrbtnAdd: TdxBarButton;
- dxbrbtn31: TdxBarButton;
- dxbrbtnEdit: TdxBarButton;
- dxbrbtnDel: TdxBarButton;
- dxbrbtn34: TdxBarButton;
- dxbrbtn35: TdxBarButton;
- dxbrbtn36: TdxBarButton;
- dxbrbtn37: TdxBarButton;
- dxbrbtn38: TdxBarButton;
- dxbrbtn39: TdxBarButton;
- dxbrbtn40: TdxBarButton;
- dxbrbtn41: TdxBarButton;
- tmrEmailAwake: TTimer;
- btnDetectEmail: TdxBarLargeButton;
- btn4: TdxBarLargeButton;
- lblDetect: TdxBarStatic;
- btnCleanRecvs: TdxBarButton;
- btnCleanAttamp: TdxBarButton;
- btnCleanSents: TdxBarButton;
- btnCleanDraft: TdxBarButton;
- actCleanRecvs: TAction;
- actCleanSents: TAction;
- actCleanDraft: TAction;
- actCleanAttamp: TAction;
- btnDeleteOneEmail: TdxBarButton;
- btn3: TdxBarButton;
- actTurn: TAction;
- HtmlEdit: THtmlEdit;
- btn5: TdxBarButton;
- cxstylrpstry1: TcxStyleRepository;
- cxstyl6: TcxStyle;
- cxstyl7: TcxStyle;
- cxstyl8: TcxStyle;
- btn6: TdxBarButton;
- btn7: TdxBarButton;
- btn8: TdxBarButton;
- btn9: TdxBarButton;
- btn10: TdxBarButton;
- btn11: TdxBarButton;
- btn12: TdxBarButton;
- btn13: TdxBarButton;
- btn14: TdxBarButton;
- btn15: TdxBarButton;
- actViewEmail: TAction;
- dxbrsbtm1: TdxBarSubItem;
- pm3: TdxBarPopupMenu;
- btn16: TdxBarButton;
- btn17: TdxBarButton;
- btn18: TdxBarButton;
- btn19: TdxBarButton;
- pm4: TdxBarPopupMenu;
- btn20: TdxBarButton;
- btn21: TdxBarButton;
- btn22: TdxBarButton;
- lbl1: TdxBarStatic;
- dxbrprgrstm1: TdxBarProgressItem;
- dxbrprgrstm2: TdxBarProgressItem;
- dxbrpmn1: TdxBarPopupMenu;
- dxBarButton22: TdxBarButton;
- dxBarButton23: TdxBarButton;
- dxBarButton24: TdxBarButton;
- dxBarButton25: TdxBarButton;
- dxBarButton26: TdxBarButton;
- dxBarButton27: TdxBarButton;
- ol1: TContactItem;
- dxbrbtn13: TdxBarButton;
- procedure JvNavPaneToolPanel1ButtonClick(Sender: TObject;
- Index: Integer);
- procedure FormCreate(Sender: TObject);
- procedure tvEMailDeletion(Sender: TObject; Node: TTreeNode);
- procedure popEmailProgress(Sender: TObject; Total, Current: Integer);
- procedure MSGProgress(Sender: TObject; Total, Current: Integer);
- procedure FormDestroy(Sender: TObject);
- procedure actRecvAllExecute(Sender: TObject);
- procedure actRecvThenDeleteExecute(Sender: TObject);
- procedure actRecvCurExecute(Sender: TObject);
- procedure actNewEmailExecute(Sender: TObject);
- procedure actAddrBookExecute(Sender: TObject);
- procedure actSuspendExecute(Sender: TObject);
- procedure actStopExecute(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure tvEMailClick(Sender: TObject);
- procedure lv1DblClick(Sender: TObject);
- procedure gtvColReadedGetDisplayText(
- Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
- var AText: String);
- procedure actDeleteCurEmailExecute(Sender: TObject);
- procedure actSendPendingEmailExecute(Sender: TObject);
- procedure dxBarLargeButton9Click(Sender: TObject);
- procedure actRenameExecute(Sender: TObject);
- procedure tvEMailExit(Sender: TObject);
- procedure tvEMailEdited(Sender: TObject; Node: TTreeNode;
- var S: String);
- procedure tvEMailEditing(Sender: TObject; Node: TTreeNode;
- var AllowEdit: Boolean);
- procedure actDeletePopExecute(Sender: TObject);
- procedure btnSendAndRecvClick(Sender: TObject);
- procedure FormShow(Sender: TObject);
- procedure actNewAccuntExecute(Sender: TObject);
- procedure tvEMailMouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure tvTableViewMouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure actPropertyExecute(Sender: TObject);
- procedure tmrAttampTimer(Sender: TObject);
- procedure TrayIconLButtonDown(Sender: TObject);
- procedure TrayIconRButtonDown(Sender: TObject);
- procedure dxbrbtn34Click(Sender: TObject);
- procedure dxbrbtn37Click(Sender: TObject);
- procedure dxbrbtn39Click(Sender: TObject);
- procedure btn1Click(Sender: TObject);
- procedure dxBarButton3Click(Sender: TObject);
- procedure dxbrbtn41Click(Sender: TObject);
- procedure TrayIconMinimizeApp(Sender: TObject);
- procedure TrayIconRestoreApp(Sender: TObject);
- procedure btnDetectEmailClick(Sender: TObject);
- procedure dxbrbtn35Click(Sender: TObject);
- procedure btn4Click(Sender: TObject);
- procedure dxbrlrgbtn4Click(Sender: TObject);
- procedure dxbrbtn18Click(Sender: TObject);
- procedure actCleanRecvsExecute(Sender: TObject);
- procedure btnCleanSentsClick(Sender: TObject);
- procedure btnCleanDraftClick(Sender: TObject);
- procedure btnCleanAttampClick(Sender: TObject);
- procedure btnUnReadClick(Sender: TObject);
- procedure actReplyExecute(Sender: TObject);
- procedure actTurnExecute(Sender: TObject);
- procedure tvTableViewFocusedRecordChanged(
- Sender: TcxCustomGridTableView; APrevFocusedRecord,
- AFocusedRecord: TcxCustomGridRecord;
- ANewItemRecordFocusingChanged: Boolean);
- procedure tvTableViewCellDblClick(Sender: TcxCustomGridTableView;
- ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
- AShift: TShiftState; var AHandled: Boolean);
- procedure lv1Deletion(Sender: TObject; Item: TListItem);
- procedure actCleanSentsExecute(Sender: TObject);
- procedure actCleanDraftExecute(Sender: TObject);
- procedure actCleanAttampExecute(Sender: TObject);
- procedure JvNavPaneToolPanel3Close(Sender: TObject);
- procedure btn12Click(Sender: TObject);
- procedure tmrEmailAwakeTimer(Sender: TObject);
- procedure actViewEmailExecute(Sender: TObject);
- procedure btn2Click(Sender: TObject);
- procedure btn9Click(Sender: TObject);
- procedure btn10Click(Sender: TObject);
- procedure dxBarButton2Click(Sender: TObject);
- procedure btnSaveAllClick(Sender: TObject);
- procedure btn17Click(Sender: TObject);
- procedure dxBarButton22Click(Sender: TObject);
- procedure dxBarButton23Click(Sender: TObject);
- procedure dxBarButton24Click(Sender: TObject);
- procedure dxBarButton27Click(Sender: TObject);
- procedure ltAddrDblClick(Sender: TObject);
- procedure dxbrbtnAddClick(Sender: TObject);
- procedure dxbrbtnDelClick(Sender: TObject);
- procedure dxbrbtnEditClick(Sender: TObject);
- procedure dxBarLargeButton10Click(Sender: TObject);
- procedure dxBarButton25Click(Sender: TObject);
- procedure dxBarButton12Click(Sender: TObject);
- private
- { Private declarations }
- //FEmailCount:Integer;
- //FCurrent:Integer;
- FEmailChecker:TCheckEmail; //检查新邮件
- FShowEmailSending:Boolean; //是否正在显示 未发邮件表格
- FEmailPropertyPageIndex:Integer;
- FUserName,
- FpopServer,
- FPwd:string;
- FRecvEMail:TRecvEmail; //pop3
- FFilter:TRuleItems; //过滤设置
- FSendEmailBox:boolean;
- FOldNodeText:string;
- FMutex:THandle;
- FUIDLList:THashedStringList; //保存已经接收的邮件的uidl
- FNewEmailUIDLList:THashedStringList; //保存新邮件UIDL
- procedure MyOnRecvEMailProgress(Sender: TObject; Total, Current: Integer) ;
- procedure MyOnRecvMsgProgress(Sender: TObject; Total, Current: Integer) ;
- procedure OnError(Sender:TObject;ErrMsg:string);
- procedure OnRetrieveed(sender: TObject;CurNum,Total:Integer;UIDL:String);
- procedure OnRecvAttch(sender:TObject; FileName:string;FileStream:TMemoryStream;CurNum,Total:Integer);
- procedure RecvComplete(Sender:TObject);
- procedure OnGetUIDL(Sender:TObject;uidl:String;var Handle:Boolean);
- procedure OnFilter(Sender:TObject;Action:TRuleAction;EmailSubject:string;EmailFrom:string;var DeleteIt:Boolean;var Ignore:Boolean);
- procedure BeginRecv(Sender:TObject);
- procedure EndRecv(Sender:TObject);
- procedure OnTerminate(Sender:TObject);
- procedure OnOneSend(Sender:TObject;Email:TEmailInfo);
- procedure OnOneSendEnd(Sender:TObject;Email:TEmailInfo);
-
- procedure DetectingEmail(Sender:TObject;Runing:Boolean) ;
- procedure OnNewEmailArrive(Sender:TObject;NewEmailUIDLs:TStrings);
- procedure MultiThreadSendComplete(Sender:TObject);
- procedure MultiThreadSendError(Sender:TObject;Email:TEmailInfo;ErrMsg:string);
- procedure AttachEvent;
- procedure GetUIDLS;
- function GetSeletedEmailAddr:string;
- procedure LoadDefaultSavePath;
- protected
- procedure WndProc(var Message: TMessage); override;
- procedure AddFileRelation(lv: TListView; filename: string);
- procedure MegerOpenIcon(var bitmap:TBitmap); //合并2张icon图片
- procedure MegerCloseIcon(var bitmap:TBitmap); //合并2张icon图片
- public
- { Public declarations }
- FRuleSaveTo,
- FEmailSaveTo,
- FAttchSaveTo:string;
- FRetryAgain:Boolean; //是否重复接收
- FEmailArrivedPlaySound:string; // 新邮件到来播放的声音文件路径
- FBlackList,
- FWhiteList:TStrings; //黑白名单
- FEmailDetect:TEmailDetectOption;
- EmailSenderMgr:TEmailSenderMgr;
- procedure GetCurPop3EMail(delete:Boolean=False);
- procedure GetAllPop3EMail(delete:Boolean=False);
- procedure LoadEmails(TreeView:TcxTreeView);
- procedure LoadAddrs;
- procedure ClearTableView(tv:TcxGridTableView);
- procedure LoadRecvEmail;
- procedure LoadSendEmail;
- procedure LoadDraft;
- procedure LoadAttamp;
- procedure LoadRules;
- procedure LoadFromFile(EmailAddr:string;Files:TStringList);
- procedure SendEmailFromFile(FilePath:string);
- procedure CreateDirs;
- procedure LoadSending;
- procedure LoadContact;
- end;
- var
- frmMain: TfrmMain;
- implementation
- uses ufrmNewSMTP, NativeXml, uCommon, ufrmCloseTip,ShellApi, ActiveX,
- uMyXml, FMTips, ufrmEmailBoxProperty, UEmailFile, ufrmRule,
- ufrmFilterPopTip, ufrmAttchMgr, uBaseEditorForm, ufrmWriteEmail,
- ufrmViewEmail, ufrmAwake, uEmailAwake, ufrmEmailAwaked, ufrmSingnals,ufrmAddr,ufrmAbout,ComObj;
- {$R *.dfm}
- procedure TfrmMain.MegerCloseIcon(var bitmap:TBitmap);
- begin
- bitmap.Canvas.Draw(0,0,imgBoxNotOpen.Picture.Graphic);
- bitmap.Canvas.Draw(imgBoxOpen.Width,0,imgAttch.Picture.Graphic);
- end;
- procedure TfrmMain.MegerOpenIcon(var bitmap:TBitmap); //合并2张icon图片
- begin
- bitmap.Canvas.Draw(0,0,imgBoxOpen.Picture.Graphic);
- bitmap.Canvas.Draw(imgBoxOpen.Width,0,imgAttch.Picture.Graphic);
- end;
- procedure TfrmMain.JvNavPaneToolPanel1ButtonClick(Sender: TObject;
- Index: Integer);
- begin
- PnlAddr.Visible:=not PnlAddr.Visible
- end;
- procedure TfrmMain.LoadAddrs;
- {var
- xml:TMyXml;
- Lst:TList;
- I:Integer; }
- begin
- { xml:=TMyXml.Create(AppPath+'EmailServers.xml');
- try
- lst:=TList.Create;
- try
- if xml.Root.FindNode('emails')=nil then Exit;
- Lst.Clear;
- xml.Root.FindNode('emails').NodesByName('email',lst);
- for I:=0 to Lst.Count-1 do
- begin
- with ltAddr.Add do
- begin
- Values[0]:=False;
- Values[1]:=TXmlNode(Lst[I]).ReadString('displayname');
- Values[2]:=TXmlNode(Lst[I]).ReadString('addr');
- end;
- end;
- finally
- Lst.Free;
- end;
- finally
- xml.Free;
- end; }
- end;
- procedure TfrmMain.LoadEmails(TreeView:TcxTreeView);
- var
- xml:TMyXml;
- Lst:TList;
- tvNode:TTreeNode;
- info:PPopInfo;
- I:Integer;
- begin
- xml:=TMyXml.Create(AppPath+'EmailServers.xml');
- try
- if (xml.Root.FindNode('pop3s')=nil) then Exit;
- //加载所有的pop3服务器到treeview
- lst:=TList.Create;
- try
- xml.Root.FindNode('pop3s').NodesByName('pop3',lst);
- TreeView.Items.Clear;
- for I:=0 to Lst.Count-1 do
- begin
- tvNode:= TreeView.Items.Add(nil,TXmlNode(Lst[I]).ReadString('displayname'));
- tvNode.ImageIndex:=109;
- tvNode.SelectedIndex:=36;
- tvNode.StateIndex:=104;
- New(info);
- ZeroMemory(info,SizeOf(TPopInfo));
- info.EMailAddr:=TXmlNode(Lst[I]).ReadString('emailaddr');
- info.pwd:=TXmlNode(Lst[I]).ReadString('pwd');
- info.saveto:= TXmlNode(Lst[I]).ReadString('emailsaveto');
- info.pop3Server:= TXmlNode(Lst[I]).ReadString('pop3server');
- tvnode.Data:=info;
- with TreeView.Items.AddChild(tvNode,'收件箱') do
- begin
- ImageIndex:=109;
- SelectedIndex:=36;
- StateIndex:=104;
- end;
- with TreeView.Items.AddChild(tvNode,'已发邮件') do
- begin
- ImageIndex:=109;
- SelectedIndex:=36;
- StateIndex:=104;
- end;
- with TreeView.Items.AddChild(tvNode,'发件箱') do
- begin
- ImageIndex:=109;
- SelectedIndex:=36;
- StateIndex:=104;
- end;
- with TreeView.Items.AddChild(tvNode,'草稿箱')do
- begin
- ImageIndex:=52;
- SelectedIndex:=48;
- StateIndex:=48;
- end;
- with TreeView.Items.AddChild(tvNode,'定时邮件') do
- begin
- ImageIndex:=86;
- SelectedIndex:=87;
- StateIndex:=87;
- end;
- end;
- finally
- Lst.Free;
- end;
- finally
- xml.Free;
- end;
- end;
- procedure TfrmMain.FormCreate(Sender: TObject);
- var
- Xml:TAppXml;
- begin
- //备份xml文件
- DeleteFile(PAnsiChar(ExtractFilePath(ParamStr(0))+'EmailServers_Backup.xml')) ;
- CopyFile(PAnsiChar(ExtractFilePath(ParamStr(0))+App_Xml),
- PAnsiChar(ExtractFilePath(ParamStr(0))+'EmailServers_Backup.xml'),
- False);
- EmailSenderMgr:=TEmailSenderMgr.Create;
- EmailSenderMgr.OnComplete:=Self.MultiThreadSendComplete;
- EmailSenderMgr.OnSendError:=Self.MultiThreadSendError;
- EmailSenderMgr.OnOneSend:=self.OnOneSend;
- EmailSenderMgr.OnOneSend:=OnOneSendEnd;
- FEmailPropertyPageIndex:=0;
- FNewEmailUIDLList:=THashedStringList.Create;
- FUIDLList:=THashedStringList.Create;
- GetUIDLS;
- FFilter:=TRuleItems.Create;
- LoadRules;
- FMutex:=0;
- pnlAttch.Visible:=false;
- FRecvEmail:=nil;
- LoadEmails(tvEMail);
- LoadAddrs;
- LoadRules;
- LoadContact;
- FBlackList:=THashedStringList.Create;
- FWhiteList:=THashedStringList.Create;
- LoadDefaultSavePath;
- CreateDirs;
- FEmailChecker:=TCheckEmail.Create;
- xml:=TAppXml.Create;
- try
- xml.GetUIDLS(FEmailChecker.OldUIDLs);
- finally
- xml.Free;
- end;
- FEmailChecker.OnNewEmailArrive:=OnNewEmailArrive;
- FEmailChecker.OnEnterState :=DetectingEmail;
- FEmailChecker.CreateChecker;
- FEmailChecker.EnterState(asInit);
- end;
- procedure TfrmMain.tvEMailDeletion(Sender: TObject; Node: TTreeNode);
- begin
- if Node.Data<>nil then Dispose(Node.Data) ;
- end;
- procedure TfrmMain.GetCurPop3EMail(delete:Boolean=False);
- var
- N:TTreeNode;
- begin
- N:=tvEMail.Selected;
- if (N=nil) then
- begin
- ShowMessage('请选择一个邮箱');
- Exit;
- end;
- if N.Level=1 then N:=N.Parent;
- //菜单不可用
- actRecvCur.Enabled:=False;
- actRecvAll.Enabled:=False;
- actRecvThenDelete.Enabled:=False;
- actStop.Enabled:=True;
- actSuspend.Enabled:=True;
- //获取当前选中的pop3的设置
- FpopServer:=PPopInfo(N.Data).pop3Server;
- FPwd :=PPopInfo(N.Data).pwd ;
- FUserName:=PPopInfo(N.Data).EMailAddr;
- if FRecvEMail<>nil then
- begin
- FRecvEMail.Terminate;
- FRecvEMail.WaitFor;
- FRecvEMail:=nil;
- end;
- //TerminateThread(FRecvEMail.Handle,0);
- FRecvEmail:=TRecvEmail.Create(FpopServer,FUserName,FPwd);
- AttachEvent;
- FRecvEMail.DeleteAfterRecv:=Delete;
- FRecvEMail.RetrieveAllMessage:=True;
- FRecvEMail.Filter:=FFilter;
- FRecvEMail.OnFilter:=OnFilter;
- FRecvEMail.Resume;
- end;
- procedure TfrmMain.popEmailProgress(Sender: TObject; Total,
- Current: Integer);
- begin
- BarProgress.Min:=0;
- BarProgress.Max:=Total;
- BarProgress.Position:=Current;
- if Total=Current then BarProgress.Position:=0;
- end;
- procedure TfrmMain.MSGProgress(Sender: TObject; Total, Current: Integer);
- begin
- { BarProgressMsg.Min:=0;
- BarProgressMsg.Max:=Total;
- BarProgressMsg.Position:=Current;
- if Total=Current then BarProgressMsg.Position:=0; }
- end;
- procedure TfrmMain.FormDestroy(Sender: TObject);
- begin
- FEmailChecker.Free;
- if FRecvEMail<>nil then TerminateThread(FRecvEMail.Handle,0);
- if FMutex<>0 then CloseHandle(FMutex);
- FUIDLList.Free;
- FFilter.Free;
- FNewEmailUIDLList.Free;
- FBlackList.Free;
- FWhiteList.Free;
- EmailSenderMgr.Free;
- end;
- procedure TfrmMain.MyOnRecvEMailProgress(Sender: TObject; Total,
- Current: Integer);
- begin
- BarProgress.Min:=0;
- BarProgress.Max:=Total;
- BarProgress.Position:=Current;
- if Total=Current then BarProgress.Position:=0;
- end;
- procedure TfrmMain.MyOnRecvMsgProgress(Sender: TObject; Total,
- Current: Integer);
- begin
- BarProgressMsg.Min:=0;
- BarProgressMsg.Max:=Total;
- BarProgressMsg.Position:=Current;
- if Total=Current then BarProgressMsg.Position:=0;
- end;
- procedure TfrmMain.OnError(Sender: TObject; ErrMsg: string);
- begin
- lblError.Style:=cxStyle1;
- lblError.Caption:=ErrMsg;
- lblTotal.Caption:='接收邮件出错';
- end;
- procedure TfrmMain.OnRetrieveed(sender: TObject;CurNum,Total:Integer;UIDL:String);
- var
- pop:TPOP2000;
- I:Integer;
- myXml:TMyXml;
- FileName:string;
- EMailFile:TEmailFile;
- begin
- lblTotal.Caption:=Format('正在接收邮件:%D/%D',[CurNum,Total]);
- pop:=TRecvEmail(sender).Pop3;
- pop.MailMessage.RebuildBody;
- //保存邮件正文
- FileName:=AppPath+'recved'+GenalFileName+'.ema';
- EMailFile:=TEmailFile.Create(FileName);
- try
- EMailFile.Subject:=pop.MailMessage.Subject;
- EMailFile.Sender:=pop.MailMessage.FromAddress;
- EMailFile.Recver:=pop.MailMessage.ReceiptAddress;//pop.MailMessage.ReplyToAddress;
- EMailFile.Date:=DateTimeToStr(pop.MailMessage.Date);
- EMailFile.Size:=IntToStr(Length(pop.MailMessage.PartSource));
- EMailFile.Content:=pop.MailMessage.TextHtml.Text;
- for I:=0 to pop.MailMessage.AttachList.Count-1 do
- EMailFile.Attchs.Add(FAttchSaveto+pop.MailMessage.AttachList[I].FileName);
- EMailFile.SaveEmail;
- finally
- EMailFile.Free;
- end;
- myXml:=TAppXml.Create;
- try
- myXml.AddNewEmail(pop.UserName,FileName,UIDL);
- finally
- myXml.Free;
- end;
- end;
- procedure TfrmMain.OnRecvAttch(sender: TObject; FileName: string;
- FileStream: TMemoryStream;CurNum,Total:Integer);
- begin
- BarProgressMsg.Caption:=Format('附件%D/%D',[CurNum,Total]);
- FileStream.SaveToFile(FAttchSaveTo+FileName); //保存附件
- end;
- procedure TfrmMain.actRecvAllExecute(Sender: TObject);
- begin
- GetAllPop3EMail;
- end;
- procedure TfrmMain.GetAllPop3EMail(delete:Boolean=False);
- var
- I:Integer;
- arr:array of string;
- S:string;
- begin
- actRecvCur.Enabled:=false;
- actRecvThenDelete.Enabled:=false;
- actStop.Enabled:=True;
- actSuspend.Enabled:=True;
- for I:=0 to tvEMail.Items.Count-1 do
- begin
- if tvEMail.Items[I].Level=1 then
- begin
- S:=PPopInfo(tvEMail.Items[I].Data).pop3Server+';';
- S:= S+PPopInfo(tvEMail.Items[I].Data).EMailAddr+';';
- S:= S+PPopInfo(tvEMail.Items[I].Data).pwd ;
- SetLength(arr,Length(arr)+1);
- arr[Length(arr)]:=S;
- end;
- end;
- if FRecvEMail<>nil then TerminateThread(FRecvEMail.Handle,0);
- FRecvEmail:=TRecvEmail.Create(arr);
- AttachEvent;
- FRecvEMail.DeleteAfterRecv:=Delete;
- FRecvEMail.RetrieveAllMessage:=True;
- FRecvEMail.Filter:=FFilter;
- FRecvEMail.OnFilter:=OnFilter;
- FRecvEMail.Resume;
- end;
- procedure TfrmMain.actRecvThenDeleteExecute(Sender: TObject);
- begin
- GetCurPop3EMail(True);
- end;
- procedure TfrmMain.actRecvCurExecute(Sender: TObject);
- begin
- lblTotal.Caption:='正在接收邮件,请稍候。';
- lblError.Caption:='';
- GetCurPop3EMail;
- end;
- procedure TfrmMain.actNewEmailExecute(Sender: TObject);
- begin
- with TfrmWriteEMail.Create(Application) do
- try
- ShowModal;
- finally
- Free;
- end;
- end;
- procedure TfrmMain.actAddrBookExecute(Sender: TObject);
- begin
- PnlAddr.Visible:=not PnlAddr.Visible;
- end;
- procedure TfrmMain.AttachEvent;
- begin
- FRecvEMail.OnRecvEMailProgress:=MyOnRecvEMailProgress;
- FRecvEMail.OnRecvMsgProgress:=MyOnRecvMsgProgress;
- FRecvEMail.OnError:=OnError;
- FRecvEMail.OnRetrieveed:=OnRetrieveed;
- FRecvEMail.OnAttachFileRetrieveed:=OnRecvAttch;
- FRecvEMail.OnComplete:=RecvComplete;
- FRecvEMail.OnGetUIDL:=OnGetUIDL;
- FRecvEMail.BeginWork:=Self.BeginRecv;
- FRecvEMail.EndWork:=Self.EndRecv;
- FRecvEMail.OnTerminate:=Self.OnTerminate;
- FRecvEMail.BlackList:=FBlackList;
- FRecvEMail.WhiteList:=FWhiteList;
- end;
- procedure TfrmMain.RecvComplete(Sender: TObject);
- begin
- actRecvThenDelete.Enabled:=True;
- actRecvCur.Enabled:=True;
- actRecvAll.Enabled:=True;
- end;
- procedure TfrmMain.actSuspendExecute(Sender: TObject);
- begin
- FRecvEMail.Suspend;
- lblTotal.Caption:='收取邮件已暂停';
- end;
- procedure TfrmMain.actStopExecute(Sender: TObject);
- begin
- if (FRecvEMail<>nil) then FRecvEMail.IsBusy:=False;
- TerminateThread(FRecvEMail.Handle,0);
- actRecvThenDelete.Enabled:=True;
- actRecvCur.Enabled:=True;
- actRecvAll.Enabled:=True;
- actSuspend.Enabled:=False;
- actStop.Enabled:=False;
- lblTotal.Caption:='收取邮件已停止';
- BarProgress.Position:=0;
- BarProgressMsg.Caption:='附件';
- BarProgressMsg.Position:=0;
- end;
- procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
- var
- frm:TfrmCloseTip;
- r:TModalResult;
- b:Boolean;
- begin
- b:=false;
- if FRecvEMail<>nil then b:=FRecvEMail.IsBusy;
- if b or EmailSenderMgr.HasEmail then
- begin
- //正在发送,收取邮件,提示是终止还是最小化。
- frm:=TfrmCloseTip.Create(Application);
- try
- if b and EmailSenderMgr.HasEmail then
- frm.lblTip.Caption:='您正在发送和收取邮件。'
- else if b then
- frm.lblTip.Caption:='您正在收取邮件。'
- else
- frm.lblTip.Caption:='您正在发送邮件。';
- r:= frm.ShowModal ;
- finally
- frm.Free;
- end;
- if r=mrok then
- begin
- Action :=caNone;
- TrayIcon.MinimizeApp;
- end
- else
- Action:=cafree;
- end
- end;
- procedure TfrmMain.AddFileRelation(lv: TListView; filename: string);
- var
- ImageListHandle: THandle;
- FileInfo: TSHFileInfo;
- sfi: TSHFileInfoA;
- PFileName:PAnsiChar;
- begin
- // 小图标
- ImageListHandle := SHGetFileInfo('', 0, FileInfo, SizeOf(FileInfo), SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
- // 同ImageList关联
- SendMessage(lv.Handle, LVM_SETIMAGELIST, LVSIL_SMALL, ImageListHandle);
- // 大图标
- ImageListHandle := SHGetFileInfo('', 0, FileInfo, SizeOf(FileInfo), SHGFI_SYSICONINDEX or SHGFI_LARGEICON);
- SendMessage(lv.Handle, LVM_SETIMAGELIST, LVSIL_NORMAL, ImageListHandle);
- SHGetFileInfo(PChar(FileName), 0, sfi, SizeOf(sfi),
- SHGFI_DISPLAYNAME or SHGFI_TYPENAME or SHGFI_SMALLICON or SHGFI_ICON);
- with lv.Items.Add do
- begin
- Caption := sfi.szDisplayName;
- ImageIndex := sfi.iIcon;
- GetMem(PFileName,length(FileName)+1) ;
- fillchar(PFileName^,length(FileName)+1,0);
- CopyMemory(PFileName,PAnsiChar(FileName),length(FileName));
- Data:=PFileName;
- end;
- end;
- procedure TfrmMain.tvEMailClick(Sender: TObject);
- begin
- if TcxTreeView(Sender).Selected=nil then Exit;
- btnUnRead.Enabled:=tvEMail.Selected.Text='收件箱';
- ClearTableView(tvTableView);//清除已有记录
- FShowEmailSending:=false;
- LoadRecvEmail; //载入收件箱邮件
- LoadSendEmail; //载入已发邮件邮件
- LoadDraft; //载入草稿箱邮件
- LoadAttamp; // 载入定时邮件
- LoadSending;
- end;
- procedure TfrmMain.lv1DblClick(Sender: TObject);
- begin
- if LV1.Selected <> nil then
- if ShellExecute(0, 'open', LV1.Selected.Data, '', '', SW_NORMAL)<=32 then
- ShellExecute(Handle,
- 'OPEN',
- PChar('explorer.exe'),
- PChar('/select, "' + PChar(LV1.Selected.Data) + '"'),
- nil,
- SW_NORMAL) ;
- end;
- procedure TfrmMain.gtvColReadedGetDisplayText(
- Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
- var AText: String);
- begin
- if ARecord.Values[0]=true then
- AText:='已读'
- else
- AText:='未读' ;
- end;
- procedure TfrmMain.MultiThreadSendComplete(Sender: TObject);
- begin
- btnSendAll.Enabled:=true;
- MsgBoxWarn('邮件发送完毕!');
- end;
- procedure TfrmMain.MultiThreadSendError(Sender: TObject;Email:TEmailInfo; ErrMsg: string);
- var
- Xml:TAppXml;
- begin
- Email.IsError:=True;
- Xml:=TAppXml.Create;
- try
- //从xml文件中删除
- Xml.DeleteSendingEmail(Email.Send.UserName,Email.Id);
- //从表格中删除数据
-
- finally
- xml.Free;
- end;
- MsgBoxError(ErrMsg);
- end;
- procedure TfrmMain.actDeleteCurEmailExecute(Sender: TObject);
- var
- xml:TAppXml;
- begin
- with tvTableView.DataController do
- begin
- if FocusedRecordIndex<0 then
- begin
- MsgBoxError('请您选中表格中的一封邮件,再执行删除操作!');
- exit;
- end;
- if MsgBoxYesOrNo(Format('您确定要删除邮件"%S"吗?',[VarToStr(Values[FocusedRecordIndex,gtvColSubject.index])]))=mrOK then
- begin
- xml:=TAppXml.Create;
- try
- xml.DeleteAEmail(VarToStr(Values[FocusedRecordIndex,gtvColMyAddr.Index]),VarToStr(Values[FocusedRecordIndex,gtvColContentFilename.Index]));
- DeleteRecord(FocusedRecordIndex);
- finally
- xml.Free;
- end;
- end;
- end;
- end;
- procedure TfrmMain.actSendPendingEmailExecute(Sender: TObject);
- var
- L,Attch:TStringList;
- xml:TMyXml;
- I:integer;
- EmailFile:TEmailFile;
- pwd:String;
- dest: TDestinationPart;
- Orig:TOriginPart;
- Email:TEmailInfo;
- Node:TTreeNode;
- Str:String;
- begin
- Node:=tvEMail.Selected;
- if Node=nil then Exit;
- if Node.Level=1 then Node:=Node.Parent;
- Str:=PPopInfo(Node.Data).EMailAddr;
-
- L:=TStringList.Create;
- xml:=TAppXml.Create; //获取所有未发邮件
- try
- xml.GetAllNotSendEmail(PPopInfo(Node.Data).EMailAddr,L);
- xml.GetAllSendingEmail(PPopInfo(Node.Data).EMailAddr,L,false);
- if L.Count=0 then
- begin
- L.Free;
- MsgBoxError('没有未发邮件');
- Exit;
- end;
- xml.AddSendingEmail(PPopInfo(Node.Data).EMailAddr,L);
- finally
- xml.Free;
- end;
-
- Attch:=TStringList.Create;
- Email:=TEmailInfo.Create;
- try
- for I:=0 to L.Count-1 do
- begin
- EmailFile:=TEmailFile.Create(L[I]);
- try
- Email.Id:=L[I];
- EmailFile.GetEmail;
- Attch.Assign(EmailFile.Attchs);
- Dest:=TDestinationPart.Create(Trim(EmailFile.Recver),Trim(EmailFile.Recver),Trim(EmailFile.Recver),'',EmailFile.Subject,EmailFile.Content,Attch);
- try
- Email.Recv:=Dest;
- finally
- Dest.Free;
- end;
-
- xml:=TAppXml.Create;
- try
- pwd:=xml.GetEMailPwd(EmailFile.Sender);
- finally
- xml.Free;
- end;
- Orig:=TOriginPart.Create(atDefault,Trim(EmailFile.Sender),Trim(EmailFile.Sender),Trim(pwd),TEMailAddress.SMTPEmailSever(Trim(EmailFile.Sender)),25);
- try
- Email.Send:=Orig;
- finally
- Orig.Free;
- end;
- finally
- EmailFile.Free;
- end;
- EmailSenderMgr.Push(Email); //加入到发送列表
- end;
- finally
- Attch.free;
- Email.Free;
- L.free;
- end;
- EmailSenderMgr.Send;
- end;
- procedure TfrmMain.dxBarLargeButton9Click(Sender: TObject);
- begin
- with TTipsForm.Create(Application) do
- try
- ShowModal;
- finally
- free;
- end;
- end;
- procedure TfrmMain.actRenameExecute(Sender: TObject);
- var
- N:TTreeNode;
- begin
- N:=tvEMail.Selected;
- if (N=nil) then Exit;
- if (N.Level=1) then N:=N.Parent;
- //if (tvEMail.Selected.Text='草稿箱') or (tvEMail.Selected.Text='定时邮件') then Exit;
- tvEMail.ReadOnly:=False;
- N.EditText;
- end;
- procedure TfrmMain.tvEMailExit(Sender: TObject);
- begin
- tvEMail.ReadOnly:=True;
- end;
- procedure TfrmMain.tvEMailEdited(Sender: TObject; Node: TTreeNode;
- var S: String);
- var
- MyXml:TMyXml;
- xmlNode:TXmlNode;
- begin
- if (Node.Level<>0) and (Node.Text='草稿箱') or (Node.Text='定时邮件') then Exit;
- MyXml:=TMyXml.Create(AppPath+'EmailServers.xml');
- try
- xmlNode:=MyXml.FindPOP3EmailAddrNode(FOldNodeText);
- if xmlNode=nil then Exit;
- xmlNode.ValueAsString:=S;
- finally
- MyXml.Free;
- end;
- end;
- procedure TfrmMain.tvEMailEditing(Sender: TObject; Node: TTreeNode;
- var AllowEdit: Boolean);
- begin
- FOldNodeText:=Node.Text;
- end;
- procedure TfrmMain.actDeletePopExecute(Sender: TObject);
- var
- text:string;
- MyXml:TMyXml;
- xmlNode:TXmlNode;
- N:TTreeNode;
- begin
- N:=tvEmail.Selected;
- if (N=nil) then Exit;
- if N.Level=1 then N:=N.Parent;
- text:=GetSeletedEmailAddr;
- if Dialogs.MessageDlg(format('你确定要删除邮箱"%S"吗?',[N.Text]),mtConfirmation,[mbYes, mbNo],0)=mrNo then Exit;
- tvEMail.Items.Delete(N);
- MyXml:=TMyXml.Create(AppPath+'EmailServers.xml');
- try
- xmlNode:=MyXml.FindPOP3EmailAddrNode(text);
- if xmlNode=nil then Exit;
- xmlNode.Parent.Delete;
- finally
- MyXml.Free;
- end;
- end;
- procedure TfrmMain.btnSendAndRecvClick(Sender: TObject);
- begin
- try
- actSendPendingEmailExecute(nil);
- finally
- actRecvAllExecute(nil);
- end;
- end;
- procedure TfrmMain.FormShow(Sender: TObject);
- var
- MyXml:TMyXml;
- loadonstatup:Boolean;
- begin
- MyXml:=TMyXml.Create(AppPath+'EmailServers.xml');
- try
- loadonstatup:=StrToBool(MyXml.Root.FindNode('tips').AttributeByName['loadonstatup']);
- finally
- MyXml.free;
- end;
- if loadonstatup then PostMessage(Self.Handle,WM_SHOW_TIP_FORM,0,0); //显示每日提示
- end;
- procedure TfrmMain.WndProc(var Message: TMessage);
- begin
- case Message.Msg of
- WM_PREVINSTRUN:
- begin
- FMutex:=THandle(Message.WParam);
- TrayIcon.RestoreApp;
- TrayIcon.ShowBalloonHint('提醒您','《邮件收发系统》已经运行了');
- end;
- WM_SHOW_TIP_FORM:
- with TTipsForm.Create(Application)do
- try
- ShowModal;
- finally
- Free;
- end;
- else
- inherited;
- end;
- end;
- procedure TfrmMain.actNewAccuntExecute(Sender: TObject);
- begin
- with TfrmNewSMTP.Create(Application) do
- try
- ShowModal;
- finally
- Free;
- end;
- end;
- procedure TfrmMain.tvEMailMouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- var
- P,pt:TPoint;
- Node:TTreeNode;
- begin
- if Button= mbRight then
- begin
- GetCursorPos(p);
- pt:=tvEMail.ScreenToClient(p);
- Node:=tvEMail.GetNodeAt(pt.x,Pt.Y);
- if Node=nil then Exit;
- pm2.Popup(p.X,p.Y);
- end;
- end;
- procedure TfrmMain.tvTableViewMouseUp(Sender: TObject;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- var
- P:TPoint;
- begin
- if Button= mbRight then
- begin
- if tvTableView.DataController.GetFocusedRecordIndex>=0 then
- begin
- GetCursorPos(p);
- pm1.Popup(p.X,p.Y);
- end;
- end;
- end;
- procedure TfrmMain.actPropertyExecute(Sender: TObject);
- var
- N:TTreeNode;
- PScr:TPoint;
- begin
- N:=tvEMail.Selected ;
- if N=nil then Exit;
- if N.Level=1 then N:=N.Parent;
- with TfrmEmailBoxProperty.Create(Application) do
- try
- ShowPage(FEmailPropertyPageIndex);
- LoadDefault(PPopInfo(N.Data).EMailAddr);
- GetCursorPos(PScr);
- if PScr.Y+Height>Screen.Height then
- PScr.Y:=Screen.Height-Height;
- Self.ScreenToClient(Pscr);
- Left:=PScr.X;
- Top:=PScr.Y;
- ShowModal;
- finally
- free;
- end;
- end;
- procedure TfrmMain.tmrAttampTimer(Sender: TObject);
- var
- MyXml:TMyXml;
- files:TStringList;
- begin
- //检测定时邮件
- files:=TStringList.Create;
- try
- MyXml:=TAppXml.Create;
- try
- myxml.GetAllAttamp(files);
- finally
- MyXml.Free;
- end;
- if files.Count>=0 then
- begin
- //有定时邮件需要发送
- end;
- finally
- files.Free;
- end;
- end;
- procedure TfrmMain.ClearTableView(tv:TcxGridTableView);
- var
- I:Integer;
- begin
- tv.BeginUpdate;
- try
- for I:=tv.DataController.RecordCount-1 downto 0 do
- begin
- tv.DataController.DeleteRecord(I);
- tv.DataController.Post;
- end;
- finally
- tv.EndUpdate;
- end;
- end;
- procedure TfrmMain.LoadAttamp;
- var
- MyXml:TMyXml;
- Str:string;
- contentFileName:TStringList;
- begin
- if tvEMail.Selected.Text<>'定时邮件' then Exit;
- WriteLog('LoadAttamp run');
- FSendEmailBox:=false;
- gtvColAttch.Visible:=True;
- gtvColMyAddr.Visible:=False;
- pnlAttch.Visible:=False;
- actReply.Enabled:=False;
- Str:=GetSeletedEmailAddr;
- gtvColSender.Caption:='收件人';
- gtvColSender.Visible:=true;
- gtvColReaded.Visible:=False;
- gtvColSubject.Visible:=true;
- gtvColSubject.Caption:='定时发送时间';
- contentFileName:=TStringList.Create;
- myXml:=TMyXml.Create(AppPath+'EmailServers.xml');
- try
- myXml.GetAllAttamp(Str,contentFileName);
- finally
- myXml.Free;
- end;
- LoadFromFile(Str,contentFileName);
- contentFileName.Free;
- end;
- procedure TfrmMain.LoadDraft;
- var
- MyXml:TMyXml;
- Str:string;
- contentFileName:TStringList;
- begin
- if tvEMail.Selected.Text<>'草稿箱' then Exit;
- WriteLog('LoadDraft run');
- FSendEmailBox:=false;
- gtvColAttch.Visible:=True;
- gtvColMyAddr.Visible:=False;
- btnUnRead.Enabled:=false;
- pnlAttch.Visible:=False;
- actReply.Enabled:=False;
- Str:=GetSeletedEmailAddr;
- gtvColSender.Caption:='收件人';
- gtvColSender.Visible:=true;
- gtvColReaded.Visible:=False;
- gtvColDate.Visible:=true;
- gtvColDate.Caption:='邮件撰写时间';
- contentFileName:=TStringList.Create;
- myXml:=TMyXml.Create(AppPath+'EmailServers.xml');
- try
- myXml.GetAllDraft(Str,contentFileName);
- finally
- myXml.Free;
- end;
- LoadFromFile(Str,contentFileName);
- contentFileName.Free;
- end;
- procedure TfrmMain.LoadRecvEmail;
- var
- contentFileName,
- Readed,
- Attch,
- uidlList,
- FileShortName:TStringList;
- Str:string;
- MyXml:TMyXml;
- I,J:Integer;
- EmailFile:TEmailFile;
- recCount:Integer;
- begin
- if tvEMail.Selected.Text<>'收件箱' then Exit;
- WriteLog('LoadRecvEmail run');
- gtvColAttch.Visible:=True;
- gtvColMyAddr.Visible:=False;
- FSendEmailBox:=false;
- pnlAttch.Visible:=False;
- actReply.Enabled:=True;
- Str:=GetSeletedEmailAddr;
- btnUnRead.Enabled:=true;
- gtvColSender.Caption:='发件人';
- gtvColSender.Visible:=true;
- gtvColReaded.Visible:=true;
- gtvColDate.Visible:=true;
- gtvColDate.Caption:='收件时间';
- contentFileName:=TStringList.Create;
- Readed:=TStringList.Create;
- Attch:=TStringList.Create;
- uidlList:=TStringList.Create;
- FileShortName:=TStringList.Create;
- try
- myXml:=TAppXml.Create;
- try
- myXml.GetAllEmail(Str,contentFileName,Readed,uidlList);
- finally
- myXml.Free;
- end;
- tvTableView.BeginUpdate;
- try
- WriteLog('recvEmail count:'+inttostr(contentFileName.Count));
- for I:=0 to contentFileName.Count-1 do
- begin
- if not FileExists(contentFileName.Strings[I]) then Continue;
- EMailFile:=TEmailFile.Create(contentFileName[I]);
- EMailFile.Attchs.Clear;
- try
- EMailFile.GetEmail;
- with tvTableView.DataController do
- begin
- recCount:=AppendRecord;
- //SetValue(recCount, 0,StrToBool(Readed[I]) );
- if FSendEmailBox then
- SetValue(recCount, gtvColSender.Index,EMailFile.Recver )
- else
- SetValue(recCount, gtvColSender.Index,EMailFile.Sender );
- SetValue(recCount, gtvColSubject.Index,EMailFile.Subject );
- SetValue(recCount,gtvColDate.Index,EMailFile.Date );
- if EMailFile.Size='' then EMailFile.Size:='0';
- if StrToInt(EMailFile.Size)>1024 then
- SetValue(recCount, gtvColSize.Index,IntToStr(StrToInt(EMailFile.Size) div 1024)+' KB')
- else
- SetValue(recCount, gtvColSize.Index,EMailFile.Size+' Bytes') ;
- SetValue(recCount, gtvColContentFilename.Index,contentFileName[I] );
- SetValue(recCount, gtvColUIDL.Index,uidlList[I] );
- SetValue(recCount, gtvColMyAddr.Index,Str);
- SetValue(recCount, gtvColAttchFullName.Index,Join(';',EMailFile.Attchs));
- WriteLog('Email '+inttostr(I)+' attchs:'+trim(EMailFile.Attchs.Text));
- WriteLog('cxGrid Show: '+Values[recCount, 9]);
- WriteLog('Join('';'',EMailFile.Attchs): '+Join(';',EMailFile.Attchs));
- WriteLog('--------------------------------------------------------') ;
- FileShortName.Clear;
- for J:=0 to EMailFile.Attchs.Count-1 do
- FileShortName.Add(ExtractFileName(EMailFile.Attchs[J]));
- SetValue(recCount, gtvColAttch.Index,Join(';',FileShortName) );
- SetValue(recCount, gtvColReaded.Index,StrToBoolDef(Readed[I],False) );
- Post;
- end;
- finally
- EMailFile.Free;
- end;
- end;
- finally
- tvTableView.EndUpdate;
- end;
- finally
- FileShortName.free;
- uidlList.free;
- contentFileName.free;
- Readed.free;
- Attch.free;
- end;
- end;
- procedure TfrmMain.LoadSendEmail;
- var
- contentFileName:TStringList;
- MyXml:TAppXml;
- Str:string;
- begin
- if tvEMail.Selected.Text<>'已发邮件' then Exit; //显示所有已发送的邮件
- WriteLog('LoadSendEmail run');
- gtvColAttch.Visible:=True;
- gtvColMyAddr.Visible:=False;
- btnRecpOne.Enabled:=false;
- btnUnRead.Enabled:=True;
- FSendEmailBox:=true;
- actReply.Enabled:=False;
- Str:=PPopInfo(tvEMail.Selected.Parent.Data).EMailAddr;
- gtvColSender.Caption:='收件人';
- gtvColReaded.Visible:=false;
- gtvColDate.Visible:=True;
- gtvColDate.Caption:='发件时间';
- contentFileName:=TStringList.Create;
- MyXml:=TAppXml.Create;
- try
- MyXml.GetAllSentEmail(Str,contentFileName);
- finally
- MyXml.Free;
- end;
- LoadFromFile(Str,contentFileName);
- contentFileName.Free;
- end;
- procedure TfrmMain.SendEmailFromFile(FilePath: string);
- begin
- end;
- procedure TfrmMain.LoadFromFile(EmailAddr:string;Files: TStringList);
- var
- FileShortName:TStringList;
- I,J:Integer;
- EmailFile:TEmailFile;
- recCount:Integer;
- begin
- FileShortName:=TStringList.Create;
- tvTableView.BeginUpdate;
- try
- recCount:=0;
- for I:=0 to Files.Count-1 do
- begin
- if not FileExists(Files.Strings[I]) then Continue;
- EMailFile:=TEmailFile.Create(Files[I]);
- EMailFile.GetEmail;
- with tvTableView.DataController do
- begin
- AppendRecord;
- //SetValue(recCount, 0,StrToBool(Readed[I]) );
- if FSendEmailBox then
- SetValue(recCount, gtvColSender.Index,EMailFile.Recver )
- else
- SetValue(recCount, gtvColSender.Index,EMailFile.Sender );
- SetValue(recCount, gtvColSubject.Index,EMailFile.Subject );
- SetValue(recCount, gtvColDate.Index,EMailFile.Date );
- if EMailFile.Size='' then EMailFile.Size:='0';
- if StrToInt(EMailFile.Size)>1024 then
- SetValue(recCount, gtvColSize.Index,IntToStr(StrToInt(EMailFile.Size) div 1024)+' KB')
- else
- SetValue(recCount, gtvColSize.Index,EMailFile.Size+' Btyes');
- //
- SetValue(recCount, gtvColContentFilename.Index,Files[I] );
- SetValue(recCount, gtvColUIDL.Index,'' );
- SetValue(recCount, gtvColMyAddr.Index,EmailAddr);
- SetValue(recCount, gtvColAttchFullName.Index,Join(';',EMailFile.Attchs));
- FileShortName.Clear;
- for J:=0 to EMailFile.Attchs.Count-1 do
- FileShortName.Add(ExtractFileName(EMailFile.Attchs[J]));
- EMailFile.Free;
- SetValue(recCount, gtvColAttch.Index,Join(';',FileShortName) );
- SetValue(recCount, gtvColReaded.Index,False );
- Post;
- end;
- Inc(recCount);
- end;
- finally
- tvTableView.EndUpdate;
- end;
- FileShortName.free;
- end;
- procedure TfrmMain.OnGetUIDL(Sender: TObject; uidl: String;
- var Handle: Boolean);
- var
- idx:integer;
- begin
- idx:=FUIDLList.IndexOf(uidl);
- if idx=-1 then FUIDLList.Add(uidl);
- handle:=(FRetryAgain) and (idx>-1);
- writelog(#$D#$A'uidl:'+uidl+#$D#$A'FUIDLList:'+FUIDLList.Text+#$D#$A);
- end;
- procedure TfrmMain.GetUIDLS;
- var
- AppXml:TAppXml;
- begin
- AppXml:=TAppXml.Create;
- try
- AppXml.GetUIDLS(FUIDLList);
- finally
- AppXml.Free;
- end;
- end;
- procedure TfrmMain.LoadRules;
- var
- MyXml:TMyXml;
- begin
- MyXml:=TMyXml.Create(AppPath+'EmailServers.xml');
- try
- if FileExists(MyXml.GetRulesFilePath ) then
- FFilter.ReadFromFile(MyXml.GetRulesFilePath,FFilter);
- finally
- MyXml.Free;
- end;
- end;
- procedure TfrmMain.OnFilter(Sender: TObject;Action:TRuleAction; EmailSubject,
- EmailFrom: string;var DeleteIt:Boolean;var Ignore:Boolean);
- begin
- DeleteIt:=Action.DeleteOnServer;
- Ignore:=Action.IgnoreNotRecv;
- try
- if FileExists(Action.PlaySound) then
- WinExec(PAnsiChar(Action.PlaySound),SW_SHOW);
- if FileExists(Action.RunExe) then
- WinExec(PAnsiChar(Action.RunExe),SW_SHOW);
- except
- end;
- if Action.PopTip then
- with TfrmFilterPopTip.Create(Application) do
- begin
- ShowInfo('过滤系统拦截到一封邮件',format('邮件主题是%S。'#$D#$A'邮件来自%S。'#$D#$A#$D#$A'你希望执行下列哪项操作?',[EmailSubject,EmailFrom]));
- try
- case ShowModal of
- mrYes: //接收邮件
- Ignore:=False;
- mrNo: //不接收
- Ignore:=True;
- mrCancel: //从服务器上删除
- DeleteIt:=True;
- else; // Exception.Create('未定义返回值');
- end;
- finally
- Free;
- end;
- end;
- end;
- procedure TfrmMain.TrayIconLButtonDown(Sender: TObject); //弹出左键菜单
- begin
- //SendMessage(Self.Handle,WM_CANCELMODE,0,0);
- //pmleft.PopupFromCursorPos;
- end;
- procedure TfrmMain.TrayIconRButtonDown(Sender: TObject); //弹出右键菜单
- begin
- SendMessage(Self.Handle,WM_CANCELMODE,0,0);
- pmRight.PopupFromCursorPos;
- end;
- procedure TfrmMain.dxbrbtn34Click(Sender: TObject);
- begin
- TrayIcon.RestoreApp;
- end;
- procedure TfrmMain.dxbrbtn37Click(Sender: TObject);
- begin
- TrayIcon.MinimizeApp;
- end;
- procedure TfrmMain.dxbrbtn39Click(Sender: TObject);
- begin
- Self.Close;
- end;
- procedure TfrmMain.CreateDirs;
- begin
- if not DirectoryExists(FRuleSaveTo) then
- begin
- FRuleSaveTo:=IncludeTrailingPathDelimiter(AppPath+'Rules');
- CreateDir(FRuleSaveTo) ;
- end;
- if not DirectoryExists(FEmailSaveTo) then
- begin
- FEmailSaveTo:=IncludeTrailingPathDelimiter(AppPath+'emailsaveto');
- CreateDir(FEmailSaveTo) ;
- end;
- if not DirectoryExists(FAttchSaveTo) then
- begin
- FAttchSaveTo:=IncludeTrailingPathDelimiter(AppPath+'emailattchsaveto');
- CreateDir(FAttchSaveTo) ;
- end;
- end;
- procedure TfrmMain.LoadDefaultSavePath;
- var
- MyXml:TMyXml;
- begin
- MyXml:=TMyXml.Create(AppPath+'EmailServers.xml');
- try
- FEmailSaveTo :=IncludeTrailingPathDelimiter(VarToStr(MyXml.Pop3sNode.AttributeByName['emailsaveto']));
- FEmailSaveTo:=GetFullPath(FEmailSaveTo);
-
- FAttchSaveTo:=IncludeTrailingPathDelimiter(VarToStr(MyXml.Pop3sNode.AttributeByName['emailattchsaveto']));
- FAttchSaveTo:=GetFullPath(FAttchSaveTo);
- FRuleSaveTo:=IncludeTrailingPathDelimiter(MyXml.Root.FindNode('Rules').AttributeByName['RulesSaveTo']);
- FRuleSaveTo:=GetFullPath(FRuleSaveTo);
- MyXml.GetBlackList(FBlackList);
- MyXml.GetWhiteList(FWhiteList);
- finally
- MyXml.Free;
- end;
- end;
- procedure TfrmMain.BeginRecv(Sender: TObject); //开始接收
- var
- myxml:TMyXml;
- begin
- actRecvCur.Enabled:=False;
- actRecvThenDelete.Enabled:=False;
- actSuspend.Enabled:=True;
- actStop.Enabled:=True;
- MyXml:=TMyXml.Create(AppPath+'EmailServers.xml');
- try
- if myxml.FindPop3(FRecvEMail.Pop3.UserName)<>nil then
- FRetryAgain:=StrToBoolDef(myxml.FindPop3(FRecvEMail.Pop3.UserName).AttributeByName['ReDownload'],False);
- finally
- MyXml.Free;
- end;
- end;
- procedure TfrmMain.EndRecv(Sender: TObject); //接收完毕(不管是否发生错误,该事件都被触发)
- begin
- BarProgress.Position:=0;
- BarProgressMsg.Position:=0;
- actSuspend.Enabled:=False;
- actStop.Enabled:=False;
- actRecvThenDelete.Enabled:=True;
- actRecvCur.Enabled:=True;
- actRecvAll.Enabled:=True;
- lblTotal.Caption:='收取完毕';
- end;
- procedure TfrmMain.OnTerminate(Sender: TObject);
- begin
- FRecvEMail:=nil;
- end;
- procedure TfrmMain.btn1Click(Sender: TObject);
- begin
- with TfrmRule.Create(Application) do
- try
- if ShowModal=mrOk then LoadRules;
- finally
- free;
- end;
- end;
- procedure TfrmMain.dxBarButton3Click(Sender: TObject);
- begin
- FEmailPropertyPageIndex:=3;
- actPropertyExecute(nil);
- end;
- procedure TfrmMain.dxbrbtn41Click(Sender: TObject);
- begin
- FEmailPropertyPageIndex:=2;
- actPropertyExecute(nil);
- end;
- procedure TfrmMain.OnNewEmailArrive(Sender: TObject;
- NewEmailUIDLs: TStrings);
- begin
- with TfrmFilterPopTip.Create(Application)do
- try
- AlignButtons;
- ShowInfo('有封新邮件啦',format('您有%D封新邮件'#$D#$A#$D#$A'您希望执行下面的哪项操作?',[NewEmailUIDLs.Count]));
- if ShowModal <>mrYes then Exit;
- finally
- free;
- end;
- actRecvCur.Enabled:=false;
- actRecvThenDelete.Enabled:=false;
- actStop.Enabled:=True;
- actSuspend.Enabled:=True;
- if FRecvEMail<>nil then TerminateThread(FRecvEMail.Handle,0);
- FRecvEmail:=TRecvEmailExt.Create;
- AttachEvent;
- FRecvEMail.DeleteAfterRecv:=False;
- FRecvEMail.RetrieveAllMessage:=True;
- FRecvEMail.Filter:=FFilter;
- FRecvEMail.OnFilter:=OnFilter;
- TRecvEmailExt(FRecvEmail).NewEmailUIDLS:=NewEmailUIDLs;
- FRecvEMail.Resume;
- end;
- procedure TfrmMain.TrayIconMinimizeApp(Sender: TObject);
- begin
- FEmailChecker.EnterState(asMin);
- end;
- procedure TfrmMain.TrayIconRestoreApp(Sender: TObject);
- begin
- FEmailChecker.EnterState(asRestore);
- end;
- procedure TfrmMain.btnDetectEmailClick(Sender: TObject);
- begin
- FEmailChecker.EnterState(asInit);
- end;
- procedure TfrmMain.dxbrbtn35Click(Sender: TObject);
- begin
- FEmailChecker.EnterState(asInit);
- end;
- procedure TfrmMain.btn4Click(Sender: TObject);
- begin
- with TfrmAttchMgr.Create(Application) do
- try
- ShowModal;
- finally
- free;
- end;
- end;
- procedure TfrmMain.dxbrlrgbtn4Click(Sender: TObject); //test
- begin
- if tvTableView.DataController.FocusedRecordIndex<0 then
- begin
- MsgBoxError('请在表格中选一封邮件。');
- exit;
- end;
-
- with TfrmAwake.Create(Application)do
- try
- with tvTableView.DataController do
- begin
- FEmailAddr:=VarToStr(Values[FocusedRecordIndex,gtvColMyAddr.Index]);
- FContentFilePath:=VarToStr(Values[FocusedRecordIndex,gtvColContentFilename.Index])
- end;
- ShowModal;
- finally
- Free;
- end;
- end;
- procedure TfrmMain.DetectingEmail(Sender: TObject; Runing: Boolean);
- begin
- btnDetectEmail.Enabled:=not Runing;
- if Runing then
- LblDetect.Caption:='正在检测新邮件'
- else
- LblDetect.Caption:='';
- end;
- procedure TfrmMain.dxbrbtn18Click(Sender: TObject); //作为附件发送
- var
- contfile:string;
- EmailFile:TEmailFile;
- tempFileName:string;
- Strm:TMemoryStream;
- I:integer;
- begin
- contfile:=VarToStr(tvTableView.DataController.GetValue(tvTableView.DataController.GetFocusedRecordIndex,gtvColContentFilename.Index));
- if not FileExists(contfile) then exit;
- tempFileName:=SysTempDir+GenalFilename+'.html';
- with TfrmWriteEMail.Create(Application) do
- try
- Caption:='发送邮件--作为附件发送';
- FSetDoc:=false;
- pnl1.Height:=234;
-
- EmailFile:=TEmailFile.Create(contfile);
- try
- EmailFile.GetEmail;
- with lstAttch.Items.Add do
- begin
- Text:=tempFileName;
- Checked:=True;
- end;
- for I:=0 to EmailFile.Attchs.Count-1 do
- begin
- with lstAttch.Items.Add do
- begin
- if FileExists(EmailFile.Attchs[I]) then
- begin
- Text:=EmailFile.Attchs[I];
- Checked:=True;
- end
- else
- begin
- Checked:=False;
- Text:='[文件不存在] '+lstAttch.Items[I].Text;
- end;
- end;
- end;
- Strm:=TMemoryStream.Create;
- Strm.Position:=0;
- Strm.WriteBuffer(EmailFile.Content[1],Length(EmailFile.Content));
- try
- Strm.SaveToFile(tempFileName);
- finally
- Strm.Free;
- end;
- finally
- EmailFile.Free;
- end;
- ShowModal;
- finally
- SysUtils.DeleteFile(tempFileName);
- Free;
- end;
- end;
- procedure TfrmMain.actCleanRecvsExecute(Sender: TObject);
- var
- Xml:TAppXml;
- begin
- if MsgBoxYesOrNo('您确定要清空收件箱吗?')=mrOK then
- begin
- xml:=TAppXml.Create;
- try
- xml.CleanRecvs(GetSeletedEmailAddr);
- finally
- Xml.Free;
- end;
- end;
- end;
- function TfrmMain.GetSeletedEmailAddr: string;
- var
- N:TTreeNode;
- begin
- Result:='';
- N:=tvEmail.Selected;
- if N=nil then exit ;
- if N.Level=1 then N:=N.Parent;
- Result:=PPopInfo(N.Data).EMailAddr
- end;
- procedure TfrmMain.btnCleanSentsClick(Sender: TObject);
- var
- Xml:TAppXml;
- begin
- xml:=TAppXml.Create;
- try
- xml.CleanSents(GetSeletedEmailAddr);
- finally
- Xml.Free;
- end;
- end;
- procedure TfrmMain.btnCleanDraftClick(Sender: TObject);
- var
- Xml:TAppXml;
- begin
- xml:=TAppXml.Create;
- try
- xml.CleanDraft(GetSeletedEmailAddr);
- finally
- Xml.Free;
- end;
- end;
- procedure TfrmMain.btnCleanAttampClick(Sender: TObject);
- var
- Xml:TAppXml;
- begin
- xml:=TAppXml.Create;
- try
- xml.CleanAttmp(GetSeletedEmailAddr);
- finally
- Xml.Free;
- end;
- end;
- procedure TfrmMain.btnUnReadClick(Sender: TObject);
- var
- Xml:TAppXml;
- I:integer;
- begin
- I:= tvTableView.DataController.FocusedRecordIndex;
- if I<0 then exit;
- Xml:=TAppXml.Create;
- try
- Xml.SetEmailUnreaded(VarToStr(tvTableView.DataController.Values[I,gtvColMyAddr.index]),VarToStr(tvTableView.DataController.Values[I,gtvColUIDL.Index]));
- finally
- Xml.Free;
- end;
- tvTableView.DataController.SetValue(I,gtvColReaded.Index,False);
- tvTableView.DataController.Post;
- end;
- procedure TfrmMain.actReplyExecute(Sender: TObject);
- begin
- if tvTableView.DataController.GetFocusedRecordIndex =-1 then
- begin
- MsgBoxError('请选中表格中的一封邮件');
- Exit;
- end;
-
- with TfrmWriteEMail.Create(nil) do
- try
- Caption:='回复邮件';
- pnl1.Height:=130;
- with tvTableView.DataController do
- begin
- cbRecver.Properties.Items.Insert(0,VarToStr(GetValue(GetFocusedRecordIndex,gtvColSender.Index))) ;
- if cbSender.Properties.Items.IndexOf(VarToStr(GetValue(GetFocusedRecordIndex,gtvColMyAddr.Index))) <>-1 then
- cbSender.ItemIndex:=cbSender.Properties.Items.IndexOf(VarToStr(GetValue(GetFocusedRecordIndex,gtvColMyAddr.Index)));
- end;
- cbRecver.ItemIndex:=0;
- ShowModal;
- finally
- Free;
- end;
- end;
- procedure TfrmMain.actTurnExecute(Sender: TObject);
- var
- contfile:string;
- EmailFile:TEmailFile;
- begin
- contfile:=VarToStr(tvTableView.DataController.GetValue(tvTableView.DataController.GetFocusedRecordIndex,gtvColContentFilename.Index));
- if not FileExists(contfile) then exit;
- with TfrmWriteEMail.Create(Application) do
- try
- Caption:='转发邮件';
- FSetDoc:=True;
-
- EmailFile:=TEmailFile.Create(contfile);
- try
- EmailFile.GetEmail;
- AddAttch(EmailFile.Attchs);
- if EmailFile.Attchs.Count>0 then pnl1.Height:=234;
- //cbAttch.Properties.Items.Assign(EmailFile.Attchs);
- FStr:=EmailFile.Content;
- finally
- EmailFile.Free;
- end;
- ShowModal;
- finally
- Free;
- end;
- end;
- procedure TfrmMain.tvTableViewFocusedRecordChanged(
- Sender: TcxCustomGridTableView; APrevFocusedRecord,
- AFocusedRecord: TcxCustomGridRecord;
- ANewItemRecordFocusingChanged: Boolean);
- begin
- actTurn.Enabled:= (tvTableView.DataController.RecordCount>0) and (tvTableView.DataController.FocusedRecordIndex>=0);
- if not btnTurn.Enabled then actReply.Enabled:=False;
- actDeleteCurEmail.Enabled:=(tvTableView.DataController.RecordCount>0) and (tvTableView.DataController.FocusedRecordIndex>=0)
- end;
- procedure TfrmMain.tvTableViewCellDblClick(Sender: TcxCustomGridTableView;
- ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
- AShift: TShiftState; var AHandled: Boolean);
- var
- I:Integer;
- S:string;
- list:TStrings;
- hasAttch:Boolean;
- MyXml:TMyXml;
- EMailFile:TEmailFile;
- begin
- pnlAttch.Visible:=False;
- //显示邮件正文
- HtmlEdit.Clear;
- with ACellViewInfo.GridView.DataController do
- begin
- I:=GetFocusedRecordIndex ;
- S:=VarToStr(GetValue(I,gtvColContentFilename.Index));
- if not FileExists(S) then Exit;
- EMailFile:=TEmailFile.Create(S);
- try
- EMailFile.GetEmail;
- HtmlEdit.HTML:=EMailFile.Content;
- //SetHtml(Web,);
- finally
- EMailFile.Free;
- end;
- if (not FSendEmailBox ) then
- begin
- if (GetValue(I,gtvColReaded.Index)=false) then
- begin
- myxml:=TMyXml.Create(AppPath+'EmailServers.xml');
- try
- myxml.SetEmailReaded(GetValue(I,gtvColMyAddr.Index),GetValue(I,gtvColContentFilename.Index));
- finally
- myxml.Free;
- end;
- SetValue(I,gtvColReaded.Index,True)
- end;
- end;
-
- S:=VarToStr(GetValue(I,gtvColAttchFullName.Index));
- end;
- //显示附件
- lv1.Items.Clear;
- if s='' then Exit;
- hasAttch:=False;
- list:=TStringList.Create;
- try
- Split(';',S,list);
- for I:=0 to list.Count-1 do
- begin
- if FileExists(list[I]) then
- begin
- AddFileRelation(lv1,list[I]);
- hasAttch:=True;
- end;
- end;
- finally
- list.Free;
- end;
- pnlAttch.Visible:=hasAttch;
- end;
- procedure TfrmMain.lv1Deletion(Sender: TObject; Item: TListItem);
- begin
- if( Item.Data<>nil) then FreeMem(PAnsiChar(Item.Data));
- end;
- procedure TfrmMain.actCleanSentsExecute(Sender: TObject);
- var
- Xml:TAppXml;
- begin
- if MsgBoxYesOrNo('您确定要清空所有''已发邮件''吗?')=mrOK then
- begin
- xml:=TAppXml.Create;
- try
- xml.CleanSents(GetSeletedEmailAddr);
- finally
- Xml.Free;
- end;
- end;
- end;
- procedure TfrmMain.actCleanDraftExecute(Sender: TObject);
- var
- Xml:TAppXml;
- begin
- if MsgBoxYesOrNo('您确定要清空草稿箱吗?')=mrOK then
- begin
- xml:=TAppXml.Create;
- try
- xml.CleanDraft(GetSeletedEmailAddr);
- finally
- Xml.Free;
- end;
- end;
- end;
- procedure TfrmMain.actCleanAttampExecute(Sender: TObject);
- var
- Xml:TAppXml;
- begin
- if MsgBoxYesOrNo('您确定要清空定时邮件吗?')=mrOK then
- begin
- xml:=TAppXml.Create;
- try
- xml.CleanAttmp(GetSeletedEmailAddr);
- finally
- Xml.Free;
- end;
- end;
- end;
- procedure TfrmMain.JvNavPaneToolPanel3Close(Sender: TObject);
- begin
- cxSplitter1.State:=ssClosed;
- btn12.Down:=False;
- end;
- procedure TfrmMain.btn12Click(Sender: TObject);
- begin
- if btn12.Down then
- cxSplitter1.State:=ssOpened
- else
- cxSplitter1.State:=ssClosed;
- end;
- procedure TfrmMain.tmrEmailAwakeTimer(Sender: TObject);
- var
- Awake:TEmailAwakeCollection;
- I:integer;
- hMutex:THandle;
- begin
- hMutex:=CreateMutex(nil,false,'TfrmEmailAwaked_One_Inst');
- if GetLastError=ERROR_ALREADY_EXISTS then
- begin
- CloseHandle(hMutex);
- Exit;
- end;
- CloseHandle(hMutex);
-
- Awake:=TEmailAwakeCollection.Create;
- try
- LoadAwakeCollectionFromXml(Awake);
- for i:=pred(Awake.Count) downto 0 do
- begin
- if TEmailAwakeItem(Awake.Items[I]).Awake.IsAwake then //该邮件需要提醒了
- begin
- with TfrmEmailAwaked.Create(Application)do
- try
- lblTitle.Caption:=TEmailAwakeItem(Awake.Items[I]).Awake.Title;
- edMemo.lines.Text:=TEmailAwakeItem(Awake.Items[I]).Awake.Memo;
- FEmailAddr:=TEmailAwakeItem(Awake.Items[I]).Awake.EmailAddr;
- FContentFilePath:= TEmailAwakeItem(Awake.Items[I]).Awake.ContentFilePath;
- TEmailAwakeItem(Awake.Items[I]).Awake.BaseTime:=TEmailAwakeItem(Awake.Items[I]).Awake.NextAwake;
- case ShowModal of
- mrOK: //打开
- Begin
- with TfrmViewEmail.Create(Application)do
- try
- FEmailAddr:=TEmailAwakeItem(Awake.Items[I]).Awake.EmailAddr;
- FContentFilePath:=TEmailAwakeItem(Awake.Items[I]).Awake.ContentFilePath;
- ShowModal;
- finally
- Awake.Delete(I);
- Free;
- end;
- End;
- mrCancel: //清除
- Begin
- Awake.Delete(I);
- MsgBoxWarn('删除成功');
- End;
- mrRetry: //再次提醒
- begin
- TEmailAwakeItem(Awake.Items[I]).Awake.UserNextAwake:=true;
- End;
-
- MrNone:;
- else;
- end;
- finally
- Free;
- end;
- SaveAwakeCollectionFromXml(Awake);
- end;
- end;
- finally
- Awake.Free;
- end;
- end;
- procedure TfrmMain.actViewEmailExecute(Sender: TObject);
- begin
- if tvTableView.DataController.FocusedRecordIndex<0 then exit;
- with TfrmViewEmail.Create(Application)do
- begin
- try
- FTableView:=tvTableView;
- FCurRecordIndex:=tvTableView.DataController.FocusedRecordIndex;
- FContentFileItemIndex:=gtvColContentFilename.Index;
- FSenderEmail:= VarToStr(tvTableView.DataController.Values[FCurRecordIndex, gtvColSender.Index]);
- FRecverEmail:= VarToStr(tvTableView.DataController.Values[FCurRecordIndex, gtvColMyAddr.Index]);
- ShowEmail;
- ShowModal;
- finally
- Free;
- end;
- end;
- end;
- procedure TfrmMain.btn2Click(Sender: TObject);
- begin
- with TfrmSingnals.Create(Application)do
- begin
- try
- ShowModal;
- finally
- Free;
- end;
- end;
- end;
- procedure TfrmMain.btn9Click(Sender: TObject);
- var
- xml:TAppXml;
- L:TStringList;
- begin
- if tvTableView.DataController.FocusedRecordIndex=-1 then
- begin
- MsgBoxError('请选中表格中的一封邮件!');
- exit;
- end;
- xml:=TAppXml.Create;
- try
- L:=TStringList.Create;
- try
- L.Add(varTostr(tvTableView.DataController.Values[tvTableView.DataController.FocusedRecordIndex,gtvColSender.Index]));
- xml.AddBlackList(L);
- finally
- L.Free;
- end;
- finally
- Xml.Free;
- end;
- MsgBoxWarn(Format('发件人%S成功加入到黑名单',[vartostr(tvTableView.DataController.Values[tvTableView.DataController.FocusedRecordIndex,gtvColSender.Index])]));
- end;
- procedure TfrmMain.btn10Click(Sender: TObject);
- var
- xml:TAppXml;
- L:TStringList;
- begin
- if tvTableView.DataController.FocusedRecordIndex=-1 then
- begin
- MsgBoxError('请选中表格中的一封邮件!');
- exit;
- end;
-
- xml:=TAppXml.Create;
- try
- L:=TStringList.Create;
- try
- L.Add(tvTableView.DataController.Values[tvTableView.DataController.FocusedRecordIndex,gtvColSender.Index]);
- xml.AddWhiteList(L);
- finally
- L.Free;
- end;
- finally
- Xml.Free;
- end;
- MsgBoxWarn(Format('发件人%S成功加入到白名单',[vartostr(tvTableView.DataController.Values[tvTableView.DataController.FocusedRecordIndex,gtvColSender.Index])]));
- end;
- procedure TfrmMain.dxBarButton2Click(Sender: TObject);
- begin
- HtmlEdit.PrintPageSetup;
- HtmlEdit.PrintPreview;
- end;
- procedure TfrmMain.btnSaveAllClick(Sender: TObject);
- begin
- HtmlEdit.PrintPageSetup;
- HtmlEdit.Print;
- end;
- procedure TfrmMain.OnOneSend(Sender: TObject;Email:TEmailInfo);
- begin
- end;
- procedure TfrmMain.OnOneSendEnd(Sender: TObject; Email: TEmailInfo);
- var
- xml:TAppXml;
- idx:Integer;
- begin
- if not email.IsError then
- begin
- xml:=TAppXml.Create;
- try
- xml.AddSentEmail(Email.Send.UserName,email.Id);
- Xml.DeleteSendingEmail(Email.Send.UserName,Email.Id);
- finally
- xml.free;
- end;
- if FShowEmailSending then //从表格中删除数据
- begin
- idx:=tvTableView.DataController.FindRecordIndexByText(0,gtvColContentFilename.Index,Email.Id,true,true,false);
- if idx>=0 then
- tvTableView.DataController.DeleteRecord(idx);
- end;
- end;
- end;
- procedure TfrmMain.LoadSending;
- var
- contentFileName:TStringList;
- MyXml:TAppXml;
- Str:string;
- begin
- if tvEMail.Selected.Text<>'发件箱' then Exit; //显示所有已发送的邮件
- //WriteLog('LoadSending run');
- FShowEmailSending:=True;
- btnRecpOne.Enabled:=false;
- btnUnRead.Enabled:=True;
- FSendEmailBox:=true;
- actReply.Enabled:=False;
- Str:=PPopInfo(tvEMail.Selected.Parent.Data).EMailAddr;
- gtvColSender.Caption:='收件人';
- gtvColMyAddr.Visible:=true;
- gtvColMyAddr.Caption:='发件人';
- gtvColReaded.Visible:=false;
- gtvColDate.Visible:=False;
- gtvColDate.Caption:='发件时间';
- gtvColAttch.Visible:=false;
-
- contentFileName:=TStringList.Create;
- MyXml:=TAppXml.Create;
- try
- MyXml.GetAllSendingEmail(Str,contentFileName);
- finally
- MyXml.Free;
- end;
- LoadFromFile(Str,contentFileName);
- contentFileName.Free;
- end;
- procedure TfrmMain.btn17Click(Sender: TObject);
- begin
- //FEmailChecker.
- end;
- procedure TfrmMain.LoadContact;
- var
- I:Integer;
- La,Ln:TStringList;
- begin
- ltAddr.Clear;
-
- Ln:=TStringList.create;
- La:=TStringList.create;
- try
- with TAppXml.Create do
- try
- LoadContacts(La,ln);
- finally
- Free;
- end;
- for I:= 0 to La.Count-1 do
- begin
- with ltAddr.Add do
- begin
- Values[0]:=False;
- Values[1]:=Ln.Strings[I];
- Values[2]:=La.Strings[I];
- end;
- end;
- finally
- Ln.Free;
- La.Free;
- end;
- end;
- procedure TfrmMain.dxBarButton22Click(Sender: TObject);
- begin
- with TfrmAddr.Create(nil) do
- try
- FContactModel:=cmAdd;
- ShowModal;
- finally
- Free;
- end;
- end;
- procedure TfrmMain.dxBarButton23Click(Sender: TObject);
- begin
- with TfrmAddr.Create(nil) do
- try
- FContactModel:=cmDelete;
- ShowModal;
- finally
- Free;
- end;
- end;
- procedure TfrmMain.dxBarButton24Click(Sender: TObject);
- begin
- with TfrmAddr.Create(nil) do
- try
- FContactModel:=cmEdit;
- ShowModal;
- finally
- Free;
- end;
- end;
- procedure TfrmMain.dxBarButton27Click(Sender: TObject);
- var
- FCurRecordIndex:Integer;
- begin
- FCurRecordIndex:= tvTableView.DataController.FocusedRecordIndex;
- if FCurRecordIndex<0 then exit;
- with TfrmAddr.Create(nil) do
- try
- FContactModel:=cmAdd;
- edAddr.Text:=VarToStr(tvTableView.DataController.Values[FCurRecordIndex, gtvColSender.Index]);
- ShowModal;
- finally
- Free;
- end;
- end;
- procedure TfrmMain.ltAddrDblClick(Sender: TObject);
- begin
- if ltAddr.SelectionCount=1 then
- begin
- with TfrmAddr.Create(nil) do
- try
- FContactModel:=cmEdit;
- edAddr.Text:=ltAddr.Selections[0].Values[2];
- edName.Text:=ltAddr.Selections[0].Values[1];
- ShowModal;
- finally
- Free;
- end;
- end;
- end;
- procedure TfrmMain.dxbrbtnAddClick(Sender: TObject);
- begin
- if ltAddr.SelectionCount=1 then
- begin
- with TfrmAddr.Create(nil) do
- try
- FContactModel:=cmAdd;
- //edAddr.Text:=ltAddr.Selections[0].Values[2];
- //edName.Text:=ltAddr.Selections[0].Values[1];
- ShowModal;
- finally
- Free;
- end;
- end;
- end;
- procedure TfrmMain.dxbrbtnDelClick(Sender: TObject);
- begin
- if ltAddr.SelectionCount=1 then
- begin
- with TfrmAddr.Create(nil) do
- try
- FContactModel:=cmDelete;
- edAddr.Text:=ltAddr.Selections[0].Values[2];
- //edName.Text:=ltAddr.Selections[0].Values[1];
- ShowModal;
- finally
- Free;
- end;
- end;
- end;
- procedure TfrmMain.dxbrbtnEditClick(Sender: TObject);
- begin
- ltAddrDblClick(nil);
- end;
- procedure TfrmMain.dxBarLargeButton10Click(Sender: TObject);
- begin
- with TfrmAbout.Create(nil) do
- begin
- try
- ShowModal;
- finally
- Free;
- end;
- end;
- end;
- procedure TfrmMain.dxBarButton25Click(Sender: TObject);
- var
- OutLook,Ns,Floder,It,Ct,oEnum:OleVariant;
- begin
- try
- OutLook:=GetActiveOleObject('Outlook.Application');
- except
- try
- OutLook:=CreateOleObject('Outlook.Application');
- except
- MessageDlg('请确认你是否安装了OutLook。' + #13#10 +
- '如果没有安装,请安装之后再重试。' + #13#10#13#10#13#10,
- mtError, [mbOK], 0);
- end;
- end;
- try
- Ns:=OutLook.GetNamespace('MAPI');
- Floder:=Ns.GetDefaultFolder(oEnum);
- It:=Floder.Items;
- Ct:=It.GetFirst;
- with TAppXml.Create do
- try //not VarIsNull(ct)
- while (Ct<>NULL) do
- begin
- AddContact(ct.Email1Address,ct.FullName,'');
- ct:= it.GetNext;
- end;
- LoadContact;
- finally
- Free;
- end;
- except
- MessageDlg('未知的错误' + #13#10#13#10#13#10#13#10 +
- #13#10, mtError, [mbOK], 0);
- end;
- ct:=null;
- it:=null;
- floder:=null;
- ns:=null;
- OutLook:=null;
- end;
- procedure TfrmMain.dxBarButton12Click(Sender: TObject);
- begin
- dxbrbtn18Click(NIL);
- end;
- initialization
- CoInitialize(nil);
- finalization
- CoUninitialize();
- end.