]>
pere.pagekite.me Git - homepage.git/blob - linux/gmanespam
3 # Author: Petter Reinholdtsen
5 # License: GNU Public License v2 or later
7 # Make it easier to report gmane messages as spam. List all new
8 # messages in a given group, and let the user mark a message as spam
9 # with a single keypress.
11 # Configuration is in ~/.gmanespam, with content like this:
12 # server news.gmane.org
13 # group gmane.linux.debian.devel.initscripts-ng
14 # group gmane.linux.debian.devel.java
16 # New version of this script is available from
17 # <URL:http://www.student.uit.no/~pere/linux/>
25 my $server = "news.gmane.org";
27 # List of groups to process
30 # Msgnum of the last visited article in the key group.
33 my @configfiles = ("/etc/gmanespam", $ENV{HOME
}."/.gmanespam");
34 my $statusfile = $ENV{HOME
}."/.gmanespamrc";
38 my $nntp = Net
::NNTP-
>new($server);
41 print "error: Unable to connect to NNTP server '$server'.\n";
45 my $ua = LWP
::UserAgent-
>new;
47 loadstatus
($statusfile);
49 for my $group (@groups) {
50 process_gmane_group
($group);
53 savestatus
($statusfile);
58 for my $filename (@configfiles) {
59 open (CFG
, "<$filename") || next;
65 $server = $1 if (m/^server (.+)$/);
66 push(@groups, $1) if (m/^group (.+)$/);
73 my $statusfile = shift;
74 open (STATUS
, "<$statusfile");
77 my ($groupname, $lastnum) = m/^(\S+): 1-(\d+)$/;
78 $grouplast{$groupname} = $lastnum;
84 my $statusfile = shift;
85 open(STATUS
, ">$statusfile") || die "Unable to write to $statusfile";
86 for my $groupname (sort keys %grouplast) {
87 print STATUS
"$groupname: 1-".$grouplast{$groupname}."\n";
92 sub process_gmane_group
{
94 my ($msgcount, $msgfirst, $msglast, $groupname) = $nntp->group($group);
95 my $curmsgnum = $grouplast{$groupname};
99 print "\n$groupname: $msgfirst -> $msglast ($msgcount)\n";
101 while (++$curmsgnum <= $msglast) {
102 print "\n[$curmsgnum/$msglast] ============ $groupname ===========\n";
104 my $headersref = $nntp->head($curmsgnum);
105 unless ($headersref) {
106 print "**** Message does not exist. Skipping.\n";
109 my ($spam, $subject, $from) = process_header
($headersref);
111 print "From: $from\n";
112 print "Subject: $subject\n";
114 print "**** Message already flagged as spam. Ignoring.\n";
117 print "Non-spam/Spam/view Body/view Full/jump #/Help/Quit [N] ? ";
121 if ("" eq $input || "n" eq $input) {
123 } elsif ("s" eq $input) {
125 push(@spammsgs, $curmsgnum);
126 } elsif ("q" eq $input) {
128 savestatus
($statusfile);
130 } elsif ($input =~ m/^(\d+)$/) {
132 $curmsgnum = $msglast if $curmsgnum > $msglast;
133 print "Jumping to message number $1\n";
136 print STDERR
"error: Unhandled choice '$input'\n";
139 for my $msgnum (@spammsgs) {
140 report_spam
($groupname, $msgnum);
142 $grouplast{$groupname} = --$curmsgnum;
143 print "Storing $curmsgnum as last read message in $groupname\n";
147 my $headerref = shift;
151 for (@{$headerref}) {
152 $from = $1 if m/^From: (.*)$/i;
153 $subject = $1 if m/^Subject: (.*)$/i;
154 $spam = 1 if m/Xref: .*gmane.spam.detected.*$/;
156 return ($spam, $subject, $from)
160 my ($groupname, $msgnum) = @_;
161 # Visit http://spam.gmane.org/gmane.linux.debian.devel.lsb:253
162 my $response = $ua->get("http://spam.gmane.org/$groupname:$msgnum");
163 if ($response->is_success) {
164 print "Reported $groupname:$msgnum as spam.\n";
166 die $response->status_line;