ufrmMain.~pas
上传用户:yjb1804
上传日期:2021-01-30
资源大小:3105k
文件大小:71k
源码类别:

Email服务器

开发平台:

Delphi

  1. unit ufrmMain;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs,uSendMail, Menus, ExtCtrls, ComCtrls,
  6.   ImgList,dxBarExtItems, dxBar, cxClasses, cxControls, cxSplitter,
  7.   cxContainer, cxTreeView, msxmldom, JvExControls,
  8.   JvNavigationPane, JvExExtCtrls, Mail2000, cxGraphics,
  9.   cxCustomData, cxStyles, cxTL, cxInplaceContainer,uRecvEmail,
  10.   cxTextEdit, cxCheckBox, OleServer,
  11.   ActnList, cxDataStorage, cxEdit, cxGridCustomTableView,
  12.   cxGridTableView, cxGridCustomView, DB, cxGridLevel, cxGrid,
  13.   cxDBData, cxGridDBTableView, OleCtrls, OALib_TLB, JvComponentBase,
  14.   JvCipher, RzTray, cxGroupBox, CommCtrl, cxLabel, cxCalendar, SHDocVw, IniFiles,
  15.   cxImage,uRulerMgr,idSMTP, uCheckEmail, cxFilter, cxData, uHtmlEdit,
  16.   dxStatusBar, dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinCaramel,
  17.   dxSkinCoffee, {dxSkinDarkRoom,} dxSkinDarkSide, {dxSkinFoggy,}
  18.   dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
  19.   dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  20.   dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  21.   dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinPumpkin, {dxSkinSeven,}
  22.   {dxSkinSharp,} dxSkinSilver, {dxSkinSpringTime,} dxSkinStardust,
  23.   dxSkinSummer2008, dxSkinsDefaultPainters, dxSkinValentine,
  24.   dxSkinXmas2008Blue, {cxTLdxBarBuiltInMenu,} dxSkinscxPCPainter,
  25.   cxLookAndFeelPainters, dxSkinsdxBarPainter, OutlookXP;
  26. type
  27.   TfrmMain = class(TForm)
  28.     dxBarManager1: TdxBarManager;
  29.     dxBarManager1Bar1: TdxBar;
  30.     dxBarManager1Bar2: TdxBar;
  31.     dxBarManager1Bar5: TdxBar;
  32.     dxBarSubItem1: TdxBarSubItem;
  33.     dxBarSubItem2: TdxBarSubItem;
  34.     dxBarSubItem3: TdxBarSubItem;
  35.     dxBarSubItem4: TdxBarSubItem;
  36.     dxBarSubItem5: TdxBarSubItem;
  37.     dxBarSubItem6: TdxBarSubItem;
  38.     dxBarButton1: TdxBarLargeButton;
  39.     dxBarButton3: TdxBarLargeButton;
  40.     dxBarButton4: TdxBarLargeButton;
  41.     dxBarButton5: TdxBarLargeButton;
  42.     dxBarButton6: TdxBarLargeButton;
  43.     dxBarButton7: TdxBarLargeButton;
  44.     dxBarButton8: TdxBarLargeButton;
  45.     dxBarButton9: TdxBarLargeButton;
  46.     dxBarButton10: TdxBarLargeButton;
  47.     dxBarButton11: TdxBarLargeButton;
  48.     dxBarLargeButton1: TdxBarLargeButton;
  49.     btnSendAll: TdxBarLargeButton;
  50.     dxBarLargeButton3: TdxBarLargeButton;
  51.     dxBarLargeButton4: TdxBarLargeButton;
  52.     btnRecp: TdxBarLargeButton;
  53.     dxBarLargeButton6: TdxBarLargeButton;
  54.     dxBarLargeButton7: TdxBarLargeButton;
  55.     dxBarButton15: TdxBarButton;
  56.     dxBarColorCombo1: TdxBarColorCombo;
  57.     dxBarFontNameCombo1: TdxBarFontNameCombo;
  58.     dxBarDateCombo1: TdxBarDateCombo;
  59.     dxBarSpinEdit1: TdxBarSpinEdit;
  60.     BarProgress: TdxBarProgressItem;
  61.     lblProgress: TdxBarStatic;
  62.     dxBarLargeButton9: TdxBarLargeButton;
  63.     dxBarLargeButton10: TdxBarLargeButton;
  64.     btnNewWindow: TdxBarLargeButton;
  65.     btnArrangeAll: TdxBarLargeButton;
  66.     btnSplit: TdxBarLargeButton;
  67.     btnNew: TdxBarLargeButton;
  68.     btnOpen: TdxBarLargeButton;
  69.     btnSendAndRecv: TdxBarLargeButton;
  70.     btnClose: TdxBarLargeButton;
  71.     btnPrint: TdxBarLargeButton;
  72.     btnSaveAs: TdxBarLargeButton;
  73.     btnSaveAll: TdxBarLargeButton;
  74.     dxBarSubItem7: TdxBarSubItem;
  75.     dxBarLargeButton8: TdxBarLargeButton;
  76.     dxBarButton2: TdxBarButton;
  77.     dxBarButton12: TdxBarButton;
  78.     dxbrbtn1: TdxBarButton;
  79.     dxbrbtn2: TdxBarButton;
  80.     Panel1: TPanel;
  81.     cxSplitter1: TcxSplitter;
  82.     Panel2: TPanel;
  83.     Panel3: TPanel;
  84.     PnlAddr: TPanel;
  85.     il1: TImageList;
  86.     JvNavPaneToolPanel1: TJvNavPaneToolPanel;
  87.     JvNavPaneToolPanel3: TJvNavPaneToolPanel;
  88.     Panel4: TPanel;
  89.     Panel5: TPanel;
  90.     cxSplitter2: TcxSplitter;
  91.     cxSplitter3: TcxSplitter;
  92.     lblMsgProgress: TdxBarStatic;
  93.     BarProgressMsg: TdxBarProgressItem;
  94.     lblError: TdxBarStatic;
  95.     cxStyleRepository1: TcxStyleRepository;
  96.     cxStyle1: TcxStyle;
  97.     dxBarButton13: TdxBarButton;
  98.     pm1: TdxBarPopupMenu;
  99.     dxBarSubItem8: TdxBarSubItem;
  100.     dxBarButton14: TdxBarButton;
  101.     dxBarButton16: TdxBarButton;
  102.     dxBarButton17: TdxBarButton;
  103.     dxBarButton18: TdxBarButton;
  104.     dxBarButton19: TdxBarButton;
  105.     dxbrbtn3: TdxBarButton;
  106.     dxbrbtn4: TdxBarButton;
  107.     dxbrbtn5: TdxBarButton;
  108.     dxbrbtn6: TdxBarButton;
  109.     dxbrbtn7: TdxBarButton;
  110.     dxbrbtn8: TdxBarButton;
  111.     dxbrbtn9: TdxBarButton;
  112.     dxbrbtn10: TdxBarButton;
  113.     dxbrbtn11: TdxBarButton;
  114.     dxBarSpinEdit2: TdxBarSpinEdit;
  115.     dxBarToolbarsListItem1: TdxBarToolbarsListItem;
  116.     dxbrtlbrslstm1: TdxBarToolbarsListItem;
  117.     dxbrtlbrslstm2: TdxBarToolbarsListItem;
  118.     dxbrtlbrslstm3: TdxBarToolbarsListItem;
  119.     ActionList1: TActionList;
  120.     actRecvCur: TAction;
  121.     actRecvAll: TAction;
  122.     actRecvThenDelete: TAction;
  123.     dxBarToolbarsListItem2: TdxBarToolbarsListItem;
  124.     dxBarControlContainerItem1: TdxBarControlContainerItem;
  125.     dxbrbtn12: TdxBarButton;
  126.     dxbrlrgbtn1: TdxBarLargeButton;
  127.     dxBarButton20: TdxBarButton;
  128.     btnRecpOne: TdxBarButton;
  129.     dxbrbtn14: TdxBarButton;
  130.     dxBarButton21: TdxBarButton;
  131.     lblTotal: TdxBarStatic;
  132.     cxGrid1Level1: TcxGridLevel;
  133.     cxGrid1: TcxGrid;
  134.     tvTableView: TcxGridTableView;
  135.     gtvColReaded: TcxGridColumn;
  136.     gtvColSender: TcxGridColumn;
  137.     gtvColSubject: TcxGridColumn;
  138.     gtvColDate: TcxGridColumn;
  139.     gtvColSize: TcxGridColumn;
  140.     gtvColAttch: TcxGridColumn;
  141.     actNewEmail: TAction;
  142.     actAddrBook: TAction;
  143.     ltAddr: TcxTreeList;
  144.     cxtrlstclmnAddrcxTreeListColumn1: TcxTreeListColumn;
  145.     cxtrlstclmnAddrcxTreeListColumn2: TcxTreeListColumn;
  146.     cxtrlstclmnAddrcxTreeListColumn3: TcxTreeListColumn;
  147.     tvEMail: TcxTreeView;
  148.     dxbrbtn15: TdxBarButton;
  149.     actSuspend: TAction;
  150.     actStop: TAction;
  151.     dxbrbtn16: TdxBarButton;
  152.     TrayIcon: TRzTrayIcon;
  153.     cxgrpbx1: TcxGroupBox;
  154.     pnlAttch: TPanel;
  155.     gtvColContentFilename: TcxGridColumn;
  156.     lv1: TListView;
  157.     gtvColUIDL: TcxGridColumn;
  158.     gtvColMyAddr: TcxGridColumn;
  159.     gtvColAttchFullName: TcxGridColumn;
  160.     btnTurn: TdxBarLargeButton;
  161.     btnDeleteEmail: TdxBarLargeButton;
  162.     dxbrlrgbtn4: TdxBarLargeButton;
  163.     dxbrlrgbtn5: TdxBarLargeButton;
  164.     pm2: TdxBarPopupMenu;
  165.     dxbrbtn17: TdxBarButton;
  166.     dxbrbtn18: TdxBarButton;
  167.     btnUnRead: TdxBarButton;
  168.     actReply: TAction;
  169.     actResend: TAction;
  170.     actDeleteCurEmail: TAction;
  171.     dxbrbtn21: TdxBarButton;
  172.     dxbrbtn22: TdxBarButton;
  173.     dxbrbtn23: TdxBarButton;
  174.     actSendPendingEmail: TAction;
  175.     actRename: TAction;
  176.     actDeletePop: TAction;
  177.     dxbrbtn24: TdxBarButton;
  178.     dxbrbtn25: TdxBarButton;
  179.     dxbrbtn26: TdxBarButton;
  180.     dxbrbtn27: TdxBarButton;
  181.     dxbrbtn28: TdxBarButton;
  182.     actProperty: TAction;
  183.     dxbrbtn29: TdxBarButton;
  184.     actNewAccunt: TAction;
  185.     cxstyl1: TcxStyle;
  186.     cxstyl2: TcxStyle;
  187.     cxstyl3: TcxStyle;
  188.     cxstyl4: TcxStyle;
  189.     cxstyl5: TcxStyle;
  190.     imgFlag: TImage;
  191.     imgRecyle: TImage;
  192.     imgBoxNotOpen: TImage;
  193.     imgBoxOpen: TImage;
  194.     imgAttch: TImage;
  195.     gtvColUnUsed: TcxGridColumn;
  196.     tmrAttamp: TTimer;
  197.     btn1: TdxBarLargeButton;
  198.     btn2: TdxBarLargeButton;
  199.     pmLeft: TdxBarPopupMenu;
  200.     pmRight: TdxBarPopupMenu;
  201.     dxbrbtnAdd: TdxBarButton;
  202.     dxbrbtn31: TdxBarButton;
  203.     dxbrbtnEdit: TdxBarButton;
  204.     dxbrbtnDel: TdxBarButton;
  205.     dxbrbtn34: TdxBarButton;
  206.     dxbrbtn35: TdxBarButton;
  207.     dxbrbtn36: TdxBarButton;
  208.     dxbrbtn37: TdxBarButton;
  209.     dxbrbtn38: TdxBarButton;
  210.     dxbrbtn39: TdxBarButton;
  211.     dxbrbtn40: TdxBarButton;
  212.     dxbrbtn41: TdxBarButton;
  213.     tmrEmailAwake: TTimer;
  214.     btnDetectEmail: TdxBarLargeButton;
  215.     btn4: TdxBarLargeButton;
  216.     lblDetect: TdxBarStatic;
  217.     btnCleanRecvs: TdxBarButton;
  218.     btnCleanAttamp: TdxBarButton;
  219.     btnCleanSents: TdxBarButton;
  220.     btnCleanDraft: TdxBarButton;
  221.     actCleanRecvs: TAction;
  222.     actCleanSents: TAction;
  223.     actCleanDraft: TAction;
  224.     actCleanAttamp: TAction;
  225.     btnDeleteOneEmail: TdxBarButton;
  226.     btn3: TdxBarButton;
  227.     actTurn: TAction;
  228.     HtmlEdit: THtmlEdit;
  229.     btn5: TdxBarButton;
  230.     cxstylrpstry1: TcxStyleRepository;
  231.     cxstyl6: TcxStyle;
  232.     cxstyl7: TcxStyle;
  233.     cxstyl8: TcxStyle;
  234.     btn6: TdxBarButton;
  235.     btn7: TdxBarButton;
  236.     btn8: TdxBarButton;
  237.     btn9: TdxBarButton;
  238.     btn10: TdxBarButton;
  239.     btn11: TdxBarButton;
  240.     btn12: TdxBarButton;
  241.     btn13: TdxBarButton;
  242.     btn14: TdxBarButton;
  243.     btn15: TdxBarButton;
  244.     actViewEmail: TAction;
  245.     dxbrsbtm1: TdxBarSubItem;
  246.     pm3: TdxBarPopupMenu;
  247.     btn16: TdxBarButton;
  248.     btn17: TdxBarButton;
  249.     btn18: TdxBarButton;
  250.     btn19: TdxBarButton;
  251.     pm4: TdxBarPopupMenu;
  252.     btn20: TdxBarButton;
  253.     btn21: TdxBarButton;
  254.     btn22: TdxBarButton;
  255.     lbl1: TdxBarStatic;
  256.     dxbrprgrstm1: TdxBarProgressItem;
  257.     dxbrprgrstm2: TdxBarProgressItem;
  258.     dxbrpmn1: TdxBarPopupMenu;
  259.     dxBarButton22: TdxBarButton;
  260.     dxBarButton23: TdxBarButton;
  261.     dxBarButton24: TdxBarButton;
  262.     dxBarButton25: TdxBarButton;
  263.     dxBarButton26: TdxBarButton;
  264.     dxBarButton27: TdxBarButton;
  265.     ol1: TContactItem;
  266.     dxbrbtn13: TdxBarButton;
  267.     procedure JvNavPaneToolPanel1ButtonClick(Sender: TObject;
  268.       Index: Integer);
  269.     procedure FormCreate(Sender: TObject);
  270.     procedure tvEMailDeletion(Sender: TObject; Node: TTreeNode);
  271.     procedure popEmailProgress(Sender: TObject; Total, Current: Integer);
  272.     procedure MSGProgress(Sender: TObject; Total, Current: Integer);
  273.     procedure FormDestroy(Sender: TObject);
  274.     procedure actRecvAllExecute(Sender: TObject);
  275.     procedure actRecvThenDeleteExecute(Sender: TObject);
  276.     procedure actRecvCurExecute(Sender: TObject);
  277.     procedure actNewEmailExecute(Sender: TObject);
  278.     procedure actAddrBookExecute(Sender: TObject);
  279.     procedure actSuspendExecute(Sender: TObject);
  280.     procedure actStopExecute(Sender: TObject);
  281.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  282.     procedure tvEMailClick(Sender: TObject);
  283.     procedure lv1DblClick(Sender: TObject);
  284.     procedure gtvColReadedGetDisplayText(
  285.       Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
  286.       var AText: String);
  287.     procedure actDeleteCurEmailExecute(Sender: TObject);
  288.     procedure actSendPendingEmailExecute(Sender: TObject);
  289.     procedure dxBarLargeButton9Click(Sender: TObject);
  290.     procedure actRenameExecute(Sender: TObject);
  291.     procedure tvEMailExit(Sender: TObject);
  292.     procedure tvEMailEdited(Sender: TObject; Node: TTreeNode;
  293.       var S: String);
  294.     procedure tvEMailEditing(Sender: TObject; Node: TTreeNode;
  295.       var AllowEdit: Boolean);
  296.     procedure actDeletePopExecute(Sender: TObject);
  297.     procedure btnSendAndRecvClick(Sender: TObject);
  298.     procedure FormShow(Sender: TObject);
  299.     procedure actNewAccuntExecute(Sender: TObject);
  300.     procedure tvEMailMouseUp(Sender: TObject; Button: TMouseButton;
  301.       Shift: TShiftState; X, Y: Integer);
  302.     procedure tvTableViewMouseUp(Sender: TObject; Button: TMouseButton;
  303.       Shift: TShiftState; X, Y: Integer);
  304.     procedure actPropertyExecute(Sender: TObject);
  305.     procedure tmrAttampTimer(Sender: TObject);
  306.     procedure TrayIconLButtonDown(Sender: TObject);
  307.     procedure TrayIconRButtonDown(Sender: TObject);
  308.     procedure dxbrbtn34Click(Sender: TObject);
  309.     procedure dxbrbtn37Click(Sender: TObject);
  310.     procedure dxbrbtn39Click(Sender: TObject);
  311.     procedure btn1Click(Sender: TObject);
  312.     procedure dxBarButton3Click(Sender: TObject);
  313.     procedure dxbrbtn41Click(Sender: TObject);
  314.     procedure TrayIconMinimizeApp(Sender: TObject);
  315.     procedure TrayIconRestoreApp(Sender: TObject);
  316.     procedure btnDetectEmailClick(Sender: TObject);
  317.     procedure dxbrbtn35Click(Sender: TObject);
  318.     procedure btn4Click(Sender: TObject);
  319.     procedure dxbrlrgbtn4Click(Sender: TObject);
  320.     procedure dxbrbtn18Click(Sender: TObject);
  321.     procedure actCleanRecvsExecute(Sender: TObject);
  322.     procedure btnCleanSentsClick(Sender: TObject);
  323.     procedure btnCleanDraftClick(Sender: TObject);
  324.     procedure btnCleanAttampClick(Sender: TObject);
  325.     procedure btnUnReadClick(Sender: TObject);
  326.     procedure actReplyExecute(Sender: TObject);
  327.     procedure actTurnExecute(Sender: TObject);
  328.     procedure tvTableViewFocusedRecordChanged(
  329.       Sender: TcxCustomGridTableView; APrevFocusedRecord,
  330.       AFocusedRecord: TcxCustomGridRecord;
  331.       ANewItemRecordFocusingChanged: Boolean);
  332.     procedure tvTableViewCellDblClick(Sender: TcxCustomGridTableView;
  333.       ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  334.       AShift: TShiftState; var AHandled: Boolean);
  335.     procedure lv1Deletion(Sender: TObject; Item: TListItem);
  336.     procedure actCleanSentsExecute(Sender: TObject);
  337.     procedure actCleanDraftExecute(Sender: TObject);
  338.     procedure actCleanAttampExecute(Sender: TObject);
  339.     procedure JvNavPaneToolPanel3Close(Sender: TObject);
  340.     procedure btn12Click(Sender: TObject);
  341.     procedure tmrEmailAwakeTimer(Sender: TObject);
  342.     procedure actViewEmailExecute(Sender: TObject);
  343.     procedure btn2Click(Sender: TObject);
  344.     procedure btn9Click(Sender: TObject);
  345.     procedure btn10Click(Sender: TObject);
  346.     procedure dxBarButton2Click(Sender: TObject);
  347.     procedure btnSaveAllClick(Sender: TObject);
  348.     procedure btn17Click(Sender: TObject);
  349.     procedure dxBarButton22Click(Sender: TObject);
  350.     procedure dxBarButton23Click(Sender: TObject);
  351.     procedure dxBarButton24Click(Sender: TObject);
  352.     procedure dxBarButton27Click(Sender: TObject);
  353.     procedure ltAddrDblClick(Sender: TObject);
  354.     procedure dxbrbtnAddClick(Sender: TObject);
  355.     procedure dxbrbtnDelClick(Sender: TObject);
  356.     procedure dxbrbtnEditClick(Sender: TObject);
  357.     procedure dxBarLargeButton10Click(Sender: TObject);
  358.     procedure dxBarButton25Click(Sender: TObject);
  359.     procedure dxBarButton12Click(Sender: TObject);
  360.   private
  361.     { Private declarations }
  362.     //FEmailCount:Integer;
  363.     //FCurrent:Integer;
  364.     FEmailChecker:TCheckEmail;  //检查新邮件
  365.     FShowEmailSending:Boolean; //是否正在显示 未发邮件表格
  366.     FEmailPropertyPageIndex:Integer;
  367.     FUserName,
  368.     FpopServer,
  369.     FPwd:string;
  370.     FRecvEMail:TRecvEmail;  //pop3
  371.     FFilter:TRuleItems;   //过滤设置
  372.     FSendEmailBox:boolean;
  373.     FOldNodeText:string;
  374.     FMutex:THandle;
  375.     FUIDLList:THashedStringList;  //保存已经接收的邮件的uidl
  376.     FNewEmailUIDLList:THashedStringList; //保存新邮件UIDL
  377.     procedure MyOnRecvEMailProgress(Sender: TObject; Total, Current: Integer) ;
  378.     procedure MyOnRecvMsgProgress(Sender: TObject; Total, Current: Integer) ;
  379.     procedure OnError(Sender:TObject;ErrMsg:string);
  380.     procedure OnRetrieveed(sender: TObject;CurNum,Total:Integer;UIDL:String);
  381.     procedure OnRecvAttch(sender:TObject; FileName:string;FileStream:TMemoryStream;CurNum,Total:Integer);
  382.     procedure RecvComplete(Sender:TObject);
  383.     procedure OnGetUIDL(Sender:TObject;uidl:String;var Handle:Boolean);
  384.     procedure OnFilter(Sender:TObject;Action:TRuleAction;EmailSubject:string;EmailFrom:string;var DeleteIt:Boolean;var Ignore:Boolean);
  385.     procedure BeginRecv(Sender:TObject);
  386.     procedure EndRecv(Sender:TObject);
  387.     procedure OnTerminate(Sender:TObject);
  388.     procedure OnOneSend(Sender:TObject;Email:TEmailInfo);
  389.     procedure OnOneSendEnd(Sender:TObject;Email:TEmailInfo);
  390.     
  391.     procedure DetectingEmail(Sender:TObject;Runing:Boolean) ;
  392.     procedure OnNewEmailArrive(Sender:TObject;NewEmailUIDLs:TStrings);
  393.     procedure MultiThreadSendComplete(Sender:TObject);
  394.     procedure  MultiThreadSendError(Sender:TObject;Email:TEmailInfo;ErrMsg:string);
  395.     procedure AttachEvent;
  396.     procedure GetUIDLS;
  397.     function GetSeletedEmailAddr:string;
  398.     procedure LoadDefaultSavePath;
  399.   protected
  400.     procedure WndProc(var Message: TMessage); override;
  401.     procedure AddFileRelation(lv: TListView; filename: string);
  402.     procedure MegerOpenIcon(var bitmap:TBitmap); //合并2张icon图片
  403.     procedure MegerCloseIcon(var bitmap:TBitmap); //合并2张icon图片
  404.   public
  405.     { Public declarations }
  406.     FRuleSaveTo,
  407.     FEmailSaveTo,
  408.     FAttchSaveTo:string;
  409.     FRetryAgain:Boolean; //是否重复接收
  410.     FEmailArrivedPlaySound:string; // 新邮件到来播放的声音文件路径
  411.     FBlackList,
  412.     FWhiteList:TStrings; //黑白名单
  413.     FEmailDetect:TEmailDetectOption;
  414.     EmailSenderMgr:TEmailSenderMgr;
  415.     procedure GetCurPop3EMail(delete:Boolean=False);
  416.     procedure GetAllPop3EMail(delete:Boolean=False);
  417.     procedure LoadEmails(TreeView:TcxTreeView);
  418.     procedure LoadAddrs;
  419.     procedure ClearTableView(tv:TcxGridTableView);
  420.     procedure LoadRecvEmail;
  421.     procedure LoadSendEmail;
  422.     procedure LoadDraft;
  423.     procedure LoadAttamp;
  424.     procedure LoadRules;
  425.     procedure LoadFromFile(EmailAddr:string;Files:TStringList);
  426.     procedure SendEmailFromFile(FilePath:string);
  427.     procedure CreateDirs;
  428.     procedure LoadSending;
  429.     procedure LoadContact;
  430.   end;
  431. var
  432.   frmMain: TfrmMain;
  433. implementation
  434. uses ufrmNewSMTP, NativeXml, uCommon, ufrmCloseTip,ShellApi, ActiveX,
  435.   uMyXml, FMTips, ufrmEmailBoxProperty, UEmailFile, ufrmRule,
  436.   ufrmFilterPopTip, ufrmAttchMgr, uBaseEditorForm, ufrmWriteEmail,
  437.   ufrmViewEmail, ufrmAwake, uEmailAwake, ufrmEmailAwaked, ufrmSingnals,ufrmAddr,ufrmAbout,ComObj;
  438. {$R *.dfm}
  439. procedure TfrmMain.MegerCloseIcon(var bitmap:TBitmap);
  440. begin
  441.   bitmap.Canvas.Draw(0,0,imgBoxNotOpen.Picture.Graphic);
  442.   bitmap.Canvas.Draw(imgBoxOpen.Width,0,imgAttch.Picture.Graphic);
  443. end;
  444. procedure TfrmMain.MegerOpenIcon(var bitmap:TBitmap); //合并2张icon图片
  445. begin
  446.   bitmap.Canvas.Draw(0,0,imgBoxOpen.Picture.Graphic);
  447.   bitmap.Canvas.Draw(imgBoxOpen.Width,0,imgAttch.Picture.Graphic);
  448. end;
  449. procedure TfrmMain.JvNavPaneToolPanel1ButtonClick(Sender: TObject;
  450.   Index: Integer);
  451. begin
  452.   PnlAddr.Visible:=not PnlAddr.Visible
  453. end;
  454. procedure TfrmMain.LoadAddrs;
  455. {var
  456.   xml:TMyXml;
  457.   Lst:TList;
  458.   I:Integer;   }
  459. begin
  460.  { xml:=TMyXml.Create(AppPath+'EmailServers.xml');
  461.   try
  462.     lst:=TList.Create;
  463.     try
  464.       if  xml.Root.FindNode('emails')=nil then Exit;
  465.       Lst.Clear;
  466.       xml.Root.FindNode('emails').NodesByName('email',lst);
  467.       for I:=0 to Lst.Count-1 do
  468.       begin
  469.         with ltAddr.Add do
  470.         begin
  471.           Values[0]:=False;
  472.           Values[1]:=TXmlNode(Lst[I]).ReadString('displayname');
  473.           Values[2]:=TXmlNode(Lst[I]).ReadString('addr');
  474.         end;
  475.       end;
  476.     finally
  477.       Lst.Free;
  478.     end;
  479.   finally
  480.     xml.Free;
  481.   end;   }
  482. end;
  483. procedure TfrmMain.LoadEmails(TreeView:TcxTreeView);
  484. var
  485.   xml:TMyXml;
  486.   Lst:TList;
  487.   tvNode:TTreeNode;
  488.   info:PPopInfo;
  489.   I:Integer;
  490. begin
  491.   xml:=TMyXml.Create(AppPath+'EmailServers.xml');
  492.   try
  493.     if  (xml.Root.FindNode('pop3s')=nil)  then Exit;
  494.     //加载所有的pop3服务器到treeview
  495.     lst:=TList.Create;
  496.     try
  497.       xml.Root.FindNode('pop3s').NodesByName('pop3',lst);
  498.       TreeView.Items.Clear;
  499.       for I:=0 to Lst.Count-1 do
  500.       begin
  501.         tvNode:= TreeView.Items.Add(nil,TXmlNode(Lst[I]).ReadString('displayname'));
  502.         tvNode.ImageIndex:=109;
  503.         tvNode.SelectedIndex:=36;
  504.         tvNode.StateIndex:=104;
  505.         New(info);
  506.         ZeroMemory(info,SizeOf(TPopInfo));
  507.         info.EMailAddr:=TXmlNode(Lst[I]).ReadString('emailaddr');
  508.         info.pwd:=TXmlNode(Lst[I]).ReadString('pwd');
  509.         info.saveto:= TXmlNode(Lst[I]).ReadString('emailsaveto');
  510.         info.pop3Server:=  TXmlNode(Lst[I]).ReadString('pop3server');
  511.         tvnode.Data:=info;
  512.         with TreeView.Items.AddChild(tvNode,'收件箱')  do
  513.         begin
  514.           ImageIndex:=109;
  515.           SelectedIndex:=36;
  516.           StateIndex:=104;
  517.         end;
  518.         with TreeView.Items.AddChild(tvNode,'已发邮件') do
  519.         begin
  520.           ImageIndex:=109;
  521.           SelectedIndex:=36;
  522.           StateIndex:=104;
  523.         end;
  524.         with TreeView.Items.AddChild(tvNode,'发件箱') do
  525.         begin
  526.           ImageIndex:=109;
  527.           SelectedIndex:=36;
  528.           StateIndex:=104;
  529.         end;
  530.         with TreeView.Items.AddChild(tvNode,'草稿箱')do
  531.         begin
  532.           ImageIndex:=52;
  533.           SelectedIndex:=48;
  534.           StateIndex:=48;
  535.         end;
  536.         with TreeView.Items.AddChild(tvNode,'定时邮件') do
  537.         begin
  538.           ImageIndex:=86;
  539.           SelectedIndex:=87;
  540.           StateIndex:=87;
  541.         end;
  542.       end;
  543.     finally
  544.       Lst.Free;
  545.     end;
  546.   finally
  547.     xml.Free;
  548.   end;
  549. end;
  550. procedure TfrmMain.FormCreate(Sender: TObject);
  551. var
  552.   Xml:TAppXml;
  553. begin
  554.   //备份xml文件
  555.   DeleteFile(PAnsiChar(ExtractFilePath(ParamStr(0))+'EmailServers_Backup.xml')) ;
  556.   CopyFile(PAnsiChar(ExtractFilePath(ParamStr(0))+App_Xml),
  557.                     PAnsiChar(ExtractFilePath(ParamStr(0))+'EmailServers_Backup.xml'),
  558.                     False);
  559.   EmailSenderMgr:=TEmailSenderMgr.Create;
  560.   EmailSenderMgr.OnComplete:=Self.MultiThreadSendComplete;
  561.   EmailSenderMgr.OnSendError:=Self.MultiThreadSendError;
  562.   EmailSenderMgr.OnOneSend:=self.OnOneSend;
  563.   EmailSenderMgr.OnOneSend:=OnOneSendEnd;
  564.   FEmailPropertyPageIndex:=0;
  565.   FNewEmailUIDLList:=THashedStringList.Create;
  566.   FUIDLList:=THashedStringList.Create;
  567.   GetUIDLS;
  568.   FFilter:=TRuleItems.Create;
  569.   LoadRules;
  570.   FMutex:=0;
  571.   pnlAttch.Visible:=false;
  572.   FRecvEmail:=nil;
  573.   LoadEmails(tvEMail);
  574.   LoadAddrs;
  575.   LoadRules;
  576.   LoadContact;
  577.   FBlackList:=THashedStringList.Create;
  578.   FWhiteList:=THashedStringList.Create;
  579.   LoadDefaultSavePath;
  580.   CreateDirs;
  581.   FEmailChecker:=TCheckEmail.Create;
  582.   xml:=TAppXml.Create;
  583.   try
  584.     xml.GetUIDLS(FEmailChecker.OldUIDLs);
  585.   finally
  586.     xml.Free;
  587.   end;
  588.   FEmailChecker.OnNewEmailArrive:=OnNewEmailArrive;
  589.   FEmailChecker.OnEnterState :=DetectingEmail;
  590.   FEmailChecker.CreateChecker;
  591.   FEmailChecker.EnterState(asInit);
  592. end;
  593. procedure TfrmMain.tvEMailDeletion(Sender: TObject; Node: TTreeNode);
  594. begin
  595.   if Node.Data<>nil then Dispose(Node.Data) ;
  596. end;
  597. procedure TfrmMain.GetCurPop3EMail(delete:Boolean=False);
  598. var
  599.   N:TTreeNode;
  600. begin
  601.   N:=tvEMail.Selected;
  602.   if (N=nil)  then
  603.   begin
  604.     ShowMessage('请选择一个邮箱');
  605.     Exit;
  606.   end;
  607.   if N.Level=1 then N:=N.Parent;
  608.   //菜单不可用
  609.   actRecvCur.Enabled:=False;
  610.   actRecvAll.Enabled:=False;
  611.   actRecvThenDelete.Enabled:=False;
  612.   actStop.Enabled:=True;
  613.   actSuspend.Enabled:=True;
  614.   //获取当前选中的pop3的设置
  615.   FpopServer:=PPopInfo(N.Data).pop3Server;
  616.   FPwd :=PPopInfo(N.Data).pwd ;
  617.   FUserName:=PPopInfo(N.Data).EMailAddr;
  618.   if FRecvEMail<>nil then
  619.   begin
  620.     FRecvEMail.Terminate;
  621.     FRecvEMail.WaitFor;
  622.     FRecvEMail:=nil;
  623.   end;
  624.     //TerminateThread(FRecvEMail.Handle,0);
  625.   FRecvEmail:=TRecvEmail.Create(FpopServer,FUserName,FPwd);
  626.   AttachEvent;
  627.   FRecvEMail.DeleteAfterRecv:=Delete;
  628.   FRecvEMail.RetrieveAllMessage:=True;
  629.   FRecvEMail.Filter:=FFilter;
  630.   FRecvEMail.OnFilter:=OnFilter;
  631.   FRecvEMail.Resume;
  632. end;
  633. procedure TfrmMain.popEmailProgress(Sender: TObject; Total,
  634.   Current: Integer);
  635. begin
  636.   BarProgress.Min:=0;
  637.   BarProgress.Max:=Total;
  638.   BarProgress.Position:=Current;
  639.   if Total=Current then BarProgress.Position:=0;
  640. end;
  641. procedure TfrmMain.MSGProgress(Sender: TObject; Total, Current: Integer);
  642. begin
  643.  { BarProgressMsg.Min:=0;
  644.   BarProgressMsg.Max:=Total;
  645.   BarProgressMsg.Position:=Current;
  646.   if Total=Current then BarProgressMsg.Position:=0;   }
  647. end;
  648. procedure TfrmMain.FormDestroy(Sender: TObject);
  649. begin
  650.   FEmailChecker.Free;
  651.   if FRecvEMail<>nil then TerminateThread(FRecvEMail.Handle,0);
  652.   if FMutex<>0 then CloseHandle(FMutex);
  653.   FUIDLList.Free;
  654.   FFilter.Free;
  655.   FNewEmailUIDLList.Free;
  656.   FBlackList.Free;
  657.   FWhiteList.Free;
  658.   EmailSenderMgr.Free;
  659. end;
  660. procedure TfrmMain.MyOnRecvEMailProgress(Sender: TObject; Total,
  661.   Current: Integer);
  662. begin
  663.   BarProgress.Min:=0;
  664.   BarProgress.Max:=Total;
  665.   BarProgress.Position:=Current;
  666.   if Total=Current then BarProgress.Position:=0;
  667. end;
  668. procedure TfrmMain.MyOnRecvMsgProgress(Sender: TObject; Total,
  669.   Current: Integer);
  670. begin
  671.   BarProgressMsg.Min:=0;
  672.   BarProgressMsg.Max:=Total;
  673.   BarProgressMsg.Position:=Current;
  674.   if Total=Current then BarProgressMsg.Position:=0;
  675. end;
  676. procedure TfrmMain.OnError(Sender: TObject; ErrMsg: string);
  677. begin
  678.   lblError.Style:=cxStyle1;
  679.   lblError.Caption:=ErrMsg;
  680.   lblTotal.Caption:='接收邮件出错';
  681. end;
  682. procedure TfrmMain.OnRetrieveed(sender: TObject;CurNum,Total:Integer;UIDL:String);
  683. var
  684.   pop:TPOP2000;
  685.   I:Integer;
  686.   myXml:TMyXml;
  687.   FileName:string;
  688.   EMailFile:TEmailFile;
  689. begin
  690.   lblTotal.Caption:=Format('正在接收邮件:%D/%D',[CurNum,Total]);
  691.   pop:=TRecvEmail(sender).Pop3;
  692.   pop.MailMessage.RebuildBody;
  693.   //保存邮件正文
  694.   FileName:=AppPath+'recved'+GenalFileName+'.ema';
  695.   EMailFile:=TEmailFile.Create(FileName);
  696.   try
  697.     EMailFile.Subject:=pop.MailMessage.Subject;
  698.     EMailFile.Sender:=pop.MailMessage.FromAddress;
  699.     EMailFile.Recver:=pop.MailMessage.ReceiptAddress;//pop.MailMessage.ReplyToAddress;
  700.     EMailFile.Date:=DateTimeToStr(pop.MailMessage.Date);
  701.     EMailFile.Size:=IntToStr(Length(pop.MailMessage.PartSource));
  702.     EMailFile.Content:=pop.MailMessage.TextHtml.Text;
  703.     for I:=0 to pop.MailMessage.AttachList.Count-1 do
  704.       EMailFile.Attchs.Add(FAttchSaveto+pop.MailMessage.AttachList[I].FileName);
  705.     EMailFile.SaveEmail;
  706.   finally
  707.     EMailFile.Free;
  708.   end;
  709.   myXml:=TAppXml.Create;
  710.   try
  711.     myXml.AddNewEmail(pop.UserName,FileName,UIDL);
  712.   finally
  713.     myXml.Free;
  714.   end;
  715. end;
  716. procedure TfrmMain.OnRecvAttch(sender: TObject; FileName: string;
  717.   FileStream: TMemoryStream;CurNum,Total:Integer);
  718. begin
  719.   BarProgressMsg.Caption:=Format('附件%D/%D',[CurNum,Total]);
  720.   FileStream.SaveToFile(FAttchSaveTo+FileName);   //保存附件
  721. end;
  722. procedure TfrmMain.actRecvAllExecute(Sender: TObject);
  723. begin
  724.   GetAllPop3EMail;
  725. end;
  726. procedure TfrmMain.GetAllPop3EMail(delete:Boolean=False);
  727. var
  728.   I:Integer;
  729.   arr:array of string;
  730.   S:string;
  731. begin
  732.   actRecvCur.Enabled:=false;
  733.   actRecvThenDelete.Enabled:=false;
  734.   actStop.Enabled:=True;
  735.   actSuspend.Enabled:=True;
  736.   for I:=0 to tvEMail.Items.Count-1 do
  737.   begin
  738.     if tvEMail.Items[I].Level=1 then
  739.     begin
  740.       S:=PPopInfo(tvEMail.Items[I].Data).pop3Server+';';
  741.       S:= S+PPopInfo(tvEMail.Items[I].Data).EMailAddr+';';
  742.       S:= S+PPopInfo(tvEMail.Items[I].Data).pwd ;
  743.       SetLength(arr,Length(arr)+1);
  744.       arr[Length(arr)]:=S;
  745.     end;
  746.   end;
  747.   if FRecvEMail<>nil then TerminateThread(FRecvEMail.Handle,0);
  748.   FRecvEmail:=TRecvEmail.Create(arr);
  749.   AttachEvent;
  750.   FRecvEMail.DeleteAfterRecv:=Delete;
  751.   FRecvEMail.RetrieveAllMessage:=True;
  752.   FRecvEMail.Filter:=FFilter;
  753.   FRecvEMail.OnFilter:=OnFilter;
  754.   FRecvEMail.Resume;
  755. end;
  756. procedure TfrmMain.actRecvThenDeleteExecute(Sender: TObject);
  757. begin
  758.   GetCurPop3EMail(True);
  759. end;
  760. procedure TfrmMain.actRecvCurExecute(Sender: TObject);
  761. begin
  762.   lblTotal.Caption:='正在接收邮件,请稍候。';
  763.   lblError.Caption:='';
  764.   GetCurPop3EMail;
  765. end;
  766. procedure TfrmMain.actNewEmailExecute(Sender: TObject);
  767. begin
  768.   with TfrmWriteEMail.Create(Application) do
  769.   try
  770.     ShowModal;
  771.   finally
  772.     Free;
  773.   end;
  774. end;
  775. procedure TfrmMain.actAddrBookExecute(Sender: TObject);
  776. begin
  777.   PnlAddr.Visible:=not  PnlAddr.Visible;
  778. end;
  779. procedure TfrmMain.AttachEvent;
  780. begin
  781.   FRecvEMail.OnRecvEMailProgress:=MyOnRecvEMailProgress;
  782.   FRecvEMail.OnRecvMsgProgress:=MyOnRecvMsgProgress;
  783.   FRecvEMail.OnError:=OnError;
  784.   FRecvEMail.OnRetrieveed:=OnRetrieveed;
  785.   FRecvEMail.OnAttachFileRetrieveed:=OnRecvAttch;
  786.   FRecvEMail.OnComplete:=RecvComplete;
  787.   FRecvEMail.OnGetUIDL:=OnGetUIDL;
  788.   FRecvEMail.BeginWork:=Self.BeginRecv;
  789.   FRecvEMail.EndWork:=Self.EndRecv;
  790.   FRecvEMail.OnTerminate:=Self.OnTerminate;
  791.   FRecvEMail.BlackList:=FBlackList;
  792.   FRecvEMail.WhiteList:=FWhiteList;
  793. end;
  794. procedure TfrmMain.RecvComplete(Sender: TObject);
  795. begin
  796.   actRecvThenDelete.Enabled:=True;
  797.   actRecvCur.Enabled:=True;
  798.   actRecvAll.Enabled:=True;
  799. end;
  800. procedure TfrmMain.actSuspendExecute(Sender: TObject);
  801. begin
  802.   FRecvEMail.Suspend;
  803.   lblTotal.Caption:='收取邮件已暂停';
  804. end;
  805. procedure TfrmMain.actStopExecute(Sender: TObject);
  806. begin
  807.   if (FRecvEMail<>nil) then FRecvEMail.IsBusy=False;
  808.   TerminateThread(FRecvEMail.Handle,0);
  809.   actRecvThenDelete.Enabled:=True;
  810.   actRecvCur.Enabled:=True;
  811.   actRecvAll.Enabled:=True;
  812.   actSuspend.Enabled:=False;
  813.   actStop.Enabled:=False;
  814.   lblTotal.Caption:='收取邮件已停止';
  815.   BarProgress.Position:=0;
  816.   BarProgressMsg.Caption:='附件';
  817.   BarProgressMsg.Position:=0;
  818. end;
  819. procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
  820. var
  821.   frm:TfrmCloseTip;
  822.   r:TModalResult;
  823.   b:Boolean;
  824. begin
  825.   b:=false;
  826.   if FRecvEMail<>nil then   b:=FRecvEMail.IsBusy;
  827.   if b or EmailSenderMgr.HasEmail then
  828.   begin
  829.     //正在发送,收取邮件,提示是终止还是最小化。
  830.     frm:=TfrmCloseTip.Create(Application);
  831.     try
  832.       if b and EmailSenderMgr.HasEmail then
  833.         frm.lblTip.Caption:='您正在发送和收取邮件。'
  834.       else if b then
  835.         frm.lblTip.Caption:='您正在收取邮件。'
  836.       else
  837.         frm.lblTip.Caption:='您正在发送邮件。';
  838.       r:= frm.ShowModal ;
  839.     finally
  840.       frm.Free;
  841.     end;
  842.     if r=mrok then
  843.     begin
  844.       Action :=caNone;
  845.       TrayIcon.MinimizeApp;
  846.     end
  847.     else
  848.       Action:=cafree;
  849.   end
  850. end;
  851. procedure TfrmMain.AddFileRelation(lv: TListView; filename: string);
  852. var
  853.   ImageListHandle: THandle;
  854.   FileInfo: TSHFileInfo;
  855.   sfi: TSHFileInfoA;
  856.   PFileName:PAnsiChar;
  857. begin
  858.   // 小图标
  859.   ImageListHandle := SHGetFileInfo('', 0, FileInfo, SizeOf(FileInfo), SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
  860.   // 同ImageList关联
  861.   SendMessage(lv.Handle, LVM_SETIMAGELIST, LVSIL_SMALL, ImageListHandle);
  862.   // 大图标
  863.   ImageListHandle := SHGetFileInfo('', 0, FileInfo, SizeOf(FileInfo), SHGFI_SYSICONINDEX or SHGFI_LARGEICON);
  864.   SendMessage(lv.Handle, LVM_SETIMAGELIST, LVSIL_NORMAL, ImageListHandle);
  865.   SHGetFileInfo(PChar(FileName), 0, sfi, SizeOf(sfi),
  866.   SHGFI_DISPLAYNAME or SHGFI_TYPENAME or SHGFI_SMALLICON or SHGFI_ICON);
  867.   with lv.Items.Add do
  868.   begin
  869.     Caption := sfi.szDisplayName;
  870.     ImageIndex := sfi.iIcon;
  871.     GetMem(PFileName,length(FileName)+1) ;
  872.     fillchar(PFileName^,length(FileName)+1,0);
  873.     CopyMemory(PFileName,PAnsiChar(FileName),length(FileName));
  874.     Data:=PFileName;
  875.   end;
  876. end;
  877. procedure TfrmMain.tvEMailClick(Sender: TObject);
  878. begin
  879.   if TcxTreeView(Sender).Selected=nil then Exit;
  880.   btnUnRead.Enabled:=tvEMail.Selected.Text='收件箱';
  881.   ClearTableView(tvTableView);//清除已有记录
  882.   FShowEmailSending:=false;
  883.   LoadRecvEmail; //载入收件箱邮件
  884.   LoadSendEmail; //载入已发邮件邮件
  885.   LoadDraft;  //载入草稿箱邮件
  886.   LoadAttamp; // 载入定时邮件
  887.   LoadSending;
  888. end;
  889. procedure TfrmMain.lv1DblClick(Sender: TObject);
  890. begin
  891. if LV1.Selected <> nil then
  892.    if ShellExecute(0, 'open', LV1.Selected.Data, '', '', SW_NORMAL)<=32 then
  893.      ShellExecute(Handle,
  894.                  'OPEN',
  895.                  PChar('explorer.exe'),
  896.                  PChar('/select, "' + PChar(LV1.Selected.Data) + '"'),
  897.                  nil,
  898.                  SW_NORMAL) ;
  899. end;
  900. procedure TfrmMain.gtvColReadedGetDisplayText(
  901.   Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
  902.   var AText: String);
  903. begin
  904.   if ARecord.Values[0]=true then
  905.     AText:='已读'
  906.   else
  907.     AText:='未读' ;
  908. end;
  909. procedure TfrmMain.MultiThreadSendComplete(Sender: TObject);
  910. begin
  911.   btnSendAll.Enabled:=true;
  912.   MsgBoxWarn('邮件发送完毕!');
  913. end;
  914. procedure TfrmMain.MultiThreadSendError(Sender: TObject;Email:TEmailInfo; ErrMsg: string);
  915. var
  916.   Xml:TAppXml;
  917. begin
  918.   Email.IsError:=True;
  919.   Xml:=TAppXml.Create;
  920.   try
  921.     //从xml文件中删除
  922.     Xml.DeleteSendingEmail(Email.Send.UserName,Email.Id);
  923.     //从表格中删除数据
  924.     
  925.   finally
  926.     xml.Free;
  927.   end;
  928.   MsgBoxError(ErrMsg);
  929. end;
  930. procedure TfrmMain.actDeleteCurEmailExecute(Sender: TObject);
  931. var
  932.   xml:TAppXml;
  933. begin
  934.   with tvTableView.DataController do
  935.   begin
  936.     if FocusedRecordIndex<0 then
  937.     begin
  938.       MsgBoxError('请您选中表格中的一封邮件,再执行删除操作!');
  939.       exit;
  940.     end;
  941.     if MsgBoxYesOrNo(Format('您确定要删除邮件"%S"吗?',[VarToStr(Values[FocusedRecordIndex,gtvColSubject.index])]))=mrOK then
  942.     begin
  943.       xml:=TAppXml.Create;
  944.       try
  945.         xml.DeleteAEmail(VarToStr(Values[FocusedRecordIndex,gtvColMyAddr.Index]),VarToStr(Values[FocusedRecordIndex,gtvColContentFilename.Index]));
  946.         DeleteRecord(FocusedRecordIndex);
  947.       finally
  948.         xml.Free;
  949.       end;
  950.     end;
  951.   end;
  952. end;
  953. procedure TfrmMain.actSendPendingEmailExecute(Sender: TObject);
  954. var
  955.   L,Attch:TStringList;
  956.   xml:TMyXml;
  957.   I:integer;
  958.   EmailFile:TEmailFile;
  959.   pwd:String;
  960.   dest: TDestinationPart;
  961.   Orig:TOriginPart;
  962.   Email:TEmailInfo;
  963.   Node:TTreeNode;
  964.   Str:String;
  965. begin
  966.   Node:=tvEMail.Selected;
  967.   if Node=nil then Exit;
  968.   if Node.Level=1 then Node:=Node.Parent;
  969.   Str:=PPopInfo(Node.Data).EMailAddr;
  970.   
  971.   L:=TStringList.Create;
  972.   xml:=TAppXml.Create;  //获取所有未发邮件
  973.   try
  974.     xml.GetAllNotSendEmail(PPopInfo(Node.Data).EMailAddr,L);
  975.     xml.GetAllSendingEmail(PPopInfo(Node.Data).EMailAddr,L,false);
  976.     if L.Count=0 then
  977.     begin
  978.       L.Free;
  979.       MsgBoxError('没有未发邮件');
  980.       Exit;
  981.     end;
  982.     xml.AddSendingEmail(PPopInfo(Node.Data).EMailAddr,L);
  983.   finally
  984.     xml.Free;
  985.   end;
  986.   
  987.   Attch:=TStringList.Create;
  988.   Email:=TEmailInfo.Create;
  989.   try
  990.     for I:=0 to L.Count-1 do
  991.     begin
  992.       EmailFile:=TEmailFile.Create(L[I]);
  993.       try
  994.         Email.Id:=L[I];
  995.         EmailFile.GetEmail;
  996.         Attch.Assign(EmailFile.Attchs);
  997.         Dest:=TDestinationPart.Create(Trim(EmailFile.Recver),Trim(EmailFile.Recver),Trim(EmailFile.Recver),'',EmailFile.Subject,EmailFile.Content,Attch);
  998.         try
  999.           Email.Recv:=Dest;
  1000.         finally
  1001.           Dest.Free;
  1002.         end;
  1003.         
  1004.         xml:=TAppXml.Create;
  1005.         try
  1006.           pwd:=xml.GetEMailPwd(EmailFile.Sender);
  1007.         finally
  1008.           xml.Free;
  1009.         end;
  1010.         Orig:=TOriginPart.Create(atDefault,Trim(EmailFile.Sender),Trim(EmailFile.Sender),Trim(pwd),TEMailAddress.SMTPEmailSever(Trim(EmailFile.Sender)),25);
  1011.         try
  1012.           Email.Send:=Orig;
  1013.         finally
  1014.           Orig.Free;
  1015.         end;
  1016.       finally
  1017.         EmailFile.Free;
  1018.       end;
  1019.       EmailSenderMgr.Push(Email);  //加入到发送列表
  1020.     end;
  1021.   finally
  1022.     Attch.free;
  1023.     Email.Free;
  1024.     L.free;
  1025.   end;
  1026.   EmailSenderMgr.Send;
  1027. end;
  1028. procedure TfrmMain.dxBarLargeButton9Click(Sender: TObject);
  1029. begin
  1030.   with  TTipsForm.Create(Application) do
  1031.   try
  1032.     ShowModal;
  1033.   finally
  1034.     free;
  1035.   end;
  1036. end;
  1037. procedure TfrmMain.actRenameExecute(Sender: TObject);
  1038. var
  1039.   N:TTreeNode;
  1040. begin
  1041.   N:=tvEMail.Selected;
  1042.   if (N=nil)  then Exit;
  1043.   if (N.Level=1) then N:=N.Parent;
  1044.   //if (tvEMail.Selected.Text='草稿箱') or (tvEMail.Selected.Text='定时邮件') then Exit;
  1045.   tvEMail.ReadOnly:=False;
  1046.   N.EditText;
  1047. end;
  1048. procedure TfrmMain.tvEMailExit(Sender: TObject);
  1049. begin
  1050.   tvEMail.ReadOnly:=True;
  1051. end;
  1052. procedure TfrmMain.tvEMailEdited(Sender: TObject; Node: TTreeNode;
  1053.   var S: String);
  1054. var
  1055.   MyXml:TMyXml;
  1056.   xmlNode:TXmlNode;
  1057. begin
  1058.   if  (Node.Level<>0) and (Node.Text='草稿箱') or (Node.Text='定时邮件') then Exit;
  1059.   MyXml:=TMyXml.Create(AppPath+'EmailServers.xml');
  1060.   try
  1061.     xmlNode:=MyXml.FindPOP3EmailAddrNode(FOldNodeText);
  1062.     if xmlNode=nil then Exit;
  1063.     xmlNode.ValueAsString:=S;
  1064.   finally
  1065.     MyXml.Free;
  1066.   end;
  1067. end;
  1068. procedure TfrmMain.tvEMailEditing(Sender: TObject; Node: TTreeNode;
  1069.   var AllowEdit: Boolean);
  1070. begin
  1071.   FOldNodeText:=Node.Text;
  1072. end;
  1073. procedure TfrmMain.actDeletePopExecute(Sender: TObject);
  1074. var
  1075.   text:string;
  1076.   MyXml:TMyXml;
  1077.   xmlNode:TXmlNode;
  1078.   N:TTreeNode;
  1079. begin
  1080.   N:=tvEmail.Selected;
  1081.   if (N=nil)  then Exit;
  1082.   if N.Level=1 then N:=N.Parent;
  1083.   text:=GetSeletedEmailAddr;
  1084.   if Dialogs.MessageDlg(format('你确定要删除邮箱"%S"吗?',[N.Text]),mtConfirmation,[mbYes, mbNo],0)=mrNo then  Exit;
  1085.   tvEMail.Items.Delete(N);
  1086.   MyXml:=TMyXml.Create(AppPath+'EmailServers.xml');
  1087.   try
  1088.     xmlNode:=MyXml.FindPOP3EmailAddrNode(text);
  1089.     if xmlNode=nil then Exit;
  1090.     xmlNode.Parent.Delete;
  1091.   finally
  1092.     MyXml.Free;
  1093.   end;
  1094. end;
  1095. procedure TfrmMain.btnSendAndRecvClick(Sender: TObject);
  1096. begin
  1097.   try
  1098.     actSendPendingEmailExecute(nil);
  1099.   finally
  1100.     actRecvAllExecute(nil);
  1101.   end;
  1102. end;
  1103. procedure TfrmMain.FormShow(Sender: TObject);
  1104. var
  1105.   MyXml:TMyXml;
  1106.   loadonstatup:Boolean;
  1107. begin
  1108.   MyXml:=TMyXml.Create(AppPath+'EmailServers.xml');
  1109.   try
  1110.      loadonstatup:=StrToBool(MyXml.Root.FindNode('tips').AttributeByName['loadonstatup']);
  1111.   finally
  1112.      MyXml.free;
  1113.   end;
  1114.   if loadonstatup then  PostMessage(Self.Handle,WM_SHOW_TIP_FORM,0,0);  //显示每日提示
  1115. end;
  1116. procedure TfrmMain.WndProc(var Message: TMessage);
  1117. begin
  1118.   case Message.Msg  of
  1119.     WM_PREVINSTRUN:
  1120.     begin
  1121.       FMutex:=THandle(Message.WParam);
  1122.       TrayIcon.RestoreApp;
  1123.       TrayIcon.ShowBalloonHint('提醒您','《邮件收发系统》已经运行了');
  1124.     end;
  1125.     WM_SHOW_TIP_FORM:
  1126.     with TTipsForm.Create(Application)do
  1127.     try
  1128.       ShowModal;
  1129.     finally
  1130.       Free;
  1131.     end;
  1132.   else
  1133.     inherited;
  1134.   end;
  1135. end;
  1136. procedure TfrmMain.actNewAccuntExecute(Sender: TObject);
  1137. begin
  1138.   with TfrmNewSMTP.Create(Application) do
  1139.   try
  1140.     ShowModal;
  1141.   finally
  1142.     Free;
  1143.   end;
  1144. end;
  1145. procedure TfrmMain.tvEMailMouseUp(Sender: TObject; Button: TMouseButton;
  1146.   Shift: TShiftState; X, Y: Integer);
  1147. var
  1148.   P,pt:TPoint;
  1149.   Node:TTreeNode;
  1150. begin
  1151.   if Button= mbRight then
  1152.   begin
  1153.     GetCursorPos(p);
  1154.     pt:=tvEMail.ScreenToClient(p);
  1155.     Node:=tvEMail.GetNodeAt(pt.x,Pt.Y);
  1156.     if Node=nil then Exit;
  1157.     pm2.Popup(p.X,p.Y);
  1158.   end;
  1159. end;
  1160. procedure TfrmMain.tvTableViewMouseUp(Sender: TObject;
  1161.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  1162. var
  1163.   P:TPoint;
  1164. begin
  1165.   if Button= mbRight then
  1166.   begin
  1167.     if tvTableView.DataController.GetFocusedRecordIndex>=0 then
  1168.     begin
  1169.       GetCursorPos(p);
  1170.       pm1.Popup(p.X,p.Y);
  1171.     end;
  1172.   end;
  1173. end;
  1174. procedure TfrmMain.actPropertyExecute(Sender: TObject);
  1175. var
  1176.   N:TTreeNode;
  1177.   PScr:TPoint;
  1178. begin
  1179.   N:=tvEMail.Selected ;
  1180.   if N=nil then Exit;
  1181.   if N.Level=1 then  N:=N.Parent;
  1182.   with TfrmEmailBoxProperty.Create(Application) do
  1183.   try
  1184.     ShowPage(FEmailPropertyPageIndex);
  1185.     LoadDefault(PPopInfo(N.Data).EMailAddr);
  1186.     GetCursorPos(PScr);
  1187.     if PScr.Y+Height>Screen.Height then
  1188.       PScr.Y:=Screen.Height-Height;
  1189.     Self.ScreenToClient(Pscr);
  1190.     Left:=PScr.X;
  1191.     Top:=PScr.Y;  
  1192.     ShowModal;
  1193.   finally
  1194.     free;
  1195.   end;
  1196. end;
  1197. procedure TfrmMain.tmrAttampTimer(Sender: TObject);
  1198. var
  1199.   MyXml:TMyXml;
  1200.   files:TStringList;
  1201. begin
  1202.   //检测定时邮件
  1203.   files:=TStringList.Create;
  1204.   try
  1205.     MyXml:=TAppXml.Create;
  1206.     try
  1207.       myxml.GetAllAttamp(files);
  1208.     finally
  1209.       MyXml.Free;
  1210.     end;
  1211.     if files.Count>=0 then
  1212.     begin
  1213.        //有定时邮件需要发送
  1214.     end;
  1215.   finally
  1216.     files.Free;
  1217.   end;
  1218. end;
  1219. procedure TfrmMain.ClearTableView(tv:TcxGridTableView);
  1220. var
  1221.   I:Integer;
  1222. begin
  1223.   tv.BeginUpdate;
  1224.   try
  1225.     for I:=tv.DataController.RecordCount-1 downto 0 do
  1226.     begin
  1227.       tv.DataController.DeleteRecord(I);
  1228.       tv.DataController.Post;
  1229.     end;
  1230.   finally
  1231.     tv.EndUpdate;
  1232.   end;
  1233. end;
  1234. procedure TfrmMain.LoadAttamp;
  1235. var
  1236.   MyXml:TMyXml;
  1237.   Str:string;
  1238.   contentFileName:TStringList;
  1239. begin
  1240.   if tvEMail.Selected.Text<>'定时邮件' then Exit;
  1241.   WriteLog('LoadAttamp run');
  1242.   FSendEmailBox:=false;
  1243.   gtvColAttch.Visible:=True;
  1244.   gtvColMyAddr.Visible:=False;
  1245.   pnlAttch.Visible:=False;
  1246.   actReply.Enabled:=False;
  1247.   Str:=GetSeletedEmailAddr;
  1248.   gtvColSender.Caption:='收件人';
  1249.   gtvColSender.Visible:=true;
  1250.   gtvColReaded.Visible:=False;
  1251.   gtvColSubject.Visible:=true;
  1252.   gtvColSubject.Caption:='定时发送时间';
  1253.   contentFileName:=TStringList.Create;
  1254.   myXml:=TMyXml.Create(AppPath+'EmailServers.xml');
  1255.   try
  1256.     myXml.GetAllAttamp(Str,contentFileName);
  1257.   finally
  1258.     myXml.Free;
  1259.   end;
  1260.   LoadFromFile(Str,contentFileName);
  1261.   contentFileName.Free;
  1262. end;
  1263. procedure TfrmMain.LoadDraft;
  1264. var
  1265.   MyXml:TMyXml;
  1266.   Str:string;
  1267.   contentFileName:TStringList;
  1268. begin
  1269.   if tvEMail.Selected.Text<>'草稿箱' then Exit;
  1270.   WriteLog('LoadDraft run');
  1271.   FSendEmailBox:=false;
  1272.   gtvColAttch.Visible:=True;
  1273.   gtvColMyAddr.Visible:=False;
  1274.   btnUnRead.Enabled:=false;
  1275.   pnlAttch.Visible:=False;
  1276.   actReply.Enabled:=False;
  1277.   Str:=GetSeletedEmailAddr;
  1278.   gtvColSender.Caption:='收件人';
  1279.   gtvColSender.Visible:=true;
  1280.   gtvColReaded.Visible:=False;
  1281.   gtvColDate.Visible:=true;
  1282.   gtvColDate.Caption:='邮件撰写时间';
  1283.   contentFileName:=TStringList.Create;
  1284.   myXml:=TMyXml.Create(AppPath+'EmailServers.xml');
  1285.   try
  1286.     myXml.GetAllDraft(Str,contentFileName);
  1287.   finally
  1288.     myXml.Free;
  1289.   end;
  1290.   LoadFromFile(Str,contentFileName);
  1291.   contentFileName.Free;
  1292. end;
  1293. procedure TfrmMain.LoadRecvEmail;
  1294. var
  1295.   contentFileName,
  1296.   Readed,
  1297.   Attch,
  1298.   uidlList,
  1299.   FileShortName:TStringList;
  1300.   Str:string;
  1301.   MyXml:TMyXml;
  1302.   I,J:Integer;
  1303.   EmailFile:TEmailFile;
  1304.   recCount:Integer;
  1305. begin
  1306.   if tvEMail.Selected.Text<>'收件箱' then Exit;
  1307.   WriteLog('LoadRecvEmail run');
  1308.   gtvColAttch.Visible:=True;
  1309.   gtvColMyAddr.Visible:=False;
  1310.   FSendEmailBox:=false;
  1311.   pnlAttch.Visible:=False;
  1312.   actReply.Enabled:=True;
  1313.   Str:=GetSeletedEmailAddr;
  1314.   btnUnRead.Enabled:=true;
  1315.   gtvColSender.Caption:='发件人';
  1316.   gtvColSender.Visible:=true;
  1317.   gtvColReaded.Visible:=true;
  1318.   gtvColDate.Visible:=true;
  1319.   gtvColDate.Caption:='收件时间';
  1320.   contentFileName:=TStringList.Create;
  1321.   Readed:=TStringList.Create;
  1322.   Attch:=TStringList.Create;
  1323.   uidlList:=TStringList.Create;
  1324.   FileShortName:=TStringList.Create;
  1325.   try
  1326.     myXml:=TAppXml.Create;
  1327.     try
  1328.       myXml.GetAllEmail(Str,contentFileName,Readed,uidlList);
  1329.     finally
  1330.       myXml.Free;
  1331.     end;
  1332.     tvTableView.BeginUpdate;
  1333.     try
  1334.       WriteLog('recvEmail count:'+inttostr(contentFileName.Count));
  1335.       for I:=0 to contentFileName.Count-1 do
  1336.       begin
  1337.         if not FileExists(contentFileName.Strings[I]) then Continue;
  1338.         EMailFile:=TEmailFile.Create(contentFileName[I]);
  1339.         EMailFile.Attchs.Clear;
  1340.         try
  1341.           EMailFile.GetEmail;
  1342.           with tvTableView.DataController do
  1343.           begin
  1344.             recCount:=AppendRecord;
  1345.             //SetValue(recCount, 0,StrToBool(Readed[I]) );
  1346.             if FSendEmailBox then
  1347.               SetValue(recCount, gtvColSender.Index,EMailFile.Recver )
  1348.             else
  1349.               SetValue(recCount, gtvColSender.Index,EMailFile.Sender );
  1350.             SetValue(recCount, gtvColSubject.Index,EMailFile.Subject );
  1351.             SetValue(recCount,gtvColDate.Index,EMailFile.Date );
  1352.             if EMailFile.Size='' then EMailFile.Size:='0';
  1353.             if StrToInt(EMailFile.Size)>1024 then
  1354.               SetValue(recCount, gtvColSize.Index,IntToStr(StrToInt(EMailFile.Size) div 1024)+' KB')
  1355.             else
  1356.               SetValue(recCount, gtvColSize.Index,EMailFile.Size+' Bytes') ;
  1357.             SetValue(recCount, gtvColContentFilename.Index,contentFileName[I] );
  1358.             SetValue(recCount, gtvColUIDL.Index,uidlList[I] );
  1359.             SetValue(recCount, gtvColMyAddr.Index,Str);
  1360.             SetValue(recCount, gtvColAttchFullName.Index,Join(';',EMailFile.Attchs));
  1361.             WriteLog('Email '+inttostr(I)+' attchs:'+trim(EMailFile.Attchs.Text));
  1362.             WriteLog('cxGrid Show: '+Values[recCount, 9]);
  1363.             WriteLog('Join('';'',EMailFile.Attchs): '+Join(';',EMailFile.Attchs));
  1364.             WriteLog('--------------------------------------------------------') ;
  1365.             FileShortName.Clear;
  1366.             for J:=0 to  EMailFile.Attchs.Count-1 do
  1367.               FileShortName.Add(ExtractFileName(EMailFile.Attchs[J]));
  1368.             SetValue(recCount, gtvColAttch.Index,Join(';',FileShortName) );
  1369.             SetValue(recCount, gtvColReaded.Index,StrToBoolDef(Readed[I],False) );
  1370.             Post;
  1371.           end;
  1372.         finally
  1373.           EMailFile.Free;
  1374.         end;
  1375.       end;
  1376.     finally
  1377.       tvTableView.EndUpdate;
  1378.     end;
  1379.   finally
  1380.     FileShortName.free;
  1381.     uidlList.free;
  1382.     contentFileName.free;
  1383.     Readed.free;
  1384.     Attch.free;
  1385.   end;
  1386. end;
  1387. procedure TfrmMain.LoadSendEmail;
  1388. var
  1389.   contentFileName:TStringList;
  1390.   MyXml:TAppXml;
  1391.   Str:string;
  1392. begin
  1393.   if tvEMail.Selected.Text<>'已发邮件' then Exit; //显示所有已发送的邮件
  1394.   WriteLog('LoadSendEmail run');
  1395.   gtvColAttch.Visible:=True;
  1396.   gtvColMyAddr.Visible:=False;
  1397.   btnRecpOne.Enabled:=false;
  1398.   btnUnRead.Enabled:=True;
  1399.   FSendEmailBox:=true;
  1400.   actReply.Enabled:=False;
  1401.   Str:=PPopInfo(tvEMail.Selected.Parent.Data).EMailAddr;
  1402.   gtvColSender.Caption:='收件人';
  1403.   gtvColReaded.Visible:=false;
  1404.   gtvColDate.Visible:=True;
  1405.   gtvColDate.Caption:='发件时间';
  1406.   contentFileName:=TStringList.Create;
  1407.   MyXml:=TAppXml.Create;
  1408.   try
  1409.     MyXml.GetAllSentEmail(Str,contentFileName);
  1410.   finally
  1411.     MyXml.Free;
  1412.   end;
  1413.   LoadFromFile(Str,contentFileName);
  1414.   contentFileName.Free;
  1415. end;
  1416. procedure TfrmMain.SendEmailFromFile(FilePath: string);
  1417. begin
  1418. end;
  1419. procedure TfrmMain.LoadFromFile(EmailAddr:string;Files: TStringList);
  1420. var
  1421.   FileShortName:TStringList;
  1422.   I,J:Integer;
  1423.   EmailFile:TEmailFile;
  1424.   recCount:Integer;
  1425. begin
  1426.   FileShortName:=TStringList.Create;
  1427.   tvTableView.BeginUpdate;
  1428.   try
  1429.     recCount:=0;
  1430.     for I:=0 to Files.Count-1 do
  1431.     begin
  1432.       if not FileExists(Files.Strings[I]) then Continue;
  1433.       EMailFile:=TEmailFile.Create(Files[I]);
  1434.       EMailFile.GetEmail;
  1435.       with tvTableView.DataController do
  1436.       begin
  1437.         AppendRecord;
  1438.         //SetValue(recCount, 0,StrToBool(Readed[I]) );
  1439.         if FSendEmailBox then
  1440.           SetValue(recCount, gtvColSender.Index,EMailFile.Recver )
  1441.         else
  1442.           SetValue(recCount, gtvColSender.Index,EMailFile.Sender );
  1443.         SetValue(recCount, gtvColSubject.Index,EMailFile.Subject );
  1444.         SetValue(recCount, gtvColDate.Index,EMailFile.Date );
  1445.         if EMailFile.Size='' then EMailFile.Size:='0';
  1446.         if StrToInt(EMailFile.Size)>1024 then
  1447.           SetValue(recCount, gtvColSize.Index,IntToStr(StrToInt(EMailFile.Size) div 1024)+' KB')
  1448.         else
  1449.           SetValue(recCount, gtvColSize.Index,EMailFile.Size+' Btyes');
  1450.         //
  1451.         SetValue(recCount, gtvColContentFilename.Index,Files[I] );
  1452.         SetValue(recCount, gtvColUIDL.Index,'' );
  1453.         SetValue(recCount, gtvColMyAddr.Index,EmailAddr);
  1454.         SetValue(recCount, gtvColAttchFullName.Index,Join(';',EMailFile.Attchs));
  1455.         FileShortName.Clear;
  1456.         for J:=0 to  EMailFile.Attchs.Count-1 do
  1457.           FileShortName.Add(ExtractFileName(EMailFile.Attchs[J]));
  1458.         EMailFile.Free;
  1459.         SetValue(recCount, gtvColAttch.Index,Join(';',FileShortName) );
  1460.         SetValue(recCount, gtvColReaded.Index,False );
  1461.         Post;
  1462.       end;
  1463.       Inc(recCount);
  1464.     end;
  1465.   finally
  1466.     tvTableView.EndUpdate;
  1467.   end;
  1468.   FileShortName.free;
  1469. end;
  1470. procedure TfrmMain.OnGetUIDL(Sender: TObject; uidl: String;
  1471.   var Handle: Boolean);
  1472. var
  1473.  idx:integer;
  1474. begin
  1475.   idx:=FUIDLList.IndexOf(uidl);
  1476.   if idx=-1 then FUIDLList.Add(uidl);
  1477.   handle:=(FRetryAgain) and (idx>-1);
  1478.   writelog(#$D#$A'uidl:'+uidl+#$D#$A'FUIDLList:'+FUIDLList.Text+#$D#$A);
  1479. end;
  1480. procedure TfrmMain.GetUIDLS;
  1481. var
  1482.   AppXml:TAppXml;
  1483. begin
  1484.   AppXml:=TAppXml.Create;
  1485.   try
  1486.     AppXml.GetUIDLS(FUIDLList);
  1487.   finally
  1488.     AppXml.Free;
  1489.   end;
  1490. end;
  1491. procedure TfrmMain.LoadRules;
  1492. var
  1493.   MyXml:TMyXml;
  1494. begin
  1495.   MyXml:=TMyXml.Create(AppPath+'EmailServers.xml');
  1496.   try
  1497.     if FileExists(MyXml.GetRulesFilePath ) then
  1498.       FFilter.ReadFromFile(MyXml.GetRulesFilePath,FFilter);
  1499.   finally
  1500.     MyXml.Free;
  1501.   end;
  1502. end;
  1503. procedure TfrmMain.OnFilter(Sender: TObject;Action:TRuleAction; EmailSubject,
  1504.   EmailFrom: string;var DeleteIt:Boolean;var Ignore:Boolean);
  1505. begin
  1506.   DeleteIt:=Action.DeleteOnServer;
  1507.   Ignore:=Action.IgnoreNotRecv;
  1508.   try
  1509.     if FileExists(Action.PlaySound) then
  1510.       WinExec(PAnsiChar(Action.PlaySound),SW_SHOW);
  1511.     if FileExists(Action.RunExe) then
  1512.       WinExec(PAnsiChar(Action.RunExe),SW_SHOW);
  1513.   except
  1514.   end;
  1515.   if Action.PopTip then
  1516.   with TfrmFilterPopTip.Create(Application) do
  1517.   begin
  1518.     ShowInfo('过滤系统拦截到一封邮件',format('邮件主题是%S。'#$D#$A'邮件来自%S。'#$D#$A#$D#$A'你希望执行下列哪项操作?',[EmailSubject,EmailFrom]));
  1519.     try
  1520.       case ShowModal of
  1521.       mrYes:   //接收邮件
  1522.         Ignore:=False;
  1523.       mrNo:    //不接收
  1524.         Ignore:=True;
  1525.       mrCancel:  //从服务器上删除
  1526.         DeleteIt:=True;
  1527.       else; // Exception.Create('未定义返回值');
  1528.       end;
  1529.     finally
  1530.       Free;
  1531.     end;
  1532.   end;
  1533. end;
  1534. procedure TfrmMain.TrayIconLButtonDown(Sender: TObject);  //弹出左键菜单
  1535. begin
  1536.   //SendMessage(Self.Handle,WM_CANCELMODE,0,0);
  1537.   //pmleft.PopupFromCursorPos;
  1538. end;
  1539. procedure TfrmMain.TrayIconRButtonDown(Sender: TObject);  //弹出右键菜单
  1540. begin
  1541.   SendMessage(Self.Handle,WM_CANCELMODE,0,0);
  1542.   pmRight.PopupFromCursorPos;
  1543. end;
  1544. procedure TfrmMain.dxbrbtn34Click(Sender: TObject);
  1545. begin
  1546.   TrayIcon.RestoreApp;
  1547. end;
  1548. procedure TfrmMain.dxbrbtn37Click(Sender: TObject);
  1549. begin
  1550.   TrayIcon.MinimizeApp;
  1551. end;
  1552. procedure TfrmMain.dxbrbtn39Click(Sender: TObject);
  1553. begin
  1554.   Self.Close;
  1555. end;
  1556. procedure TfrmMain.CreateDirs;
  1557. begin
  1558.   if not DirectoryExists(FRuleSaveTo) then
  1559.   begin
  1560.     FRuleSaveTo:=IncludeTrailingPathDelimiter(AppPath+'Rules');
  1561.     CreateDir(FRuleSaveTo) ;
  1562.   end;
  1563.   if not DirectoryExists(FEmailSaveTo) then
  1564.   begin
  1565.     FEmailSaveTo:=IncludeTrailingPathDelimiter(AppPath+'emailsaveto');
  1566.     CreateDir(FEmailSaveTo) ;
  1567.   end;
  1568.   if not DirectoryExists(FAttchSaveTo) then
  1569.   begin
  1570.     FAttchSaveTo:=IncludeTrailingPathDelimiter(AppPath+'emailattchsaveto');
  1571.     CreateDir(FAttchSaveTo) ;
  1572.   end;
  1573. end;
  1574. procedure TfrmMain.LoadDefaultSavePath;
  1575. var
  1576.   MyXml:TMyXml;
  1577. begin
  1578.   MyXml:=TMyXml.Create(AppPath+'EmailServers.xml');
  1579.   try
  1580.     FEmailSaveTo :=IncludeTrailingPathDelimiter(VarToStr(MyXml.Pop3sNode.AttributeByName['emailsaveto']));
  1581.     FEmailSaveTo:=GetFullPath(FEmailSaveTo);
  1582.     
  1583.     FAttchSaveTo:=IncludeTrailingPathDelimiter(VarToStr(MyXml.Pop3sNode.AttributeByName['emailattchsaveto']));
  1584.     FAttchSaveTo:=GetFullPath(FAttchSaveTo);
  1585.     FRuleSaveTo:=IncludeTrailingPathDelimiter(MyXml.Root.FindNode('Rules').AttributeByName['RulesSaveTo']);
  1586.     FRuleSaveTo:=GetFullPath(FRuleSaveTo);
  1587.     MyXml.GetBlackList(FBlackList);
  1588.     MyXml.GetWhiteList(FWhiteList);
  1589.   finally
  1590.     MyXml.Free;
  1591.   end;
  1592. end;
  1593. procedure TfrmMain.BeginRecv(Sender: TObject); //开始接收
  1594. var
  1595.   myxml:TMyXml;
  1596. begin
  1597.   actRecvCur.Enabled:=False;
  1598.   actRecvThenDelete.Enabled:=False;
  1599.   actSuspend.Enabled:=True;
  1600.   actStop.Enabled:=True;
  1601.   MyXml:=TMyXml.Create(AppPath+'EmailServers.xml');
  1602.   try
  1603.     if myxml.FindPop3(FRecvEMail.Pop3.UserName)<>nil then
  1604.       FRetryAgain:=StrToBoolDef(myxml.FindPop3(FRecvEMail.Pop3.UserName).AttributeByName['ReDownload'],False);
  1605.   finally
  1606.     MyXml.Free;
  1607.   end;
  1608. end;
  1609. procedure TfrmMain.EndRecv(Sender: TObject); //接收完毕(不管是否发生错误,该事件都被触发)
  1610. begin
  1611.   BarProgress.Position:=0;
  1612.   BarProgressMsg.Position:=0;
  1613.   actSuspend.Enabled:=False;
  1614.   actStop.Enabled:=False;
  1615.   actRecvThenDelete.Enabled:=True;
  1616.   actRecvCur.Enabled:=True;
  1617.   actRecvAll.Enabled:=True;
  1618.   lblTotal.Caption:='收取完毕';
  1619. end;
  1620. procedure TfrmMain.OnTerminate(Sender: TObject);
  1621. begin
  1622.   FRecvEMail:=nil;
  1623. end;
  1624. procedure TfrmMain.btn1Click(Sender: TObject);
  1625. begin
  1626.   with TfrmRule.Create(Application) do
  1627.   try
  1628.     if ShowModal=mrOk then LoadRules;
  1629.   finally
  1630.     free;
  1631.   end;
  1632. end;
  1633. procedure TfrmMain.dxBarButton3Click(Sender: TObject);
  1634. begin
  1635.   FEmailPropertyPageIndex:=3;
  1636.   actPropertyExecute(nil);
  1637. end;
  1638. procedure TfrmMain.dxbrbtn41Click(Sender: TObject);
  1639. begin
  1640.   FEmailPropertyPageIndex:=2;
  1641.   actPropertyExecute(nil);
  1642. end;
  1643. procedure TfrmMain.OnNewEmailArrive(Sender: TObject;
  1644.   NewEmailUIDLs: TStrings);
  1645. begin
  1646.   with TfrmFilterPopTip.Create(Application)do
  1647.   try
  1648.     AlignButtons;
  1649.     ShowInfo('有封新邮件啦',format('您有%D封新邮件'#$D#$A#$D#$A'您希望执行下面的哪项操作?',[NewEmailUIDLs.Count]));
  1650.     if ShowModal <>mrYes then Exit;
  1651.   finally
  1652.     free;
  1653.   end;
  1654.   actRecvCur.Enabled:=false;
  1655.   actRecvThenDelete.Enabled:=false;
  1656.   actStop.Enabled:=True;
  1657.   actSuspend.Enabled:=True;
  1658.   if FRecvEMail<>nil then TerminateThread(FRecvEMail.Handle,0);
  1659.   FRecvEmail:=TRecvEmailExt.Create;
  1660.   AttachEvent;
  1661.   FRecvEMail.DeleteAfterRecv:=False;
  1662.   FRecvEMail.RetrieveAllMessage:=True;
  1663.   FRecvEMail.Filter:=FFilter;
  1664.   FRecvEMail.OnFilter:=OnFilter;
  1665.   TRecvEmailExt(FRecvEmail).NewEmailUIDLS:=NewEmailUIDLs;
  1666.   FRecvEMail.Resume;
  1667. end;
  1668. procedure TfrmMain.TrayIconMinimizeApp(Sender: TObject);
  1669. begin
  1670.   FEmailChecker.EnterState(asMin);
  1671. end;
  1672. procedure TfrmMain.TrayIconRestoreApp(Sender: TObject);
  1673. begin
  1674.   FEmailChecker.EnterState(asRestore);
  1675. end;
  1676. procedure TfrmMain.btnDetectEmailClick(Sender: TObject);
  1677. begin
  1678.   FEmailChecker.EnterState(asInit);
  1679. end;
  1680. procedure TfrmMain.dxbrbtn35Click(Sender: TObject);
  1681. begin
  1682.   FEmailChecker.EnterState(asInit);
  1683. end;
  1684. procedure TfrmMain.btn4Click(Sender: TObject);
  1685. begin
  1686.   with TfrmAttchMgr.Create(Application) do
  1687.   try
  1688.     ShowModal;
  1689.   finally
  1690.     free;
  1691.   end;
  1692. end;
  1693. procedure TfrmMain.dxbrlrgbtn4Click(Sender: TObject);  //test
  1694. begin
  1695.   if tvTableView.DataController.FocusedRecordIndex<0 then
  1696.   begin
  1697.     MsgBoxError('请在表格中选一封邮件。');
  1698.     exit;
  1699.   end;
  1700.   
  1701.   with TfrmAwake.Create(Application)do
  1702.   try
  1703.     with tvTableView.DataController do
  1704.     begin
  1705.       FEmailAddr:=VarToStr(Values[FocusedRecordIndex,gtvColMyAddr.Index]);
  1706.       FContentFilePath:=VarToStr(Values[FocusedRecordIndex,gtvColContentFilename.Index])
  1707.     end;
  1708.     ShowModal;
  1709.   finally
  1710.     Free;
  1711.   end;
  1712. end;
  1713. procedure TfrmMain.DetectingEmail(Sender: TObject; Runing: Boolean);
  1714. begin
  1715.   btnDetectEmail.Enabled:=not Runing;
  1716.   if Runing then
  1717.     LblDetect.Caption:='正在检测新邮件'
  1718.   else
  1719.     LblDetect.Caption:='';
  1720. end;
  1721. procedure TfrmMain.dxbrbtn18Click(Sender: TObject);  //作为附件发送
  1722. var
  1723.   contfile:string;
  1724.   EmailFile:TEmailFile;
  1725.   tempFileName:string;
  1726.   Strm:TMemoryStream;
  1727.   I:integer;
  1728. begin
  1729.   contfile:=VarToStr(tvTableView.DataController.GetValue(tvTableView.DataController.GetFocusedRecordIndex,gtvColContentFilename.Index));
  1730.   if not FileExists(contfile) then exit;
  1731.   tempFileName:=SysTempDir+GenalFilename+'.html';
  1732.   with TfrmWriteEMail.Create(Application) do
  1733.   try
  1734.     Caption:='发送邮件--作为附件发送';
  1735.     FSetDoc:=false;
  1736.     pnl1.Height:=234;
  1737.     
  1738.     EmailFile:=TEmailFile.Create(contfile);
  1739.     try
  1740.       EmailFile.GetEmail;
  1741.       with lstAttch.Items.Add do
  1742.       begin
  1743.         Text:=tempFileName;
  1744.         Checked:=True;
  1745.       end;
  1746.       for I:=0 to EmailFile.Attchs.Count-1 do
  1747.       begin
  1748.         with lstAttch.Items.Add do
  1749.         begin
  1750.           if FileExists(EmailFile.Attchs[I]) then
  1751.           begin
  1752.           Text:=EmailFile.Attchs[I];
  1753.           Checked:=True;
  1754.           end
  1755.           else
  1756.           begin
  1757.             Checked:=False;
  1758.             Text:='[文件不存在] '+lstAttch.Items[I].Text;
  1759.           end;
  1760.         end;
  1761.       end;
  1762.       Strm:=TMemoryStream.Create;
  1763.       Strm.Position:=0;
  1764.       Strm.WriteBuffer(EmailFile.Content[1],Length(EmailFile.Content));
  1765.       try
  1766.         Strm.SaveToFile(tempFileName);
  1767.       finally
  1768.         Strm.Free;
  1769.       end;
  1770.     finally
  1771.       EmailFile.Free;
  1772.     end;
  1773.     ShowModal;
  1774.   finally
  1775.     SysUtils.DeleteFile(tempFileName);
  1776.     Free;
  1777.   end;
  1778. end;
  1779. procedure TfrmMain.actCleanRecvsExecute(Sender: TObject);
  1780. var
  1781.   Xml:TAppXml;
  1782. begin
  1783.   if MsgBoxYesOrNo('您确定要清空收件箱吗?')=mrOK  then
  1784.   begin
  1785.     xml:=TAppXml.Create;
  1786.     try
  1787.       xml.CleanRecvs(GetSeletedEmailAddr);
  1788.     finally
  1789.       Xml.Free;
  1790.     end;
  1791.   end;
  1792. end;
  1793. function TfrmMain.GetSeletedEmailAddr: string;
  1794. var
  1795.   N:TTreeNode;
  1796. begin
  1797.   Result:='';
  1798.   N:=tvEmail.Selected;
  1799.   if N=nil then  exit ;
  1800.   if N.Level=1 then  N:=N.Parent;
  1801.   Result:=PPopInfo(N.Data).EMailAddr
  1802. end;
  1803. procedure TfrmMain.btnCleanSentsClick(Sender: TObject);
  1804. var
  1805.   Xml:TAppXml;
  1806. begin
  1807.   xml:=TAppXml.Create;
  1808.   try
  1809.     xml.CleanSents(GetSeletedEmailAddr);
  1810.   finally
  1811.     Xml.Free;
  1812.   end;
  1813. end;
  1814. procedure TfrmMain.btnCleanDraftClick(Sender: TObject);
  1815. var
  1816.   Xml:TAppXml;
  1817. begin
  1818.   xml:=TAppXml.Create;
  1819.   try
  1820.     xml.CleanDraft(GetSeletedEmailAddr);
  1821.   finally
  1822.     Xml.Free;
  1823.   end;
  1824. end;
  1825. procedure TfrmMain.btnCleanAttampClick(Sender: TObject);
  1826.   var
  1827.   Xml:TAppXml;
  1828. begin
  1829.   xml:=TAppXml.Create;
  1830.   try
  1831.     xml.CleanAttmp(GetSeletedEmailAddr);
  1832.   finally
  1833.     Xml.Free;
  1834.   end;
  1835. end;
  1836. procedure TfrmMain.btnUnReadClick(Sender: TObject);
  1837. var
  1838.   Xml:TAppXml;
  1839.   I:integer;
  1840. begin
  1841.   I:= tvTableView.DataController.FocusedRecordIndex;
  1842.   if I<0 then exit;
  1843.   Xml:=TAppXml.Create;
  1844.   try
  1845.     Xml.SetEmailUnreaded(VarToStr(tvTableView.DataController.Values[I,gtvColMyAddr.index]),VarToStr(tvTableView.DataController.Values[I,gtvColUIDL.Index]));
  1846.   finally
  1847.     Xml.Free;
  1848.   end;
  1849.   tvTableView.DataController.SetValue(I,gtvColReaded.Index,False);
  1850.   tvTableView.DataController.Post;
  1851. end;
  1852. procedure TfrmMain.actReplyExecute(Sender: TObject);
  1853. begin
  1854.   if tvTableView.DataController.GetFocusedRecordIndex =-1 then
  1855.   begin
  1856.     MsgBoxError('请选中表格中的一封邮件');
  1857.     Exit;
  1858.   end;
  1859.   
  1860.   with TfrmWriteEMail.Create(nil) do
  1861.   try
  1862.     Caption:='回复邮件';
  1863.     pnl1.Height:=130;
  1864.     with tvTableView.DataController do
  1865.     begin
  1866.       cbRecver.Properties.Items.Insert(0,VarToStr(GetValue(GetFocusedRecordIndex,gtvColSender.Index))) ;
  1867.       if cbSender.Properties.Items.IndexOf(VarToStr(GetValue(GetFocusedRecordIndex,gtvColMyAddr.Index))) <>-1 then
  1868.         cbSender.ItemIndex:=cbSender.Properties.Items.IndexOf(VarToStr(GetValue(GetFocusedRecordIndex,gtvColMyAddr.Index)));
  1869.     end;
  1870.     cbRecver.ItemIndex:=0;
  1871.     ShowModal;
  1872.   finally
  1873.     Free;
  1874.   end;
  1875. end;
  1876. procedure TfrmMain.actTurnExecute(Sender: TObject);
  1877. var
  1878.   contfile:string;
  1879.   EmailFile:TEmailFile;
  1880. begin
  1881.   contfile:=VarToStr(tvTableView.DataController.GetValue(tvTableView.DataController.GetFocusedRecordIndex,gtvColContentFilename.Index));
  1882.   if not FileExists(contfile) then exit;
  1883.   with TfrmWriteEMail.Create(Application) do
  1884.   try
  1885.     Caption:='转发邮件';
  1886.     FSetDoc:=True;
  1887.     
  1888.     EmailFile:=TEmailFile.Create(contfile);
  1889.     try
  1890.       EmailFile.GetEmail;
  1891.       AddAttch(EmailFile.Attchs);
  1892.       if EmailFile.Attchs.Count>0 then pnl1.Height:=234;
  1893.       //cbAttch.Properties.Items.Assign(EmailFile.Attchs);
  1894.       FStr:=EmailFile.Content;
  1895.     finally
  1896.       EmailFile.Free;
  1897.     end;
  1898.     ShowModal;
  1899.   finally
  1900.     Free;
  1901.   end;
  1902. end;
  1903. procedure TfrmMain.tvTableViewFocusedRecordChanged(
  1904.   Sender: TcxCustomGridTableView; APrevFocusedRecord,
  1905.   AFocusedRecord: TcxCustomGridRecord;
  1906.   ANewItemRecordFocusingChanged: Boolean);
  1907. begin
  1908.   actTurn.Enabled:= (tvTableView.DataController.RecordCount>0) and (tvTableView.DataController.FocusedRecordIndex>=0);
  1909.   if not btnTurn.Enabled then actReply.Enabled:=False;
  1910.   actDeleteCurEmail.Enabled:=(tvTableView.DataController.RecordCount>0) and (tvTableView.DataController.FocusedRecordIndex>=0)
  1911. end;
  1912. procedure TfrmMain.tvTableViewCellDblClick(Sender: TcxCustomGridTableView;
  1913.   ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  1914.   AShift: TShiftState; var AHandled: Boolean);
  1915. var
  1916.   I:Integer;
  1917.   S:string;
  1918.   list:TStrings;
  1919.   hasAttch:Boolean;
  1920.   MyXml:TMyXml;
  1921.   EMailFile:TEmailFile;
  1922. begin
  1923.   pnlAttch.Visible:=False;
  1924.   //显示邮件正文
  1925.   HtmlEdit.Clear;
  1926.   with ACellViewInfo.GridView.DataController do
  1927.   begin
  1928.     I:=GetFocusedRecordIndex ;
  1929.     S:=VarToStr(GetValue(I,gtvColContentFilename.Index));
  1930.     if not FileExists(S) then Exit;
  1931.     EMailFile:=TEmailFile.Create(S);   
  1932.     try
  1933.       EMailFile.GetEmail;
  1934.       HtmlEdit.HTML:=EMailFile.Content;
  1935.       //SetHtml(Web,);
  1936.     finally
  1937.       EMailFile.Free;
  1938.     end;
  1939.     if (not FSendEmailBox ) then
  1940.     begin
  1941.       if  (GetValue(I,gtvColReaded.Index)=false) then
  1942.       begin
  1943.         myxml:=TMyXml.Create(AppPath+'EmailServers.xml');
  1944.         try
  1945.           myxml.SetEmailReaded(GetValue(I,gtvColMyAddr.Index),GetValue(I,gtvColContentFilename.Index));
  1946.         finally
  1947.           myxml.Free;
  1948.         end;
  1949.         SetValue(I,gtvColReaded.Index,True)
  1950.       end;
  1951.     end;
  1952.     
  1953.     S:=VarToStr(GetValue(I,gtvColAttchFullName.Index));
  1954.   end;
  1955.   //显示附件
  1956.   lv1.Items.Clear;
  1957.   if s='' then Exit;
  1958.   hasAttch:=False;
  1959.   list:=TStringList.Create;
  1960.   try
  1961.     Split(';',S,list);
  1962.     for I:=0 to list.Count-1 do
  1963.     begin
  1964.       if FileExists(list[I]) then
  1965.       begin
  1966.         AddFileRelation(lv1,list[I]);
  1967.         hasAttch:=True;
  1968.       end;
  1969.     end;
  1970.   finally
  1971.     list.Free;
  1972.   end;
  1973.   pnlAttch.Visible:=hasAttch;
  1974. end;
  1975. procedure TfrmMain.lv1Deletion(Sender: TObject; Item: TListItem);
  1976. begin
  1977.   if( Item.Data<>nil) then FreeMem(PAnsiChar(Item.Data));
  1978. end;
  1979. procedure TfrmMain.actCleanSentsExecute(Sender: TObject);
  1980. var
  1981.   Xml:TAppXml;
  1982. begin
  1983.   if MsgBoxYesOrNo('您确定要清空所有''已发邮件''吗?')=mrOK  then
  1984.   begin
  1985.     xml:=TAppXml.Create;
  1986.     try
  1987.       xml.CleanSents(GetSeletedEmailAddr);
  1988.     finally
  1989.       Xml.Free;
  1990.     end;
  1991.   end;
  1992. end;
  1993. procedure TfrmMain.actCleanDraftExecute(Sender: TObject);
  1994. var
  1995.   Xml:TAppXml;
  1996. begin
  1997.   if MsgBoxYesOrNo('您确定要清空草稿箱吗?')=mrOK  then
  1998.   begin
  1999.     xml:=TAppXml.Create;
  2000.     try
  2001.       xml.CleanDraft(GetSeletedEmailAddr);
  2002.     finally
  2003.       Xml.Free;
  2004.     end;
  2005.   end;
  2006. end;
  2007. procedure TfrmMain.actCleanAttampExecute(Sender: TObject);
  2008. var
  2009.   Xml:TAppXml;
  2010. begin           
  2011.   if MsgBoxYesOrNo('您确定要清空定时邮件吗?')=mrOK  then
  2012.   begin
  2013.     xml:=TAppXml.Create;
  2014.     try
  2015.       xml.CleanAttmp(GetSeletedEmailAddr);
  2016.     finally
  2017.       Xml.Free;
  2018.     end;
  2019.   end;
  2020. end;
  2021. procedure TfrmMain.JvNavPaneToolPanel3Close(Sender: TObject);
  2022. begin
  2023.   cxSplitter1.State:=ssClosed;
  2024.   btn12.Down:=False;
  2025. end;
  2026. procedure TfrmMain.btn12Click(Sender: TObject);
  2027. begin
  2028.   if btn12.Down then
  2029.     cxSplitter1.State:=ssOpened
  2030.   else
  2031.     cxSplitter1.State:=ssClosed;
  2032. end;
  2033. procedure TfrmMain.tmrEmailAwakeTimer(Sender: TObject);
  2034. var
  2035.   Awake:TEmailAwakeCollection;
  2036.   I:integer;
  2037.   hMutex:THandle;
  2038. begin
  2039.   hMutex:=CreateMutex(nil,false,'TfrmEmailAwaked_One_Inst');
  2040.   if GetLastError=ERROR_ALREADY_EXISTS  then
  2041.   begin
  2042.     CloseHandle(hMutex);
  2043.     Exit;
  2044.   end;
  2045.   CloseHandle(hMutex);
  2046.   
  2047.   Awake:=TEmailAwakeCollection.Create;
  2048.   try
  2049.     LoadAwakeCollectionFromXml(Awake);
  2050.     for i:=pred(Awake.Count) downto 0  do
  2051.     begin
  2052.       if TEmailAwakeItem(Awake.Items[I]).Awake.IsAwake then //该邮件需要提醒了
  2053.       begin
  2054.         with TfrmEmailAwaked.Create(Application)do
  2055.         try
  2056.           lblTitle.Caption:=TEmailAwakeItem(Awake.Items[I]).Awake.Title;
  2057.           edMemo.lines.Text:=TEmailAwakeItem(Awake.Items[I]).Awake.Memo;
  2058.           FEmailAddr:=TEmailAwakeItem(Awake.Items[I]).Awake.EmailAddr;
  2059.           FContentFilePath:= TEmailAwakeItem(Awake.Items[I]).Awake.ContentFilePath;
  2060.           TEmailAwakeItem(Awake.Items[I]).Awake.BaseTime:=TEmailAwakeItem(Awake.Items[I]).Awake.NextAwake;
  2061.           case  ShowModal of
  2062.           mrOK: //打开
  2063.           Begin
  2064.             with TfrmViewEmail.Create(Application)do
  2065.             try
  2066.               FEmailAddr:=TEmailAwakeItem(Awake.Items[I]).Awake.EmailAddr;
  2067.               FContentFilePath:=TEmailAwakeItem(Awake.Items[I]).Awake.ContentFilePath;
  2068.               ShowModal;
  2069.             finally
  2070.               Awake.Delete(I);
  2071.               Free;
  2072.             end;
  2073.           End;
  2074.           mrCancel: //清除
  2075.           Begin
  2076.             Awake.Delete(I);
  2077.             MsgBoxWarn('删除成功');
  2078.           End;
  2079.           mrRetry: //再次提醒
  2080.           begin
  2081.             TEmailAwakeItem(Awake.Items[I]).Awake.UserNextAwake:=true;
  2082.           End;
  2083.           
  2084.           MrNone:;
  2085.           else;
  2086.           end;
  2087.         finally
  2088.           Free;
  2089.         end;
  2090.         SaveAwakeCollectionFromXml(Awake);
  2091.       end;
  2092.     end;
  2093.   finally
  2094.     Awake.Free;
  2095.   end;
  2096. end;
  2097. procedure TfrmMain.actViewEmailExecute(Sender: TObject);
  2098. begin
  2099.   if tvTableView.DataController.FocusedRecordIndex<0 then exit;
  2100.   with TfrmViewEmail.Create(Application)do
  2101.   begin
  2102.     try
  2103.       FTableView:=tvTableView;
  2104.       FCurRecordIndex:=tvTableView.DataController.FocusedRecordIndex;
  2105.       FContentFileItemIndex:=gtvColContentFilename.Index;
  2106.       FSenderEmail:= VarToStr(tvTableView.DataController.Values[FCurRecordIndex, gtvColSender.Index]);
  2107.       FRecverEmail:= VarToStr(tvTableView.DataController.Values[FCurRecordIndex, gtvColMyAddr.Index]);
  2108.       ShowEmail;
  2109.       ShowModal;
  2110.     finally
  2111.       Free;
  2112.     end;
  2113.   end;
  2114. end;
  2115. procedure TfrmMain.btn2Click(Sender: TObject);
  2116. begin
  2117.   with TfrmSingnals.Create(Application)do
  2118.   begin
  2119.     try
  2120.       ShowModal;
  2121.     finally
  2122.       Free;
  2123.     end;
  2124.   end;
  2125. end;
  2126. procedure TfrmMain.btn9Click(Sender: TObject);
  2127. var
  2128.   xml:TAppXml;
  2129.   L:TStringList;
  2130. begin
  2131.   if tvTableView.DataController.FocusedRecordIndex=-1 then
  2132.   begin
  2133.     MsgBoxError('请选中表格中的一封邮件!');
  2134.     exit;
  2135.   end;
  2136.   xml:=TAppXml.Create;
  2137.   try
  2138.     L:=TStringList.Create;
  2139.     try
  2140.       L.Add(varTostr(tvTableView.DataController.Values[tvTableView.DataController.FocusedRecordIndex,gtvColSender.Index]));
  2141.       xml.AddBlackList(L);
  2142.     finally
  2143.       L.Free;
  2144.     end;
  2145.   finally
  2146.     Xml.Free;
  2147.   end;
  2148.   MsgBoxWarn(Format('发件人%S成功加入到黑名单',[vartostr(tvTableView.DataController.Values[tvTableView.DataController.FocusedRecordIndex,gtvColSender.Index])]));
  2149. end;
  2150. procedure TfrmMain.btn10Click(Sender: TObject);
  2151. var
  2152.   xml:TAppXml;
  2153.   L:TStringList;
  2154. begin
  2155.   if tvTableView.DataController.FocusedRecordIndex=-1 then
  2156.   begin
  2157.     MsgBoxError('请选中表格中的一封邮件!');
  2158.     exit;
  2159.   end;
  2160.   
  2161.   xml:=TAppXml.Create;
  2162.   try
  2163.     L:=TStringList.Create;
  2164.     try
  2165.       L.Add(tvTableView.DataController.Values[tvTableView.DataController.FocusedRecordIndex,gtvColSender.Index]);
  2166.       xml.AddWhiteList(L);
  2167.     finally
  2168.       L.Free;
  2169.     end;
  2170.   finally
  2171.     Xml.Free;
  2172.   end;
  2173.   MsgBoxWarn(Format('发件人%S成功加入到白名单',[vartostr(tvTableView.DataController.Values[tvTableView.DataController.FocusedRecordIndex,gtvColSender.Index])]));
  2174. end;
  2175. procedure TfrmMain.dxBarButton2Click(Sender: TObject);
  2176. begin
  2177.   HtmlEdit.PrintPageSetup;
  2178.   HtmlEdit.PrintPreview;
  2179. end;
  2180. procedure TfrmMain.btnSaveAllClick(Sender: TObject);
  2181. begin
  2182.   HtmlEdit.PrintPageSetup;
  2183.   HtmlEdit.Print;
  2184. end;
  2185. procedure TfrmMain.OnOneSend(Sender: TObject;Email:TEmailInfo);
  2186. begin
  2187. end;
  2188. procedure TfrmMain.OnOneSendEnd(Sender: TObject; Email: TEmailInfo);
  2189. var
  2190.   xml:TAppXml;
  2191.   idx:Integer;
  2192. begin
  2193.   if not email.IsError then
  2194.   begin
  2195.     xml:=TAppXml.Create;
  2196.     try
  2197.       xml.AddSentEmail(Email.Send.UserName,email.Id);
  2198.       Xml.DeleteSendingEmail(Email.Send.UserName,Email.Id);
  2199.     finally
  2200.       xml.free;
  2201.     end;
  2202.     if FShowEmailSending then //从表格中删除数据
  2203.     begin
  2204.       idx:=tvTableView.DataController.FindRecordIndexByText(0,gtvColContentFilename.Index,Email.Id,true,true,false);
  2205.       if idx>=0 then
  2206.        tvTableView.DataController.DeleteRecord(idx);
  2207.     end;
  2208.   end;
  2209. end;
  2210. procedure TfrmMain.LoadSending;
  2211. var
  2212.   contentFileName:TStringList;
  2213.   MyXml:TAppXml;
  2214.   Str:string;
  2215. begin
  2216.   if tvEMail.Selected.Text<>'发件箱' then Exit; //显示所有已发送的邮件
  2217.   //WriteLog('LoadSending run');
  2218.   FShowEmailSending:=True;
  2219.   btnRecpOne.Enabled:=false;
  2220.   btnUnRead.Enabled:=True;
  2221.   FSendEmailBox:=true;
  2222.   actReply.Enabled:=False;
  2223.   Str:=PPopInfo(tvEMail.Selected.Parent.Data).EMailAddr;
  2224.   gtvColSender.Caption:='收件人';
  2225.   gtvColMyAddr.Visible:=true;
  2226.   gtvColMyAddr.Caption:='发件人';
  2227.   gtvColReaded.Visible:=false;
  2228.   gtvColDate.Visible:=False;
  2229.   gtvColDate.Caption:='发件时间';
  2230.   gtvColAttch.Visible:=false;
  2231.   
  2232.   contentFileName:=TStringList.Create;
  2233.   MyXml:=TAppXml.Create;
  2234.   try
  2235.     MyXml.GetAllSendingEmail(Str,contentFileName);
  2236.   finally
  2237.     MyXml.Free;
  2238.   end;
  2239.   LoadFromFile(Str,contentFileName);
  2240.   contentFileName.Free;
  2241. end;
  2242. procedure TfrmMain.btn17Click(Sender: TObject);
  2243. begin
  2244.   //FEmailChecker.
  2245. end;
  2246. procedure TfrmMain.LoadContact;
  2247. var
  2248.   I:Integer;
  2249.   La,Ln:TStringList;
  2250. begin
  2251.   ltAddr.Clear;
  2252.   
  2253.   Ln:=TStringList.create;
  2254.   La:=TStringList.create;
  2255.   try
  2256.     with TAppXml.Create do
  2257.     try
  2258.       LoadContacts(La,ln);
  2259.     finally
  2260.       Free;
  2261.     end;
  2262.     for I:= 0 to La.Count-1 do
  2263.     begin
  2264.       with ltAddr.Add do
  2265.       begin
  2266.         Values[0]:=False;
  2267.         Values[1]:=Ln.Strings[I];
  2268.         Values[2]:=La.Strings[I];
  2269.       end;
  2270.     end;
  2271.   finally
  2272.     Ln.Free;
  2273.     La.Free;
  2274.   end;
  2275. end;
  2276. procedure TfrmMain.dxBarButton22Click(Sender: TObject);
  2277. begin
  2278.   with TfrmAddr.Create(nil) do
  2279.   try
  2280.     FContactModel:=cmAdd;
  2281.     ShowModal;
  2282.   finally
  2283.     Free;
  2284.   end;
  2285. end;
  2286. procedure TfrmMain.dxBarButton23Click(Sender: TObject);
  2287. begin
  2288.   with TfrmAddr.Create(nil) do
  2289.   try
  2290.     FContactModel:=cmDelete;
  2291.     ShowModal;
  2292.   finally
  2293.     Free;
  2294.   end;
  2295. end;
  2296. procedure TfrmMain.dxBarButton24Click(Sender: TObject);
  2297. begin
  2298.   with TfrmAddr.Create(nil) do
  2299.   try
  2300.     FContactModel:=cmEdit;
  2301.     ShowModal;
  2302.   finally
  2303.     Free;
  2304.   end;
  2305. end;
  2306. procedure TfrmMain.dxBarButton27Click(Sender: TObject);
  2307. var
  2308.   FCurRecordIndex:Integer;
  2309. begin
  2310.   FCurRecordIndex:= tvTableView.DataController.FocusedRecordIndex;
  2311.   if FCurRecordIndex<0 then exit;
  2312.   with TfrmAddr.Create(nil) do
  2313.   try
  2314.     FContactModel:=cmAdd;
  2315.     edAddr.Text:=VarToStr(tvTableView.DataController.Values[FCurRecordIndex, gtvColSender.Index]);
  2316.     ShowModal;
  2317.   finally
  2318.     Free;
  2319.   end;
  2320. end;
  2321. procedure TfrmMain.ltAddrDblClick(Sender: TObject);
  2322. begin
  2323.   if ltAddr.SelectionCount=1 then
  2324.   begin
  2325.     with TfrmAddr.Create(nil) do
  2326.     try
  2327.       FContactModel:=cmEdit;
  2328.       edAddr.Text:=ltAddr.Selections[0].Values[2];
  2329.       edName.Text:=ltAddr.Selections[0].Values[1];
  2330.       ShowModal;
  2331.     finally
  2332.       Free;
  2333.     end;
  2334.   end;
  2335. end;
  2336. procedure TfrmMain.dxbrbtnAddClick(Sender: TObject);
  2337. begin
  2338.   if ltAddr.SelectionCount=1 then
  2339.   begin
  2340.     with TfrmAddr.Create(nil) do
  2341.     try
  2342.       FContactModel:=cmAdd;
  2343.       //edAddr.Text:=ltAddr.Selections[0].Values[2];
  2344.       //edName.Text:=ltAddr.Selections[0].Values[1];
  2345.       ShowModal;
  2346.     finally
  2347.       Free;
  2348.     end;
  2349.   end;
  2350. end;
  2351. procedure TfrmMain.dxbrbtnDelClick(Sender: TObject);
  2352. begin
  2353.   if ltAddr.SelectionCount=1 then
  2354.   begin
  2355.     with TfrmAddr.Create(nil) do
  2356.     try
  2357.       FContactModel:=cmDelete;
  2358.       edAddr.Text:=ltAddr.Selections[0].Values[2];
  2359.       //edName.Text:=ltAddr.Selections[0].Values[1];
  2360.       ShowModal;
  2361.     finally
  2362.       Free;
  2363.     end;
  2364.   end;
  2365. end;
  2366. procedure TfrmMain.dxbrbtnEditClick(Sender: TObject);
  2367. begin
  2368.   ltAddrDblClick(nil);
  2369. end;
  2370. procedure TfrmMain.dxBarLargeButton10Click(Sender: TObject);
  2371. begin
  2372.   with TfrmAbout.Create(nil) do
  2373.   begin
  2374.     try
  2375.       ShowModal;
  2376.     finally
  2377.       Free;
  2378.     end;
  2379.   end;
  2380. end;
  2381. procedure TfrmMain.dxBarButton25Click(Sender: TObject);
  2382. var
  2383.   OutLook,Ns,Floder,It,Ct,oEnum:OleVariant;
  2384. begin
  2385.   try
  2386.     OutLook:=GetActiveOleObject('Outlook.Application');
  2387.   except
  2388.     try
  2389.       OutLook:=CreateOleObject('Outlook.Application');
  2390.     except
  2391.       MessageDlg('请确认你是否安装了OutLook。' + #13#10 +
  2392.               '如果没有安装,请安装之后再重试。' + #13#10#13#10#13#10,
  2393.               mtError, [mbOK], 0);
  2394.     end;
  2395.   end;
  2396.   try
  2397.     Ns:=OutLook.GetNamespace('MAPI');
  2398.     Floder:=Ns.GetDefaultFolder(oEnum);
  2399.     It:=Floder.Items;
  2400.     Ct:=It.GetFirst;
  2401.     with TAppXml.Create do
  2402.     try     //not  VarIsNull(ct)
  2403.       while (Ct<>NULL) do
  2404.       begin
  2405.          AddContact(ct.Email1Address,ct.FullName,'');
  2406.          ct:= it.GetNext;
  2407.       end;
  2408.       LoadContact;
  2409.     finally
  2410.       Free;
  2411.     end;
  2412.   except
  2413.       MessageDlg('未知的错误' + #13#10#13#10#13#10#13#10 +
  2414.         #13#10,  mtError, [mbOK], 0);
  2415.   end;
  2416.   ct:=null;
  2417.   it:=null;
  2418.   floder:=null;
  2419.   ns:=null;
  2420.   OutLook:=null;
  2421. end;
  2422. procedure TfrmMain.dxBarButton12Click(Sender: TObject);
  2423. begin
  2424.   dxbrbtn18Click(NIL);
  2425. end;
  2426. initialization
  2427.   CoInitialize(nil);
  2428. finalization
  2429.   CoUninitialize();
  2430. end.