in reply to Strange problem trying to clean garbage from start of mailbox file
(That assumes that the backup directory is not on a distinct disk volume.)my $path = "./mail"; my $bkup = "./backup"; open MAILDIR, $path; for my $mbox ( grep { -f "$path/$_" and -s _ } readdir MAILDIR ) { rename "$path/$mbox", "$bkup/$mbox"; system( "perl -ne 'print if /^From/..-1' $bkup/$mbox > $path/$mbox +" ); }
update: as capoeiraolly points out below, that version backs up all mailbox files, not just the ones that need fixing. To avoid that, just add a few lines at the top of the for loop:
for my $mbox ( grep { -f "$path/$_" and -s _ } readdir MAILDIR ) { my $first = do { open M, "$path/$_"; <M> }; close M; next if ( $first =~ /^From / ); # ... do rename and system calls on bad files only rename "$path/$mbox", "$bkup/$mbox"; system( "perl -ne 'print if /^From/..-1' $bkup/$mbox > $path/$mbox +" ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Strange problem trying to clean garbage from start of mailbox file
by capoeiraolly (Initiate) on Feb 03, 2006 at 04:19 UTC |