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