home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxjiscmd.zip / PMMLRECV.CMD next >
OS/2 REXX Batch file  |  1996-06-20  |  7KB  |  207 lines

  1. /* product name: RXJIS                                                */
  2. /* Version:      0.40                                                 */
  3. /* author:       YANO Takashi                                         */
  4. /* target:       OS/2 Warp J3.0+                                      */
  5. /* module name:  MIMERECV.CMD                                         */
  6. /* source name:  MIMERECV.CMD                                         */
  7. /* compiler:     N.A.                                                 */
  8. /* address:      tyano@ca2.so-net.or.jp or tyano@yamato.ibm.co.jp     */
  9. /* comment:      RXJIS is a utility functions for REXX.               */
  10. /*               It encodes and decodes JIS 7 bit strings and MIME    */
  11. /*               format strings.                                      */
  12. /*                                                                    */
  13. /*               MIMERECV.CMD is a sample program how to use          */
  14. /*               RXJIS. I am using it with PostRoadMailer 1.03a.      */
  15. /*               It converts a mail message with MIME or JIS 7bit     */
  16. /*               into PC Kanji codet mail message.                    */
  17. /*                                                                    */
  18. /* how to use:   MIMERECV fn                                          */
  19. /*               fn is a mail message file. The converted result is   */
  20. /*               in fn. The original is lost.                         */
  21. /*                                                                    */
  22. /* history:      1996-2-5 0.00 initial release                        */
  23. /*               1996-3-2 0.20 try to remove control chars in         */
  24. /*                             message.                               */
  25. /*                             Use RxLoadFuncs.                       */
  26. /*               1996-04-21 0.30 charset can be lower.                */
  27. /*               1996-05-01 0.40 Use RxJisMimeJisTo.                  */
  28. /*               1996-05-24 0.51 Quit to translate control chars      */
  29. /*                                                                    */
  30. /*               1997-02-20 x.xx modify for PMMail                    */
  31.  
  32. options 'ETMODE'
  33.  
  34. remove_code = 'de'x    /* remove code for PMMail */
  35. alter_code_first_byte = '81'x    /* alter code is ü¼ */
  36. alter_code_second_byte = 'ac'x
  37. japanese_code1 = '81'x    /* first byte code of Japanese */
  38. japanese_code2 = '9f'x
  39. japanese_code3 = 'e0'x
  40. japanese_code4 = 'fc'x
  41. LF = '0a'x
  42. TAB = '09'x
  43. SPC = '20'x
  44. PAD = '!'
  45. check_count = 60
  46. cont_char_counter = 1
  47. char_counter = 1
  48. subject_line_num = 0
  49. first_char = 0
  50.  
  51. signal on novalue
  52. arg fn
  53. parse source . . a
  54. workingdir = filespec('D', a) || filespec('P', a)
  55. errorlog = workingdir || 'errorlog.log'
  56. call rxfuncadd 'RxJisLoadFuncs', 'RXJIS', 'RxJisLoadFuncs'
  57. call RxJisLoadFuncs
  58. call rxfuncadd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs' /* A@0.20 */
  59. call SysLoadFuncs                                         /* A@0.20 */
  60. if stream(fn, 'c', 'query exists') = '' then exit
  61. do i = 1 by 1 while lines(fn)
  62.     line.i = linein(fn)
  63.     if line.i = '' then iterate
  64.     line.i = RxJisMimeJisTo(line.i)
  65.  
  66.     /* add following */
  67.     first_word = word(translate(line.i), 1)
  68.     if first_word = 'SUBJECT:' then do
  69.         subject_line_num = 1
  70.         tmp_subject_line = strip(strip(subword(line.i, 2), ,TAB))
  71.         line.i = word(line.i, 1) || ' '
  72.         call process_subject
  73.     end
  74.     else if subject_line_num <> 0 then do
  75.         if (substr(line.i, 1, 1) = TAB) | (substr(line.i, 1, 1) = SPC) then do
  76.             tmp_subject_line = ' ' || strip(strip(line.i, ,TAB))
  77.             line.i = ''
  78.             call process_subject
  79.         end
  80.         else do
  81.             subject_line_num = 0
  82.         end
  83.     end
  84.     else if first_word = 'FROM:' | first_word = 'TO:' then do
  85.         tmp_line = line.i
  86.         line.i = ''
  87.         call process_address
  88.     end
  89.     /* add above */
  90.  
  91. end /* do */
  92.  
  93. call stream fn, 'c', 'close'
  94. line.0 = i - 1
  95. tfn = value('TMP', , 'OS2ENVIRONMENT')
  96. if tfn = '' then tfn = workingdir
  97. if right(tfn, 1) <> '\' then tfn = tfn || '\'
  98. tfn = SysTempFileName(tfn || '????')
  99. do i = 1 to line.0
  100.     call lineout tfn, line.i
  101. end /* do */
  102. call stream tfn, 'c', 'close'
  103. '@copy' tfn fn '> NUL 2>&1'
  104. call SysFileDelete tfn
  105. exit
  106.  
  107. process_subject:
  108. tmp_subject_line_num = length(tmp_subject_line)
  109. char_counter = 1
  110. do while(char_counter <= tmp_subject_line_num)
  111.     first_char = substr(tmp_subject_line, char_counter, 1)
  112.     if cont_char_counter > check_count then do
  113.         line.i = line.i || first_char
  114.     end 
  115.     else do
  116.         if (first_char >= japanese_code1) & (first_char <=japanese_code2) then do
  117.             if cont_char_counter = check_count then do
  118.                 line.i = line.i || PAD
  119.             end
  120.             char_counter = char_counter + 1
  121.             cont_char_counter = cont_char_counter + 1
  122.             second_char = substr(tmp_subject_line, char_counter, 1)
  123.             if second_char = remove_code then do
  124.                 line.i = line.i || alter_code_first_byte
  125.                 line.i = line.i || alter_code_second_byte
  126.             end 
  127.             else do
  128.                 line.i = line.i || first_char
  129.                 line.i = line.i || second_char
  130.             end 
  131.         end
  132.         else if (first_char >= japanese_code3) & (first_char <= japanese_code4) then do
  133.             if cont_char_counter = check_count then do
  134.                 line.i = line.i || PAD
  135.             end
  136.             char_counter = char_counter + 1
  137.             cont_char_counter = cont_char_counter + 1
  138.             second_char = substr(tmp_subject_line, char_counter, 1)
  139.             if second_char = remove_code then do
  140.                 line.i = line.i || alter_code_first_byte
  141.                 line.i = line.i || alter_code_second_byte
  142.             end 
  143.             else do
  144.                 line.i = line.i || first_char
  145.                 line.i = line.i || second_char
  146.             end 
  147.         end
  148.         else do
  149.             line.i = line.i || first_char
  150.         end
  151.     end
  152.     char_counter = char_counter + 1
  153.     cont_char_counter = cont_char_counter + 1
  154. end
  155.  
  156. if cont_char_counter >= check_count then do
  157.     subject_line_num = 0
  158. end
  159.  
  160. return
  161.  
  162. process_address:
  163. tmp_line_num = length(tmp_line)
  164. char_counter = 1
  165. do while(char_counter <= tmp_line_num)
  166.     first_char = substr(tmp_line, char_counter, 1)
  167.     if (first_char >= japanese_code1) & (first_char <=japanese_code2) then do
  168.         char_counter = char_counter + 1
  169.         second_char = substr(tmp_line, char_counter, 1)
  170.         if second_char = remove_code then do
  171.             line.i = line.i || alter_code_first_byte
  172.             line.i = line.i || alter_code_second_byte
  173.         end 
  174.         else do
  175.             line.i = line.i || first_char
  176.             line.i = line.i || second_char
  177.         end 
  178.     end
  179.     else if (first_char >= japanese_code3) & (first_char <= japanese_code4) then do
  180.         char_counter = char_counter + 1
  181.         second_char = substr(tmp_line, char_counter, 1)
  182.         if second_char = remove_code then do
  183.             line.i = line.i || alter_code_first_byte
  184.             line.i = line.i || alter_code_second_byte
  185.         end 
  186.         else do
  187.             line.i = line.i || first_char
  188.             line.i = line.i || second_char
  189.         end 
  190.     end
  191.     else do
  192.         line.i = line.i || first_char
  193.     end
  194.     char_counter = char_counter + 1
  195. end
  196.  
  197. return
  198.  
  199. novalue:
  200. call lineout errorlog, date('S') time() condition('C') '@' sigl
  201. call lineout errorlog, date('S') time() condition('D')
  202. call lineout errorlog, date('S') time() condition('I')
  203. call stream errorlog, 'c', 'close'
  204. say 'SEE:' errorlog
  205. exit
  206.  
  207.