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

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