/*
//  NoAdvert.rexx v1.2
//
//  George Stagakis (gallant@cryogen.com)
//  Web: http://gallant.home.ml.org
//  IRC: Gallant, #amiga, AmigaNet
//            or  #cafe, GreekNet
*/

options results

address command
'resident c:delete PURE'
'resident c:rename PURE'
'resident c:filenote PURE'

nl='0a'x

netmatch = nl'Thanks for using NetForward!'||nl
netmatch = netmatch'http://www.netforward.com'||nl
netmatch = netmatch'v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v'||nl

address YAM

'GetFolderInfo MAX'
entries = result

'GetMailInfo ACTIVE'
active = result

chk = 0

do i=0 to entries-1
	'SetMail' i
	chk = chk + checkmail(mailstat)
end

if chk > 0 then 'mailupdate'

'SetMail' active

address command
'resident delete REMOVE'
'resident rename REMOVE'
'resident filenote REMOVE'

exit

checkmail: procedure expose netmatch
	options results
	'GetMailInfo STATUS'
	mailstat = result
	'GetMailInfo FILE'
	mail = result
	if ~open(1,mail,'R') then call sayx 'unable to read mail. being used?'
	a=readch(1,1024)
	netchk=pos(netmatch,a)
	if netchk>0 then do
		a = delstr(a,netchk,length(netmatch))
		mailnew = mail'.tmp'
		if ~open(2,mailnew,'w') then call sayx 'unable to write mail. being used?'
		call writech(2,a)
		do until eof(1)
			b = readch(1,65535)
			call writech(2,b)
		end
		call close(1)
		call close(2)
		address command
		'delete >nil: 'mail
		'rename 'mailnew' 'mail
		'filenote 'mail' 'mailstat
		return 1
	end
	call close(1)
return 0

sayx: procedure;parse arg a;say '***' a;exit
