File: Bcheck

package info (click to toggle)
xlbiff 4.6.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 648 kB
  • sloc: sh: 4,969; ansic: 754; python: 389; xml: 67; perl: 45; makefile: 44
file content (78 lines) | stat: -rwxr-xr-x 1,848 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/perl -w
#
# Bcheck -- check for new mail in "bulk" maildrops
#
# Called by xlbiff(1).  Not intended for general consumption.
#
# $Id: Bcheck,v 1.3 2003/11/09 00:17:51 esm Exp $
#
(our $ME = $0) =~ s,.*/,,;

our $State = ".$ME.results";

use strict;
use Digest::MD5;

my $context = Digest::MD5->new;

# All operations take place under our Mail dir.  Theoretically we should
# read this (Mail) from the Path: component of ~/.mh_profile.  But I'm lazy.
chdir "$ENV{HOME}/Mail"
  or die "$ME: cd: $!\n";

my $seen = 0;					# Number of unseen messages

# Exmh keeps this nice cache for us.  If you don't use exmh, you could
# instead run 'folders -fast -recurse'.
open FOLDERS, ".folders"
  or die "$ME: open(.folders): $!\n";
while (defined (my $f = <FOLDERS>)) {
  chomp $f;

  open SEQ, "$f/.mh_sequences"
    or next;
  while (<SEQ>) {
    if (/^unseen:\s+(.*)/) {
#      printf STDERR "$f: $1\n";
      $seen++;
      $context->add($f, $1);
    }
  }
  close SEQ;
}
close FOLDERS;

print "0\n";	# xlbiff expects this

# If no new messages exist, pop down the window
if ($seen == 0) {
  exit 2;			# 0 = change, 1 = no change, 2 = zero'ed
}

# Read results from the last time we ran.
my $last_results = "";
open LAST, $State and do {
  chop ($last_results = <LAST>);
  close LAST;
};

# Compare our results now against those from last time.  If no change, exit now
my $new = $context->hexdigest;
#printf STDERR "old: %s\nnew: %s\n", $last_results, $new;
if ($new eq $last_results) {
  exit 1;			# 1 = no change, 0 = change, 2 = zero'ed
}


# Something changed. Write out our new results, and exit with status 0 (change)
my $tmp = "$State.tmp.$$";
open OUT, ">", $tmp
  or die "$ME: Error creating $tmp: $!\n";
print OUT $new,"\n";
close OUT;

chmod 0600, $tmp;
rename $tmp => $State
  or die "$ME: rename ($tmp => $State): $!\n";

exit 0;