home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Extra 1997 #5 / AmigaPlus_Extra-CD_5-97.iso / online-tools / mail / yamtools1.7 / ytdedup.rexx < prev    next >
OS/2 REXX Batch file  |  1997-06-17  |  13KB  |  348 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. /*                      MUIREXX TAGS & VARIABLES                              */
  66. /******************************************************************************/
  67.  
  68. TRUE=1
  69. FALSE=0
  70.  
  71. help.SQUIT=''
  72. node.SQUIT=''
  73. help.STEXT=''
  74. node.STEXT=''
  75.  
  76. missing='.'
  77.  
  78. /**************************************************************************/
  79. /*                      MAIN LOGIC FOR YTDEDUP.rexx                       */
  80. /**************************************************************************/
  81. Call CheckYam                           /* make sure Yam is running       */
  82.  
  83. if filename='' then do
  84.    errmsg=_text._choosefold
  85.    Call ErrorMsg
  86. end
  87.  
  88. Call GetMinfo                           /* get info for all mail in folder*/
  89. Call FindDups                           /* sort array & identify dups     */
  90. Call DeleteDups                         /* go do the deletes              */
  91.  
  92. exit
  93.  
  94. /**************************************************************************/
  95. /*                Get From and Subject using YAM facilities               */
  96. /*                                                                        */
  97. /* minfo array: from subject date mailnumber size                         */
  98. /**************************************************************************/
  99. GetMinfo:       
  100.  
  101.    minfo.=missing
  102.    minfo.0=0
  103.  
  104.    Address YAM 'GetFolderInfo Number'
  105.    anum=result
  106.    Address YAM 'GetFolderInfo Max'
  107.    mailcnt=result
  108.    minfo.0=mailcnt
  109.    do i=0 to mailcnt-1
  110.       mnum=i
  111.       j=i+1
  112.       Address YAM 'Setmail' mnum 
  113.       Address YAM 'Getmailinfo From'
  114.       mfrom=result
  115.       Address YAM 'Getmailinfo Subject'
  116.       msubj=result
  117.       Address YAM 'Getmailinfo File'
  118.       mpath=result
  119.       mdate=missing
  120.       msize=missing
  121.       Call GetDate
  122.       mstring=mfrom'|'mdate'|'msize'|'msubj'|'anum'|'mnum'|'mpath
  123.       minfo.j=mstring
  124.    end
  125.  
  126. Return
  127.  
  128. /**************************************************************************/
  129. /*                Read mail file for Date: line                           */
  130. /**************************************************************************/
  131. GetDate:    
  132.  
  133.    goodopen=open('IN',mpath,'R')
  134.    datefound=FALSE
  135.    if goodopen then do 
  136.        finfo=statef(mpath)    
  137.        parse var finfo type msize rest
  138.       do until eof('IN') | datefound
  139.          linein=readln('IN')
  140.          if linein='' then datefound=TRUE
  141.          if word(linein,1)='Date:' then do
  142.             mdate=subword(linein,2)
  143.             mdate=strip(mdate)
  144.             datefound=TRUE
  145.          end
  146.       end
  147.       result=close('IN')
  148.    end
  149.    else do
  150.       errmsg=_text._badmail
  151.       Call ErrorMsg
  152.       exit
  153.    end
  154.  
  155. Return
  156.  
  157. /**************************************************************************/
  158. /*                Sort mail info array and locate duplicates              */
  159. /**************************************************************************/
  160. FindDups:          
  161.  
  162.    if show('L','rexxtricks.library') then do /* use tricks library        */
  163.       call QSORT(minfo)                      /* sort by name, line number */
  164.    end
  165.    else do                                   /* use QuickSort format      */
  166.       call QSORT(1, minfo.0, minfo)          /* sort by name, line number */
  167.    end 
  168.  
  169.    dinfo.=missing                            /* array of duplicates       */
  170.    dinfo.0=0  
  171.  
  172.    oldfrom=missing                           /* set break values          */
  173.    olddate=missing
  174.    oldsize=missing
  175.    oldsubj=missing
  176.  
  177.    do i=1 to minfo.0
  178.       parse var minfo.i mfrom '|' mdate '|' msize '|' msubj '|' anum '|' mnum '|' mpath
  179.       if mfrom~=oldfrom | mdate~=olddate | msize~=oldsize | msubj~=oldsubj then do
  180.          oldfrom=mfrom
  181.          olddate=mdate   
  182.          oldsize=msize
  183.          oldsubj=msubj
  184.       end
  185.       else do
  186.          j=1+dinfo.0
  187.          dinfo.0=j
  188.          dstring=anum'|'mnum'|'mpath
  189.          dinfo.j=dstring
  190.       end
  191.    end
  192.  
  193. Return
  194.  
  195. /**************************************************************************/
  196. /*        Sort Duplicate list, check for list change, do deletes          */
  197. /*    Process in reverse list order to keep from changing list order      */
  198. /**************************************************************************/
  199. DeleteDups:        
  200.  
  201.    if dinfo.0=0 then do                      /* no duplicates found       */
  202.       errmsg=_text._nodups
  203.       Call ErrorMsg
  204.       exit
  205.    end
  206.  
  207.    if show('L','rexxtricks.library') then do /* use tricks library        */
  208.       call QSORT(dinfo)                      
  209.    end
  210.    else do                                   /* use QuickSort format      */
  211.       call QSORT(1, dinfo.0, dinfo)          
  212.    end 
  213.  
  214.    do i=dinfo.0 to 1 by -1
  215.       parse var dinfo.i anum '|' mnum '|' mpath
  216.       Address YAM 'Setfolder' anum
  217.       Address YAM 'Setmail'   mnum
  218.       Address YAM 'Getmailinfo File'
  219.       testpath=result
  220.       if mpath~=testpath then do
  221.          errmsg=_text._chgfolder
  222.          Call ErrorMsg
  223.          exit
  224.       end
  225.       Address YAM 'maildelete'
  226.    end
  227.  
  228.    errmsg=dinfo.0||_text._maildeleted
  229.    Call ErrorMsg
  230.    exit
  231.  
  232. Return
  233.  
  234. /**************************************************************************/
  235. /*              Make sure YAM  and YAMTOOLS are running. Show YAM.        */
  236. /**************************************************************************/
  237. CheckYAM:
  238.  
  239.    if ~show('p','YAMTOOLS') then do
  240.       errmsg=_text._noyt
  241.       say errmsg
  242.       exit
  243.    end
  244.  
  245.    Address YAMTOOLS
  246.  
  247.    if ~show('p','YAM') then do
  248.       errmsg=_text._noyam
  249.       Call ErrorMsg
  250.       exit
  251.    end
  252.  
  253.    Address YAM 'show'                       /* uniconify YAM's screen     */  
  254.  
  255.     Address YAM 'info SCREEN'                /* get YAM's screen           */
  256.     screen=result
  257.     if screen='' then screen='Workbench'
  258.  
  259. Return
  260.  
  261. /******************************************************************************/
  262. /*  Display ERROR message and EXIT.                                           */
  263. /******************************************************************************/
  264. ErrorMsg:
  265.  
  266.    Address YAMTOOLS
  267.  
  268.    request ID ERRM GADGETS _text._ok errmsg
  269.  
  270.    exit
  271.  
  272. Return
  273.  
  274. /******************************************************************************/
  275. /*                      MUIREXX TAGS & VARIABLES                              */
  276. /******************************************************************************/
  277. Muivars:
  278.  
  279. TRUE=1
  280. FALSE=0
  281.  
  282. Return
  283. /**************************************************************************/
  284. /*           Various values used throughout the various routines          */
  285. /**************************************************************************/
  286. YTvars:
  287.  
  288. missing='.'
  289.  
  290. Return
  291.  
  292. /**************************************************************************/
  293. /*    Messages, text, etc. constructed using previously defined values    */
  294. /**************************************************************************/
  295. Builtvars:
  296.  
  297. Return
  298.  
  299. /**************************************************************************/
  300. /*               Pointers into the YamTools.guide documentation           */
  301. /**************************************************************************/
  302. Helpvars:
  303.  
  304. node.SQUIT=''
  305. node.STEXT=''
  306.  
  307. Return
  308.  
  309. /**************************************************************************/
  310. /*       Mui Gadgets, text, msgs, etc. used in YamTools                   */
  311. /**************************************************************************/
  312. Localize:
  313.  
  314. /*********************************/
  315. /* Miscellaneous info strings    */
  316. /*********************************/
  317.  
  318. _text._ok='Ok'                              /* various OK buttons         */
  319.  
  320. /*********************************/
  321. /* Various error conditions      */
  322. /*********************************/
  323.  
  324. _text._noyam='You need YAM running to use YTDeDup'    /* yam not running */
  325. _text._noyt='You need YAMTOOLS running to use YTDeDup'   /* no yamtools  */
  326. _text._chgfolder='Folder order has changed--quitting this folder'
  327. _text._maildeleted=' mail(s) in folder deleted'
  328. _text._nodups='No Duplicates Found in Folder'
  329. _text._badmail='Unable to open a mailfile--exiting'
  330. _text._choosefold='Choose Folder for Locating Similar Mail'
  331.  
  332.  
  333. /**************************************************************************/
  334. /*           Help Messages to display with MUI bubble facility.           */
  335. /*                                                                        */
  336. /* Format is simple: help.ID where ID is the id specified on the MUI      */
  337. /* object statement.                                                      */
  338. /* Similar approach for accessing the .guide information using the NODE   */
  339. /* option on the object statement.                                        */
  340. /*                                                                        */
  341. /**************************************************************************/
  342.  
  343. help.SQUIT=''
  344. help.STEXT=''
  345.  
  346. Return
  347.  
  348.