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

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