home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / u2pmail2.zip / u2pmmail.org < prev    next >
Text File  |  1995-10-26  |  9KB  |  306 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. TempBag = charin(PmmailBag'.bag',LCLength+1,chars(PmmailBag'.bag')-LCLength)
  140. call lineout 'U2PMMAIL.LOG','There are 'LetterCount' letters already in 'PmmailFol'.'
  141.  
  142.  
  143. /*  Unburst Ultimail envelopes */
  144.  
  145. do Env = 1 to Envelopes.0
  146.  
  147.    TempFile =   ''
  148.    Header =     0
  149.    HeadField =  ''
  150.    BagDD =      ''
  151.    BagMon =     ''
  152.    BagMM =      ''
  153.    BagYY =      ''
  154.    BagTime =    ''
  155.    BagSub =     ''
  156.    BagFrom =    ''
  157.    BagName =    ''
  158.    BagContent = ''
  159.    LetterBody = ''
  160.    Skip =       0
  161.  
  162.    call linein Envelopes.Env,,0
  163.  
  164.    do while lines(Envelopes.Env) = 1
  165.       ln = linein(Envelopes.Env)
  166.       HeadField = Word(ln,1)
  167.       select
  168.          when HeadField = 'Date:' then
  169.             do
  170.                BagDD = word(ln,3)
  171.                BagMon = word(ln,4)
  172.                select
  173.                   when BagMon = 'Jan' then BagMM = '01'
  174.                   when BagMon = 'Feb' then BagMM = '02'
  175.                   when BagMon = 'Mar' then BagMM = '03'
  176.                   when BagMon = 'Apr' then BagMM = '04'
  177.                   when BagMon = 'May' then BagMM = '05'
  178.                   when BagMon = 'Jun' then BagMM = '06'
  179.                   when BagMon = 'Jul' then BagMM = '07'
  180.                   when BagMon = 'Aug' then BagMM = '08'
  181.                   when BagMon = 'Sep' then BagMM = '09'
  182.                   when BagMon = 'Oct' then BagMM = '10'
  183.                   when BagMon = 'Nov' then BagMM = '11'
  184.                   otherwise BagMM = '12'
  185.                end  /* select */
  186.                if wordlength(ln,5) = 2 then
  187.                   do
  188.                      BagYY = word(ln,5)
  189.                   end
  190.                else
  191.                   do
  192.                      BagYY = substr(word(ln,5),3,2)
  193.                   end
  194.                BagTime = word(ln,6)
  195.             end
  196.          when HeadField = 'Subject:' then BagSub = subword(ln,2)
  197.          when HeadField = 'From:' then
  198.             do
  199.                if words(ln) = 2 then
  200.                  do
  201.                     BagFrom = word(ln,2)
  202.                     BagName = '(null)'
  203.                  end
  204.                else
  205.                  do
  206.                     BagFrom = word(ln,words(ln))
  207.                     BagFrom = substr(BagFrom,2,length(BagFrom)-2)
  208.                     BagName = subword(ln,2,words(ln)-2)
  209.                     BagName = substr(BagName,2,length(BagName)-2)
  210.                  end
  211.             end
  212.          when HeadField = 'Content-Type:' then
  213.             do
  214.                if word(ln,2) = 'text/plain;' then
  215.                   do
  216.                      BagContent = subword(ln,1,words(ln)-1)
  217.                      BagContent = substr(BagContent,1,length(BagContent)-1)
  218.                      LetterBody = word(ln,words(ln))
  219.                      LetterBody = substr(LetterBody,10)
  220.                      FileSize = chars(UmailDir'\'LetterBody)
  221.  
  222.                      if FileSize = '' then
  223.                         do
  224.                            call lineout 'U2PMMAIL.LOG',"   Unable to open "Envelopes.Env"'s body -- "UnailDir'\'LetterBody'.'
  225.                            Skip = 1
  226.                         end
  227.  
  228.                      TempFile = TempFile || BagContent || crlf || crlf
  229.                      TempFile = TempFile || charin(UmailDir'\'LetterBody,1,FileSize)
  230.                      call stream UmailDir'\'LetterBody,'c','close'
  231.                      leave
  232.                   end
  233.                else
  234.                   do
  235.                      Header = 1
  236.                   end
  237.             end
  238.          otherwise nop
  239.       end  /* select */
  240.  
  241.       if Header = 0 then
  242.          do
  243.             TempFile = TempFile || ln || crlf
  244.          end
  245.    
  246.    end /* do while */
  247.  
  248.    call stream Envelopes.Env,'c','close'
  249.  
  250. /* Create PMMail message and update bag */
  251.  
  252.    if skip = 1 then iterate
  253.    
  254.    PmmailMsg = substr(LetterBody,3,6)
  255.    PmmailMsg = PmmailMsg'00.msg'
  256.  
  257.    if lines('FOLDERS\'PmmailBag'\'PmmailMsg) = 0 then
  258.       do
  259.          call charout 'FOLDERS\'PmmailBag'\'PmmailMsg, TempFile
  260.       end
  261.    else
  262.       do
  263.          erase 'FOLDERS\'PmmailBag'\'PmmailMsg
  264.          call charout 'FOLDERS\'PmmailBag'\'PmmailMsg, TempFile
  265.       end
  266.  
  267.    if Result = 0 then
  268.       do 
  269.          call lineout 'U2PMMAIL.LOG', '      'PmmailMsg' created from 'Envelopes.Env'.'
  270.       end
  271.    else
  272.       do
  273.          call lineout 'U2PMMAIL.LOG', '   Failed to create 'PmmailMsg' from 'Envelopes.Env'.'
  274.          iterate
  275.       end
  276.  
  277.    call stream 'FOLDERS\'PmmailBag'\'PmmailMsg,'c','close'
  278.  
  279.   TempBag = TempBag || crlf || BagYY'-'BagMM'-'BagDD'▐'BagTime'▐'BagSub'▐'BagFrom'▐'BagName'▐'PmmailMsg'▐Yß'
  280.   LetterCount = LetterCount+1
  281.  
  282. end /* do Envelopes */
  283.  
  284. /* write new bag */
  285.  
  286. call charout PmmailBag'.bag', LetterCount || crlf || TempBag,1
  287. if Result = '0' then
  288.    do
  289.       call lineout 'U2PMMAIL.LOG', '   'PmmailBag'.bag was created.'
  290.    end
  291. else
  292.    do
  293.       call lineout 'U2PMMAIL.LOG', '   Error: 'PmmailBag'.bag was not created.'
  294.    end
  295.  
  296. call stream PmmailBag'.bag','c','close'
  297.  
  298. /* write end to log */
  299.  
  300. call lineout 'U2PMMAIL.LOG', LetterCount' messages are now in 'PmmailFol'.'
  301. call lineout 'U2PMMAIL.LOG','-----------------------------------------------------------------------------'
  302. call stream 'U2PMMAIL.LOG','c','close'
  303.  
  304. say 'Task completed successfully.'
  305. exit
  306.