Article View: news.software.nntp
Article #27148Re: NoCeM generation?
From: Alan Schwartz
Date: Tue, 24 Mar 1998 00:00
Date: Tue, 24 Mar 1998 00:00
153 lines
4903 bytes
4903 bytes
Dougal Campbell <dougal@vespucci.advicom.net> writes:
>I asked this a couple of months ago (in several places: newsgroups,
>mailing lists, private email to some current issuers....), but never
>got any responses except for other people looking for the same info.
>What the heck, let's try again....
>
>Does anyone out there already have code they're willing to share which
>will automatically generate NoCeM notices for spam? I've considered
>hacking it into CleanFeed, but I've been horribly short on time, and
>was hoping that I could mooch someone else's efforts :)
>
>I want to start issuing notices on a couple of regional
>hierarchies (hsv.* and alabama.*).
How about this:
#!/usr/local/bin/perl -w
#
# mknocem - Given a news article or mbox file of news articles on stdin,
# issue a NoCeM notice for those articles
#
# Copyright (c) 1998 by Alan Schwartz
#
use strict 'subs';
use strict 'refs';
use English;
use Mail::Header;
require 'ctime.pl';
#######################################################################
# USER CONFIGURATION: VARIABLES YOU MUST SET
#######################################################################
# Your email address
$issuer = 'myname@myhost';
# Location of the pgp program:
$pgp = '/usr/local/bin/pgp';
# The id of the PGP key to sign messages with
$pgpid = 'myname@myhost';
# Put your PGP key pass phrase here if you don't want to be
# prompted for it.
$ENV{'PGPPASS'} = 'pgp pass phrase here';
# The tag to go at the end of the Subject: header:
# Use "@@NCM" if you're hiding spam/spew
# Use "@@<newsgroup name>" if you're hiding off-topic postings
$subjecttag = '@@NCM';
# The "type" of notice. Example: spam, spew, mmf
$type = "spam";
# You can put an explanation here of the purpose of these notices.
# The paragraph must end with the string EOP, on a line by itself.
$explanation = <<'EOP';
This is an automatically generated NoCeM ("no-see-um") notice. It is
purely advisory and does not cancel the message listed below. It's a
convenience for Usenet readers who may choose to mark these articles as
"already read".
EOP
#######################################################################
# END OF USER CONFIGURATION
#######################################################################
sub read_mbox_stdin;
my @messages = read_mbox_stdin();
die "No articles to process\n" unless @messages;
my @nocems;
my $id = "$issuer-$$-" . time;
unless ($subjecttag eq '@@NCM') {
$newsgroup = $subjecttag;
$newsgroup =~ s/\@\@//;
}
my $nltab = "\n\t";
foreach my $msgref (@messages) {
my $header = new Mail::Header $msgref, MailFrom => 'IGNORE';
my $messageid = $header->get("Message-ID");
chomp($messageid);
my $newsgroups = $header->get("Newsgroups");
chomp($newsgroups);
$newsgroups =~ s/,/$nltab/og;
push(@nocems,"$messageid\t$newsgroups\n");
}
my $headers = <<EOP;
Newsgroups: alt.nocem.misc,news.lists.filters
From: $issuer
Subject: NoCeM notice $id $subjecttag
EOP
my $tempfile = "/tmp/mknocem.$$";
open(OUT,">$tempfile") or die "Unable to open temporary file $tempfile: $!\n";
print OUT <<EOP;
$explanation
\@\@BEGIN NCM HEADERS
Version: 0.93
Issuer: $issuer
Type: $type
Action: hide
EOP
print OUT "Newsgroup: $newsgroup\n" if $newsgroup;
print OUT "Count: ", scalar(@nocems), "\n";
print OUT '@@BEGIN NCM BODY', "\n";
print OUT join("",@nocems);
print OUT '@@END NCM BODY', "\n";
close(OUT);
system("$pgp -s $tempfile -u $pgpid");
open(OUT,"$tempfile.asc") or
die "Unable to open pgp-signed temporary file $tempfile.asc: $!\n";
print $headers;
print <OUT>;
close(OUT);
unlink("$tempfile");
unlink("$tempfile.asc");
exit 0;
# Based on read_mbox in Graham Barr's MailTools module
# Returns an array of references to messages, where each
# message is an array of lines.
sub read_mbox_stdin {
my @mail = ();
my $mail = [];
my $blank = 1;
while(<STDIN>) {
if($blank && /\AFrom .*\d{4}/) {
push(@mail, $mail) if scalar(@{$mail});
$mail = [ $_ ];
$blank = 0;
} else {
$blank = m#\A\Z#o ? 1 : 0;
push(@{$mail}, $_);
}
}
push(@mail, $mail) if scalar(@{$mail});
return wantarray ? @mail : \@mail;
}
Technical Details
Message-ID:
<6f8mus$1u26$1@piglet.cc.uic.edu>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mailReferences:
<6f8h32$q41$1@polo.advicom.net>Show Full Headers
Complete Article Headers
Message-ID: <6f8mus$1u26$1@piglet.cc.uic.edu> Subject: Re: NoCeM generation? Date: Tue, 24 Mar 1998 00:00:00 +0000 From: alansz@araw.mede.uic.edu (Alan Schwartz) References: <6f8h32$q41$1@polo.advicom.net> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail X-Deja-AN: 337227131 Keywords: nocem cleanfeed spam cancel Organization: University of Illinois at Chicago Newsgroups: news.software.nntp,alt.nocem.policy