home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / u2pmail2.zip / u2pmmail.cmd < prev    next >
OS/2 REXX Batch file  |  1996-01-15  |  10KB  |  312 lines

  1. /*
  2.    U2PMMAIL--A batch file processor that will unburst ULTIMAIL bursted letters
  3.    and add them to PMMAIL. Run this command from the PMMAIL directory. It will
  4.    request the path of the ULTIMAIL folder that you wish to add:
  5.      e.g. C:\tcpip\UMAIL\MAIL\Bob\Business.
  6.    It will then request the PMMAIL folder you wish to add the letters to. U2PMMAIL
  7.    will merge the files with the envelopes and move them to the selected PMMAIL 
  8.    folder and update the "bag." U2PMMAIL will save the original "bag." U2PMMAIL.LOG
  9.    Is a text file that reports on the success or failure of each letter that was 
  10.    converted in the folder, and the name of the old "bag." This command file will not
  11.    over-write the original mail, and old "bag is easily restored. Multimedia attachments
  12.    will not be restored and the textfile will report this. U2PMMAIL must be run for 
  13.    each ULTIMAIL folder you wish to convert.
  14.  
  15.    (c) 1995 Curtis C. Hovey.
  16. */
  17.  
  18.  
  19. /*  
  20.   Add RexxUtil functions 
  21. */
  22.  
  23. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  24. call SysLoadFuncs
  25.  
  26.  
  27. /*
  28.   --Initialize UmailDir, Envelopes, PmmailFol, Folders, PmmailBag; open log--
  29. */
  30.  
  31. parse Arg Info
  32. crlf = '0D0A'x
  33.  
  34. if lines('U2PMMAIL.LOG') \= 0 then
  35.    do
  36.       call stream 'U2PMMAIL.LOG','c','seek <0'
  37.       call charout 'U2PMMAIL.LOG', crlf || crlf
  38.    end
  39. call lineout 'U2PMMAIL.LOG','============================================================================='
  40. call lineout 'U2PMMAIL.LOG',date('L')', 'time('C')
  41.  
  42.  
  43. /*
  44.   Main
  45. */
  46.  
  47. /* Get the source information */
  48.  
  49. if word(Info, 1) =  '' then
  50.    do 
  51.       say 'What is the path of the Ultimail directory you wish to migrate?'
  52.       pull UmailDir
  53.    end
  54. else
  55.    do
  56.       UmailDir = word(Info,1)
  57.    end
  58.  
  59. call SysFileTree Umaildir'\*.ENV', 'Envelopes', FO
  60. if Envelopes.0 = 0 then
  61.    do
  62.       say 'No Envelopes were found in 'UmailDir
  63.       call stream 'U2PMMAIL.LOG','c','close'
  64.       exit
  65.    end
  66.  
  67.  
  68. /* Get the target information */
  69.  
  70. if word(Info, 2) = '' then
  71.    do
  72.       say 'What is the name of PM Mail folder use wish to place the mail in?'
  73.       say '(Folders names are case sensative)'
  74.       parse pull PmmailFol
  75.       if PmmailFol = '' then
  76.          do
  77.             PmmailFol = 'Inbox'
  78.          end
  79.    end
  80. else
  81.    do
  82.       PmmailFol = word(Info, 2)
  83.    end
  84.  
  85. if lines('FOLDERS.INI') = 0 then
  86.    do
  87.       say 'Cannot locate FOLDERS.INI. This command must be run from the PMMAIL directory.'
  88.       call stream 'U2PMMAIL.LOG','c','close'
  89.       exit
  90.    end
  91.  
  92. PmmailBag = ''
  93. do while lines('FOLDERS.INI') = 1
  94.    Folders = linein('FOLDERS.INI')
  95.    if Folders = PmmailFol then PmmailBag = linein('FOLDERS.INI')
  96.    if PmmailBag \= '' then leave
  97. end /* do while */
  98. call stream 'FOLDERS.INI','c','close'
  99.  
  100. if PmmailBag = '' then
  101.    do
  102.       say 'The folder ' || PmmailFol || ' does not exist.'
  103.       say 'You must create it in PMMail first.'
  104.       call stream 'U2PMMAIL.LOG','c','close'
  105.       exit
  106.    end
  107.  
  108.  
  109. /*  Report the variables */
  110.  
  111. call lineout 'U2PMMAIL.LOG',''
  112. call lineout 'U2PMMAIL.LOG','-----------------------------------------------------------------------------'
  113. call lineout 'U2PMMAIL.LOG','   UmailDir is 'UmailDir
  114. do Env = 1 to Envelopes.0
  115.    call lineout 'U2PMMAIL.LOG','      Envelope 'Env' is 'Envelopes.Env
  116. end /* do */
  117. call lineout 'U2PMMAIL.LOG','   PmmailFol is 'PmmailFol
  118. call lineout 'U2PMMAIL.LOG','   PmmailBag is 'PmmailBag
  119. call lineout 'U2PMMAIL.LOG','-----------------------------------------------------------------------------'
  120.  
  121.  
  122. /*  Prepare Bag */
  123.  
  124. copy PmmailBag'.BAG' PmmailBag'.OLD'
  125. if rc \= 0 then
  126.    do
  127.       call lineout 'U2PMMAIL.LOG','Cannot copy 'PmmailBag'.BAG to 'PmmailBag'.OLD.'
  128.       call stream 'U2PMMAIL.LOG','c','close'
  129.       exit
  130.    end
  131. else
  132.    do
  133.       call lineout 'U2PMMAIL.LOG',PmmailBag'.bag copied to 'PmmailBag'.OLD.'
  134.    end
  135.  
  136. LetterCount = linein(PmmailBag'.bag')
  137. LetterCount = word(LetterCount,1)
  138. LCLength = length(LetterCount)+2
  139. if LetterCount <> 0 then
  140.    TempBag = charin(PmmailBag'.bag',LCLength+1,chars(PmmailBag'.bag')-LCLength)
  141. else
  142.    TempBag = ''
  143. call lineout 'U2PMMAIL.LOG','There are 'LetterCount' letters already in 'PmmailFol'.'
  144.  
  145.  
  146. /*  Unburst Ultimail envelopes */
  147.  
  148. do Env = 1 to Envelopes.0
  149.  
  150.    TempFile =   ''
  151.    Header =     0
  152.    HeadField =  ''
  153.    BagDD =      ''
  154.    BagMon =     ''
  155.    BagMM =      ''
  156.    BagYY =      ''
  157.    BagTime =    ''
  158.    BagSub =     ''
  159.    BagFrom =    ''
  160.    BagName =    ''
  161.    BagContent = ''
  162.    LetterBody = ''
  163.    Skip =       0
  164.  
  165.    call linein Envelopes.Env,,0
  166.  
  167.    do while lines(Envelopes.Env) = 1
  168.       ln = linein(Envelopes.Env)
  169.       HeadField = Word(ln,1)
  170.       select
  171.          when HeadField = 'Date:' then
  172.             do
  173.                BagDD = word(ln,3)
  174.                BagMon = word(ln,4)
  175.                select
  176.                   when BagMon = 'Jan' then BagMM = '01'
  177.                   when BagMon = 'Feb' then BagMM = '02'
  178.                   when BagMon = 'Mar' then BagMM = '03'
  179.                   when BagMon = 'Apr' then BagMM = '04'
  180.                   when BagMon = 'May' then BagMM = '05'
  181.                   when BagMon = 'Jun' then BagMM = '06'
  182.                   when BagMon = 'Jul' then BagMM = '07'
  183.                   when BagMon = 'Aug' then BagMM = '08'
  184.                   when BagMon = 'Sep' then BagMM = '09'
  185.                   when BagMon = 'Oct' then BagMM = '10'
  186.                   when BagMon = 'Nov' then BagMM = '11'
  187.                   otherwise BagMM = '12'
  188.                end  /* select */
  189.                if wordlength(ln,5) = 2 then
  190.                   do
  191.                      BagYY = word(ln,5)
  192.                   end
  193.                else
  194.                   do
  195.                      BagYY = substr(word(ln,5),3,2)
  196.                   end
  197.                BagTime = word(ln,6)
  198.             end
  199.          when HeadField = 'Subject:' then BagSub = subword(ln,2)
  200.          when HeadField = 'From:' then
  201.             do
  202.                if words(ln) = 2 then
  203.                  do
  204.                     BagFrom = word(ln,2)
  205.                     BagName = '(null)'
  206.                  end
  207.                else
  208.                  do
  209.                     BagFrom = word(ln,words(ln))
  210.                     BagFrom = substr(BagFrom,2,length(BagFrom)-2)
  211.                     BagName = subword(ln,2,words(ln)-2)
  212.                     BagName = substr(BagName,2,length(BagName)-2)
  213.                  end
  214.             end
  215.          when HeadField = 'Content-Type:' then
  216.             do
  217.                if translate(word(ln,2)) = 'TEXT/PLAIN;' then
  218.                   do
  219.                      BagContent = subword(ln,1,words(ln)-1)
  220.                      BagContent = substr(BagContent,1,length(BagContent)-1)
  221.                      LetterBody = word(ln,words(ln))
  222.                      LetterBody = substr(LetterBody,10)
  223.                      FileSize = chars(UmailDir'\'LetterBody)
  224.  
  225.                      if FileSize = '' then
  226.                         do
  227.                            call lineout 'U2PMMAIL.LOG',"   Unable to open "Envelopes.Env"'s body -- "UnailDir'\'LetterBody'.'
  228.                            Skip = 1
  229.                         end
  230.  
  231.                      TempFile = TempFile || BagContent || crlf || crlf
  232.                      TempFile = TempFile || charin(UmailDir'\'LetterBody,1,FileSize)
  233.                      call stream UmailDir'\'LetterBody,'c','close'
  234.                      leave
  235.                   end
  236.                else
  237.                   do
  238.                      Header = 1
  239.                   end
  240.             end
  241.          otherwise nop
  242.       end  /* select */
  243.  
  244.       if Header = 0 then
  245.          do
  246.             TempFile = TempFile || ln || crlf
  247.          end
  248.    
  249.    end /* do while */
  250.  
  251.    call stream Envelopes.Env,'c','close'
  252.  
  253. /* Create PMMail message and update bag */
  254.  
  255.    if skip = 1 then iterate
  256.    
  257.    PmmailMsg = substr(LetterBody,3,6)
  258.    PmmailMsg = PmmailMsg'00.msg'
  259.  
  260.    if lines('FOLDERS\'PmmailBag'\'PmmailMsg) = 0 then
  261.       do
  262.          call charout 'FOLDERS\'PmmailBag'\'PmmailMsg, TempFile
  263.       end
  264.    else
  265.       do
  266.          erase 'FOLDERS\'PmmailBag'\'PmmailMsg
  267.          call charout 'FOLDERS\'PmmailBag'\'PmmailMsg, TempFile
  268.       end
  269.  
  270.    if Result = 0 then
  271.       do 
  272.          call lineout 'U2PMMAIL.LOG', '      'PmmailMsg' created from 'Envelopes.Env'.'
  273.       end
  274.    else
  275.       do
  276.          call lineout 'U2PMMAIL.LOG', '   Failed to create 'PmmailMsg' from 'Envelopes.Env'.'
  277.          iterate
  278.       end
  279.  
  280.    call stream 'FOLDERS\'PmmailBag'\'PmmailMsg,'c','close'
  281.  
  282.   if length(TempBag) > 0 then
  283.      TempBag = TempBag || crlf || BagYY'-'BagMM'-'BagDD'▐'BagTime'▐'BagSub'▐'BagFrom'▐'BagName'▐'PmmailMsg'▐Yß'
  284.   else
  285.      TempBag = BagYY'-'BagMM'-'BagDD'▐'BagTime'▐'BagSub'▐'BagFrom'▐'BagName'▐'PmmailMsg'▐Yß'
  286.   LetterCount = LetterCount+1
  287.  
  288. end /* do Envelopes */
  289.  
  290. /* write new bag */
  291.  
  292. call charout PmmailBag'.bag', LetterCount || crlf || TempBag,1
  293. if Result = '0' then
  294.    do
  295.       call lineout 'U2PMMAIL.LOG', '   'PmmailBag'.bag was created.'
  296.    end
  297. else
  298.    do
  299.       call lineout 'U2PMMAIL.LOG', '   Error: 'PmmailBag'.bag was not created.'
  300.    end
  301.  
  302. call stream PmmailBag'.bag','c','close'
  303.  
  304. /* write end to log */
  305.  
  306. call lineout 'U2PMMAIL.LOG', LetterCount' messages are now in 'PmmailFol'.'
  307. call lineout 'U2PMMAIL.LOG','-----------------------------------------------------------------------------'
  308. call stream 'U2PMMAIL.LOG','c','close'
  309.  
  310. say 'Task completed successfully.'
  311. exit
  312.