home *** CD-ROM | disk | FTP | other *** search
/ ANews 1 / AnewsCD01.iso / Internet / Newsgroup / THOR_2.6 / THOR26_AREXX.LHA / Rexx / CopyMessages.thor < prev    next >
Text File  |  1999-01-17  |  8KB  |  289 lines

  1. /*
  2. ** $VER: CopyMessages.thor 0.1 (7.10.97)
  3. ** by Eirik Nicolai Synnes
  4. **
  5. ** Set all absolutely all conf tags like original conf?
  6. ** What if original is EMail?
  7. **
  8. */
  9.  
  10. options results
  11. options failat 31
  12.  
  13. parse arg arguments
  14.  
  15. /*
  16. ** Initialize some variables
  17. */
  18.  
  19. version  = subword(sourceline(2), 4, 1)
  20. returned = 0; progwin = 0
  21.  
  22. CDB_MARK_OWN_MSGS      = 22           /* Also mark messages from user when adding messages. */
  23. CDF_NOT_ON_BBS         = '00008000'x  /* This conference is not on the bbs. */
  24.  
  25. CDNT_NONET             = 0  /* This conference is a local conference. This is the default values for new conferences. */
  26. CDNT_MAILFOLDER        = 3  /* This conference is a virtual mail folder */
  27.  
  28. MDB_READ               =  0  /* Message is read. */
  29. MDB_REPLIED            =  1  /* Message is replied. */
  30. MDB_PRIVATE            =  2  /* Message is private. */
  31. MDB_DELETED            =  5  /* Message is deleted. */
  32. MDB_KEEP               =  7  /* Keep message. Message will not be deleted during conference packing. */
  33. MDB_MARKED             = 10  /* Message is marked.  */
  34. MDB_URGENT             = 11  /* Message is urgent.    */
  35. MDB_IMPORTANT          = 12  /* Message is important. */
  36. MDB_SUPERMARKED        = 13  /* Message will not be unmarked as long as this flag is set. */
  37. MDB_CONFIDENTIAL       = 17  /* Message is confidential. */
  38.  
  39.  
  40. /*
  41. ** Check for Thor's ARexx port
  42. */
  43.  
  44. thorport = address()
  45. if (left(thorport, 5) ~= 'THOR.') then do
  46.     say 'CopyMessages.thor can only be run from within Thor.'
  47.     exit(0)
  48. end
  49.  
  50.  
  51. /*
  52. ** Find/open BBSREAD ARexx port
  53. */
  54.  
  55. if ~(show('P', 'BBSREAD')) then do
  56.     address(command)
  57.     'Run >NIL: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  58.     'WaitForPort BBSREAD'
  59.     if (rc ~= 0) then do
  60.         say 'Could not find BBSRead''s ARexx port.'
  61.         exit(20)
  62.     end
  63. end
  64.  
  65.  
  66. /*
  67. ** Utilize BBSRead's copyback buffer
  68. */
  69.  
  70. address(bbsread)
  71. 'BUFMODE COPYBACK'
  72.  
  73.  
  74. /*
  75. ** Get system and conference names
  76. */
  77.  
  78. nosys = 0
  79. address(thorport)
  80. 'CURRENTSYSTEM 'cursys
  81. if (rc = 1) then nosys = 1
  82. else if (rc ~= 0) then signal error
  83.  
  84. if (nosys) | (cursys.CONFNAME = '') then do
  85.     'REQUESTNOTIFY "No current system or conference.\n\nPlease make sure you have entered\na conference in Thor and selected\nmessages to copy before running\nCopyMessages." "Ok"'
  86.     signal cleanup
  87. end
  88. drop nosys
  89.  
  90.  
  91. /*
  92. ** Build msglist stem
  93. */
  94.  
  95.  
  96. address(thorport)
  97. 'GETMSGLISTSELECTED STEM 'msglist
  98. if (rc = 3) then do
  99.     'CURRENTMSG 'curmsg
  100.     if (rc = 30) & (THOR.LASTERROR = 'No current message.') then msglist.count = 0
  101.     else if (rc ~= 0) then signal error
  102.     else do
  103.         msglist.1 = curmsg.MSGNR; msglist.count = 1; drop curmsg.
  104.     end
  105. end
  106. else if (rc ~= 0) then signal error
  107.  
  108. if (msglist.count = 0) then do
  109.     'REQUESTNOTIFY "No current or multiselected messages.\n\nMake sure you either have a current message\nor have multiselected some messages before\nrunning CopyMessages.thor." "Ok"'
  110.     signal cleanup
  111. end
  112.  
  113.  
  114. /*
  115. ** Get destination system and conference
  116. */
  117.  
  118. address(bbsread)
  119. 'GETBBSLIST STEM 'bbslist
  120. if (rc ~= 0) then signal error
  121. if (bbslist.COUNT = 0) then do
  122.     address(thorport)
  123.     'REQUESTNOTIFY "No available systems!" "That''s odd"'
  124.     signal cleanup
  125. end
  126.  
  127. address(thorport)
  128. 'REQUESTLIST INSTEM 'bbslist' TITLE "Copy to system" SIZEGADGET'
  129. if (rc = 5) then signal cleanup
  130. else if (rc ~= 0) then signal error
  131. destsys = result
  132.  
  133. address(bbsread)
  134. 'GETCONFLIST BBSNAME "'destsys'" STEM 'conflist
  135. if (rc ~= 0) then signal error
  136.  
  137. menulist.1 = 'Create new conference'
  138. menulist.2 = ''
  139. do i = 1 to conflist.count
  140.     mcnt = i + 2; menulist.mcnt = conflist.i
  141. end
  142. menulist.count = i + 1
  143.  
  144. address(thorport)
  145. 'REQUESTLIST INSTEM 'menulist' TITLE "Copy to conference" SIZEGADGET'
  146. if (rc = 5) then signal cleanup
  147. else if (rc ~= 0) then signal error
  148. destconf = result
  149.  
  150. if (destconf = 'Create new conference') then do
  151.     address(thorport)
  152.     'REQUESTSTRING TITLE "Destination conference" BODY "Enter name of new conference" BT "Ok|Cancel"'
  153.     if (rc = 5) then signal cleanup
  154.     else if (rc ~= 0) then signal error
  155.     destconf = result
  156.  
  157.     address(bbsread)
  158.     'GETCONFDATA "'cursys.BBSNAME'" "'cursys.CONFNAME'" STEM 'confdata
  159.     if (rc ~= 0) then signal error
  160.  
  161.     'CONFIGCONF "'destsys'" "'destconf'" CONFNETTYPE 'confdata.CONFNETTYPE' SETFLAGS 'c2x(confdata.FLAGS)
  162.     if (rc ~= 0) then signal error
  163. end
  164.  
  165. drop bbslist. conflist. menulist. confdata.
  166.  
  167. if (msglist.count = 0) then signal cleanup
  168.  
  169. address(thorport)
  170. 'OPENPROGRESS TITLE "CopyMessages.thor" TOTAL 'msglist.count' AT "Abort" PT "Copying 'msglist.count' messages..."'
  171. if (rc ~= 0) then signal error
  172. progwin = result
  173.  
  174. address(bbsread)
  175. do i = 1 to msglist.count
  176.  
  177.     /*
  178.     ** Read message's header and text stems
  179.     */
  180.  
  181.     address(bbsread)
  182.     'READBRMESSAGE "'cursys.BBSNAME'" "'cursys.CONFNAME'" 'msglist.i' HEADSTEM 'head' DATASTEM 'data' TEXTSTEM 'text
  183.     if (rc ~= 0) then signal error
  184.  
  185.  
  186.     /*
  187.     ** Create header for new message
  188.     */
  189.  
  190.     text.fromname = head.FROMNAME
  191.     if (symbol('head.FROMADDR') = 'VAR')        then text.fromaddr        = head.FROMADDR
  192.     if (symbol('head.TONAME') = 'VAR')          then text.toname          = head.TONAME
  193.     if (symbol('head.TOADDR') = 'VAR')          then text.toaddr          = head.TOADDR
  194.     if (symbol('head.MSGID') = 'VAR')           then text.msgid           = head.MSGID
  195.     if (symbol('head.REFID') = 'VAR')           then text.refid           = head.REFID
  196.     if (symbol('head.CREATIONDATE') = 'VAR')    then text.creationdate    = head.CREATIONDATE
  197.     if (symbol('head.CREATIONDATETXT') = 'VAR') then text.creationdatetxt = head.CREATIONDATETXT
  198.     if (symbol('head.SUBJECT') = 'VAR')         then text.subject         = head.SUBJECT    
  199.  
  200.  
  201.     /*
  202.     ** Set the selected message flags
  203.     */
  204.  
  205.     writeflags = ''
  206.     if (bittst(data.FLAGS, MDB_READ))         then writeflags = writeflags || 'READ '
  207.     if (bittst(data.FLAGS, MDB_PRIVATE))      then writeflags = writeflags || 'PRIVATE '
  208.     if (bittst(data.FLAGS, MDB_URGENT))       then writeflags = writeflags || 'URGENT '
  209.     if (bittst(data.FLAGS, MDB_IMPORTANT))    then writeflags = writeflags || 'IMPORTANT '
  210.     if (bittst(data.FLAGS, MDB_CONFIDENTIAL)) then writeflags = writeflags || 'CONFIDENTIAL '
  211.  
  212.     updateflags = ''
  213.     if (bittst(data.flags,  MDB_REPLIED))     then updateflags = updateflags || 'SETREPLIED '
  214.     if (bittst(data.flags,  MDB_KEEP))        then updateflags = updateflags || 'SETKEEP '
  215.     if (bittst(data.flags,  MDB_SUPERMARKED)) then updateflags = updateflags || 'SETSUPERUNREAD '
  216.     if (symbol('data.HAZELEVEL') = 'VAR') & (data.HAZELEVEL > 0) then updateflags = updateflags || 'HAZELEVEL 'data.HAZELEVEL' '
  217.  
  218.  
  219.     /*
  220.     ** Write the message
  221.     */
  222.  
  223.     address(bbsread)
  224.     'WRITEBRMESSAGE "'destsys'" "'destconf'" STEM 'text' 'writeflags
  225.     if (rc ~= 0) then signal error
  226.     msgnr = result
  227.  
  228.  
  229.     /*
  230.     ** If the new message's number is -1 then it was caught by a kill
  231.     */
  232.  
  233.     if (msgnr ~= -1) then do
  234.  
  235.         /*
  236.         ** Give the new message it's flags
  237.         */
  238.  
  239.         if (updateflags ~= '') then do
  240.             'UPDATEBRMESSAGE "'destsys'" "'destconf'" 'msgnr' 'updateflags
  241.             if (rc ~= 0) then signal error
  242.         end
  243.     end
  244.  
  245.     drop head. data. text. msgnr
  246.  
  247.     address(thorport)
  248.     'UPDATEPROGRESS REQ 'progwin' CURRENT 'i
  249.     if (rc ~= 0) then signal error
  250. end
  251.  
  252. returned = 0; signal cleanup
  253.  
  254.  
  255. /*
  256. ** Some error detection stuff
  257. */
  258.  
  259. error:
  260. syntax:
  261.  
  262. returned = rc
  263.  
  264. select
  265.     when symbol('THOR.LASTERROR') = 'VAR' then say 'In line 'sigl' Thor returned 'returned': 'THOR.LASTERROR
  266.     when symbol('BBSREAD.LASTERROR') = 'VAR' then say 'In line 'sigl' BBSRead returned 'returned': 'BBSREAD.LASTERROR
  267.     when symbol('myerr') = 'VAR' then say 'In line 'sigl' I returned 'returned': 'myerr
  268.     otherwise say 'In line 'sigl' ARexx returned 'returned': 'errortext(returned)
  269. end
  270.  
  271. break_c:
  272. halt:
  273. cleanup:
  274.  
  275.  
  276. /*
  277. ** Turn off copyback buffer
  278. */
  279.  
  280. address(bbsread)
  281. 'BUFMODE ENDCOPYBACK'
  282.  
  283. if (progwin > 0) then do
  284.     address(thorport)
  285.     'CLOSEPROGRESS REQ 'progwin
  286. end
  287.  
  288. exit(returned)
  289.