#!/home/tdbengine/bin/tdbengine
/*
Das Programm geht davon aus, dass EMails im Verzeichnis mails mit der Extension .msg vorliegen.
Es prüft dieses Verzeichnis alle 10 Sekunden und versendet diese Mails via sendmail.
Das Log-File befindet in mailsmail.log.
*/
PROCEDURE clear_spooler
VAR l : STRING = firstdir('mails/*.msg','')
VAR fn, s_to, s_from, host : STRING
VAR p,q : INTEGER
host:=getenv('SERVER_NAME')
WHILE l DO
fn:=rtrim(l[1,63])
loadtemplate('mails/'+fn)
IF p:=ramtext_find('ramtext','To: ') THEN
q:=ramtext_find('ramtext',^J,p+1)
IF q-p FROM 1 TO 255 THEN s_to:=ramtext_part('ramtext',p+4,q-p-4) END
END
IF p:=ramtext_find('ramtext','From: ') THEN
q:=ramtext_find('ramtext',^J,p+1)
IF q-p FROM 1 TO 255 THEN s_from:=ramtext_part('ramtext',p+6,q-p-6) END
END
IF s_to, s_from THEN
CGIExec('sendmail -v -pSMTP:'+host+' -f '+s_from+' '+s_to+' < mails/'+fn+' >> mails/mail.log')
delfile('mails/'+fn)
END
l:=nextdir
END
ENDPROC
PROCEDURE Main
EndSema
REPEAT
pause(1000)
clear_spooler
UNTIL 0
ENDPROC