home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / prmconv.zip / UML2POST.CMD < prev    next >
OS/2 REXX Batch file  |  1996-01-19  |  29KB  |  855 lines

  1. /* UML2POST.CMD -- Converts UltiMail folders and address books to
  2.                    the Post Road Mailer */
  3. /* Parameters: UltiMail subdirectory.  If no parameter is used, utility 
  4.                prompts user to enter UltiMail subdirectory.*/
  5. /* (c) Copyright, 1996, InnoVal System Solutions, Inc., Luis Reyes     */
  6.  
  7.  /* Possible code values: */
  8.  X.SAVE_FILECARDS        = X2C('0700'); X.SAVE_GROUPS           = X2C('0800')
  9.  X.SAVE_GNAME            = X2C('2000'); X.SAVE_ADDRESSES        = X2C('2200')
  10.  X.SAVE_GADDRESS         = X2C('2400'); X.SAVE_BOOK_NAME        = X2C('3000')
  11.  X.SAVE_FIRST            = X2C('3500'); X.SAVE_CNAME            = X2C('4000')
  12.  X.SAVE_COMPANY          = X2C('4500'); X.SAVE_EMAIL1           = X2C('5000')
  13.  X.SAVE_PHONE1           = X2C('8000'); X.SAVE_PHONE2           = X2C('8500')
  14.  X.SAVE_FAX              = X2C('9000'); X.SAVE_ADDRESS          = X2C('9500')
  15.  X.SAVE_NICKNAME1        = X2C('0001'); X.SAVE_NICKNAME2        = X2C('0101')
  16.  
  17.  Signal on HALT 
  18.  
  19.  If LoadRexxUtil() then Do
  20.     Say 'Err: Could not load Rexx Library...'
  21.     Exit
  22.   end /* If Do */
  23.                                         
  24.  If Arg() <> 0 then Do
  25.      Arg subdir
  26.      If subdir = '?' then Signal Help
  27.  end /* If */
  28.  Else Do
  29.        Say "Enter UltiMail subdirectory: "
  30.        Pull subdir
  31.  end  /* Else */
  32.  
  33.  If Right( subdir, Length( subdir ) ) = '\' then
  34.     subdir = Left( subdir, Length( subdir ) - 1 )
  35.  
  36.  Call SysCls
  37.  Call GreetingMsg
  38.  
  39.  PostDir = Directory()
  40.  If Stream( PostDir|| '\POSTROAD.EXE','C','QUERY EXISTS') = '' then Signal Err
  41.  If Stream( subdir || '\UMAIL.EXE','C', 'QUERY EXISTS') = '' then Signal Err1
  42.  If Stream( subdir || '\UMAILSRV.PRO','C','QUERY EXISTS') = '' then Signal Err1
  43.  
  44.  inBas = '\' || GetInbasketName( PostDir ) || '\'
  45.  Book. = ''
  46.  
  47.  Call SetUpall
  48.  
  49. Exit
  50. /*------------------------------------------------------------------------*/
  51. SETUPALL: Procedure Expose subdir X. Book. inBas PostDir
  52.  /* Set up several variables, Do menu */
  53.  
  54.   UmIniFile = subdir || '\UMAILSRV.PRO'
  55.   i = 1
  56.   BkCount = 0
  57.   fldCount = 0
  58.  
  59.   Do While lines( UmIniFile )
  60.      lin = Translate( LineIn( UmIniFile ) )
  61.      If Left( lin, 7 ) = ':ACCESS' then Do
  62.         Parse Var lin . lin
  63.         Do While lin <> '.'
  64.            Parse Var lin valu . lin
  65.            valu = Translate( valu )
  66.            Select
  67.               When valu = 'NAME' then
  68.                  Book.Name.i = SubStr( lin, 2, Length( lin ) - 2 )
  69.               When valu = 'USER' then
  70.                  Book.User.i = SubStr( lin, 2, Length( lin ) - 2 )
  71.               When valu = 'PASSWORD' then
  72.                  Book.PassWord.i = SubStr( lin, 2, Length( lin ) - 2 )
  73.               When valu = 'ACCESS' then
  74.                  Book.AcRights.i = SubStr( lin, 2, Length( lin ) - 2 )
  75.               When valu = 'ROOT' then
  76.                  Book.AdrBook.i = SubStr( lin, 2, Length( lin ) - 2 )
  77.               Otherwise Nop
  78.            end  /* Select */
  79.            lin = LineIn( UmIniFile )
  80.         end /* Do While */
  81.         Book.Count = i
  82.         i = i + 1
  83.      end /* If Do */
  84.   end /* Do While */
  85.  
  86.   menu.0 = 3
  87.   menu.1.txt = 'Convert Address Books'
  88.   menu.1.row = 9; menu.1.col = 39 - Length( menu.1.txt ) % 2
  89.   menu.1.act = 'Call BookStart'
  90.                                 
  91.   menu.2.txt = 'Convert Folders'
  92.   menu.2.row = 10; menu.2.col = 39 - Length( menu.2.txt ) % 2
  93.   menu.2.act = 'Call ConvertFolders'
  94.                                  
  95.   menu.3.txt = 'Exit'
  96.   menu.3.row = 11; menu.3.col = 39 - Length( menu.3.txt ) % 2
  97.   menu.3.act = 'Call Exiting'
  98.                                  
  99.   Call DoMenu
  100.  
  101.   Return
  102. /*----------------------------------------------------------------------*/
  103.  
  104. DOMENU:
  105.   colorNormal = '1B'x || '[37;40m'
  106.   colorReverse = '1B'x || '[30;47m'
  107.   keyEnter = '0D'x
  108.   keyUp = '48'x
  109.   keyDown = '50'x
  110.   keyPrefix1 = '00'x
  111.   keyPrefix2 = 'E0'x
  112.  
  113.   Call SysCls
  114.   Call GreetingMsg
  115.  
  116.   Call SysCurState 'OFF'
  117.   Call CharOut 'CON:', colorNormal
  118.   Do r = 1 to menu.0
  119.      Call SysCurPos menu.r.row, menu.r.col
  120.      Call CharOut 'CON:', menu.r.txt
  121.   end
  122.   r = 1
  123.  
  124.   Do Forever
  125.      Call SysCurPos menu.r.row, menu.r.col
  126.      Call CharOut 'CON:', colorReverse || menu.r.txt
  127.      Call CharOut 'CON:', colorNormal
  128.      key = SysGetKey('NoEcho' )
  129.      next = r
  130.      Select
  131.         When key == keyEnter then
  132.            Interpret menu.r.act
  133.         When key == keyPrefix1 | key == keyPrefix2 then Do
  134.            key = SysGetKey( 'NoEcho' )
  135.            Select
  136.               When key == keyUp then
  137.                 If r > 1 then next = r - 1
  138.                 Else next = menu.0
  139.               When key == keyDown then
  140.                 If r < menu.0 then next = r + 1
  141.                 Else next = 1
  142.              Otherwise Nop
  143.            end /* Select */
  144.         end /* When Do */
  145.         Otherwise Nop
  146.      end  /* Select */
  147.      If next <> r then Do
  148.         Call SysCurPos menu.r.row, menu.r.col
  149.         Call CharOut 'CON:', menu.r.txt
  150.         r = next
  151.      end /* If Do */
  152.   end /* Do Forever */
  153.  
  154. Return
  155. /*------------------------------------------------------------------------*/
  156. /*            Address Book Conversion Procedures and Functions            */
  157. /*------------------------------------------------------------------------*/
  158.  
  159. BOOKSTART: Procedure Expose X. Book. i BkCount menu. colorNormal r
  160.   /* Start Address Book Conversion.  */
  161.  
  162.   Call SysCurPos 13,0
  163.   Call SysCurState( 'ON' )
  164.  
  165.   Do i = 1 to Book.count
  166.     Say 'Do you wish to convert the' Strip( Book.user.i ) 'address book? (Y,n)'
  167.     Pull Ans
  168.       If Left( Ans,1 ) = 'Y' then
  169.          Call ConvertBook
  170.     Say;
  171.   end /* Do i... */
  172.      Call SysCls
  173.      Call GreetingMsg
  174.      Call SysCurState 'OFF'
  175.      Call CharOut 'CON:', colorNormal
  176.      Do r = 1 to menu.0
  177.         Call SysCurPos menu.r.row, menu.r.col
  178.         Call CharOut 'CON:', menu.r.txt
  179.      end
  180.      r = 1
  181.  
  182.   Return
  183. /*-------------------------------------------------------------------------*/
  184. CONVERTBOOK: Procedure Expose X. Book. i BkCount
  185.   /* Read Address book and write to an ascii format */
  186.   /* Remark out the "@ERASE outfile" commands in order to save the ascii format */
  187.   /* of the address books */
  188.  
  189.   outfile = Book.AdrBook.i || '.ASC'
  190.  
  191.   PostDir = Directory()
  192.   FileName = Right( Book.AdrBook.i, Length(Book.AdrBook.i)-LastPos( '\',Book.AdrBook.i))
  193.   FileName = PostDir || '\' || FileName || '.ADR'
  194.   NewBkName = Book.User.i
  195.  
  196.   If Stream(FileName,'C','QUERY EXISTS') <> '' then Do
  197.     Say Strip( newBkName ) 'already exists. Do you want to replace it?(Y/n)'
  198.     Pull ans
  199.     If Left( ans,1) = 'Y' then
  200.        '@ERASE' FileName
  201.     Else Do
  202.        Say 'Do you wish to rename destination file? (Y/n)'
  203.        Pull ans
  204.          If Left( ans, 1 ) = 'Y' then
  205.             outfile = CheckFileName( outfile )
  206.          Else Return
  207.     end /* Else Do */
  208.   end /* Main If Do */
  209.  
  210.   /* Write address book name and write to output file */
  211.   If Book.Name.i <> '' then
  212.      Call LineOut outfile, '<BOOK_NAME>' || Book.Name.i
  213.   Else
  214.      Call LineOut outfile, '<BOOK_NAME>' || Book.User.i
  215.  
  216.   Call LineOut outfile, '*Created from UltiMail' Book.User.i 'addressbook'
  217.   Call LineOut outfile, ''
  218.  
  219.   infile = Book.AdrBook.i || '\ADDRESS.HNM'
  220.   Entry. = ''
  221.   Entry.Count = 0
  222.   j = 0
  223.  
  224.   /* Read in entire input file to memory. */
  225.   Do While Lines(infile) > 0
  226.     lin = LineIn( infile )
  227.     Parse Var lin valu '.' lin
  228.     valu = Translate( valu )
  229.     If valu = ':NICK' then
  230.        newSeries = 1
  231.     Else newSeries = 0
  232.     If newSeries = 1 then Do
  233.       Entry.Count = j
  234.       j = j + 1
  235.     end /* If Do */
  236.     Select
  237.        When valu = ':NAME'then
  238.          Entry.j.Name = lin
  239.        When valu = ':NICK' then
  240.          Entry.j.Nick = lin
  241.        When valu = ':PHONE' then
  242.          Entry.j.Phone = lin
  243.        When valu = ':USERID' then
  244.          Entry.j.UserId = lin
  245.        When valu = ':NODE' then
  246.          Entry.j.Node = lin
  247.        When valu = ':LIST' then
  248.          Entry.j.List = lin
  249.        Otherwise Nop
  250.     end /* Select */
  251.   end /* Do while */
  252.  
  253.   Entry.Count = Entry.Count + 1
  254.  
  255.   Call LineOut infile  /* Close infile file */
  256.  
  257.   Do j = 1 To Entry.Count
  258.      If Translate( Entry.j.UserId ) <> 'ULTIMAIL_DISTRIBUTION_LIST' then Do
  259.        Entry.j.Email = Entry.j.UserId || '@' || Entry.j.Node
  260.        Call NameSave
  261.        Call LineOut outfile, '<LAST_NAME>' || Entry.j.Last
  262.        Call LineOut outfile, '<FIRST_NAME>' || Entry.j.First
  263.        Call LineOut outfile, '<EMAIL1>' || Entry.j.Email
  264.        Call LineOut outfile, '<PHONE1>' || Entry.j.Phone
  265.        Call LineOut outfile, '<NICKNAME1>' || Entry.j.Nick
  266.        Call LineOut outfile, '<COMMENTS>'
  267.        Call LineOut outfile, ''
  268.      end /* If Do */
  269.      Else Do
  270.        Call LineOut outfile, '<GROUP_NAME>' || Entry.j.Nick
  271.        k = j
  272.  
  273.        Do While Words( Entry.k.List ) > 0
  274.           j = 1
  275.           found = 0
  276.           Parse Var Entry.k.List nickName Entry.k.List
  277.           Do while found <> 1 & j < Entry.Count
  278.              If Translate( Entry.j.Nick ) = nickName then Do
  279.                 found = 1
  280.                 Call NameSave
  281.                 Email = Entry.j.UserId || '@' || Entry.j.Node
  282.                 Gaddr = Entry.j.Last || ',' Entry.j.First '<' || Email || '>'
  283.                 Call LineOut outfile, '<GADDRESS>' || Gaddr
  284.              end  /* Do */
  285.              Else found = 0
  286.              j = j + 1
  287.           end /* Do while */
  288.        end /* Do While */
  289.        j = k
  290.        Call LineOut outfile, ''
  291.      end  /* Else Do */
  292.   end /* Do */
  293.  
  294.   Call CharOut outfile /* Close output file */
  295.   Call Asc2Adr
  296.   BkCount = BkCount + 1
  297.  
  298.   If Stream( outfile, 'C', 'QUERY EXISTS') <> '' then
  299.     '@ERASE' outfile 
  300.  
  301.   Return
  302. /*--------------------------------------------------------------------------*/
  303.  
  304. ASC2ADR: Procedure Expose X. outfile Book. i
  305.   /* Writing to output file. */
  306.   /* Based on Code Written by Tom Springall, Innoval Systems Solutions, Inc */
  307.  
  308.   CRLF = X2C('0D0A')
  309.   filespec = outfile
  310.   AdrFile = Right( outfile, Length( outfile ) - LastPos( '\',outfile ) + 1)
  311.   AdrFile = Directory() || Left( AdrFile, LastPos( '.',AdrFile ) ) || 'ADR'
  312.   Lin = LineIn(filespec)
  313.  
  314.  /* Must be in the first row */
  315.   If Left(lin,11) <> '<BOOK_NAME>' then Signal Err2
  316.   Call SaveIt X.SAVE_BOOK_NAME, Substr(lin,12)
  317.  
  318.   y = 1 ; activity = 0 ; cards = 0 ; groups = 0 ; data. = ''
  319.                                                                              
  320.  /* Read in entire input file to memory. */                                  
  321.   Do While Lines(filespec) > 0
  322.                                                                              
  323.     lin = LineIn(filespec)
  324.     first = Left(lin,1)
  325.     Select
  326.       /* blank line means new address or group */
  327.       When first = ' ' & activity > 0 then do
  328.         /* check values since last blank, if any */
  329.         Call CheckI
  330.         activity = 0
  331.         end /* of When */
  332.       When first = '<' then do                /* it's a tag */
  333.         Parse var lin '<' tag '>' valu
  334.         Select
  335.           When tag = 'COMMENTS' then do       /* gotta append these */
  336.             If data.y.COMMENTS <> '' then
  337.                data.y.COMMENTS = data.y.COMMENTS || CRLF
  338.             data.y.COMMENTS = data.y.COMMENTS || valu
  339.             end
  340.           When tag = 'GADDRESS' then do       /* gotta count these */
  341.             z = data.y.addresses
  342.             If z = '' then z = 1
  343.             Else z = z + 1
  344.             data.y.GADDRESS.z = valu
  345.             data.y.addresses = z
  346.             end
  347.           Otherwise                           /* otherwise, just save value */
  348.             /* assign valu to data.y.field */
  349.             V = Value('data.y.' || tag, valu)
  350.           end /* of Select */
  351.         activity = 1    /* indicate that something has been saved at level i */
  352.         end
  353.       Otherwise Nop                          /* skip comments, etc. */
  354.       end /* of Select */
  355.     end /* of Do While */
  356.   Call LineOut filespec                      /* close input file */
  357.                                                                              
  358.  /* entire file read in. check if last y has anything in it */
  359.   If y <> 0 & activity > 0 then Call CheckI
  360.                                                                              
  361.  /* save card and group counts */                                            
  362.   Call SaveIt X.SAVE_FILECARDS, MakeNum(cards)
  363.   Call SaveIt X.SAVE_GROUPS, MakeNum(groups)
  364.  
  365.  /* write out each level (each level contains an address page or group) */   
  366.   Do z = 1 to y - 1
  367.     Select
  368.       When typ.z = 'CARD' then Do
  369.        /* address page must start with last name field */                    
  370.         Call SaveIt X.SAVE_CNAME, data.z.LAST_NAME  /* must be 1st */
  371.         Call SaveIt X.SAVE_FIRST, data.z.FIRST_NAME
  372.         Call SaveIt X.SAVE_EMAIL1, data.z.EMAIL1
  373.         Call SaveIt X.SAVE_PHONE1, data.z.PHONE1
  374.         Call SaveIt X.SAVE_ADDRESS, data.z.COMMENTS
  375.         Call SaveIt X.SAVE_NICKNAME1, data.z.NICKNAME1
  376.       end /* of When */
  377.                                                                              
  378.       When typ.z = 'GROUP' then do         /* it's a group */
  379.        /* group must begin with name of group */                             
  380.         Call SaveIt X.SAVE_GNAME, data.z.GROUP_NAME
  381.        /* number of addresses in group */                                    
  382.         Call SaveIt X.SAVE_ADDRESSES, MakeNum(data.z.addresses)
  383.        /* then, each address */                                              
  384.         Do k = 1 to data.z.addresses
  385.           Call SaveIt X.SAVE_GADDRESS, data.z.GADDRESS.k
  386.         end                                                                 
  387.       end /* of When */                                                     
  388.       Otherwise Nop
  389.     end /* of Select */                                                     
  390.   end /* of Do j... */                                                      
  391.                                                                              
  392.   Call CharOut AdrFile                /* close output files */
  393.  
  394.   Return
  395. /*--------------------------------------------------------------------------*/
  396.  
  397. NAMESAVE:
  398.   /* Extract name */
  399.  
  400.   lin = Entry.j.Name
  401.   NameNum = words( lin )
  402.   Select
  403.      When NameNum >= 4 then Do
  404.         first = word( lin, 1 ) || ' ' || word( lin, 2 )
  405.         last = word( lin, NameNum - 1) || ' ' || word( lin, NameNum )
  406.      end  /* Do */
  407.      When NameNum = 3 then Do
  408.         first = word( lin, 1 ) || ' ' || word( lin, 2 )
  409.         last = word( lin, NameNum )
  410.      end  /* Do */
  411.      When NameNum = 0 then Do
  412.         first = 'Name'
  413.         last = 'Needed'
  414.      end  /* Do */
  415.      Otherwise Do
  416.        first = word(lin,1)
  417.        last = word( lin, NameNum )
  418.      end /* Do */
  419.   end  /* select */
  420.  
  421.   Entry.j.First = first
  422.   Entry.j.Last = last
  423.  
  424.   Return
  425. /*--------------------------------------------------------------------------*/
  426.  
  427. SAVEIT: Procedure Expose AdrFile
  428.    /* write field to output file */
  429.  
  430.   code = Left(Arg(1),4,D2C(0))
  431.   valu = Arg(2)
  432.   len = MakeNum(Length(valu))
  433.  
  434.   If 0 <> CharOut(AdrFile, code || len || valu) then Signal Err3
  435.  
  436.   Return
  437. /*--------------------------------------------------------------------------*/
  438.  
  439. MAKENUM: Procedure
  440. /* Convert integer into 4-byte Intel format */
  441.  
  442.   Return Intel(D2C(Arg(1),4))
  443. /*---------------------------------------------------------------------------*/
  444.  
  445. INTEL:  Procedure
  446.   /* Swaps bytes in an Intel 2 or 4 byte number. */
  447.  
  448.   Parse arg x
  449.  
  450.   If Length(x) = 2 then
  451.     Return Right(x,1) || Left(x,1)
  452.   Else
  453.     Return Intel(Right(x,2)) || Intel(Left(x,2))
  454. /*----------------------------------------------------------------------*/
  455.  
  456. CHECKI: Procedure Expose y data. cards groups typ.
  457.                                                                        
  458.   /* Check to see if any real stuff collected at the current level (y) */
  459.   /* is it a card? */           
  460.   If data.y.LAST_NAME <> '' | data.y.ORGANIZATION <> '' then do
  461.     typ.y = 'CARD'
  462.     cards = cards + 1
  463.     y = y + 1
  464.     end
  465.   Else
  466.     If data.y.GROUP_NAME <> '' then Do /* is it a group? */
  467.       typ.y = 'GROUP'
  468.       groups = groups + 1
  469.       y = y + 1
  470.     end
  471.     Else
  472.       data.y. = ''               /* false alarm. reset */
  473.  
  474.   Return
  475. /*--------------------------------------------------------------------------*/
  476.  
  477. CHECKFILENAME: Procedure
  478.  
  479.   Arg outfile
  480.   nfn = ''
  481.   Do while nfn = ''
  482.     Say 'Enter new file name: '
  483.     Pull nfn
  484.   end /* Do while */
  485.   nfnsav = nfn
  486.  
  487.   If LastPos( '\', nfn ) <> 0 then
  488.      nfn = Right( nfn, Length( nfn ) - LastPos( '\', nfn ) )
  489.   If LastPos( '.', nfn ) <> 0 then
  490.      nfn = Left( nfn, LastPos( '.', nfn ) - 1 )
  491.   If Length( nfn ) > 8 then
  492.      nfn = Left( nfn, 8 )
  493.   nfn = Directory() || '\' || nfn
  494.  
  495.   If Stream( nfn || '.ADR', 'C', 'QUERY EXISTS' ) <> '' then Do
  496.      Say;Say Strip( nfnsav ) 'already exists.'
  497.      nfn = CheckFileName( nfn || '.ADR' )
  498.      If LastPos( '.', nfn ) <> 0 then
  499.        nfn = Left( nfn, LastPos( '.', nfn ) - 1 )
  500.   end  /* Do */
  501.  
  502.   Return( nfn || '.ASC' )
  503. /*-------------------------------------------------------------------------*/
  504. /*                      Folder Conversion                                  */
  505. /*-------------------------------------------------------------------------*/
  506.  
  507. CONVERTFOLDERS: Procedure Expose subdir inBas Book. fldcount menu. colorNormal r
  508.  
  509.   curdir = Directory()
  510.  
  511.   Call SysCurPos 13,0
  512.   Call SysCurState( 'ON' )
  513.  
  514.   Say; Say 'Converting folders from UltiMail to PostRoad Mailer...'
  515.  
  516.   Do z = 1 to Book.Count
  517.     Call SysFileTree Book.AdrBook.z || '\*.', folder, 'DO'
  518.  
  519.     Do y = 1 to folder.0
  520.       Msgs = folder.y || '\*.'
  521.       folder.y = Right( folder.y, Length( folder.y ) - LastPos( '\', folder.y ) )
  522.       outfile = curdir || inBas || folder.y || '.NLG'
  523.  
  524.       If Stream( Msgs || 'ENV', 'C', 'QUERY EXISTS' ) <> '' then Do
  525.          /* Get the names of the UltiMail msgs */
  526.          Call SysFileTree Msgs, infile, 'DO' 
  527.  
  528.         outfile = CheckFoldName( outfile Book.User.z )
  529.         Call LineOut outfile, D2C(4) || folder || ' UltiMail Folder'
  530.         Call LineOut outfile, ''
  531.                                                                               
  532.         Do w = 1 to infile.0
  533.            Note. = ''
  534.            To_Flag = 0
  535.            infsav = infile.w
  536.            infile.w = infile.w || '.ENV'
  537.            Do While Lines( infile.w ) > 0
  538.               Lin = LineIn( infile.w )
  539.               If To_Flag = 1 & LastPos( ':', Word( Lin, 1 ) ) > 0 then
  540.                  To_Flag = 0
  541.               If To_Flag = 1 then Lin = 'To: ' || Lin
  542.               Select
  543.                  When Word( Lin,1 ) = 'To:' then Do
  544.                       To_Flag = 1
  545.                       Num = Length( lin ) - Pos( '<', lin ) + 1
  546.                       If Num >= Length( lin ) then
  547.                          Note.UserTo = Note.UserTo || SubWord(lin, 2, Words(lin) )
  548.                       Else
  549.                          Note.UserTo = Note.UserTo || Right( lin, Num )
  550.                  end /* When Do */
  551.                  When Word( Lin,1 ) = 'From:' then
  552.                     Note.From = Word( Lin, 2 )
  553.                  When Word( Lin,1 ) = 'Subject:' then
  554.                     Note.SubjLine = Right( lin, Length( lin ) - 9 )
  555.                  When Word( Lin,1 ) = 'Date:' then
  556.                     Note.DateLin = Right( lin, Length( lin ) - 6 )
  557.                  When Word( Lin,1 ) = 'Reply-To:' then
  558.                     Note.ReplyLine = Word( Lin, 2 )
  559.                  When Word( Lin,1 ) = 'Sender:' then
  560.                     Note.Nick = SubWord( lin, 2, Words( lin ) - 1 )
  561.                  Otherwise Nop
  562.               end  /* select */
  563.            end /* Do While */
  564.  
  565.            num = WordLength( Note.DateLin, Words( Note.DateLin ) )
  566.            Note.DateLin = Left( Note.DateLin, Length( Note.DateLin ) - num )
  567.            Note.RUser = Right(Note.UserTo,Length(Note.UserTo)-LastPos(',',Note.UserTo ) )
  568.  
  569.            Call WriteNote
  570.  
  571.            Call LineOut outfile, ''
  572.            Call LineOut infile.w
  573.         end /* Do While */
  574.  
  575.         Call Charout outfile
  576.         fldcount = fldcount + 1
  577.       end /* If Stream */
  578.     end /* Do while */
  579.   end /*Do z.. */
  580.  
  581.   '@PAUSE'
  582.  
  583.   Call SysCls
  584.   Call GreetingMsg
  585.   Call SysCurState 'OFF'
  586.   Call CharOut 'CON:', colorNormal
  587.   Do r = 1 to menu.0
  588.      Call SysCurPos menu.r.row, menu.r.col
  589.      Call CharOut 'CON:', menu.r.txt
  590.   end
  591.   r = 1
  592.  
  593.   Return
  594. /*----------------------------------------------------------------------*/
  595. WRITENOTE: Procedure Expose Note. outfile infsav
  596. /* Writes Letter to Folder in PRM Format */
  597.  
  598.   num = 49 - Length( Note.RUser )
  599.  
  600.   Call CharOut outfile, '<<NEW NOTE>> ' || D2C(1) || Strip( Note.RUser )
  601.   Call CharOut outfile, Copies(' ', num )
  602.   Call CharOut outfile, ConvertDate( Note.DateLin ) || 'STZ            '
  603.   Call CharOut outfile, '0   ' || Note.From || D2C(1) || Note.SubjLine
  604.   Call CharOut outfile, D2C(1) || D2C(1) || Note.From||D2C(2)||Note.UserTo
  605.   Call LineOut outfile, D2C(3) || Note.ReplyLine
  606.   Call LineOut outfile, 'To:' Note.UserTo
  607.   Call LineOut outfile, 'Date:' Note.DateLin || 'STZ'
  608.   Call LineOut outfile, 'From:' Note.From
  609.   Call LineOut outfile, 'Reply-To: <' || Note.ReplyLine || '>'
  610.   Call LineOut outfile, ''
  611.   Call LineOut outfile, 'Subject:' Note.SubjLine
  612.   Call LineOut outfile, ''
  613.  
  614.   Call SysFileTree infsav || '\*.TXT', TxtFile, 'FO' 
  615.  
  616.   Do i = 1 to TxtFile.0
  617.     Do While Lines( TxtFile.i ) > 0
  618.       Lin = LineIn( TxtFile.i )
  619.       Call LineOut outfile, Lin
  620.     end /* Do While */
  621.     Call LineOut TxtFile.i
  622.   end /*Do While */
  623.  
  624.   Call LineOut outfile, D2C( 254 ) || D2C( 4 ) || Note.SubjLine
  625.  
  626.   Return
  627. /*-------------------------------------------------------------------------*/
  628.  
  629. CHECKFOLDNAME: Procedure
  630.  /* Check to see if folder file exists. If so, rename it */
  631.  
  632.   Arg outfile user
  633.  
  634.   fn = Right( outfile, Length(outfile) - LastPos( '\',outfile ) )
  635.   FoldName = Left( fn, LastPos( '.', fn ) - 1 )
  636.   folddir = Left( outfile, LastPos( '\', outfile ) )
  637.   i = 0
  638.  
  639.   If Stream( outfile, 'C', 'QUERY EXISTS') <> '' then Do
  640.     If Length( fn ) >= 12 then
  641.       outfile = Left( outfile, LastPos( '.', outfile ) - 2 )
  642.     Else
  643.       outfile = Left( outfile, LastPos( '.', outfile ) - 1 )
  644.  
  645.     Do until Stream( outfile || i || '.NLG', 'C', 'QUERY EXISTS') = ''
  646.        i = i + 1
  647.     end /* Do Until */
  648.  
  649.     outfile = outfile || i || '.NLG'
  650.  
  651.     Say 'A' Strip( FoldName ) 'folder already exists.'
  652.     Say 'Creating another' Strip(FoldName) 'folder for Ultimail user' Strip(User);Say;
  653.  
  654.   end /* If Stream Do */
  655.   Else Do
  656.      If fn > 8 then
  657.         fn = Left( fn, 8 )
  658.      If LastPos( '.', fn ) <> 0 then
  659.         Num = LastPos( '.', fn ) - 1
  660.      Else Num = Length( fn )
  661.      outfile = folddir || Strip( Left( fn, Num )) || '.NLG'
  662.      If Stream( outfile, 'C', 'QUERY EXISTS') <> '' then
  663.         outfile = checkFoldName( outfile user )
  664.   end  /* Do */
  665.  
  666.   Return( outfile )
  667. /*----------------------------------------------------------------------*/
  668.  
  669. CONVERTDATE: Procedure
  670. /* Function returns a numeric equivalent from the abbreviated month */               
  671.                                                                                      
  672.   Arg Date
  673.                                                                                      
  674.   Dummy = Word( Date, 1 )
  675.   Day = Word( Date, 2 )
  676.   Month = Word( Date, 3 )
  677.   Year = Word( Date, 4 )
  678.   Time = Word( Date, 5 )
  679.   Stand = Word( Date, 6 )
  680.   num = LastPos( ':', Time ) - 1
  681.   Time = Left( Time, num )
  682.   If Length( Time ) < 5 then
  683.      Time = '0' || Time
  684.                                                                                      
  685.   Select
  686.      When Month = 'JAN' then
  687.         Month = '01'
  688.      When Month = 'FEB' then
  689.         Month = '02'
  690.      When Month = 'MAR' then
  691.         Month = '03'
  692.      When Month = 'APR' then
  693.         Month = '04'
  694.      When Month = 'MAY' then
  695.         Month = '05'
  696.      When Month = 'JUN' then
  697.         Month = '06'
  698.      When Month = 'JUL' then
  699.         Month = '07'
  700.      When Month = 'AUG' then
  701.         Month = '08'
  702.      When Month = 'SEP' then
  703.         Month = '09'
  704.      When Month = 'OCT' then
  705.         Month = '10'
  706.      When Month = 'NOV' then
  707.         Month = '11'
  708.      Otherwise Month = '12'
  709.   end  /* select */
  710.  
  711.   DateString = '0'|| Year || '/' || Month || '/' || Day || Time
  712.  
  713.   Return( DateString )
  714. /*----------------------------------------------------------------------*/
  715. /*                      Other Functions and Procedures                  */
  716. /*----------------------------------------------------------------------*/
  717.  
  718. GETINBASKETNAME: Procedure
  719. /* Matches inbasket Name and extracts directory */
  720.  
  721.   Arg PostDir
  722.   basfile = PostDir || '\INBASKET.NIX'
  723.   found = 0
  724.  
  725.   Say;Say "Enter your Inbasket name: "
  726.   Pull inName
  727.   If inName = '' then
  728.     outName = GetInbasketName( PostDir )
  729.   Else Do
  730.     basfile = PostDir || '\INBASKET.NIX'
  731.     Do While lines(basfile) > 0 & found <> 1
  732.       lin = Translate( LineIn( basfile ) )
  733.       inName = Translate( inName )
  734.       dirName = Word( lin, 1 )
  735.       BasIdent = SubWord( lin,2, Words(lin)-1 )
  736.       If inName = BasIdent then found = 1
  737.     end /* While Do */
  738.  
  739.     Call LineOut basfile
  740.  
  741.     If found <> 1 then Signal Err4
  742.     Else outName = dirName
  743.  
  744.   end  /* Else Do */
  745.   Say; Say;
  746.  
  747.   Return( outName )
  748. /*--------------------------------------------------------------------------*/
  749.  
  750. LoadRexxUtil: Procedure
  751.   If rxFuncQuery( 'SysLoadFuncs' ) then Do
  752.     If RxFuncAdd( 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' ) then Do
  753.        Say "Error: Couldn't load RexxUtil library."
  754.        Return 1
  755.     end /* If Do */
  756.     Call SysLoadFuncs
  757.   end /* If Do */
  758. Return 0
  759. /*----------------------------------------------------------------------*/
  760.  
  761. EXITING:
  762.  
  763.  Say;Say;
  764.  Say '      ' BkCount 'Address books converted.'
  765.  Say '      ' fldcount 'Folders converted.'
  766.  EXIT
  767. /*----------------------------------------------------------------------*/
  768.  
  769. HPFS: Procedure
  770. /* This function puts quotes around a directory name to enable the HPFS to read the directory*/
  771.  
  772.   Arg DirName
  773.  
  774.   Do While Pos( '"', DirName ) <> 0
  775.     If Pos( '"', DirName ) = 1 then
  776.       DirName = Right( DirName, Length( DirName ) - 1 )
  777.     Else
  778.       DirName = Left( DirName, Pos( '"', DirName ) - 1 )
  779.   end /* Do While */
  780.  
  781.   DirName = '"' || DirName || '"'
  782.  
  783.   Return DirName
  784. /*----------------------------------------------------------------------*/
  785.  
  786. HALT:
  787.   Call SysCls
  788.   Say;Say 'Program Interupted..'
  789.   Say 'Ending UML2POST.CMD run...'
  790.  
  791.   Exit
  792. /*----------------------------------------------------------------------*/
  793.  
  794. HELP:
  795.  
  796.  Say ''
  797.  Say 'UML2POST.CMD converts UltiMail folders and address books for use with'
  798.  Say 'the Post Road Mailer.'
  799.  Say ''
  800.  Say 'Syntax is:  UML2POST <path>'
  801.  Say ''
  802.  Say 'All UltiMail folders and address books will be visible in PostRoad'
  803.  Say 'Mailer after execution of this utiltity.'
  804.  Say ''
  805.  Say 'UML2POST will prompt for the UltiMail subdirectory if a path is not'
  806.  Say '         specified.'
  807.  Say ''
  808.  
  809.  Exit
  810. /*--------------------------------------------------------------------------*/
  811.  
  812. GREETINGMSG:
  813.   Say ''
  814.   Say Center('UML2POST.CMD Converting Utility               (c)Innoval Systems Solutions,Inc',79)
  815.   Say ''
  816.   Say Center( '*--Converts UltiMail folders and address books for use with the--*',79)
  817.   Say Center( 'Post Road Mailer',79)
  818.   Say ''
  819.  
  820.   Return
  821. /*---------------------------------------------------------------------------*/
  822.  
  823. ERR:
  824.  Say 'Err: This Utility must be run from within PostRoad Mailer root directory.'
  825.  Call Beep 450, 250
  826.  Exit 1
  827. /*--------------------------------------------------------------------------*/
  828.  
  829. ERR1:
  830.  Say 'Err: UltiMail is not installed in this directory or is missing files.'
  831.  Call Beep 450, 250
  832.  Exit 1
  833. /*--------------------------------------------------------------------------*/
  834.  
  835. ERR2:
  836.  Say 'Err: File' Strip(filespec) 'does not appear to be in ascii address book format.'
  837.  Call LineOut filespec
  838.  Call Beep 450, 250
  839.  Exit 1
  840. /*---------------------------------------------------------------------------*/
  841.  
  842. ERR3:
  843.  Say 'Err: Error writing to file' Strip( AdrFile )
  844.  Call LineOut filespec
  845.  Call CharOut AdrFile
  846.  Call Beep 450, 250
  847.  Exit 1
  848. /*---------------------------------------------------------------------------*/
  849.  
  850. ERR4:
  851.  Say;Say 'Err:' Strip( inName ) 'is not an inbasket name.'
  852.  Say '     Please review your PostRoad Mailer title bar for the Inbasket name.'
  853.  Call Beep 450, 250
  854.  Exit 1    
  855.