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

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*                            YTDeDup.rexx                                    */
  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 locate and delete duplicate mail in a YAM folder.                       */
  10. /*----------------------------------------------------------------------------*/
  11. /*                                                                            */
  12. /* Logic: This script considers 2 mail to be duplicates IFF:                  */
  13. /* 1) From fields are the same, AND                                           */
  14. /* 2) Subject fields are the same, AND                                        */
  15. /* 3) Date fields are the same, AND                                           */
  16. /* 4) Mail sizes in bytes are exactly the same.                               */
  17. /*                                                                            */
  18. /*----------------------------------------------------------------------------*/
  19. /*                                                                            */
  20. /* Standard Disclaimer: I wrote it, it works for me, I don't guarantee        */
  21. /* that it will do anything productive for anyone else, etc. etc. ;-)         */
  22. /*                                                                            */
  23. /*HOWEVER, if you DO find a use for it: I homeschool my kids and they         */
  24. /*would love a postcard from where EVER you live.                             */
  25. /*                                                                            */
  26. /*Instant GEOGRAPHY lesson;)                                                  */
  27. /*                                                                            */
  28. /*                                                                            */
  29. /*POSTCARDS:    Dick Whiting                                                  */
  30. /*              28590 S. Beavercreek Rd.                                      */
  31. /*              Mulino, Oregon 97042                                          */
  32. /*              USA                                                           */
  33. /*                                                                            */
  34. /*----------------------------------------------------------------------------*/
  35. /*                                                                            */
  36. /*               Address Bug Reports or Comments to:                          */
  37. /*                Dick Whiting <dwhiting@europa.com>                          */
  38. /*                           26 March 1997                                    */
  39. /*                                                                            */
  40. /******************************************************************************/
  41. /*
  42. $VER: 1.0 Copyright ©1997 by Dick Whiting
  43. $AUTHOR: Dick Whiting
  44. $DESCRIPTION: Find and Delete Duplicate Mail in a YAM folder
  45. */
  46.  
  47. options results
  48. options failat 9999         /* keep maildelete return from showing */
  49.  
  50. filename=''
  51. rest=''
  52.  
  53. parse arg filename rest    
  54.  
  55. /**************************************************************************/
  56. /*                         Initialize Variables                           */
  57. /**************************************************************************/
  58. Call MUIvars                                /* go define vars for MUI use */
  59. Call YTvars                                 /* various values used in YT  */
  60. Call Helpvars                               /* pointers into HELP guide   */
  61. Call Localize                               /* vars for localizing strings*/
  62. Call Builtvars                              /* built using previous values*/
  63.  
  64. /**************************************************************************/
  65. /*                      MAIN LOGIC FOR YTDEDUP.rexx                       */
  66. /**************************************************************************/
  67. Call CheckYam                           /* make sure Yam is running       */
  68.  
  69. if filename='' then do
  70.    errmsg=_text._choosefold
  71.    Call ErrorMsg
  72. end
  73.  
  74. Call GetMinfo                           /* get info for all mail in folder*/
  75. Call FindDups                           /* sort array & identify dups     */
  76. Call DeleteDups                         /* go do the deletes              */
  77.  
  78. exit
  79.  
  80. /**************************************************************************/
  81. /*                Get From and Subject using YAM facilities               */
  82. /*                                                                        */
  83. /* minfo array: from subject date mailnumber size                         */
  84. /**************************************************************************/
  85. GetMinfo:       
  86.  
  87.    minfo.=missing
  88.    minfo.0=0
  89.  
  90.    Address YAM 'GetFolderInfo Number'
  91.    anum=result
  92.    Address YAM 'GetFolderInfo Max'
  93.    mailcnt=result
  94.    minfo.0=mailcnt
  95.    do i=0 to mailcnt-1
  96.       mnum=i
  97.       j=i+1
  98.       Address YAM 'Setmail' mnum 
  99.       Address YAM 'Getmailinfo From'
  100.       mfrom=result
  101.       Address YAM 'Getmailinfo Subject'
  102.       msubj=result
  103.       Address YAM 'Getmailinfo File'
  104.       mpath=result
  105.       mdate=missing
  106.       msize=missing
  107.       Call GetDate
  108.       mstring=mfrom'|'mdate'|'msize'|'msubj'|'anum'|'mnum'|'mpath
  109.       minfo.j=mstring
  110.    end
  111.  
  112. Return
  113.  
  114. /**************************************************************************/
  115. /*                Read mail file for Date: line                           */
  116. /**************************************************************************/
  117. GetDate:    
  118.  
  119.    goodopen=open('IN',mpath,'R')
  120.    datefound=FALSE
  121.    if goodopen then do 
  122.        finfo=statef(mpath)    
  123.        parse var finfo type msize rest
  124.       do until eof('IN') | datefound
  125.          linein=readln('IN')
  126.          if linein='' then datefound=TRUE
  127.          if word(linein,1)='Date:' then do
  128.             mdate=subword(linein,2)
  129.             mdate=strip(mdate)
  130.             datefound=TRUE
  131.          end
  132.       end
  133.       result=close('IN')
  134.    end
  135.    else do
  136.       errmsg=_text._badmail
  137.       Call ErrorMsg
  138.       exit
  139.    end
  140.  
  141. Return
  142.  
  143. /**************************************************************************/
  144. /*                Sort mail info array and locate duplicates              */
  145. /**************************************************************************/
  146. FindDups:          
  147.  
  148.    if show('L','rexxtricks.library') then do /* use tricks library        */
  149.       call QSORT(minfo)                      /* sort by name, line number */
  150.    end
  151.    else do                                   /* use QuickSort format      */
  152.       call QSORT(1, minfo.0, minfo)          /* sort by name, line number */
  153.    end 
  154.  
  155.    dinfo.=missing                            /* array of duplicates       */
  156.    dinfo.0=0  
  157.  
  158.    oldfrom=missing                           /* set break values          */
  159.    olddate=missing
  160.    oldsize=missing
  161.    oldsubj=missing
  162.  
  163.    do i=1 to minfo.0
  164.       parse var minfo.i mfrom '|' mdate '|' msize '|' msubj '|' anum '|' mnum '|' mpath
  165.       if mfrom~=oldfrom | mdate~=olddate | msize~=oldsize | msubj~=oldsubj then do
  166.          oldfrom=mfrom
  167.          olddate=mdate   
  168.          oldsize=msize
  169.          oldsubj=msubj
  170.       end
  171.       else do
  172.          j=1+dinfo.0
  173.          dinfo.0=j
  174.          dstring=anum'|'mnum'|'mpath
  175.          dinfo.j=dstring
  176.       end
  177.    end
  178.  
  179. Return
  180.  
  181. /**************************************************************************/
  182. /*        Sort Duplicate list, check for list change, do deletes          */
  183. /*    Process in reverse list order to keep from changing list order      */
  184. /**************************************************************************/
  185. DeleteDups:        
  186.  
  187.    if dinfo.0=0 then do                      /* no duplicates found       */
  188.       errmsg=_text._nodups
  189.       Call ErrorMsg
  190.       exit
  191.    end
  192.  
  193.    if show('L','rexxtricks.library') then do /* use tricks library        */
  194.       call QSORT(dinfo)                      
  195.    end
  196.    else do                                   /* use QuickSort format      */
  197.       call QSORT(1, dinfo.0, dinfo)          
  198.    end 
  199.  
  200.    do i=dinfo.0 to 1 by -1
  201.       parse var dinfo.i anum '|' mnum '|' mpath
  202.       Address YAM 'Setfolder' anum
  203.       Address YAM 'Setmail'   mnum
  204.       Address YAM 'Getmailinfo File'
  205.       testpath=result
  206.       if mpath~=testpath then do
  207.          errmsg=_text._chgfolder
  208.          Call ErrorMsg
  209.          exit
  210.       end
  211.       Address YAM 'maildelete'
  212.    end
  213.  
  214.    errmsg=dinfo.0||_text._maildeleted
  215.    Call ErrorMsg
  216.    exit
  217.  
  218. Return
  219.  
  220. /**************************************************************************/
  221. /*              Make sure YAM  and YAMTOOLS are running. Show YAM.        */
  222. /**************************************************************************/
  223. CheckYAM:
  224.  
  225.    if ~show('p','YAMTOOLS') then do
  226.       errmsg=_text._noyt
  227.       say errmsg
  228.       exit
  229.    end
  230.  
  231.    Address YAMTOOLS
  232.  
  233.    if ~show('p','YAM') then do
  234.       errmsg=_text._noyam
  235.       Call ErrorMsg
  236.       exit
  237.    end
  238.  
  239.    Address YAM 'show'                       /* uniconify YAM's screen     */  
  240.  
  241.     Address YAM 'info SCREEN'                /* get YAM's screen           */
  242.     screen=result
  243.     if screen='' then screen='Workbench'
  244.  
  245. Return
  246.  
  247. /******************************************************************************/
  248. /*  Display ERROR message and EXIT.                                           */
  249. /******************************************************************************/
  250. ErrorMsg:
  251.  
  252.    Address YAMTOOLS
  253.  
  254.    request ID ERRM GADGETS _text._ok errmsg
  255.  
  256.    exit
  257.  
  258. Return
  259.  
  260. /******************************************************************************/
  261. /*                      MUIREXX TAGS & VARIABLES                              */
  262. /******************************************************************************/
  263. Muivars:
  264.  
  265. TRUE=1
  266. FALSE=0
  267.  
  268. Return
  269. /**************************************************************************/
  270. /*           Various values used throughout the various routines          */
  271. /**************************************************************************/
  272. YTvars:
  273.  
  274. missing='.'
  275.  
  276. Return
  277.  
  278. /**************************************************************************/
  279. /*    Messages, text, etc. constructed using previously defined values    */
  280. /**************************************************************************/
  281. Builtvars:
  282.  
  283. Return
  284.  
  285. /**************************************************************************/
  286. /*               Pointers into the YamTools.guide documentation           */
  287. /**************************************************************************/
  288. Helpvars:
  289.  
  290. node.SQUIT=''
  291. node.STEXT=''
  292.  
  293. Return
  294.  
  295. /**************************************************************************/
  296. /*       Mui Gadgets, text, msgs, etc. used in YamTools                   */
  297. /**************************************************************************/
  298. Localize:
  299.  
  300. /*********************************/
  301. /* Miscellaneous info strings    */
  302. /*********************************/
  303.  
  304. _text._ok="Ok"                              /* various OK buttons         */
  305.  
  306. /*********************************/
  307. /* Various error conditions      */
  308. /*********************************/
  309.  
  310. _text._noyam="You need YAM running to use YTDeDup"     /* yam not running */
  311. _text._noyt="You need YAMTOOLS running to use YTDeDup"    /* no yamtools  */
  312. _text._chgfolder="Folder order has changed--quitting this folder"
  313. _text._maildeleted=" mail(s) in folder deleted"
  314. _text._nodups="No Duplicates Found in Folder"
  315. _text._badmail="Unable to open a mailfile--exiting"
  316. _text._choosefold="Choose Folder for Locating Similar Mail"
  317.  
  318.  
  319. /**************************************************************************/
  320. /*           Help Messages to display with MUI bubble facility.           */
  321. /*                                                                        */
  322. /* Format is simple: help.ID where ID is the id specified on the MUI      */
  323. /* object statement.                                                      */
  324. /* Similar approach for accessing the .guide information using the NODE   */
  325. /* option on the object statement.                                        */
  326. /*                                                                        */
  327. /**************************************************************************/
  328.  
  329. help.SQUIT=""""""
  330. help.STEXT=""""""
  331.  
  332. Return
  333.  
  334.  
  335.  
  336.