unit DOutMonMain; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, OutlookMonClient, Vcl.Buttons, Vcl.ExtCtrls, Vcl.Menus, Tocsg.Controls, VirtualTrees; const WM_NOTIFY_SEND_DATA = WM_USER + 8547; type TMailKind = (mkRcv, mkSend); PMailItem = ^TMailItem; TMailItem = record Kind: TMailKind; sSubject, sSender, sFolder, sTo, sCC, sBCC, sBody, sAttachs: String; dwAttachSize: DWORD; dtRcv: TDateTime; end; TDlgOutMonMain = class(TForm) pnTop: TPanel; MainMenu: TMainMenu; miSecu: TMenuItem; miAddIn: TMenuItem; miAddInReg: TMenuItem; miAddInUnreg: TMenuItem; miActive: TMenuItem; N5: TMenuItem; miDeactivce: TMenuItem; N6: TMenuItem; miExit: TMenuItem; chCollectSendMail: TCheckBox; chMailCttSch: TCheckBox; chCollectAttach: TCheckBox; edCollectAttachPath: TEdit; chAttachLimit: TCheckBox; edAttachLimit: TEdit; CheckBox6: TCheckBox; chCollectRcvMail: TCheckBox; btnSetPatterns: TSpeedButton; vtList: TVirtualStringTree; mmInfo: TMemo; Splitter1: TSplitter; popFun: TPopupMenu; N1: TMenuItem; cbCttSchProc: TComboBox; Label1: TLabel; lbState: TLabel; tState: TTimer; procedure miExitClick(Sender: TObject); procedure btnSetPatternsClick(Sender: TObject); procedure miSecuClick(Sender: TObject); procedure miActiveClick(Sender: TObject); procedure miDeactivceClick(Sender: TObject); procedure vtListGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize: Integer); procedure vtListFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode); procedure vtListGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle; var HintText: string); procedure vtListGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string); procedure vtListFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex); procedure N1Click(Sender: TObject); procedure tStateTimer(Sender: TObject); procedure miAddInRegClick(Sender: TObject); procedure miAddInUnregClick(Sender: TObject); private { Private declarations } MgCtrls_: TManagerInputControlsData; Client_: TOutlookMonClient; procedure SetOptEnabled(bVal: Boolean); public { Public declarations } Constructor Create(aOwner: TComponent); override; Destructor Destroy; override; procedure process_WM_NOTIFY_SEND_DATA(var msg: TMessage); Message WM_NOTIFY_SEND_DATA; procedure process_WM_SYSCOMMAND(var msg: TWMSysCommand); Message WM_SYSCOMMAND; end; var DlgOutMonMain: TDlgOutMonMain; gMain: TDlgOutMonMain = nil; implementation uses Tocsg.Packet, Tocsg.Registry, Tocsg.Path, Tocsg.Safe, DSelectPattern, Define, GlobalOutAddInDefine, Tocsg.Convert, Tocsg.VTUtil, Tocsg.Process, Tocsg.Shell; {$R *.dfm} Constructor TDlgOutMonMain.Create(aOwner: TComponent); begin Inherited Create(aOwner); ASSERT(gMain = nil); gMain := Self; Caption := APP_TITLE; MgCtrls_ := TManagerInputControlsData.Create(CutFileExt(GetRunExePath) + '.ini'); MgCtrls_.RegInputCtrl(chCollectSendMail); MgCtrls_.RegInputCtrl(chCollectRcvMail); MgCtrls_.RegInputCtrl(cbCttSchProc); MgCtrls_.RegInputCtrl(chCollectAttach); MgCtrls_.RegInputCtrl(chAttachLimit); MgCtrls_.RegInputCtrl(edCollectAttachPath); MgCtrls_.RegInputCtrl(edAttachLimit); MgCtrls_.Load; Client_ := TOutlookMonClient.Create; mmInfo.Clear; tState.Enabled := true; end; Destructor TDlgOutMonMain.Destroy; begin gMain := nil; Client_.DeactiveW2W; FreeAndNil(Client_); FreeAndNil(MgCtrls_); Inherited; end; procedure TDlgOutMonMain.SetOptEnabled(bVal: Boolean); begin chCollectSendMail.Enabled := bVal; chMailCttSch.Enabled := bVal; cbCttSchProc.Enabled := bVal; chCollectAttach.Enabled := bVal; btnSetPatterns.Enabled := bVal; edCollectAttachPath.Enabled := bVal; chAttachLimit.Enabled := bVal; edAttachLimit.Enabled := bVal; chCollectRcvMail.Enabled := bVal; end; procedure TDlgOutMonMain.tStateTimer(Sender: TObject); begin if Client_.Connected then begin lbState.Caption := 'Outlook ¿¬°á (º¸¾È)'; lbState.Font.Color := clBlue; end else if Client_.GetSelfWnd <> 0 then begin lbState.Caption := 'Outlook ¿¬°á ´ë±âÁß..'; lbState.Font.Color := clGreen; end else if not ExistsKey(HKEY_CLASSES_ROOT, REG_BS1OutlookAddInKey) then begin lbState.Caption := 'Ç÷¯±×ÀÎ ¹Ì¼³Ä¡'; lbState.Font.Color := clGray; end else begin lbState.Caption := 'º¸¾È ´ë±âÁß..'; lbState.Font.Color := clBlack; end; end; procedure TDlgOutMonMain.btnSetPatternsClick(Sender: TObject); var dlg: TDlgSelectPattern; begin Guard(dlg, TDlgSelectPattern.Create(Self)); dlg.ShowModal; end; procedure TDlgOutMonMain.miActiveClick(Sender: TObject); begin if Client_.GetSelfWnd = 0 then begin if not ExistsKey(HKEY_CLASSES_ROOT, REG_BS1OutlookAddInKey) then begin MessageBox(Handle, PChar('º¸¾È Ç÷¯±×ÀÎÀÌ ¼³Ä¡µÇ¾î ÀÖÁö ¾Ê½À´Ï´Ù.'+#13+#10+ '[¸Þ´º > º¸¾È > Outlook Ç÷¯±×ÀÎ > ¼³Ä¡]¸¦ ¼öÇà ÇØÁÖ¼¼¿ä.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; with Client_.MailPo do begin bCollectRcvMail := chCollectRcvMail.Checked; bCollectSendMail := chCollectSendMail.Checked; bMailCttSch := chMailCttSch.Checked; bCollectAttach := chCollectAttach.Checked; bBlockAttSize := chAttachLimit.Checked; llAttachLimit := StrToInt64Def(edAttachLimit.Text, 0) * 1048576; case cbCttSchProc.ItemIndex of 0 : MailCttSchProc := mcspMask; 1 : MailCttSchProc := mcspClear end; sCttSchPtrnPath := GetRunExePathDir + 'ptnsch.dat'; sCollectAttachPath := edCollectAttachPath.Text; if bMailCttSch and (sCollectAttachPath <> '') and not ForceDirectories(sCollectAttachPath) then sCollectAttachPath := ''; end; MgCtrls_.Save; SetOptEnabled(false); if Client_.ActiveW2W then SetRegValueString(HKEY_CURRENT_USER, 'Software\BS1Addin', 'OutMon', IntToStr(Client_.GetSelfWnd), true); end; end; procedure TDlgOutMonMain.miAddInRegClick(Sender: TObject); var sPath: String; begin if ExistsKey(HKEY_CLASSES_ROOT, REG_BS1OutlookAddInKey) then begin MessageBox(Handle, PChar('Ç÷¯±×ÀÎÀÌ ÀÌ¹Ì ¼³Ä¡µÇ¾î ÀÖ½À´Ï´Ù.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; if GetProcessPidByName('OUTLOOK.EXE') <> 0 then begin MessageBox(Handle, PChar('OutlookÀÌ ½ÇÇà µÇ¾î ÀÖ½À´Ï´Ù.'+#13+#10+ 'OutlookÀ» Á¾·á ÈÄ ´Ù½Ã ½ÃµµÇØÁֽʽÿÀ.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; sPath := GetRunExePathDir; if DirectoryExists(GetProgramFilesDir + 'Microsoft Office') then begin // 32bit ȯ°æÀ̱⠶§¹®¿¡ "C:\Program Files (x86)\Microsoft Office"·Î ÀÎÁö ÇØ¾ßÇÔ sPath := sPath + 'Bs1out.dll'; end else sPath := sPath + 'Bs1out64.dll'; if not FileExists(sPath) then begin MessageBox(Handle, PChar('Ç÷¯±×ÀÎ DLLÀÌ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; ExecutePath_hide('regsvr32.exe', Format('/i /s "%s"', [sPath])); MessageBox(Handle, PChar('Ç÷¯±×ÀÎÀÌ ¼³Ä¡ µÇ¾ú½À´Ï´Ù.'), PChar(Caption), MB_ICONINFORMATION or MB_OK); end; procedure TDlgOutMonMain.miAddInUnregClick(Sender: TObject); var sPath: String; begin if not ExistsKey(HKEY_CLASSES_ROOT, REG_BS1OutlookAddInKey) then begin MessageBox(Handle, PChar('Ç÷¯±×ÀÎÀÌ ¼³Ä¡µÇ¾î ÀÖÁö ¾Ê½À´Ï´Ù.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; if GetProcessPidByName('OUTLOOK.EXE') <> 0 then begin MessageBox(Handle, PChar('OutlookÀÌ ½ÇÇà µÇ¾î ÀÖ½À´Ï´Ù.'+#13+#10+ 'OutlookÀ» Á¾·á ÈÄ ´Ù½Ã ½ÃµµÇØÁֽʽÿÀ.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; if MessageBox(Handle, PChar('Ç÷¯±×ÀÎÀ» Á¦°Å ÇϽðڽÀ´Ï±î?'), PChar(Caption), MB_ICONQUESTION or MB_YESNO) = IDNO then exit; Client_.DeactiveW2W; SetOptEnabled(true); sPath := GetRunExePathDir; if DirectoryExists(GetProgramFilesDir + 'Microsoft Office') then begin // 32bit ȯ°æÀ̱⠶§¹®¿¡ "C:\Program Files (x86)\Microsoft Office"·Î ÀÎÁö ÇØ¾ßÇÔ sPath := sPath + 'Bs1out.dll'; end else sPath := sPath + 'Bs1out64.dll'; if not FileExists(sPath) then begin MessageBox(Handle, PChar('Ç÷¯±×ÀÎ DLLÀÌ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; ExecutePath_hide('regsvr32.exe', Format('/u /s "%s"', [sPath])); MessageBox(Handle, PChar('Ç÷¯±×ÀÎÀÌ Á¦°Å µÇ¾ú½À´Ï´Ù.'), PChar(Caption), MB_ICONINFORMATION or MB_OK); end; procedure TDlgOutMonMain.miDeactivceClick(Sender: TObject); begin if Client_.GetSelfWnd <> 0 then begin if MessageBox(Handle, PChar('Outlook º¸¾ÈÀ» ÇØÁ¦ ÇϽðڽÀ´Ï±î?'), PChar(Caption), MB_ICONQUESTION or MB_YESNO) = IDNO then exit; Client_.DeactiveW2W; end; SetOptEnabled(true); end; procedure TDlgOutMonMain.miExitClick(Sender: TObject); begin if ExistsKey(HKEY_CLASSES_ROOT, REG_BS1OutlookAddInKey) then begin if MessageBox(Handle, PChar('Ç÷¯±×ÀÎÀÌ Á¦°Å µÇÁö ¾ÊÀº »óÅÂÀÔ´Ï´Ù.'+#13+#10+'Á¾·áÇϽðڽÀ´Ï±î?'), PChar(Caption), MB_ICONWARNING or MB_YESNO) = IDNO then exit; end else if MessageBox(Handle, PChar('Á¾·áÇϽðڽÀ´Ï±î?'), PChar(Caption), MB_ICONQUESTION or MB_YESNO) = IDNO then exit; Close; end; procedure TDlgOutMonMain.miSecuClick(Sender: TObject); begin miActive.Enabled := not (Client_.GetSelfWnd <> 0); // Client_.Connected; miDeactivce.Enabled := not miActive.Enabled; miActive.Checked := not miActive.Enabled; miAddInReg.Enabled := not ExistsKey(HKEY_CLASSES_ROOT, REG_BS1OutlookAddInKey); miAddInUnreg.Enabled := not miAddInReg.Enabled; miAddInReg.Checked := not miAddInReg.Enabled; end; procedure TDlgOutMonMain.N1Click(Sender: TObject); begin if MessageBox(Handle, PChar('¸ñ·ÏÀ» ÃʱâÈ­ ÇϽðڽÀ´Ï±î?'), PChar(Caption), MB_ICONQUESTION or MB_YESNO) = IDNO then exit; VT_Clear(vtList); mmInfo.Clear; end; procedure TDlgOutMonMain.vtListFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex); var pData: PMailItem; begin if Node = nil then exit; pData := Sender.GetNodeData(Node); mmInfo.Clear; mmInfo.Lines.Add(Format('Á¦¸ñ : %s', [pData.sSubject])); mmInfo.Lines.Add(Format('º¸³½ »ç¶÷ : %s', [pData.sSender])); mmInfo.Lines.Add(Format('¹Þ´Â »ç¶÷ : %s', [pData.sTo])); mmInfo.Lines.Add(Format('ÂüÁ¶ : %s', [pData.sCC])); mmInfo.Lines.Add(Format('¼ûÀº ÂüÁ¶ : %s', [pData.sBCC])); mmInfo.Lines.Add(Format('¼ö½Å ½Ã°£ : %s', [DateTimeToStr(pData.dtRcv)])); if pData.sAttachs <> '' then mmInfo.Lines.Add(Format('÷ºÎ ÆÄÀÏ : %s (Àüü Å©±â : %s)', [pData.sAttachs, ByteSizeToStr(pData.dwAttachSize)])); mmInfo.Lines.Add(''); mmInfo.Lines.Add(pData.sBody); mmInfo.SelStart := 0; mmInfo.Perform(EM_SCROLLCARET, 0, 0); end; procedure TDlgOutMonMain.vtListFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode); var pData: PMailItem; begin pData := Sender.GetNodeData(Node); Finalize(pData^); end; procedure TDlgOutMonMain.vtListGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle; var HintText: string); begin HintText := vtList.Text[Node, Column]; end; procedure TDlgOutMonMain.vtListGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize: Integer); begin NodeDataSize := SizeOf(TMailItem); end; procedure TDlgOutMonMain.vtListGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string); var pData: PMailItem; begin pData := Sender.GetNodeData(Node); case Column of 0 : CellText := IntToStr(Node.Index + 1); 1 : begin if pData.Kind = mkRcv then begin if pData.sFolder = '' then CellText := '¹ÞÀº ÆíÁö' else CellText := Format('¹ÞÀº ÆíÁö (%s)', [pData.sFolder]); end else CellText := 'º¸³½ ÆíÁö'; end; 2 : CellText := pData.sSender; 3 : CellText := pData.sTo; 4 : CellText := pData.sCC; 5 : CellText := pData.sBCC; 6 : CellText := pData.sSubject; 7 : CellText := pData.sAttachs; 8 : CellText := ByteSizeToStr(pData.dwAttachSize); 9 : CellText := DateTimeToStr(pData.dtRcv); end; end; procedure TDlgOutMonMain.process_WM_NOTIFY_SEND_DATA(var msg: TMessage); var Rcv: IRcvPacket; pData: PMailItem; begin Rcv := IRcvPacket(msg.LParam); vtList.BeginUpdate; try pData := VT_AddChildData(vtList); pData.Kind := mkRcv; with Rcv do begin pData.sSubject := S['Subject']; pData.sSender := S['Sender']; pData.sTo := S['To']; pData.sCC := S['CC']; pData.sBCC := S['BCC']; pData.sBody := S['Body']; pData.sAttachs := S['Attachments']; pData.dwAttachSize := I['Size']; pData.sFolder := S['Folder']; pData.dtRcv := StrToDateTimeDef(S['ReceivedTime'], 0); end; case msg.WParam of OAI_MAILITEM_RCV_DATA : pData.Kind := mkRcv; OAI_MAILITEM_SEND_DATA : pData.Kind := mkSend; end; finally vtList.EndUpdate; end; end; procedure TDlgOutMonMain.process_WM_SYSCOMMAND(var msg: TWMSysCommand); begin if msg.CmdType = SC_CLOSE then begin miExit.Click; exit; end; Inherited; end; end.