/[perl]/fix_mbox.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /fix_mbox.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Sat Feb 1 00:43:51 2003 UTC (16 years, 9 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/plain
fix mbox-es: e.g. remove virus messages from them

1 #!/usr/bin/perl -w
2
3 #David Luyer <david_luyer@pacific.net.au> provides us with a similar
4 #script in perl. Its attached. Run from /var/spool with $files = `echo mail/*`
5 #or $files = result of building list from grep. No forks, execs, etc, etc,
6 #so it can be run over a few hundred thousand mailboxes without too much pain,
7 #although the locking is very ugly and doesn't actually test the lock.
8
9 # Additional code, dies etc. Dobrica Pavlinusic <dpavlin@rot13.org>
10
11 # pipe list of mailboxes to this script!!!
12 # eg. find /var/spool/mail | fix.pl | tee stat
13
14 $virusremoved = 0;
15 $mboxes = 0;
16
17 $|=1; # don't buffer
18
19 while(<>) {
20 chomp;
21 $file=$_;
22 next if (-d "$file"); # skip dirs
23 print STDERR "$file";
24 $mboxes++;
25 $msg = "";
26 $isvirus = 0;
27 $isnotvirus = 0;
28 open (TMP, ">$file.lock") || die "lock: $!";
29 close (TMP);
30 (undef,undef,$mode,undef,$uid,$gid,undef,undef,$atime,$mtime) = stat($file);
31 rename ("$file", "$file.TMP-RM-VIRUS") || die "rename: $!";
32 open (FILEOLD, "<$file.TMP-RM-VIRUS") || die "old: $!";
33 open (FILENEW, ">$file") || die "new: $!";
34 while (<FILEOLD>) {
35 if (/^From /) {
36 if (!$isvirus) {
37 print FILENEW $msg;
38 } else {
39 $virusremoved++;
40 print STDERR " $virusremoved";
41 $infected{$file}++;
42 }
43 $msg = "";
44 $isvirus = 0;
45 $isnotvirus = 0;
46 }
47 $msg .= $_;
48 if (/^$/ && !$isvirus) {
49 $isnotvirus++;
50 }
51 if (/^Subject: fwd: Joke$/) {
52 $isvirus++ if (!$isnotvirus);
53 }
54 }
55
56 print FILENEW $msg if (!$isvirus);
57 $virusremoved++ if ($isvirus);
58 $msg = "";
59 $isvirus = 0;
60 $isnotvirus = 0;
61 close (FILEOLD);
62 close (FILENEW);
63 unlink("$file.TMP-RM-VIRUS") || die "unlink: $!";
64 unlink("$file.lock") || die "unlock: $!";
65 chown $uid, $gid, $file || die "chown: $!";
66 chmod $mode, $file || die "chmod: $!";
67 utime $atime, $mtime, $file || die "utime: $!";
68 print STDERR "\n";
69 }
70
71 print "stat: $mboxes mailboxes, $virusremoved viruses found\n";
72 foreach $k (keys %infected) {
73 print "$k $infected{$k}|";
74 }

  ViewVC Help
Powered by ViewVC 1.1.26