Generated by htmldiff.sh

nottoomuch-addresses-1.0.pl nottoomuch-addresses-1.1.pl
3# $ nottoomuch-addresses.pl $3# $ nottoomuch-addresses.pl $
4#4#
5# Created: Thu 27 Oct 2011 17:38:46 EEST too5# Created: Thu 27 Oct 2011 17:38:46 EEST too
6# Last modified: Wed 30 Nov 2011 22:56:10 EET too6# Last modified: Fri 02 Dec 2011 19:11:33 EET too
77
8# Add this to your notmuch elisp configuration file:8# Add this to your notmuch elisp configuration file:
9#9#
11# (setq notmuch-address-command "/path/to/nottoomuch-addresses.pl")11# (setq notmuch-address-command "/path/to/nottoomuch-addresses.pl")
12# (notmuch-address-message-insinuate)12# (notmuch-address-message-insinuate)
1313
14# Documentation at the end.14# Documentation at the end. HISTORY after BEGIN block below. Encoding: utf-8.
1515
16#BEGIN { system '/bin/sh', '-c', 'env > $HOME/na-ENV.$$'; }16#BEGIN { system '/bin/sh', '-c', 'env > $HOME/na-ENV.$$'; }
1717
22 $configdir = ($ENV{XDG_CONFIG_HOME}||$ENV{HOME}.'/.config').'/nottoomuch';22 $configdir = ($ENV{XDG_CONFIG_HOME}||$ENV{HOME}.'/.config').'/nottoomuch';
23 $adbpath = $configdir . '/addresses';23 $adbpath = $configdir . '/addresses';
2424
25 if ($ENV{TERM} eq 'dumb' or @ARGV and $ARGV[0] !~ /^--/)25 if (@ARGV and $ARGV[0] !~ /^--/)
26 {26 {
27 my $search_str = "@ARGV";27 my $search_str = "@ARGV";
28 exit 0 unless length $search_str >= 3; # more than 2 chars required...28 exit 0 unless length $search_str >= 3; # more than 2 chars required...
37 exit 0;37 exit 0;
38 }38 }
39}39}
40
41# HISTORY
42#
43# Version 1.1 2011-12-02 17:11:33 UTC
44# * Removed Naïve assumption that on-one runs update on 'dumb' terminal.
45# * Check address database file first line whether it is known to us.
46#
47# Thanks to Bart Bunting for providing a good bug report.
48#
49# Version 1.0 2011-11-30 20:56:10 UTC
50# * Initial release
4051
41use 5.8.1;52use 5.8.1;
42use strict;53use strict;
66 require Pod::Perldoc;77 require Pod::Perldoc;
67 $SIG{__DIE__} = 'DEFAULT';78 $SIG{__DIE__} = 'DEFAULT';
68 # in case PAGER is not set, perldoc runs /usr/bin/perl -isr ...79 # in case PAGER is not set, perldoc runs /usr/bin/perl -isr ...
69 $ENV{LESS} .= 'R' if $ENV{PAGER} eq 'less' and $ENV{LESS} !~ /[rR]/;80 if ( ($ENV{PAGER} || '') eq 'less') {
81 $ENV{LESS} .= 'R' if ($ENV{LESS} || '') !~ /[rR]/;
82 }
70 @ARGV = ( $0 );83 @ARGV = ( $0 );
71 exit ( Pod::Perldoc->run() );84 exit ( Pod::Perldoc->run() );
72}85}
88101
89 mkdirs $configdir unless -d $configdir;102 mkdirs $configdir unless -d $configdir;
90103
91 unlink $adbpath if defined $ARGV[1] and $ARGV[1] eq "--rebuild";104 unlink $adbpath if defined $ARGV[1] and $ARGV[1] eq '--rebuild';
92105
93 my ($sstr, $acount);106 my ($sstr, $acount) = (0, 0);
94 my $stime = time;107 my $stime = time;
95 if (-f $adbpath) {108 if (-s $adbpath) {
96 die "Cannot open '$adbpath': $!\n" unless open I, '<', $adbpath;109 die "Cannot open '$adbpath': $!\n" unless open I, '<', $adbpath;
110 no warnings;
97 $sstr = <I>;111 $sstr = int <I>;
112 }
113 if ($sstr > 1e8) { # arbitrary value: 86400 * 1157.4 (1973-03-03 09:46:40Z)
98 $sstr -= 86400 * 7; # one week extra to (re)look.114 $sstr -= 86400 * 7; # one week extra to (re)look.
99 print "Updating '$adbpath', since $sstr.\n";115 print "Updating '$adbpath', since $sstr.\n";
100 $sstr .= '..';116 $sstr .= '..';
103 $acount = scalar @list;119 $acount = scalar @list;
104 }120 }
105 else {121 else {
122 die "'$adbpath' exists but contains unknown content!\n" if -s $adbpath;
106 print "Creating '$adbpath'. This may take some time...\n";123 print "Creating '$adbpath'. This may take some time...\n";
107 $sstr = '*';124 $sstr = '*';
108 $acount = 0;
109 }125 }
110 my %hash = map { $_ => 1 } @list;126 my %hash = map { $_ => 1 } @list;
111 if (-f $ignpath) {127 if (-f $ignpath) {
281 undef %hash;297 undef %hash;
282 undef %seen;298 undef %seen;
283 my $etime = time;299 my $etime = time;
284 open O, '>', $adbpath or die;300 open O, '>', $adbpath or die "Cannot write to '$adbpath': $!\n";
285 print O $etime, "\n";301 print O $etime, "\n";
286 print O join("\n", sort @list), "\n";302 print O join("\n", sort @list), "\n";
287 close O;303 close O;