1 # Mail counter statusbar item
2 # for irssi 0.7.99 by Timo Sirainen
3 # /SET mail_ext_program - specify external mail checker program
4 # /SET mail_file - specifies mbox file location
5 # /SET mail_refresh_time - in seconds, how often to check for new mail
11 my ($last_refresh_time, $refresh_tag);
14 my ($last_size, $last_mtime, $last_mailcount);
19 my @stat = stat($mailfile);
23 # if the file hasn't changed, get the count from cache
24 return $last_mailcount if ($last_size == $size && $last_mtime == $mtime);
33 return 0 if (!open(F, $mailfile));
37 $count++ if (/^From /);
38 $count-- if (/^Subject: .*FOLDER INTERNAL DATA/);
43 $last_mailcount = $count;
48 my ($item, $get_size_only) = @_;
50 my $count = mbox_count(Irssi::settings_get_str('mail_file'));
52 # no mail - don't print the [Mail: ] at all
54 $item->{min_size} = $item->{max_size} = 0;
57 $item->default_handler($get_size_only, undef, $count, 1);
62 Irssi::statusbar_items_redraw('mail');
66 $extprog = Irssi::settings_get_str('mail_ext_program');
67 my $time = Irssi::settings_get_int('mail_refresh_time');
68 return if ($time == $last_refresh_time);
70 $last_refresh_time = $time;
71 Irssi::timeout_remove($refresh_tag) if ($refresh_tag);
72 $refresh_tag = Irssi::timeout_add($time*1000, 'refresh_mail', undef);
75 Irssi::settings_add_str('misc', 'mail_ext_program', '');
76 Irssi::settings_add_str('misc', 'mail_file', $ENV{'MAIL'});
77 Irssi::settings_add_int('misc', 'mail_refresh_time', 60);
79 Irssi::statusbar_item_register('mail', '{sb Mail: $0-}', 'mail');
82 Irssi::signal_add('setup changed', 'read_settings');
83 mbox_count(Irssi::settings_get_str('mail_file'));