home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 35 Internet
/
35-Internet.zip
/
nstomr2.zip
/
nsm2mr2.cmd
< prev
next >
Wrap
OS/2 REXX Batch file
|
1999-03-12
|
20KB
|
586 lines
/* Netscape Navigator for OS/2 mail conversion to MR2ICE utility
Freeware by Art Heimsoth <heimsoth@doglover.com>
Copyright (c) Art Heimsoth 1997 - all rights reserved */
/* REXX command file to convert Netscape Navigator for OS/2 mail to
the folder and mail item format for MR/2 ICE. It is assumed that
NETSCAPE.EXE can be found either in the current directory, or in the
PATH. The location of NETSCAPE.EXE is also assumed to be the location
of the NETSCAPE.INI file containing the location for the Netscape
mail. It is further assumed that MR2i.EXE can also be found in
either the current directory or in the PATH. The location of MR2i is
used to find the MR/2 ICE mail folder directories.
The above means that this command can be executed from the Navigator/2
directory, in which case the MR2i must be found via the PATH statement,
or if executed from the MR2i directory, then NETSCAPE must be found
via tha PATH statement.
If neither is the case, then both directories can be temporarily added
to the current path using the form:
set path=%path%;[drive]:\netscape;[drive]:\mr2i;
substituting the string "[drive]:\netscape;" or the string "[drive]:\mr2i;"
with the drive and directory location for the respective program.
Any existing mail entries will be kept in the current MR2i mail folders.
Mail from the Netscape files will be added to existing folders if their
names match those of the existing (if any) MR/2 folders. If the folders
do not exist, then new folders with the Netscape names will be created.
The Netscape Inbox mail will be added to the MR/2 In box folder, and the
Netscape Sent mail will be added to the MR/2 Out box folder.
An optional parameter of test can be passed to indicate to run only in
test mode, in which case the real MR2i mail files will not be altered.
Temporary mail folders and files will be created in a directory named
"tempmail" in the mr2i directory. This temporary directory will contain
the full result of what would have been created without destroying any
existing MR/2 mail folders or items. */
version = '1.03'
if (rxfuncquery('rexxutil') = 1) then do
Say 'Loading the Rexx Utilities package'
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs
end
signal on error name synerr
signal on syntax name synerr
signal on failure name synerr
signal on novalue name synerr
parse source . . ourname . /* find out our name to use later */
ourname = FileSpec('Name',ourname)
parse var ourname ourname '.' x
/* program variables */
nets = ''
mr2i = ''
netini = 'netscape.ini' /* Netscape Navigator .INI file */
mr2mail = 'mail\folders.ndx' /* MR/2 ICE mail directory */
mr2nmail= 'tempmail' /* test mode mail directory */
nsmailf. = ''
nsmailf.0 = 0 /* stem for Netscape Mail info */
nfldr.='' /* folder indexes created */
nfldr.0 = 0
date = 0
month = 'JAN 31 FEB 28 MAR 31 APR 30 MAY 31 JUN 30'
month = month 'JUL 31 AUG 31 SEP 30 OCT 31 NOV 30 DEC 31'
parse arg a1
if wordpos('?',a1) > 0 then signal tell
if wordpos('TEST',translate(a1)) > 0 then
testmode = 'x'
else
testmode = ''
if wordpos('DEBUG',translate(a1)) > 0 then
debug = 'x'
else
debug = ''
if debug <> '' then
testmode = 'x'
db = 'mdebug.dat'
if debug <> '' then
if stream(db,'c','query exists') <> '' then
call SysFileDelete db
/* testmode <> '' means do not change existing mail files/folders */
Say 'Convert Netscape for OS/2 mail to MR/2 ICE format - version' version
Say ' Copyright (c) Art Heimsoth - 1997 - all rights reserved.'
if testmode <> '' then
Say 'Will run in test mode, i.e., will not alter the existing MR/2 ICE files.'
call dbout 'Parameters:' a1
call getmaildir /* locate existing MR/2 mail locns */
call cantemps /* get rid of any prior tempmail */
call getnsmailf /* get the NS mail folder info */
call movemr2 /* move existing MR/2 mail if test */
/* and build new folder index info */
call copynsm /* now copy the Netscape mail */
call savefldr /* add the new entries to folder.ndx*/
if debug <> '' then
call lineout db /* close the debug file */
Say ''
Say 'Conversion complete.'
exit
dbout:
/* output the passed string if debug is active */
if debug = '' then
return
parse arg dataline
call lineout db,dataline
return
savefldr:
/* add the new mail folder items to the folder.ndx file for MR/2 */
mr2m = mr2i || 'folders.ndx'
call stream mr2m,'c','open write'
do i=1 to nfldr.0
parse var nfldr.i dirname fldr '"' name '"' popup .
fldr = strip(fldr)
lineoutp = name || '01'x || fldr || '01'x || dirname || '01'x || 'Y' || '01'x || '0'
if popup = '' then do
call lineout mr2m,lineoutp
call dbout 'Added to folders.ndx:' lineoutp
end
end
call stream mr2m,'c','close'
return
copynsm:
/* copy the Netscape mail from the Netscape files into separate files */
/* in the MR/2 mail directory with an appropriate timestamp name. */
do i=1 to nfldr.0
mr2m = mr2i || word(nfldr.i,1) || '\'
ns2m = ''
fldrn = 'folder.ndx'
do k=1 to nsmailf.0
if translate(FileSpec('Name',nsmailf.k)) = translate(word(nfldr.i,2)) then
ns2m = nsmailf.k
end
if ns2m = '' then
iterate
call dbout 'Processing' ns2m 'to' mr2m
call copyfldr /* generate and copy the mail items */
end
ns2m = FileSpec('Drive',nets) || FileSpec('Path',nets || 'x') || 'Sent'
mr2m = mr2i
fldrn = 'mr2i.out'
call dbout 'Processing' ns2m 'to' mr2m
call copyfldr /* generate and copy the outbox items */
ns2m = FileSpec('Drive',nets) || FileSpec('Path',nets || 'x') || 'Inbox'
mr2m = mr2i
fldrn = 'mr2i.ndx'
call dbout 'Processing' ns2m 'to' mr2m
call copyfldr /* generate and copy the Inbox items */
return
copyfldr:
/* copy the mail items from the *ns2m* location to the *mr2m* location */
index.=''
index.0=0
tosub.=''
fldrea=''
eatype=''
ealen=''
eadata=''
mon=''
day=''
year=''
time=''
call loadndx /* loadup any existing index info */
call stream ns2m,'c','open read'
mr2mf = ''
do forever
if stream(ns2m,'state') <> 'READY' then
leave
lineinp = linein(ns2m)
if (words(lineinp) = 7) & ,
(translate(subword(lineinp,1,2)) = 'FROM -') then do
if mr2mf <> '' then do
call stream mr2mf,'c','close'
k = index.0
index.k = index.k stream(mr2mf,'c','query size') || 'o'
mr2mf = ''
end
repos = stream(ns2m,'c','seek + 0')
search = 'x'
datehold = subword(lineinp,4)
k=index.0+1
index.0=k
temail = ' '
subj = ' '
femail = ' '
msgid = ' '
do while(search <> '')
lineinp = linein(ns2m)
if stream(ns2m,'state') <> 'READY' then
search = ''
else if lineinp = '' then
search = ''
else if translate(word(lineinp,1)) = 'SUBJECT:' then
subj = subword(lineinp,2)
else if translate(word(lineinp,1)) = 'MESSAGE-ID:' then
msgid = subword(lineinp,2)
else if translate(word(lineinp,1)) = 'APPARENTLY-TO:' then
temail= subword(lineinp,2)
else if translate(word(lineinp,1)) = 'TO:' then
temail= subword(lineinp,2)
else if translate(word(lineinp,1)) = 'FROM:' then
femail= subword(lineinp,2)
else if translate(word(lineinp,1)) = 'DATE:' then do
if pos(',',lineinp) > 0 then
parse var lineinp . ',' day mon year time .
else if pos(':',subword(lineinp,2)) > 0 then do
ti = pos(':',subword(lineinp,2))
dt = substr(subword(lineinp,2),1,ti)
if words(dt) > 3 then do
day = word(dt,words(dt)-3)
mon = word(dt,words(dt)-2)
year = word(dt,words(dt)-1)
time = word(lineinp,words(dt)+1)
end
end
if length(time) > 8 then
time = left(strip(time),8)
if length(year) < 3 then
if year < 70 & year <> '' then
year = '20' || year
else
year = '19' || year
if mon <> '' & day <> '' & time <> '' & year <> '' then
datehold = mon day time year
end
end
call stream ns2m,'c','seek =' repos
if words(datehold) <> 4 then
datehold = 'Jan 1 00:00:00 1970'
call datetime datehold
k = index.0
h1 = '01'x
tosub.k = femail || h1 || subj || h1 || h1 || temail || h1 || msgid
if length(mon) > 2 then
do l=1 to words(month)
if left(translate(mon),3) = word(month,(l*2)-1) then
mon = l
end
if translate(right(ns2m,4)) = 'SENT' then do
mr2mf = mr2m || date || '.OUT'
do while(stream(mr2mf,'c','query exists') <> '')
date = x2d(date)+1
date = right(d2x(date),8,'0')
mr2mf = mr2m || date || '.OUT'
end
index.k = date 'OUT' right(year,2) || '/' || right(mon,2,'0') || '/' ,
|| right(day,2,'0') left(time,5) 'S'
end
else do
mr2mf = mr2m || date || '.RCV'
do while(stream(mr2mf,'c','query exists') <> '')
date = x2d(date)+1
date = right(d2x(date),8,'0')
mr2mf = mr2m || date || '.RCV'
end
index.k = date 'RCV' right(year,2) || '/' || right(mon,2,'0') || '/' ,
|| right(day,2,'0') left(time,5) 'Y'
end
call stream mr2mf,'c','open write'
call dbout 'Copying mail item' mr2mf
lineinp = linein(ns2m)
end
call lineout mr2mf,lineinp
end
call stream ns2m,'c','close'
if mr2mf <> '' then do
call stream mr2mf,'c','close'
k = index.0
index.k = index.k stream(mr2mf,'c','query size') || 'o'
end
mr2mf = ''
call bldndx
return
bldndx:
/* build a new folder from all info collected.. name is in fldrn */
fldrea = ''
eadata = index.0
call dbout 'EA data entry (dec) not reversed:' eadata
eadata = right(d2x(eadata),8,'0')
do l=length(eadata) to 2 by -2
fldrea = fldrea || substr(eadata,l-1,2)
end
call dbout 'built EA count (hex) reversed:' fldrea
fldrea = x2c('FEFF0400' || fldrea)
mr2mf = mr2m || fldrn
sortea = ''
if stream(mr2mf,'c','query exists') <> '' then do
call SysGetEA mr2mf,'SORTSPEC','sortea'
call SysFileDelete mr2mf
end
call stream mr2mf,'c','open write'
do l=1 to index.0
parse var index.l fn ext date time status size .
if pos('.',fn) > 0 then do
parse var index.l fn date time status size .
parse var fn fn '.' ext
end
if date = '.' then
date = ''
if time = '.' then
time = ''
if status = '.' then
status = ''
lineoutp = right(fn,35,' ') ext right(size,12,' ') left(date,8,' ') ,
left(time,5,' ') right(status,10,' ') ' ' tosub.l
call dbout lineoutp
call lineout mr2mf,lineoutp
end
call stream mr2mf,'c','close'
call SysPutEA mr2mf,'MESSAGECTR',fldrea
if sortea <> '' then
call SysPutEA mr2mf,'SORTSPEC',sortea
call dbout index.0 'Entries built for:' mr2m || fldrn
return
loadndx:
/* load the index info (if any) from the index file for the working
folder... the name will be in fldrn */
k=index.0
fldrr = stream(mr2m || fldrn,'c','query exists')
if fldrr = '' then do
call dbout 'No index entries found in:' mr2m || fldrn
return
end
call stream fldrr,'c','open read'
do forever
lineinp = linein(fldrr)
if stream(fldrr,'state') <> 'READY' then
leave
if lineinp = '' then
iterate
k=k+1
parse var lineinp firstp 84 tosub.k
parse var firstp fn ext size date time 78 status .
if pos('.',fn) > 0 then do
parse var firstp fn size date time 78 status .
parse var fn fn '.' ext
end
if date = '' then
date = '.'
if time = '' then
time = '.'
if status = '' then
status = '.'
index.k = fn ext date time status size
end
call stream fldrr,'c','close'
index.0 = k
call SysGetEA fldrr,'MESSAGECTR','fldrea'
tempea = c2x(fldrea)
call dbout 'EA Data (hex) reversed:' tempea
eatype = substr(tempea,3,2) || substr(tempea,1,2)
ealen = substr(tempea,7,2) || substr(tempea,5,2)
eadata = ''
do ea=length(tempea) to 9 by -2
eadata = eadata || substr(tempea,ea-1,2)
end
call dbout 'EA for MessageCTR is: type=' eatype 'length=' ealen 'data='eadata
call dbout index.0 'index entries found in fldr:' fldrr
return
datetime:
/* convert the date/time stamp to an 8 hex character value for file name*/
parse arg mon day time year .
date = 0
j = year-1
do while(j > 1969)
if (j // 4) = 0 then
date = date+366
else
date = date+365
j = j-1
end
if (year // 4) = 0 then
month = subword(month,1,3) 29 subword(month,5)
else
month = subword(month,1,3) 28 subword(month,5)
do j=1 to 12
if left(translate(mon),3) = word(month,((i*2)-1)) then
j=12
else
date = date + word(month,2)
end
date = date + day
date = date * 86400
parse var time hr ':' min ':' sec .
date = date + (hr * 3600) + (min * 60) + sec
date = d2x(date)
date = right(date,8,'0')
call dbout mon day time year '==>' date
return
movemr2:
/* create directories for new folders and move existing MR/2 mail if test */
if testmode <> '' then do
mr2it = left(mr2i,length(mr2i)-1)
mr2it = FileSpec('Drive',mr2it) || FileSpec('Path',mr2it) || mr2nmail || '\*'
copycmd = '@xcopy' mr2i || '*.*' mr2it '/h/o/t/s/e/r/v'
call dbout copycmd
copycmd '> nul:'
mr2i = FileSpec('Drive',mr2it) || FileSpec('Path',mr2it)
end
lists.0 = 0
call SysFileSearch 'F',mr2i || 'folders.ndx','lists'
hex01 = '01'x
findx = 1
do i=1 to lists.0
parse var lists.i name (hex01) fldr (hex01) dirnam (hex01) popup (hex01) .
k=nfldr.0+1
nfldr.k = dirnam fldr '"' || name || '"' popup
nfldr.0 = k
fldr = substr(dirnam,2) +0
findx = max(findx,fldr)
end
call dbout nfldr.0 'existing MR/2 folders found.'
call dbout findx 'is highest mail directory found.'
findx = findx+1
if length(findx) < 3 then
findx = right(findx,3,'0')
do i=1 to nsmailf.0
newfldr = FileSpec('Name',nsmailf.i)
do k=1 to nfldr.0
if translate(word(nfldr.k,2)) = translate(newfldr) then
newfldr = ''
end
if newfldr = '' then
iterate
k=nfldr.0+1
nfldr.k = 'F' || findx newfldr '"' || newfldr || '"'
call SysMkDir mr2i || 'F' || findx
call dbout 'Added folder for:' nfldr.k
findx = findx+1
if length(findx) < 3 then
findx = right(findx,3,'0')
nfldr.0 = k
end
call dbout nfldr.0 '= total folders after adding Netscape Mail.'
return
getnsmailf:
/* get the folder info for the Netscape mail to be moved... */
call SysFileTree nets || '*.','lists','FO'
do i=1 to lists.0
if translate(FileSpec('Name',lists.i)) <> 'TRASH' & ,
translate(FileSpec('Name',lists.i)) <> 'OUTBOX' & ,
translate(FileSpec('Name',lists.i)) <> 'SENT' & ,
translate(FileSpec('Name',lists.i)) <> 'INBOX' then do
k=nsmailf.0 +1
nsmailf.k = lists.i
nsmailf.0 = k
end
end
return
cantemps:
/* clean out the tempmail directory if it exists */
mr2it = left(mr2i,length(mr2i)-1)
mr2it = FileSpec('Drive',mr2it) || FileSpec('Path',mr2it) || mr2nmail
call dbout 'Cleaning out:' mr2it
call SysFileTree mr2it || '\*.*','lists','FO'
do i=1 to lists.0
call SysFileDelete lists.i
end
clean = lists.0
do while(clean <> '')
call SysFileTree mr2it || '\*.','lists','DO'
if lists.0 = 0 then
clean = ''
else
clean = 0
do i=1 to lists.0
call SysFileTree lists.i || '\*.*','files','FO'
do k=1 to files.0
call SysFileDelete files.k
end
xx = SysRmDir(lists.i)
if xx > 2 then
clean = clean -1
end
if clean < 1 then
clean = ''
end
return
getmaildir:
/* find the directories needed for the mail folders.... */
nets = stream(netini,'c','query exists')
mr2i = stream(mr2mail,'c','query exists')
if nets = '' then
nets = SysSearchPath('PATH',netini)
if mr2i = '' then
mr2i = SysSearchPath('PATH',mr2mail)
if nets = '' | mr2i = '' then
Say ''
if mr2i = '' then do
mr2i = stream('mr2i.exe','c','query exists')
if mr2i = '' then
mr2i = SysSearchPath('PATH','mr2i.exe')
if mr2i = '' then do
Say 'Cannot find the directory for the' mr2mail 'file. Please insure'
Say 'the MR/2 directory is in your PATH environment and retry.'
exit 8
end
else do
mr2path = FileSpec('Drive',mr2i) || FileSpec('Path',mr2i)
mr2i = mr2path || mr2mail
Say 'Cannot find the MR2i' mr2mail 'file - a new one will be created.'
end
end
if nets = '' then do
Say 'Cannot find the Netscape' netini 'file.'
Say 'Please insure the Netscape directory is in your PATH environment'
Say 'and retry.'
exit 8
end
nsmail = SysIni(nets,'Mail','MailDirectory')
if nsmail = '' then do
Say 'Cannot find the Mail information in the Netscape INI file at:'
Say ' ' nets
exit 8
end
nets = nsmail || '\'
mr2i = FileSpec('Drive',mr2i) || FileSpec('Path',mr2i)
call dbout 'NS Mail:' nets
call dbout 'MR/2 Mail:' mr2i
return
synerr:
errline = sigl
linenbr= errline
Say 'Unexpected error occurred.'
if datatype(rc,'W') then
if errortext(rc) = ' ' then
Say 'Error on line' linenbr
else
Say 'Error on line' linenbr 'was 'errortext(rc)
else
Say 'Error on line' linenbr
Say 'Error line: 'sourceline(errline)
exit 8
tell:
Say 'Convert Netscape for OS/2 mail to MR/2 ICE format - version' version
Say ' Copyright (c) Art Heimsoth - 1997 - all rights reserved.'
Say ''
Say 'Calling syntax:'
Say ' ' ourname '[?] [update] [test]'
Say ' where ? = display this help information'
Say ' test = do not alter existing MR/2 ICE mail direcories,'
Say ' but create new directories in the' mr2nmail
Say ' directory tree.'
Say ''
Say ' This program will convert the mail from Netscape for OS/2'
Say ' to a format compatable with MR/2 ICE. See the NSToMR2.DOC file'
Say ' in this package for additional detailed information.'
Say ''
exit 100