(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 +" ); }
In reply to Re: Strange problem trying to clean garbage from start of mailbox file
by graff
in thread Strange problem trying to clean garbage from start of mailbox file
by capoeiraolly
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |