chiark / gitweb /
mount-keys: Exit non-zero if cfsd fails to restart the second time as well.
[bin.git] / get-corr
1 #! /usr/bin/perl -w
2 use strict;
3
4 use Mail::Util qw(read_mbox);
5
6 sub recurse ($)
7 {
8     my $file = shift;
9     -d $file or return ($file);
10     opendir DIR, $file or return ($file);
11     my @contents = map { recurse("$file/$_") } grep !/^\.\.?$/, readdir DIR;
12     closedir DIR;
13     return @contents;
14 }
15
16 my @folders = recurse "$ENV{HOME}/mail";
17
18 foreach my $folder (@folders)
19 {
20     my @messages = read_mbox($folder);
21     foreach my $message (@messages)
22     {
23         my $from;
24         my $print_from = 0;
25         my $scan = 0;
26         foreach my $line (@$message)
27         {
28             last if $line =~ /^$/;
29             if ($line =~ /^From:[ \t](.*)/)
30             {
31                 $from = $1;
32             }
33             if ($line =~ /^(?:To|Cc)/)
34             {
35                 $scan = 1;
36             }
37             elsif ($line !~ /^[ \t]/)
38             {
39                 $scan = 0;
40             }
41             if ($scan)
42             {
43                 if ($line =~ /cjw44|cjwatson/)
44                 {
45                     $print_from = 1;
46                     last;
47                 }
48             }
49         }
50         print "$from\n" if $print_from and defined $from;
51     }
52 }
53