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

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*                            YTARCHIVE                                       */
  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. /*----------------------------------------------------------------------------*/
  13. /*                                                                            */
  14. /* Standard Disclaimer: I wrote it, it works for me, I don't guarantee        */
  15. /* that it will do anything productive for anyone else, etc. etc. ;-)         */
  16. /*                                                                            */
  17. /*HOWEVER, if you DO find a use for it: I homeschool my kids and they         */
  18. /*would love a postcard from where EVER you live.                             */
  19. /*                                                                            */
  20. /*Instant GEOGRAPHY lesson;)                                                  */
  21. /*                                                                            */
  22. /*                                                                            */
  23. /*POSTCARDS:    Dick Whiting                                                  */
  24. /*              28590 S. Beavercreek Rd.                                      */
  25. /*              Mulino, Oregon 97042                                          */
  26. /*              USA                                                           */
  27. /*                                                                            */
  28. /*----------------------------------------------------------------------------*/
  29. /*                                                                            */
  30. /*               Address Bug Reports or Comments to:                          */
  31. /*                Dick Whiting <dwhiting@europa.com>                          */
  32. /*                         28 February 1997                                   */
  33. /*                                                                            */
  34. /******************************************************************************/
  35. /*
  36. $VER: 1.0 Copyright ©1997 by Dick Whiting
  37. $AUTHOR: Dick Whiting
  38. $DESCRIPTION: Archiver for use with YAMTOOLS
  39. */
  40.  
  41. options results
  42. options failat 21
  43.  
  44. targarch=''
  45. targanum=''
  46.  
  47. parse arg targarch ',' targanum 
  48.  
  49. /**************************************************************************/
  50. /*                         Initialize Variables                           */
  51. /**************************************************************************/
  52. Call MUIvars                                /* go define vars for MUI use */
  53. Call YTvars                                 /* various values used in YT  */
  54. Call Helpvars                               /* pointers into HELP guide   */
  55. Call Localize                               /* vars for localizing strings*/
  56. Call Builtvars                              /* built using previous values*/
  57.  
  58. Address YAMTOOLS
  59.  
  60. Call CheckYam
  61.  
  62. Select
  63.    when targarch='' then do
  64.       Call CheckMailList
  65.       Call ArchWindow
  66.       Call DisplayArchs
  67.    end
  68.    otherwise do
  69.       Call ProcessArchs
  70.    end
  71. end
  72.  
  73.  
  74. exit
  75.  
  76. /**************************************************************************/
  77. /*                Check that there is some mail to process                */
  78. /**************************************************************************/
  79. CheckMailList:
  80.  
  81.    list ID MLST ATTRS MUIA_List_Entries
  82.    mcnt=result
  83.    if mcnt=0 then do
  84.       errmsg=_text._nomail
  85.       Call ErrorMsg
  86.    end
  87.  
  88. Return
  89.  
  90. /**************************************************************************/
  91. /*                        Display list of Archives                        */
  92. /**************************************************************************/
  93. DisplayArchs:
  94.  
  95.    list ID ALST ATTRS MUIA_List_Entries
  96.    acnt=result
  97.  
  98.    do i=3 to acnt-1
  99.       list ID ALST POS i
  100.       aline=result
  101.       if aline='' then break
  102.       parse var aline arch ',' size ',' file ',' anum ',' rest
  103.       liststr=arch','anum
  104.       list ID ARCHF INSERT POS MUIV_List_Insert_Bottom STRING liststr
  105.    end            
  106.    
  107. Return
  108.  
  109. /**************************************************************************/
  110. /*                           Process Archivals                            */
  111. /**************************************************************************/
  112. ProcessArchs:
  113.  
  114.    if targanum < 3 then do
  115.       errmsg=bo||targarch||' '||np||_text._badtarg
  116.       Call ErrorMsg
  117.    end
  118.  
  119.    window ID YTARC close
  120.  
  121.    infotitle=_title._info
  122.    infotext=np||_text._inmail
  123.    infobuttons=_text._squit1||comma||_text._squit2||comma||_text._squit3
  124.    showbusy=TRUE
  125.  
  126.    Call InfoWindow
  127.    
  128.    list ID MLST ATTRS MUIA_List_Entries
  129.    mcnt=result
  130.  
  131.    archlist.=missing
  132.    archlist.0=0
  133.    Updlist.=missing
  134.    Updlist.0=0
  135.    acnt=0
  136.  
  137.    do i=0 to mcnt-1
  138.       list ID MLST
  139.       mline=result
  140.       if mline='' then break
  141.       parse var mline arch ',' from ',' subj ',' mfor ',' mnum ',' anum ',' file
  142.       acnt=acnt+1
  143.       anum=right(anum,6,'0')
  144.       mnum=right(mnum,6,'0')
  145.       Archlist.0=acnt
  146.       Archlist.acnt=anum mnum file subj
  147.       archlist.0=acnt
  148.       radio ID SQUIT 
  149.       if result~=_text._squit1 then leave
  150.    end
  151.    Updlist.0=Archlist.0
  152.  
  153.    if acnt=0 then do
  154.       errmsg=_text._nomail
  155.       Call ErrorMsg     
  156.    end
  157.  
  158.    if show('L','rexxtricks.library') then do    /* use tricks library     */
  159.       call QSORT(archlist)                   /* sort by name, line number */
  160.    end
  161.    else do                                   /* use QuickSort format      */
  162.       call QSORT(1, archlist.0, archlist)      /* sort by name, number    */
  163.    end 
  164.  
  165.    do i=archlist.0 to 1 by -1                /* process in reverse order  */
  166.       anum=word(Archlist.i,1)
  167.       anum=strip(anum,'L','0')
  168.       if anum='' then anum=0
  169.       mnum=word(Archlist.i,2)
  170.       mnum=strip(mnum,'L','0')
  171.       if mnum='' then mnum=0
  172.       file=word(Archlist.i,3)
  173.       subj=subword(Archlist.i,4)
  174.       Updlist.i=anum
  175.       Updlist.i.1=mnum
  176.       Updlist.i.1.1=file
  177.       Updlist.i.1.1.1=subj
  178.       if anum~=0 then do                     /* only INCOMING is valid    */
  179.          updlist.i.1.1.1.1=bo||_text._skipped
  180.          iterate i
  181.       end
  182.       Address YAM 'setfolder 'anum           /* goto folder               */
  183.       Address YAM 'setmail 'mnum             /* set to mail               */
  184.       Address YAM "getmailinfo file"         /* verify filename           */
  185.       xfile=result
  186.       xlen=length(file)
  187.       xfile=right(xfile,xlen)
  188.       Address YAM "getmailinfo subject"      /* verify subject            */
  189.       xsubj=result      
  190.       xsubj=translate(xsubj,' ',',')
  191.       if file~=xfile | xsubj~=subj then do
  192.          Updlist.i.1.1.1.1=bo||_text._error
  193.       end 
  194.       else do
  195.          Updlist.i.1.1.1.1=bo||_text._archived
  196.          Address YAM "mailarchive " targanum
  197.       end
  198.    end
  199.    
  200.    do i=1 to Updlist.0
  201.       do j=0 to mcnt-1
  202.          list ID MLST POS j
  203.          mline=result
  204.          if mline='' then break
  205.          parse var mline arch ',' from ',' subj ',' mfor ',' mnum ',' anum ',' file
  206.          if Updlist.i=anum & Updlist.i.1=mnum then do
  207.             arch=Updlist.i.1.1.1.1
  208.             mline=arch||','||from||','||subj||','||mfor||','||mnum||','||anum||','||file
  209.             list ID MLST POS j STRING mline
  210.             iterate i
  211.          end
  212.       end
  213.    end
  214.  
  215.    window ID YTINF CLOSE
  216.  
  217. Return
  218.  
  219. /**************************************************************************/
  220. /*              Make sure YAM  and YAMTOOLS are running. Show YAM.        */
  221. /**************************************************************************/
  222. CheckYAM:
  223.  
  224.    if ~show('p','YAMTOOLS') then do
  225.       errmsg=_text._noyt
  226.       say errmsg
  227.       exit
  228.    end
  229.  
  230.    if ~show('p','YAM') then do
  231.       errmsg=_text._noyam
  232.       Call ErrorMsg
  233.       exit
  234.    end
  235.  
  236.    Address YAM 'show'                       /* uniconify YAM's screen     */  
  237.  
  238.     Address YAM 'info SCREEN'                /* get YAM's screen           */
  239.     screen=result
  240.     if screen='' then screen='Workbench'
  241.  
  242. Return
  243.  
  244. /******************************************************************************/
  245. /*  Display ERROR message and EXIT.                                           */
  246. /******************************************************************************/
  247. ErrorMsg:
  248.  
  249.    window ID YTINF CLOSE
  250.  
  251.    request ID ERRM GADGETS _text._ok errmsg
  252.  
  253.    exit
  254.  
  255. Return
  256.  
  257. /******************************************************************************/
  258. /*  Display list of Archives for archive target selection.                    */
  259. /******************************************************************************/
  260. ArchWindow:
  261.  
  262.    window ID YTARC TITLE _title._main,
  263.           COMMAND '"window ID YTARC close"' PORT YAMTOOLS,
  264.           ATTRS MUIA_Window_PublicScreen screen
  265.  
  266.         group
  267.          group
  268.                text LABEL bc||_text._selfolder
  269.          endgroup
  270.          group 
  271.             list ID ARCHF COMMAND '"YTArchive.rexx %s"', 
  272.                HELP help.ARCHF NODE node.ARCHF,
  273.                TITLE _title._archf,
  274.                INSERT NODUP, 
  275.                ATTRS MUIA_List_Format '"BAR,P=\033r"'
  276.          endgroup
  277.         endgroup
  278.  
  279.    endwindow
  280.  
  281. Return
  282.  
  283. /******************************************************************************/
  284. /*  Simple information/error message window.                                  */
  285. /******************************************************************************/
  286. InfoWindow:
  287.  
  288.    window ID YTINF TITLE _title._info ATTRS MUIA_Window_PublicScreen screen,
  289.           MUIA_Window_SizeGadget FALSE,
  290.           MUIA_Window_DepthGadget FALSE
  291.  
  292.       group 
  293.          group 
  294.             text ID STEXT HELP help.STEXT  NODE node.STEXT LABEL infotext
  295.          endgroup
  296.          if showbusy then do
  297.             group
  298.                object CLASS '"Busy.mcc"' ATTRS MUIA_VertWeight 25
  299.             endgroup
  300.          end
  301.          if infobuttons ~='' then do
  302.             group HORIZ
  303.                group 
  304.                   space HORIZ 
  305.                endgroup
  306.                group 
  307.                   radio ID SQUIT HELP help.SQUIT  NODE node.SQUIT LABELS infobuttons
  308.                endgroup
  309.                group 
  310.                   space HORIZ 
  311.                endgroup
  312.             endgroup
  313.          end
  314.          else do
  315.             group 
  316.                space HORIZ 100
  317.             endgroup
  318.          end
  319.       endgroup
  320.    endwindow
  321.  
  322. Return
  323.  
  324. /******************************************************************************/
  325. /*                      MUIREXX TAGS & VARIABLES                              */
  326. /******************************************************************************/
  327. Muivars:
  328.  
  329. MUIA_List_Format =          0x80423c0a 
  330. MUIA_List_Entries =         0x80421654 
  331. MUIA_VertWeight =           0x804298d0 
  332. MUIA_Window_DepthGadget  =  0x80421923
  333. MUIA_Window_DragBar  =      0x8042045d
  334. MUIA_Window_PublicScreen =  0x804278e4
  335. MUIA_Window_SizeGadget  =   0x8042e33d
  336.  
  337. TRUE=1
  338. FALSE=0
  339.  
  340. MUIV_List_Insert_Active = -1
  341.  
  342. Return
  343. /**************************************************************************/
  344. /*           Various values used throughout the various routines          */
  345. /**************************************************************************/
  346. YTvars:
  347.  
  348. comma=','
  349. missing='.'
  350.  
  351. bo='\033b'                                  /* print control BOLD         */
  352. bc='\033b\033c'                             /* print control BOLD CENTER  */
  353. nc='\033n\033c'                             /* print control NORM CENTER  */
  354. np='\033n'                                  /* print control NORM         */
  355. nl='\n'                                     /* print control 1 NEW LINE   */
  356. nl2='\n\n'                                  /* print control 2 NEW LINES  */
  357. ct='\033c'                                  /* print control CENTER       */
  358. lf='\033l'                                  /* print control LEFT ALIGN   */
  359. rt='\033r'                                  /* print control RIGHT ALIGN  */
  360.  
  361. Return
  362.  
  363. /**************************************************************************/
  364. /*    Messages, text, etc. constructed using previously defined values    */
  365. /**************************************************************************/
  366. Builtvars:
  367.  
  368. _title._archf='"'||bo||_col._archf1||comma||bo||_col._archf2'"'
  369.  
  370. Return
  371.  
  372. /**************************************************************************/
  373. /*               Pointers into the YamTools.guide documentation           */
  374. /**************************************************************************/
  375. Helpvars:
  376.  
  377. node.SQUIT='7.3.'
  378. node.STEXT='7.3.'
  379. node.ARCHF='7.3.'
  380.  
  381. Return
  382.  
  383. /**************************************************************************/
  384. /*       Mui Gadgets, text, msgs, etc. used in YamTools                   */
  385. /**************************************************************************/
  386. Localize:
  387.  
  388. /*********************************/
  389. /* Miscellaneous info strings    */
  390. /*********************************/
  391. _title._main="""YTArchive"""                /* main screen title          */
  392. _title._info="""YTArchive Info"""           /* default title on infomsg   */
  393. _title._user="""YTArchive User Info"""      /* title for user info screen */
  394.  
  395. _text._ok="Ok"                              /* various OK buttons         */
  396. _text._cancel="Cancel"                      /* LABEL for CANCEL button    */
  397. _text._squit1="Continue"                    /* CONTINUE option on infowin */
  398. _text._squit2="Interrupt"                   /* INTERRUPT option on infowin*/
  399. _text._squit3="Abort"                       /* ABORT    option on infowin */
  400.  
  401. _col._archf1="Yam Folder Name"              /* heading for ARCHF column 1 */
  402. _col._archf2="Number"                       /* heading for ARCHF column 2 */
  403.  
  404. _text._selfolder="Select Target Folder For Archiving"
  405.  
  406. _text._error="error"                        /* error on archiving mail    */
  407. _text._skipped="skipped"                    /* skipped archiving mail     */
  408. _text._archived="archived"                  /* indicate mail archived     */
  409. _text._inmail="Only Incoming Mail will be processed ..."
  410.  
  411.  
  412. /*********************************/
  413. /* Various error conditions      */
  414. /*********************************/
  415.  
  416. _text._noyam="You need YAM running to use YTArchive"   /* yam not running */
  417. _text._noyt="You need YAMTOOLS running to use YTArchive"  /* no yamtools  */
  418. _text._nomail="You need to SELECT mail to Archive"
  419. _text._badtarg=" is not a valid target for archiving"
  420.  
  421. /**************************************************************************/
  422. /*           Help Messages to display with MUI bubble facility.           */
  423. /*                                                                        */
  424. /* Format is simple: help.ID where ID is the id specified on the MUI      */
  425. /* object statement.                                                      */
  426. /* Similar approach for accessing the .guide information using the NODE   */
  427. /* option on the object statement.                                        */
  428. /*                                                                        */
  429. /**************************************************************************/
  430.  
  431. help.SQUIT=""""""
  432. help.STEXT=""""""
  433. help.ARCHF=""""""
  434.  
  435. Return
  436.  
  437.  
  438.  
  439.