home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / internet / yamtools20 / yamtools20english / ytarcmove.rexx < prev    next >
OS/2 REXX Batch file  |  1997-08-08  |  21KB  |  562 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*                            YTARCMOVE                                       */
  4. /*                 Copyright ©1997 by Dick Whiting                            */
  5. /*                                                                            */
  6. /*----------------------------------------------------------------------------*/
  7. /* This script requires YAMTOOLS for it to work. If you don't have YAMTOOLS   */
  8. /* you can get it on Aminet in directory comm/mail. This script allows you    */
  9. /* to archive all selected mail to a folder. This is only really useful from  */
  10. /* the mail list of a SEARCH. Otherwise, use YAM's normal capabilities.       */
  11. /*                                                                            */
  12. /*    WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!         */
  13. /*                                                                            */
  14. /* This one as of Yam 1.3.4 MAY be breaking some of Marcel's rules. I really  */
  15. /* don't know. This allows you to archive FROM ANY folder TO any folder other */
  16. /* than INCOMING,SENT, and OUTGOING. I calculate the new name according to    */
  17. /* what I have surmised Marcel does. No Guarantees that this is entirely      */
  18. /* compatible with the way Marcel intended. Hope so.                          */
  19. /*                                                                            */
  20. /* Version 1.1 of YTARCMOVE includes a test for the YAM version, which kill   */
  21. /* this script if the YAM version is greater than 1.3.x  If (and I don't      */
  22. /* think so) there is a need for this script for later versions of YAM, then  */
  23. /* I will rewrite it as necessary. - Dick                                     */
  24. /*                                                                            */
  25. /*----------------------------------------------------------------------------*/
  26. /*                                                                            */
  27. /* Standard Disclaimer: I wrote it, it works for me, I don't guarantee        */
  28. /* that it will do anything productive for anyone else, etc. etc. ;-)         */
  29. /*                                                                            */
  30. /*HOWEVER, if you DO find a use for it: I homeschool my kids and they         */
  31. /*would love a postcard from where EVER you live.                             */
  32. /*                                                                            */
  33. /*Instant GEOGRAPHY lesson;)                                                  */
  34. /*                                                                            */
  35. /*                                                                            */
  36. /*POSTCARDS:    Dick Whiting                                                  */
  37. /*              28590 S. Beavercreek Rd.                                      */
  38. /*              Mulino, Oregon 97042                                          */
  39. /*              USA                                                           */
  40. /*                                                                            */
  41. /*----------------------------------------------------------------------------*/
  42. /*                                                                            */
  43. /*               Address Bug Reports or Comments to:                          */
  44. /*                Dick Whiting <dwhiting@europa.com>                          */
  45. /*                           11 March 1997                                    */
  46. /*                                                                            */
  47. /******************************************************************************/
  48. /*
  49. $VER: 1.1 Copyright ©1997 by Dick Whiting
  50. $AUTHOR: Dick Whiting
  51. $DESCRIPTION: Archiver-Mover for use with YAMTOOLS
  52. */
  53.  
  54. options results
  55. options failat 21
  56.  
  57. targarch=''
  58. targanum=''
  59. targdir=''
  60.  
  61. parse arg targarch ',' targanum ',' targdir
  62.  
  63. /**************************************************************************/
  64. /*                         Initialize Variables                           */
  65. /**************************************************************************/
  66. Call MUIvars                                /* go define vars for MUI use */
  67. Call YTvars                                 /* various values used in YT  */
  68. Call Helpvars                               /* pointers into HELP guide   */
  69. Call Localize                               /* vars for localizing strings*/
  70. Call Builtvars                              /* built using previous values*/
  71.  
  72. Address YAMTOOLS
  73.  
  74. Call CheckYam
  75.  
  76. Select
  77.    when targarch='' then do
  78.       Call CheckMailList
  79.       Call ArchWindow
  80.       Call DisplayArchs
  81.    end
  82.    otherwise do
  83.       Call ProcessArchs
  84.    end
  85. end
  86.  
  87.  
  88. exit
  89.  
  90. /**************************************************************************/
  91. /*                Check that there is some mail to process                */
  92. /**************************************************************************/
  93. CheckMailList:
  94.  
  95.    list ID MLST ATTRS MUIA_List_Entries
  96.    mcnt=result
  97.    if mcnt=0 then do
  98.       errmsg=_text._nomail
  99.       Call ErrorMsg
  100.    end
  101.  
  102. Return
  103.  
  104. /**************************************************************************/
  105. /*                        Display list of Archives                        */
  106. /**************************************************************************/
  107. /*         Don't allow Incoming, Outgoing, Sent as target folders         */
  108. /**************************************************************************/
  109. DisplayArchs:
  110.  
  111.    list ID ALST ATTRS MUIA_List_Entries
  112.    acnt=result
  113.  
  114.    do i=3 to acnt-1
  115.       list ID ALST POS i
  116.       aline=result
  117.       if aline='' then break
  118.       parse var aline arch ',' size ',' file ',' anum ',' rest
  119.       liststr=arch','anum','file
  120.       list ID ARCHF INSERT POS MUIV_List_Insert_Bottom STRING liststr
  121.    end            
  122.    
  123. Return
  124.  
  125. /**************************************************************************/
  126. /*                           Process Archivals                            */
  127. /**************************************************************************/
  128. ProcessArchs:
  129.  
  130.    if targanum < 3 then do
  131.       errmsg=bo||targarch||' '||np||_text._badtarg
  132.       Call ErrorMsg
  133.    end
  134.  
  135.    window ID YTARC close
  136.  
  137.    infotitle=_title._info
  138.    infotext=np||_text._inmail
  139.    infobuttons=_text._squit1||comma||_text._squit2||comma||_text._squit3
  140.    showbusy=TRUE
  141.  
  142.    Call InfoWindow
  143.    
  144.    list ID MLST ATTRS MUIA_List_Entries
  145.    mcnt=result
  146.  
  147.    archlist.=missing
  148.    archlist.0=0
  149.    Updlist.=missing
  150.    Updlist.0=0
  151.    acnt=0
  152.  
  153. /**************************************************************************/
  154. /*                     build list of mail to archive                      */
  155. /**************************************************************************/
  156.  
  157.    do i=0 to mcnt-1
  158.       list ID MLST
  159.       mline=result
  160.       if mline='' then break
  161.       parse var mline arch ',' from ',' subj ',' mfor ',' mnum ',' anum ',' file
  162.       acnt=acnt+1
  163.       anum=right(anum,6,'0')
  164.       mnum=right(mnum,6,'0')
  165.       Archlist.0=acnt
  166.       Archlist.acnt=anum mnum file subj
  167.       archlist.0=acnt
  168.       radio ID SQUIT 
  169.       if result~=_text._squit1 then signal ProcessArchsEnd
  170.    end
  171.    Updlist.0=Archlist.0
  172.  
  173.    if acnt=0 then do
  174.       errmsg=_text._nomail
  175.       Call ErrorMsg     
  176.    end
  177.  
  178. /**************************************************************************/
  179. /*                      sort the list in preparation                      */
  180. /**************************************************************************/
  181.  
  182.    if show('L','rexxtricks.library') then do    /* use tricks library     */
  183.       call QSORT(archlist)                   /* sort by name, line number */
  184.    end
  185.    else do                                   /* use QuickSort format      */
  186.       call QSORT(1, archlist.0, archlist)      /* sort by name, number    */
  187.    end 
  188.  
  189.    radio ID SQUIT 
  190.    if result~=_text._squit1 then signal ProcessArchsEnd
  191.  
  192. /**************************************************************************/
  193. /*              Loop thru mail verifying nothing has changed              */
  194. /*          do it in reverse order to keep from rearranging list          */
  195. /**************************************************************************/
  196.  
  197.    do i=archlist.0 to 1 by -1                /* process in reverse order  */
  198.       radio ID SQUIT 
  199.       if result~=_text._squit1 then leave /* skip remaining & do cleanup  */
  200.       anum=word(Archlist.i,1)
  201.       anum=strip(anum,'L','0')
  202.       if anum='' then anum=0
  203.       mnum=word(Archlist.i,2)
  204.       mnum=strip(mnum,'L','0')
  205.       if mnum='' then mnum=0
  206.       file=word(Archlist.i,3)
  207.       subj=subword(Archlist.i,4)
  208.       Updlist.i=anum
  209.       Updlist.i.1=mnum
  210.       Updlist.i.1.1=file
  211.       Updlist.i.1.1.1=subj
  212.       Address YAM 'setfolder 'anum           /* goto folder               */
  213.       Address YAM 'setmail 'mnum             /* set to mail               */
  214.       Address YAM "getmailinfo file"         /* verify filename           */
  215.       xfile=result
  216.       fullfile=xfile                         /* copy complete path/fn     */
  217.       xlen=length(file)
  218.       xfile=right(xfile,xlen)
  219.       Address YAM "getmailinfo subject"      /* verify subject            */
  220.       xsubj=result      
  221.       xsubj=translate(xsubj,' ',',')
  222.       if file~=xfile | xsubj~=subj then do
  223.          Updlist.i.1.1.1.1=bo||_text._error
  224.       end 
  225.       else do
  226.          if anum=0 then do               /* use ARCHIVE cmd for Incoming  */
  227.             Address YAM "mailarchive " targanum
  228.             Updlist.i.1.1.1.1=bo||_text._archived
  229.          end
  230.          else do                             /* Handle others             */
  231.                Call MoveIt
  232.          end
  233.       end
  234.    end
  235.    
  236. /**************************************************************************/
  237. /*                    Update target and source folders                    */
  238. /**************************************************************************/
  239.  
  240.    infotext=np||_text._updindex
  241.    text ID STEXT LABEL infotext
  242.  
  243.    Address YAM 'setfolder 'targanum          /* set to target folder      */
  244.    Address YAM 'mailupdate'                  /* update the index          */
  245.    oldarch=missing                           /* level break control       */
  246.    do i=1 to Updlist.0
  247.       if Updlist.i~=oldarch then do
  248.          Address YAM 'setfolder ' Updlist.i  /* goto folder               */
  249.          Address YAM 'mailupdate'            /* update the index          */
  250.          oldarch=Updlist.i
  251.       end
  252.    end
  253.  
  254. /**************************************************************************/
  255. /*                   Update list of mail archived/moved                   */
  256. /**************************************************************************/
  257.  
  258.    infotext=np||_text._update
  259.    text ID STEXT LABEL infotext
  260.  
  261.    do i=1 to Updlist.0                       /* display status messages   */
  262.       do j=0 to mcnt-1
  263.          list ID MLST POS j
  264.          mline=result
  265.          if mline='' then break
  266.          parse var mline arch ',' from ',' subj ',' mfor ',' mnum ',' anum ',' file
  267.          if Updlist.i=anum & Updlist.i.1=mnum then do
  268.             if Updlist.i.1.1.1.1~=missing then arch=Updlist.i.1.1.1.1
  269.             mline=arch||','||from||','||subj||','||mfor||','||mnum||','||anum||','||file
  270.             list ID MLST POS j STRING mline
  271.             iterate i
  272.          end
  273.       end
  274.    end
  275.  
  276. ProcessArchsEnd:
  277.  
  278.    window ID YTINF CLOSE
  279.  
  280. Return
  281.  
  282. /**************************************************************************/
  283. /* Find the LAST filename in the target dir, calculate new name, do a DOS */
  284. /* COPY command for output and a DOS delete command for the input.        */
  285. /* !! DON'T USE 'i' as a pointer in this routine                          */
  286. /**************************************************************************/
  287. MoveIt:
  288.  
  289.     targfn=right(date('I'),5,'0')
  290.  
  291.    dirlist=showdir(targdir,'FILE')
  292.    highfile='.index'
  293.    do filecnt=1 to words(dirlist)
  294.       if word(dirlist,filecnt) > highfile then do
  295.          highfile=word(dirlist,filecnt)
  296.       end
  297.    end
  298.  
  299.    highname=substr(highfile,1,5)
  300.    highext=substr(highfile,7,3)
  301.  
  302.    if targfn>highname then do
  303.       highname=targfn
  304.       highext='001'
  305.    end
  306.    else do
  307.       highext=highext+1
  308.       highext=right(highext,3,'0')
  309.    end   
  310.  
  311.    if highext='000' then do                    /* gone over 999           */
  312.       highname=right(highname+1,5,'0')         /* use next days date      */
  313.       highext='001'                            /* new series              */
  314.    end
  315.  
  316.    Address Command 'Copy ' fullfile 'TO' targdir'/'highname'.'highext 'QUIET CLONE'
  317.    if rc=0 then do
  318.       Updlist.i.1.1.1.1=bo||_text._moved
  319.       Address Command 'Delete ' fullfile 'QUIET'
  320.    end
  321.    else do
  322.       Updlist.i.1.1.1.1=bo||_text._error
  323.    end
  324.  
  325. Return
  326.  
  327. /**************************************************************************/
  328. /*              Make sure YAM  and YAMTOOLS are running. Show YAM.        */
  329. /**************************************************************************/
  330. CheckYAM:
  331.  
  332.    if ~show('p','YAMTOOLS') then do
  333.       errmsg=_text._noyt
  334.       say errmsg
  335.       exit
  336.    end
  337.  
  338.    if ~show('p','YAM') then do
  339.       errmsg=_text._noyam
  340.       Call ErrorMsg
  341.       exit
  342.    end
  343.  
  344.    Address YAM 'info version'               /* check YAM's version        */
  345.    yamver=word(result,3)
  346.  
  347.    if left(yamver,3)~=goodver then do       /* only 1.3.x or lower valid  */
  348.       errmsg=_text._badver||yamver
  349.       Call ErrorMsg
  350.       exit     
  351.    end
  352.  
  353.    Address YAM 'show'                       /* uniconify YAM's screen     */  
  354.  
  355.     Address YAM 'info SCREEN'                /* get YAM's screen           */
  356.     screen=result
  357.     if screen='' then screen='Workbench'
  358.  
  359. Return
  360.  
  361. /******************************************************************************/
  362. /*  Display ERROR message and EXIT.                                           */
  363. /******************************************************************************/
  364. ErrorMsg:
  365.  
  366.    window ID YTINF CLOSE
  367.  
  368.    request ID ERRM GADGETS _text._ok errmsg
  369.  
  370.    exit
  371.  
  372. Return
  373.  
  374. /******************************************************************************/
  375. /*  Display list of Archives for archive target selection.                    */
  376. /******************************************************************************/
  377. ArchWindow:
  378.  
  379.    window ID YTARC TITLE _title._main,
  380.           COMMAND '"window ID YTARC close"' PORT YAMTOOLS,
  381.           ATTRS MUIA_Window_PublicScreen screen
  382.  
  383.         group
  384.          group
  385.                text LABEL bc||_text._selfolder
  386.          endgroup
  387.          group 
  388.             list ID ARCHF COMMAND '"YTArcMove.rexx %s"', 
  389.                HELP help.ARCHF NODE node.ARCHF,
  390.                TITLE _title._archf,
  391.                INSERT NODUP, 
  392.                ATTRS MUIA_List_Format '"BAR,P=\033r"'
  393.          endgroup
  394.         endgroup
  395.  
  396.    endwindow
  397.  
  398. Return
  399.  
  400. /******************************************************************************/
  401. /*  Simple information/error message window.                                  */
  402. /******************************************************************************/
  403. InfoWindow:
  404.  
  405.    window ID YTINF TITLE _title._info ATTRS MUIA_Window_PublicScreen screen,
  406.           MUIA_Window_DepthGadget FALSE
  407.  
  408.       group 
  409.          group 
  410.             text ID STEXT HELP help.STEXT  NODE node.STEXT LABEL infotext
  411.          endgroup
  412.          if showbusy then do
  413.             group
  414.                object CLASS '"Busy.mcc"' ATTRS MUIA_VertWeight 25
  415.             endgroup
  416.          end
  417.          if infobuttons ~='' then do
  418.             group HORIZ
  419.                group 
  420.                   space HORIZ 
  421.                endgroup
  422.                group 
  423.                   radio ID SQUIT HELP help.SQUIT  NODE node.SQUIT LABELS infobuttons
  424.                endgroup
  425.                group 
  426.                   space HORIZ 
  427.                endgroup
  428.             endgroup
  429.          end
  430.          else do
  431.             group 
  432.                space HORIZ 100
  433.             endgroup
  434.          end
  435.       endgroup
  436.    endwindow
  437.  
  438. Return
  439.  
  440. /******************************************************************************/
  441. /*                      MUIREXX TAGS & VARIABLES                              */
  442. /******************************************************************************/
  443. Muivars:
  444.  
  445. MUIA_List_Format =          0x80423c0a 
  446. MUIA_List_Entries =         0x80421654 
  447. MUIA_VertWeight =           0x804298d0 
  448. MUIA_Window_DepthGadget  =  0x80421923
  449. MUIA_Window_DragBar  =      0x8042045d
  450. MUIA_Window_PublicScreen =  0x804278e4
  451. MUIA_Window_SizeGadget  =   0x8042e33d
  452.  
  453. TRUE=1
  454. FALSE=0
  455.  
  456. MUIV_List_Insert_Active = -1
  457.  
  458. Return
  459. /**************************************************************************/
  460. /*           Various values used throughout the various routines          */
  461. /**************************************************************************/
  462. YTvars:
  463.  
  464. goodver='1.3'                       /* this script is valid for YAM 1.3.x */
  465.  
  466. comma=','
  467. missing='.'
  468.  
  469. bo='\033b'                                  /* print control BOLD         */
  470. bc='\033b\033c'                             /* print control BOLD CENTER  */
  471. nc='\033n\033c'                             /* print control NORM CENTER  */
  472. np='\033n'                                  /* print control NORM         */
  473. nl='\n'                                     /* print control 1 NEW LINE   */
  474. nl2='\n\n'                                  /* print control 2 NEW LINES  */
  475. ct='\033c'                                  /* print control CENTER       */
  476. lf='\033l'                                  /* print control LEFT ALIGN   */
  477. rt='\033r'                                  /* print control RIGHT ALIGN  */
  478.  
  479. Return
  480.  
  481. /**************************************************************************/
  482. /*    Messages, text, etc. constructed using previously defined values    */
  483. /**************************************************************************/
  484. Builtvars:
  485.  
  486. _title._archf='"'||bo||_col._archf1||comma||bo||_col._archf2'"'
  487.  
  488. Return
  489.  
  490. /**************************************************************************/
  491. /*               Pointers into the YamTools.guide documentation           */
  492. /**************************************************************************/
  493. Helpvars:
  494.  
  495. node.SQUIT='7.3.'
  496. node.STEXT='7.3.'
  497. node.ARCHF='7.3.'
  498.  
  499. Return
  500.  
  501. /**************************************************************************/
  502. /*       Mui Gadgets, text, msgs, etc. used in YamTools                   */
  503. /**************************************************************************/
  504. Localize:
  505.  
  506. /*********************************/
  507. /* Miscellaneous info strings    */
  508. /*********************************/
  509. _title._main="""YTArcMove"""                /* main screen title          */
  510. _title._info="""YTArcMove Info"""           /* default title on infomsg   */
  511. _title._user="""YTArcMove User Info"""      /* title for user info screen */
  512.  
  513. _text._ok="Ok"                              /* various OK buttons         */
  514. _text._cancel="Cancel"                      /* LABEL for CANCEL button    */
  515. _text._squit1="Continue"                    /* CONTINUE option on infowin */
  516. _text._squit2="Interrupt"                   /* INTERRUPT option on infowin*/
  517. _text._squit3="Abort"                       /* ABORT    option on infowin */
  518.  
  519. _col._archf1="Yam Folder Name"              /* heading for ARCHF column 1 */
  520. _col._archf2="Number"                       /* heading for ARCHF column 2 */
  521.  
  522. _text._selfolder="Select Target Folder For Archiving"
  523.  
  524. _text._error="error"                        /* error on archiving mail    */
  525. _text._moved="moved"                        /* mail has been moved        */
  526. _text._skipped="skipped"                    /* skipped archiving mail     */
  527. _text._archived="archived"                  /* indicate mail archived     */
  528. _text._update="Updating Mail Status..."     /* updating entries           */
  529. _text._updindex="Updating Folder Indexes..." /* updating the indexes      */
  530.  
  531. _text._inmail="Doing Archiving and Moving..."
  532.  
  533.  
  534. /*********************************/
  535. /* Various error conditions      */
  536. /*********************************/
  537.  
  538. _text._noyam="You need YAM running to use YTArcMove"   /* yam not running */
  539. _text._noyt="You need YAMTOOLS running to use YTArcMove"  /* no yamtools  */
  540. _text._nomail="You need to SELECT mail to Archive"
  541. _text._badtarg=" is not a valid target for archiving"
  542. _text._badver="This script is not valid for YAM "
  543.  
  544. /**************************************************************************/
  545. /*           Help Messages to display with MUI bubble facility.           */
  546. /*                                                                        */
  547. /* Format is simple: help.ID where ID is the id specified on the MUI      */
  548. /* object statement.                                                      */
  549. /* Similar approach for accessing the .guide information using the NODE   */
  550. /* option on the object statement.                                        */
  551. /*                                                                        */
  552. /**************************************************************************/
  553.  
  554. help.SQUIT=""""""
  555. help.STEXT=""""""
  556. help.ARCHF=""""""
  557.  
  558. Return
  559.  
  560.  
  561.  
  562.