#!/usr/bin/perl -w
#
#  Copyright owner:  Paul Millar <paulm@astro.gla.ac.uk>
#  Copyright BSD-like license:  do what you want, but don't remove this
#                               license
#
#  CVS id $Id: bulkNoCheckMail.pl,v 1.3 2004/08/11 14:01:36 paulm Exp $
#  Version 0.1
#
#  Simple script for uncheckbox-ing the check-mail in kmail.  Please email
#  me diffs of changes.

my $inside;
my $changed=0;
my $count=0;

my $IMAP="Physics%20and%20Astronomy";
my $dir="mail";

my $re= "^\\[Folder-\\.$IMAP\\.directory/\\.$dir\\.directory";

open KDERC,$ENV{HOME}."/.kde/share/config/kmailrc" || die "Cannot open kmailrc file";
open NEW,">/tmp/new-kmailrc" || die "Cannot create new file";


while( <KDERC>) {
#  For convenience, we hard-code this in:
#  [Folder-.<IMAP name>.directory/.<dir1>.directory/.<dir2>.directory/...]
#  
  if( /$re/) {
    $inside=1;
  }
  if( /^$/) {
    $inside=0;
  }

  /^checkmail=/ && $count++; 

  if( $inside) {
    if( /^checkmail=true/ ) {
      s/^checkmail=true/checkmail=false/;
      $changed++;
    }
  }

  print NEW;
}

close NEW;
close KDERC;

print "Changed $changed (of $count) entries\n";

