newscache_clean.pl 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/perl
  2. # * Copyright 2001 Paul Mangan <claws@thewildbeast.co.uk>
  3. # *
  4. # * This file is free software; you can redistribute it and/or modify it
  5. # * under the terms of the GNU General Public License as published by
  6. # * the Free Software Foundation; either version 2 of the License, or
  7. # * (at your option) any later version.
  8. # *
  9. # * This program is distributed in the hope that it will be useful, but
  10. # * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # * General Public License for more details.
  13. # *
  14. # * You should have received a copy of the GNU General Public License
  15. # * along with this program; if not, write to the Free Software
  16. # * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. # *
  18. use File::Path;
  19. chdir;
  20. chdir '.sylpheed-claws' || die("You don't appear to have Sylpheed-Claws installed\n");
  21. open(ACCOUNTRC, "<accountrc") || die("Can't find accountrc\n");
  22. @accountrc = <ACCOUNTRC>;
  23. close ACCOUNTRC;
  24. foreach $accountrc (@accountrc) {
  25. if ($accountrc =~ m/nntp_server=[A-Za-z0-9]/) {
  26. $accountrc =~ s/nntp_server=//;
  27. chomp $accountrc;
  28. push(@newsserver, "$accountrc");
  29. }
  30. }
  31. %seen = ();
  32. foreach $newsserver (@newsserver) {
  33. $seen{$newsserver}++;
  34. }
  35. opendir(NEWSCACHE, "newscache") || die("Can't open newscache\n");
  36. push(@cached,(readdir(NEWSCACHE)));
  37. closedir(NEWSCACHE);
  38. splice(@cached, 0, 2);
  39. foreach $cached (@cached) { ## remove old newsserver directory tree
  40. rmtree("./newscache/$cached") unless $seen{$cached};
  41. }
  42. open(FOLDERLIST, "<folderlist.xml") || die("Can't find folderlist.xml\n");
  43. @folderlist = <FOLDERLIST>;
  44. close FOLDERLIST;
  45. %saw = ();
  46. $wegotnews = 0;
  47. foreach $folderlist (@folderlist) { ## remove old newsgroups directory trees
  48. unless ($wegotnews) {
  49. if ($folderlist =~ m/<folder type="news"/) {
  50. $wegotnews = 1;
  51. $done_grp = 0;
  52. $nntpserver = shift(@newsserver);
  53. }
  54. }
  55. if ($wegotnews && $folderlist =~ m/<\/folder>\n/ && !$done_grp) {
  56. opendir(NEWSGCACHE, "newscache/$nntpserver") || die("Can't open newscache/$nntpserver\n");
  57. push(@cachedgrp,(readdir(NEWSGCACHE)));
  58. closedir(NEWSGCACHE);
  59. splice(@cachedgrp, 0, 2);
  60. foreach $cachedgrp (@cachedgrp) {
  61. rmtree("./newscache/$nntpserver/$cachedgrp") unless ($saw{$cachedgrp}) || ($cachedgrp eq ".newsgroup_list");
  62. }
  63. $done_grp = 1;
  64. $wegotnews = 0;
  65. @cachedgrp = ();
  66. }
  67. if ($wegotnews && $folderlist !~ m/<\/folder>\n/) {
  68. if ($folderlist =~ m/<folderitem type="normal"/) {
  69. $folderlist =~ s/<folderitem type="normal" name="[A-Z0-9.]+" path="//i;
  70. $folderlist =~ s/" threaded="[0-1]+//;
  71. $folderlist =~ s/" hidereadmsgs="[0-1]+//;
  72. $folderlist =~ s/" mtime="[0-9]+" new="[0-9]+" unread="[0-9]+" total="[0-9]+" \/>//;
  73. $folderlist =~ s/ +//;
  74. chomp $folderlist;
  75. $saw{$folderlist}++;
  76. }
  77. }
  78. }
  79. print "Finished cleaning Sylpheed-Claws' newscache\n";
  80. exit;