unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, popunit, gitUpdateUnit; type { TForm1 } TForm1 = class(TForm) Button1: TButton; CheckBox1: TCheckBox; CheckBox2: TCheckBox; emailsDaIcon: TImage; nichtsDaIcon: TImage; Memo1: TMemo; TrayIcon1: TTrayIcon; procedure Button1Click(Sender: TObject); procedure CheckBox1Click(Sender: TObject); procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure FormResize(Sender: TObject); procedure FormShow(Sender: TObject); procedure TrayIcon1Click(Sender: TObject); procedure TrayIcon1DblClick(Sender: TObject); procedure TrayIcon1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); private { private declarations } lb: tMouseButton; public { public declarations } pc: tPopClient; procedure neueNachrichten(sender: tObject); end; var Form1: TForm1; implementation uses myStringListUnit, lowLevelUnit, process; {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject); var sl: tMyStringList; s,ga: string; begin ga:='.*@eckner\.net' +'|'+ '(ee|intern|vorstand)@wurzel\.org' +'|'+ 'erich\.eckner@uni-jena\.de' +'|'+ 'erich\.eckner@gmx\.de' +'|'+ '(ioq_(nlo|staff)|alle_mitarbeiter|fsr-physik-newsletter)@listserv\.uni-jena\.de' +'|'+ '(sox-users|logwatch-devel)@lists\.sourceforge\.net' +'|'+ 'gmp-discuss@gmplib\.org' +'|'+ 'hashcash@freelists\.org' +'|'+ 'crux(-commits)?@lists\.crux\.nu' +'|'+ 'radvd-devel-l@lists\.litech\.org' +'|'+ 'arch-general-request@archlinux\.org'; if fileexists(extractfilepath(application.exename)+'optionen.konf') then begin sl:=tMyStringList.create; sl.loadFromFile(extractfilepath(application.exename)+'optionen.konf'); s:=sl.grepFirst('^aufploppen\s*='); erstesArgument(s,'='); if uppercase(s)='JA' then checkBox1.checked:=true else if uppercase(s)='NEIN' then checkBox1.checked:=false else if s<>'' then raise exception.create(''''+s+''' ist kein gültiger Wert für ''aufploppen'' (ja|nein)!'); s:=sl.grepFirst('^Ton\s+geben\s*='); erstesArgument(s,'='); if uppercase(s)='JA' then checkBox2.checked:=true else if uppercase(s)='NEIN' then checkBox2.checked:=false else if s<>'' then raise exception.create(''''+s+''' ist kein gültiger Wert für ''Ton geben'' (ja|nein)!'); s:=sl.grepFirst('^gültiger\s+Adressat\s*='); if s<>'' then ga:=s; sl.free; end; pc:=tPopClient.create; pc.timeout:=10; pc.neueNachrichten:=@neueNachrichten; // pc.sshUser:='erich'; pc.host:='eckner.net'; pc.user:='notify@eckner.net'; pc.pass:='C7sd7k8*'; pc.gueltigerAdressat:='('+ga+')'; pc.port:=995; end; procedure TForm1.FormDestroy(Sender: TObject); begin pc.free; end; procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction); begin pc.threadAnhalten; pc.aufThreadWarten; end; procedure TForm1.CheckBox1Click(Sender: TObject); var sl: tMyStringList; begin sl:=tMyStringList.create; if checkBox1.checked then sl.add('aufploppen = JA') else sl.add('aufploppen = NEIN'); if checkBox2.checked then sl.add('Ton geben = JA') else sl.add('Ton geben = NEIN'); sl.add('gültiger Adressat = '+copy(pc.gueltigerAdressat,2,length(pc.gueltigerAdressat)-2)); sl.saveToFile(extractfilepath(application.exename)+'optionen.konf'); sl.free; end; procedure TForm1.Button1Click(Sender: TObject); begin pc.loeschen; form1.visible:=false; end; procedure TForm1.FormResize(Sender: TObject); begin button1.top:=form1.clientHeight-button1.height; checkBox1.top:=button1.top + (button1.height-checkBox1.height) div 2; checkBox2.top:=button1.top + (button1.height-checkBox2.height) div 2; button1.left:=(form1.clientWidth - button1.width - checkBox1.width - checkBox2.width) div 6; checkBox1.left:=button1.left+button1.width + (form1.clientWidth - button1.width - checkBox1.width - checkBox2.width) div 3; checkBox2.left:=checkBox1.left+checkBox1.width + (form1.clientWidth - button1.width - checkBox1.width - checkBox2.width) div 3; memo1.width:=form1.clientWidth-memo1.left; memo1.height:=button1.top-memo1.top; end; const __erstesMal: boolean = true; __letzterTon: extended = 0; procedure TForm1.FormShow(Sender: TObject); begin if __erstesMal then begin __erstesMal:=false; form1.visible:=false; end; if form1.visible then begin form1.top:=screen.monitors[screen.monitorCount-1].top + (screen.monitors[screen.monitorCount-1].height-form1.height-24) div 2; form1.left:=screen.monitors[screen.monitorCount-1].left + (screen.monitors[screen.monitorCount-1].width-form1.width) div 2; end; end; procedure TForm1.TrayIcon1Click(Sender: TObject); begin form1.visible:=not form1.visible; end; procedure TForm1.TrayIcon1DblClick(Sender: TObject); begin if (lb=mbRight) or ((lb=mbLeft) and (messageDlg('Email-Tool beenden?',mtConfirmation,[mbYes,mbNo],0)=mrYes)) then form1.close; end; procedure TForm1.TrayIcon1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin lb:=button; end; procedure tForm1.neueNachrichten(sender: tObject); var i,ung,mitMarkeDa: longint; argumente: array of string; ausgabe: string; begin mitMarkeDa:=0; memo1.lines.clear; ung:=0; for i:=pc.nAnz-1 downto 0 do case pc.marke(i) of mvGueltig: begin inc(mitMarkeDa); memo1.lines.add('! '+pc.zeit(i)+' '+pc.von(i)+': '+pc.betreff(i)); end; mvUngueltig: begin memo1.lines.add('( '+pc.zeit(i)+' '+pc.von(i)+': '+pc.betreff(i)+' )'); inc(ung); end; mvKeine: memo1.lines.add(' '+pc.zeit(i)+' '+pc.von(i)+': '+pc.betreff(i)); end{of case}; if pc.nAnz<=ung then begin trayIcon1.icon:=nichtsDaIcon.picture.icon; trayIcon1.hint:='keine Post'; end else begin trayIcon1.icon:=emailsDaIcon.picture.icon; trayIcon1.hint:=inttostr(pc.nAnz-ung)+' neue Nachrichten'; if mitMarkeDa>0 then begin trayIcon1.hint:=trayIcon1.hint+', davon '+inttostr(mitMarkeDa)+' mit Marke'; if checkBox1.checked then form1.visible:=true; if checkBox2.checked and ((now-__letzterTon > 1/24/60/3) or (now<__letzterTon)) then begin __letzterTon:=now; setlength(argumente,1); argumente[0]:=extractFilePath(application.exename)+'gotmail.wav'; ausgabe:=''; runCommand('play',argumente,ausgabe); setlength(argumente,0); end; end; end; if ung>0 then trayIcon1.hint:=trayIcon1.hint+' (und noch '+inttostr(ung)+' mit ungültiger Marke)'; trayIcon1.visible:=true; form1.icon:=trayIcon1.icon; form1.caption:=trayIcon1.hint; end; end.