🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #15464

Re: TRN: change .signature by newsgroup

#15464
From: Tim Pierce
Date: Wed, 22 Feb 1995 23:08
171 lines
6512 bytes
In article <3iearp$227@news.cais.com>, J.D. Falk <jdfalk@cais.com> wrote:

>	I currently use a Perl script to randomly choose my .signature 
>file (very simple -- each time I run it my .signature changes.)  Also, 
>there are a few newsgroups in which I'd like to consistently have the 
>same .signature (each and every time I post there.)

I wrote a Perl script a couple of years ago, based heavily
on Tom Christiansen's getsig.pl, to do just that.  It's not
entirely functional: it must be run by inews after your
article has been written (i.e. won't work with all TIN
implementations) and getting it to work right for Elm or
something would require a lot of work.

Here's the overview: create a directory named ".Signatures"
in your home directory.  (Or call it something else, and
change the value of $SIGS in the script.)  This directory
contains two configuration files, "news-index" and
"mail-index", which specify which signature to use for
different mail and news messages.

For example, here's the contents of a recent news-index file
of mine:

uchi\..*	local
soc\.motss	global
news\.		green-card
soc\.genealogy\.surnames	surnames
^		unsolicited-email

The first field is a regexp identifying the newsgroup in
question.  The second is the name of a file in your
.signatures directory to use as the .signature.
"green-card" is the "Green Card fodder" signature I was
using recently, "unsolicited-email" is the current one, and
so on.  The algorithm used is a first-match: if I
crossposted an article between uchi.general and
news-admin.misc, the script would use "local" for the
signature rather than "green-card."

Presented without warranty: you gets what you pays for.  Any
elegance, cleverness or beauty in this script is entirely
the fault of Tom Christiansen, and it's a wonder it survived
until the present day.

#!/usr/local/bin/perl
#
# signature.pl -- supply a .signature based on whether the newsgroup or
# recipient name matches a certain pattern
#
# Unless changed by the user, all signatures are in the directory
# $HOME/.Signatures.  This directory also contains two files, "news-index" and
# "mail-index".  Each line of each file contains two fields, separated
# by whitespace.  The first field is a regular expression matching a set
# of newsgroup names (or, in the case of mail-index, e-mail addresses),
# and the second field names the signature file that is to be used for
# those newsgroups (or mail addresses).
#
# This script first determines whether the user is posting or mailing
# based on the modification times of $HOME/.article and $HOME/.letter.
# Then it identifies the first recipient (either newsgroup or e-mail
# address) of the message and, for lack of a better yardstick, uses that
# as the sole determinant in choosing a .signature.  Then it searches
# news-index (or mail-index) for the first regexp that matches the
# target newsgroup or address, and uses the file thus named for the
# contents of the signature file.
#
# Tim Pierce, March 1993.  Liberally hacked from Tom Christiansen's
# sigrand.pl.
################################################################
# begin configuration section 

$MKNOD = "/etc/mknod";

&gethome;

$FIFO 		= "$DOTDIR/.signature";
$ART 		= "$DOTDIR/.article";
$LET            = "$DOTDIR/.letter";
$SIGS 		=   "$HOME/.Signatures";
$SEMA		=   "$HOME/.getsigpid";

# end configuration section -- HOME gets autoconf'd
################################################################

&setup;

&justme;

fork && exit; 	# be a daemon 

open (SEMA, ">$SEMA") || die "can't write $SEMA: $!";
print SEMA "$$\n";
close SEMA || die "can't close $SEMA: $!";

MAIN: while (1) {
    open (FIFO, "> $FIFO") || die "can't write $FIFO: $!";

    # choose signature based on mtimes of .article and .letter
    if ((stat($ART))[9] > (stat($LET))[9]) {
	$target = '^Newsgroups: ';
        $INFILE = $ART;
	$INDEX = "$SIGS/news-index";
    } else {
	$target = '^To: ';
        $INFILE = $LET;
	$INDEX = "$SIGS/mail-index";
    }
    $signame = &choose;

    if ($signame) {
       open (SIGFILE, "$SIGS/$signame");
       while (<SIGFILE>) { print FIFO; }
    } else {
       print "$0: warning: found no signature\n";
    }
    close FIFO;
    sleep 2; # to avoid dup sigs
}

################################################################

sub setup {
    unless (-p $FIFO) {
	if (!-e _) {
	    system("$MKNOD $FIFO p") && die "can't mknod $FIFO";
	    warn "created $FIFO as a named pipe\n";
	} else {
	    die "$0: won't overwrite file .signature\n";
	} 
    }
}

sub choose {
    local ($line, $pat, $file);
    open INFILE || die "cannot open $INFILE";
    while (<INFILE>) {
        /\S/ || return "";
	/$target/ && last;
    }
    ($_) = /: ([^,\s]*)/;
    open INDEX || die "cannot open $INDEX";
    while ($line = <INDEX>) {
	next if ($line =~ /^\#/);
	chop ($line);
	($pat, $file) = split (/\s+/, $line);
	last if /$pat/;
    }
    (defined ($line)) ? $file : "";
}

sub gethome {
    @pw = getpwuid($<);
    $HOME = $ENV{HOME} || $ENV{LOGDIR} || $pw[7]
		       || die "no home directory for user $<";
    $DOTDIR = $ENV{DOTDIR} || $HOME;
}

# "There can be only one."  --the Highlander
sub justme {
    if (open SEMA) {
	chop($pid = <SEMA>);
	kill(0, $pid) && die "$0 already running (pid $pid)\n";
	#warn "COOL: no $pid: $!";
	close SEMA;
    } 
} 

-- 
Unsolicited commercial electronic mail sent to this address will be
proofread at a cost of $200/hour (one half-hour minimum).
Technical Details
Message-ID: <D4FC9H.1qG@midway.uchicago.edu>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!archive!mbox2nntp-news.software.readers.mbox.zip!nntp.gmd.de!news.rwth-aachen.de!news.rhrz.uni-bonn.de!news.uni-stuttgart.de!rz.uni-karlsruhe.de!news.rz.uni-ulm.de!zib-berlin.de!news.mathworks.com!news.alpha.net!uwm.edu!vixen.cso.uiuc.edu!uchinews!twpierce
References: <3iearp$227@news.cais.com>

Show Full Headers
Complete Article Headers
Message-ID: <D4FC9H.1qG@midway.uchicago.edu>
Subject: Re: TRN: change .signature by newsgroup
Date: Wed, 22 Feb 1995 23:08:05 GMT
From: twpierce@midway.uchicago.edu (Tim Pierce)
References: <3iearp$227@news.cais.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!archive!mbox2nntp-news.software.readers.mbox.zip!nntp.gmd.de!news.rwth-aachen.de!news.rhrz.uni-bonn.de!news.uni-stuttgart.de!rz.uni-karlsruhe.de!news.rz.uni-ulm.de!zib-berlin.de!news.mathworks.com!news.alpha.net!uwm.edu!vixen.cso.uiuc.edu!uchinews!twpierce
Newsgroups: news.software.readers
X-Nntp-Posting-Host: quads.uchicago.edu
Keywords: trn signature macro
Sender: news@midway.uchicago.edu (News Administrator)
Organization: alt.* cabal, Professor Emeritus
Lines: 171