[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: What is "comsat" for?



>>>>> "M" == Michael Alan Dorman <mdorman@lot49.med.miami.edu> writes:


    M> Actually, I'm curious as to whether anyone knows of an X
    M> program that'll use comsat for notifying you of new mail?  All
    M> of the ones I can find seem to want to check the filesytem,
    M> something that would be less than optimal for me, since I've
    M> got a bazillion folders stuff can be filtered into---procmail
    M> can send comsat notification, though, if something can respond
    M> to it.

You can touch a file in your .procmailrc and have xbiff monitor that
file. That way you get the notification, but you have to turn off
xbiff by clicking on it. Alternatively, you can use the newmail script
which I append to notify xbiff (assuming you use MH and the unseen
sequence). I meant to inprove the script but I'm not using it right
now (too little memory to run X all the time)... You have to call
xbiff with something like
	xbiff -xrm '*checkCommand: newmail' -geometry 80x80-0-0 &
or put the checkCommand resource in your X resources file.

		Cheers,
			Lukas

------------------------------ newmail ------------------------------
#!/usr/local/bin/perl
# -*-perl-*- script to check for new mail in unseen sequences in 
# selected folders 
#

chomp($mailpath = `mhparam path`);
$mailpath = $ENV{"HOME"} . '/' . ($mailpath || 'Mail');
$mh_sequences = '.mh_sequences';

@infolders = qw(inbox comp/debian comp/fvwm bbs/AP bbs/PH bbs/TH comp/plplot);

$last_unseen = "$mailpath/LAST-UNSEEN";

# read list of old unseen messages
if (open(LAST,$last_unseen)) {
    while (<LAST>) {
	chomp;
	($folder,$unseen) = split(':',$_);
	$last_unseen{$folder} = $unseen;
    }
    close LAST;
}

# get current unseen messages
foreach $folder (@infolders) {
    if (open(SEQ,"$mailpath/$folder/$mh_sequences")) {
	while (<SEQ>) {
	    next unless /^unseen:/;
	    chomp;
	    ($dummy,$unseen) = split(':',$_);
	    $unseen{$folder} = $unseen;
	    last;
	}
	close SEQ;
    }
}

$exit = 1;			# default: no changes (for xbiff)
CHECK: foreach $folder (@infolders) {
    if (!$last_unseen{$folder} && !$unseen{$folder}) {
	next CHECK;		# no new or old sequence
    }
    if ($last_unseen{$folder} && !$unseen{$folder}) {
	$exit = 2;		# mail read in this folder
	next CHECK;		# so we look at the next folder...
    }
    if (!$last_unseen{$folder} && $unseen{$folder}) {
	$exit = 0;		# certainly new mail here
	last CHECK;		# so we're done
    }

    # make array of flags of unseen messages
    @u = ();
    foreach $s (split(' ', $unseen{$folder})) {
	if ($s =~/(\d+)-(\d+)/) {
	    foreach $i ($1..$2) {
		$u[$i] = 1;
	    }
	} else {
	    $u[$s] = 1;
	}
    }

    # make array of flags of unseen messages
    @l = ();
    foreach $s (split(' ', $last_unseen{$folder})) {
	if ($s =~ /(\d+)-(\d+)/) {
	    foreach $i ($1..$2) {
		$l[$i] = 1;
	    }
	} else {
	    $l[$s] = 1;
	}
    }

    # look at the length of the array to shortcut decision...
    if (@l > @u) {		# last unseen array longer -->
	$exit = 2;		# mail read in at least one folder
	next CHECK;		# so we look at the next folder...
    }
    if (@l > @u) {		# last unseen array shorter -->
	$exit = 0;		# certainly new mail here
	last CHECK;		# so we're done
    }

    # it seems that we have to look at the arrays in detail...
    for ($i=$#l+1; --$i; ){
	if ( $l[$i] && !$u[$i] ) {
	    $exit = 2;		# this message has been read
	} elsif ( !$l[$i] && $u[$i] ) {
	    $exit = 1;		# this message is new
	    last CHECK;		# so we're done
	}
    }
}

# save list of unseen mail
open(LAST, ">$last_unseen") || die "Cannot open $last_unseen for writing.\n";
foreach $folder (keys %unseen) {
    print LAST "$folder:$unseen{$folder}\n";
}
close LAST;

exit $exit;


Reply to: