Re: [vox-tech] mutt question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [vox-tech] mutt question
- Subject: Re: [vox-tech] mutt question
- From: Matt Roper <MAPSmdroper@ucdavis.edu>
- Date: Wed, 10 Jan 2001 19:45:14 -0800
- References: 20010110112928.A9989@dirac.org
I don't use mutt, so I don't know whether it has a builtin feature to
rotate sigs, but I think you can get this type of behavior by writing a
simple perl script that uses named pipes (also known as FIFOs). Basically
you convert your .signature file into a named pipe and then have a perl
script (or other small program) that acts as a daemon and sits in a loop
writing randomly selected signatures into .signature (re-opening and
closing the file for each signature). When another program (e.g. mutt)
wants to get your signature, it opens .signature for reading and reads
until it hits EOF. The reading program never even knows that .signature
isn't a regular file. When a program (in this case the daemon) tries to
open a named pipe for writing, the operating system causes the function
call to block until there is actually another program on the other side
trying to read from the named pipe, so your daemon isn't actually spinning
around inside an infinite loop if no programs are reading your signature.
I realize that explanation isn't very well written, so here's an example
of a signature daemon (written in perl) that basically does what you want.
I just hacked out this program in a few minutes, so there may be some
minor bugs in it that need to be ironed out, but it should give you the
general idea of what I'm talking about...
#!/usr/bin/perl
use strict;
my $NAMED_PIPE = "signature_file";
my $SIG_DB = "sigs.txt";
my $SIG_DELIM = "<<SIG>>"; ### Delimiter in sig database
my @allsigs; ### List of all signatures
my @cursig; ### Lines of signature being read from DB
### Make sure the named pipe exists. If not, set it up.
unless (-p $NAMED_PIPE) {
system("rm $NAMED_PIPE") if -e $NAMED_PIPE;
if (system("mkfifo $NAMED_PIPE")) {
die "Couldn't make named pipe ($NAMED_PIPE)\n";
}
}
### Read in possible signatures.
open(SIGDB,$SIG_DB) || die "Can't open signature database: $!\n";
while(my $line = <SIGDB>) {
if ($line =~ /$SIG_DELIM/) {
push(@allsigs,join("",@cursig));
@cursig = ();
next;
}
push(@cursig, $line);
}
push(@allsigs,join("",@cursig));
### Loop forever
while(1) {
open(SIG,">signature_file") || die "Can't write to named pipe.\n";
### Pick a signature file somehow...
my $sig = $allsigs[rand(scalar(@allsigs))];
### Send it to the named pipe
print SIG $sig;
### Close the named pipe (the current program will think it has read the
### entire file.
close(SIG);
### Prevent the next pipe we open from catching the end of the current
### request.
sleep 1;
}
On Wed, 10 Jan 2001, Peter Jay Salzman wrote:
> i assume this is a mutt question.
>
> is there a way of getting rotating .sigs?
>
> pete
>
Matt
=========================
Matt Roper
mdroper@ucdavis.edu
http://www.mattrope.com
=========================
|