/* ============================================================= */
/* ============================================================= */
call RxFuncAdd SysLoadFuncs,RexxUtil,SysLoadFuncs
call SysLoadFuncs

parse arg accountName

if length(accountName) < 1 then
	accountName = 'mail'

call SysFileTree accountName'\f*', 'file', 'D'

filename = accountName'\folders.ndx-new'
'del 'filename' >nul 2>nul'
	
idir = -1
i = 1
do while i <= file.0
	pos = lastpos('\',file.i)
	if pos = 0 then
		pos = lastpos(' ',file.i)
	fname = substr(file.i,pos+1)
   
	path = fname
	fname = accountName'\'fname'\folder.ndx'
	say fName
   
	rc = SysGetEA(fname, ".LONGNAME", "eainfo")
   
	if rc = 0 then do
		pos = lastpos("00"x,eainfo) + 1
		longname = substr(eainfo,pos)
	end
	else longname = ""
   
	rc = SysGetEA(fname, "MR2I.FOLDERINFO", "eainfo")
   
	folderLine = ""
	if rc = 0 then do
		pos = lastpos("00"x,eainfo) + 1
		folderLine = substr(eainfo,pos)
	end
	
	if length(folderLine) < 5 then do
		if length(longname) > 0 then
			folderLine = longname
		else folderLine = path
		folderLine = folderLine''path''path'N0'
	end
	rc = lineout(filename,folderLine)
   
	i = i + 1
end

return 0


