home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 35 Internet
/
35-Internet.zip
/
nstomr2.zip
/
nsa2mr2.cmd
< prev
next >
Wrap
OS/2 REXX Batch file
|
1997-02-18
|
22KB
|
647 lines
/* Netscape Navigator for OS/2 address book conversion to MR2ICE utility
Freeware by Art Heimsoth <heimsoth@doglover.com>
Copyright (c) Art Heimsoth 1997 - all rights reserved */
/* REXX command file to convert a Netscape Navigator for OS/2 address book
to address and group entries in the MR/2 ICE address book format.
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 address.htm file containing the
addressbook for Netscape Navigator. 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 address and group files.
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 address entries will be kept in the current MR2i address book,
but if an entry matches an entry from the Netscape address book, it can
optionally be updated from the Netscape address information. Only the
email address part is checked to determine this condition. If the update
option is not selected, the matching entry from the Netscape address book
will be skipped.
An optional parameter of test can be passed to indicate to run only in
test mode, in which case the real MR2i address and group file will not
be altered, but what would have been the new files will be named
mr2inew.adr and mr2inew.grp instead. If either of these files already
exist, they will be replaced.
The form of the email name may optionally be selected by the parameter
shown below. The default is jb123@windy.com if no is parameter provided.
"Joe Blow" <jb123@windy.com .. parameter = addr1
Joe Blow <jb123@windy.com .. parameter = addr2
jb123@windy.com (Joe Blow) .. parameter = addr3
(above complements of Julian Thomas as found in his ADRSTUFF.ZIP package)
All data from the name, email name, alias, distribution list, and comment
fields will be moved without change (other than the form of the email name)
to the address and group files for MR2i. */
version = '1.0'
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 = ''
mr2b = ''
flagsw = '' /* flag setting from prototype */
nameform = 0 /* email address form to use */
netbook = 'address.htm' /* Netscape Navigator address book */
mr2book = 'mr2i.adr' /* MR/2 ICE address book */
mr2grp = 'mr2i.grp' /* MR/2 ICE Group book */
mr2newb = 'mr2inew.adr' /* test mode address book created */
mr2newg = 'mr2inew.grp' /* test mode group book created */
name. = '' /* array for full name */
email.= '' /* email name array */
flag. = '' /* popup flag array */
alias.= '' /* alias array */
cmt. = '' /* comment array */
grp. = '' /* group indicator */
name.0= 0
parse arg a1
if wordpos('?',a1) > 0 then signal tell
if wordpos('TEST',translate(a1)) > 0 then
testmode = 'x'
else
testmode = ''
if wordpos('UPDATE',translate(a1)) > 0 then
update = 'x'
else
update = ''
if wordpos('DEBUG',translate(a1)) > 0 then
debug = 'x'
else
debug = ''
if debug <> '' then
testmode = 'x'
db = 'debug.dat'
if debug <> '' then
if stream(db,'c','query exists') <> '' then
call SysFileDelete db
/* testmode <> '' means do not destroy existing address or group files
update <> '' means to update matching entries found with Netscape data */
Say 'Convert Netscape for OS/2 addresses to MR/2 ICE format - version' version
Say ' Copyright (c) Art Heimsoth - 1997 - all rights reserved.'
if update <> '' then
Say 'Will update any matching names found in the MR/2 ICE address book.'
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 getbookdir /* locate address book directories */
call loadnetscape /* get the netscape address info */
call loadmr2i /* get the existing MR2i addr info */
call prototype /* get address form if provided */
call setoutput /* handle test mode for output files*/
call dooutput /* finally build the new files */
if debug <> '' then do
nsize = 1
esize = 1
csize = 1
asize = 1
do i=1 to name.0
nsize = max(nsize,length(name.i))
esize = max(esize,length(email.i))
csize = max(csize,length(cmt.i))
asize = max(asize,length(alias.i))
end
do i=1 to name.0
outline = left(name.i,nsize,' ') left(email.i,esize,' ') left(alias.i,asize,' ') ,
flag.i grp.i
call lineout db,outline
outline = cmt.i
call lineout db,outline
end
call lineout db
end
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
dooutput:
/* build the content of the arrays into the new files - for the address
book and for the address groups (if any). */
if stream(mr2i,'c','query exists') <> '' then
call SysFileDelete mr2i
if stream(mr2b,'c','query exists') <> '' then
call SysFileDelete mr2b
call stream mr2i,'c','open write'
do i=1 to name.0
if email.i = '' then
iterate
if grp.i <> '' then
iterate
parse var email.i . '@' dummychk .
if translate(dummychk) = 'DOMAIN.USE' then
iterate
lineoutp = name.i || '\' || email.i || '\' || flag.i || '\' || alias.i
call lineout mr2i,lineoutp
if length(cmt.i) > 0 then do
lineoutp = '' || length(cmt.i)
call lineout mr2i,lineoutp
call lineout mr2i,cmt.i
call lineout mr2i,''
end
end
call stream mr2i,'c','close'
/* now build the address group file (if needed) */
ingrp = ''
higrp = 0
do i=1 to name.0
if grp.i <> '' & grp.i > 0 then do
ingrp = 'x'
higrp = max(higrp,grp.i)
end
end
if ingrp = '' then
return
call stream mr2b,'c','open write'
do ingrp = 1 to higrp
call dogroup
end
call stream mr2b,'c','close'
return
dogroup:
/* handle a single address group */
grouplist = ''
do i=1 to name.0
if grp.i = ingrp then do
if grouplist = '' then do
lineoutp = '!' || alias.i || '\' || name.i || '\' || flag.i
call lineout mr2b,lineoutp
if length(cmt.i) > 1 then do
lineoutp = '#' || length(cmt.i)
call lineout mr2b,lineoutp
call lineout mr2b,cmt.i
call lineout mr2b,''
end
grouplist = '+'
end
else do
do k=1 to name.0
if translate(name.k) = translate(name.i) & grp.k <> ingrp then do
grouplist = grouplist || alias.k
call lineout mr2b,grouplist
grouplist = '+'
k=name.0
end
end
end
end
end
return
setoutput:
/* set the mr2i and mr2b names for the output files. If not in test
mode, first save the existing address book and group files in a
backup file. */
mr2path = FileSpec('Drive',mr2i) || FileSpec('Path',mr2i)
if testmode <> '' then do
mr2i = mr2path || mr2newb
mr2b = mr2path || mr2newg
Say 'New files created in:'
Say ' Address Book ==>' mr2i
Say ' Address Group =>' mr2b
end
else do
if stream(mr2i,'c','query exists') <> '' then do
if stream(mr2path || 'mr2iadr.bak','c','query exists') <> '' then
call SysFileDelete mr2path || 'mr2iadr.bak'
'@rename' mr2i 'mr2iadr.bak'
Say mr2i 'saved as' mr2path || 'mr2iadr.bak'
end
if stream(mr2b,'c','query exists') <> '' then do
if stream(mr2path || 'mr2igrp.bak','c','query exists') <> '' then
call SysFileDelete mr2path || 'mr2igrp.bak'
'@rename' mr2b 'mr2igrp.bak'
Say mr2b 'saved as' mr2path || 'mr2igrp.bak'
end
end
return
prototype:
/* get the prototype form for the address (if any found) to allow the */
/* flag and email address form to be built to match the prototype. */
/* only the following forms of the email address will be supported:
"Joe Blow" <jb123@windy.com (addr1)
Joe Blow <jb123@windy.com (addr2)
jb123@windy.com (Joe Blow) (addr3)
If one of the above forms are not found, then the email name will
default to not include any real name. The popup flag will default to Y */
if wordpos('ADDR1',translate(a1)) > 0 then
nameform = 1
else if wordpos('ADDR2',translate(a1)) > 0 then
nameform = 2
else if wordpos('ADDR3',translate(a1)) > 0 then
nameform = 3
if flagsw = '' then
flagsw = 'Y'
/* now set the flag for all entries that came from Netscape (the ones
that currently do not have the flag set either way.. */
do i=1 to name.0
if flag.i = '' then
flag.i = flagsw
end
/* now set the email address up for all those that currently are not
set in one of the above forms - unless a prototype was not found,
in which case the emails will be left alone... */
do i=1 to name.0
if verify('"<(',email.i,'Match') > 0 then
iterate
if nameform = 0 then
iterate
if email.i = '' then
iterate
if nameform = 1 then
email.i = '"' || name.i || '" <' || email.i
else if nameform = 2 then
email.i = name.i '<' || email.i
else if nameform = 3 then
email.i = email.i '(' || name.i || ')'
end
return
loadmr2i:
/* load the stem variables with the existing content from the MR2i addr bk*/
xx = stream(mr2i,'c','open read')
xx = stream(mr2i,'state')
call dbout 'Input from:' mr2i
do while(xx = 'READY')
lineinp = linein(mr2i)
call dbout lineinp
lineinp = strip(lineinp)
xx = stream(mr2i,'state')
if xx <> 'READY' then leave
if lineinp = '' then iterate
i = name.0 +1
parse var lineinp name.i '\' email.i '\' flag.i '\' alias.i
name.i = strip(name.i)
email.i = strip(email.i)
flag.i = strip(flag.i)
alias.i = strip(alias.i)
call dbout 'Item' i 'set for' name.i 'alias:' alias.i
lineinp = linein(mr2i)
call dbout lineinp
if stream(mr2i,'state') <> 'READY' then
leave
if left(lineinp,1) = '' then do
cmt.i = linein(mr2i)
call dbout cmt.i
cmt.i = strip(cmt.i)
xx = stream(mr2i,'state')
end
else do
call stream mr2i,'c','seek -' (length(lineinp)+4)
cmt.i = linein(mr2i)
call dbout 'backspaced and re-read:' cmt.i
cmt.i = ''
end
if pos('<',email.i) > 0 then
parse var email.i . '<' temail .
else
parse var email.i temail .
do k=1 to name.0
if temail = email.k then do
if update <> '' then do
call dbout 'Item' i 'reset - found at' k
end
else do
call dbout 'Item' k 'replaced with item' i
name.k = name.i
email.k = email.i
flag.k = flag.i
alias.k = alias.i
grp.k = grp.i
cmt.k = cmt.i
end
i = i-1
k = i
end
end
name.0 = i
end
call stream mr2i,'c','close'
call dbout 'File closed:' mr2i
if mr2b = '' then
return
if stream(mr2b,'c','query exists') = '' then
return
xx = stream(mr2b,'c','open read')
xx = stream(mr2b,'state')
call dbout 'Input from:' mr2b
higrp = ingrp
do while(xx = 'READY')
lineinp = linein(mr2b)
call dbout lineinp
lineinp = strip(lineinp)
xx = stream(mr2b,'state')
if xx <> 'READY' then leave
if lineinp = '' then iterate
if left(lineinp,1) = '!' then do
i = name.0+1
parse var lineinp . '!' alias.i '\' name.i '\' flag.i
alias.i = strip(alias.i)
name.i = strip(name.i)
flag.i = strip(flag.i)
email.i = ''
call dbout 'Entry' i 'setup for group name' name.i 'alias:' alias.i
lineinp = linein(mr2b)
call dbout lineinp
if stream(mr2b,'state') <> 'READY' then
leave
if left(lineinp,1) = '#' then do
cmt.i = linein(mr2b)
call dbout cmt.i
cmt.i = strip(cmt.i)
xx = stream(mr2b,'state')
end
else do
call stream mr2b,'c','seek -' (length(lineinp)+4)
cmt.i = linein(mr2b)
call dbout 'Backspaced and re-read:' cmt.i
cmt.i = ''
end
temail = 'x'
do k=1 to name.0
if alias.i = alias.k & grp.k <> '' then do
if update <> '' then do
ingrp = 0
call dbout 'Entry' i 'reset - found at' k 'group:' ingrp
end
else do
call dbout 'Entry' k 'replaced with entry' i 'group:' ingrp
ingrp = grp.k
name.k = name.i
flag.k = flag.i
cmt.k = cmt.i
do j=1 to name.0
if grp.j = grp.k & j <> k then
grp.j = 0
end
end
k = i
temail = ''
end
end
if temail <> '' then do
if higrp = '' then
higrp = 1
else
higrp = higrp + 1
ingrp = higrp
call dbout 'Group # set to' ingrp
grp.i = ingrp
name.0 = i
end
end
else if left(lineinp,1) = '+' then do
if ingrp = '' | ingrp = 0 then
iterate
parse var lineinp . '+' search
do while(search <> '')
parse var search sname ',' search
call dbout 'Processing item:' sname
sname = strip(sname)
do i=1 to name.0
if translate(alias.i) = translate(sname) & ,
grp.i <> ingrp then do
k = name.0+1
call dbout 'Assuming entry:' k 'first entry:' i '=' name.i
do j=i to name.0
if translate(name.j) = translate(name.i) & ,
translate(alias.j) = translate(alias.i) & ,
grp.j = ingrp then do
call dbout 'Match found at:' j '=' name.j 'alias:' alias.j
k=j
end
end
call dbout 'Item set to entry:' k 'from entry' i
name.k = name.i
alias.k = alias.i
cmt.k = cmt.i
email.k = email.i
flag.k = flag.i
grp.k = ingrp
name.0 = max(name.0,k)
i = k
end
end
end
end
iterate
end
call stream mr2b,'c','close'
call dbout 'File closed:' mr2b
return
loadnetscape:
/* load the stem variables with the content from the Netscape address bk */
xx = stream(nets,'c','open read')
xx = stream(nets,'state')
call dbout 'File input:' nets
ingrp = ''
innam = ''
i = name.0 + 1 /* initialize for 1st name */
do while(xx = 'READY')
lineinp = linein(nets)
call dbout lineinp
lineinp = strip(lineinp)
xx = stream(nets,'state')
if xx <> 'READY' then leave
if lineinp = '' then iterate
k = pos('MAILTO:',translate(lineinp))
if k = 0 then do
if left(lineinp,4) = '<DD>' then do
k=i-1
if k>0 then
cmt.k = substr(lineinp,5)
call dbout 'Comment for' alias.k 'set to:' left(cmt.k,40,' ')
iterate
end
if left(lineinp,2) = '<H' then do
if innam = '' then
innam = 'x'
end
if left(lineinp,6) = '<DT><H' then do
if innam = '' then
iterate
else if ingrp = '' then
ingrp = 1
else
ingrp = ingrp + 1
call dbout 'Group # set to:' ingrp
end
if pos('NICKNAME=',lineinp) = 0 then
iterate
end
if innam = '' then iterate
if k > 0 then do
k = k+7
email.i = substr(lineinp,k,pos('"',substr(lineinp,k))-1)
end
k = pos('NICKNAME=',translate(lineinp))
if k > 0 then
alias.i = substr(lineinp,k+10,pos('"',substr(lineinp,k+10))-1)
k = lastpos('>',left(lineinp,length(lineinp)-2))
if k > 5 then
name.i = substr(lineinp,k+1,lastpos('<',substr(lineinp,k+1))-1)
if ingrp <> '' then
grp.i = ingrp
if name.i = '' then
name.i = left(email.i,pos('@',email)-1)
if alias.i = '' then do
do k=1 to name.0
if name.k = name.i then
alias.i = alias.k
end
end
call dbout 'Item' i 'setup for' name.i 'alias:' alias.i 'group:' grp.i
name.0 = i
i = i+1
end
call stream nets,'c','close'
call dbout 'File closed:' nets
return
getbookdir:
/* find the directories needed for the address books... */
nets = stream(netbook,'c','query exists')
mr2i = stream(mr2book,'c','query exists')
mr2b = stream(mr2grp,'c','query exists')
if nets = '' then
nets = SysSearchPath('PATH',netbook)
if mr2i = '' then
mr2i = SysSearchPath('PATH',mr2book)
if mr2b = '' then
mr2b = SysSearchPath('PATH',mr2grp)
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' mr2book 'file. Please insure'
Say 'it is in your PATH environment and retry.'
exit 8
end
else do
mr2path = FileSpec('Drive',mr2i) || FileSpec('Path',mr2i)
mr2i = mr2path || mr2book
Say 'Cannot find the MR2i' mr2book 'file - a new one will be created.'
end
end
if nets = '' then do
Say 'Cannot find the Netscape' netbook 'file.'
Say 'Please insure it is in the current directory or can be found via'
Say ' the PATH environment, and retry.'
exit 8
end
if mr2b = '' then do
mr2path = FileSpec('Drive',mr2i) || FileSpec('Path',mr2i)
mr2b = mr2path || mr2grp
end
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)
trace '?i'
errline = errline
exit 8
tell:
Say 'Convert Netscape for OS/2 addresses to MR/2 ICE format - version' version
Say ' Copyright (c) Art Heimsoth - 1997 - all rights reserved.'
Say ''
Say 'Calling syntax:'
Say ' ' ourname '[?] [update] [test] [addr1|2|3]'
Say ' where ? = display this help information'
Say ' update = update any MR/2 ICE entries with the matching'
Say ' information from the Netscape address book,'
Say ' Default is to keep the existing MR/2 information.'
Say ' addr1|2|3 = format the imported (converted) email addresses'
Say ' to one of 3 possible formats:'
Say ' addr1 = "Joe Blow" <jb123@windy.com'
Say ' addr2 = Joe Blow <jb123@windy.com'
Say ' addr3 = jb123@windyy.com (Joe Blow)'
Say ' test = do not alter existing MR/2 ICE address entries,'
Say ' but create new files of mr2inew.adr and mr2inew.grp'
Say ' with the converted information.'
Say ' if multiple parameters are provided, they must be separated with'
Say ' one or more blanks.'
Say ''
Say ' This program will convert the address book 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