]>
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";
26 my $spamurl = "http://spam.gmane.org/{group}:{msgnum}";
28 # List of groups to process
31 # Msgnum of the last visited article in the key group.
34 my @configfiles = ("/etc/gmanespam", $ENV{HOME
}."/.gmanespam");
35 my $statusfile = $ENV{HOME
}."/.gmanespamrc";
39 my $nntp = Net
::NNTP-
>new($server);
42 print "error: Unable to connect to NNTP server '$server'.\n";
46 my $ua = LWP
::UserAgent-
>new;
48 loadstatus
($statusfile);
50 for my $group (@groups) {
51 process_gmane_group
($group);
54 savestatus
($statusfile);
59 for my $filename (@configfiles) {
60 open (CFG
, "<$filename") || next;
66 $server = $1 if (m/^server (.+)$/);
67 $spamurl = $1 if (m/^spamurl (.+)$/);
68 push(@groups, $1) if (m/^group (.+)$/);
75 my $statusfile = shift;
76 open (STATUS
, "<$statusfile");
79 my ($groupname, $lastnum) = m/^(\S+): 1-(\d+)$/;
80 $grouplast{$groupname} = $lastnum;
86 my $statusfile = shift;
87 open(STATUS
, ">$statusfile") || die "Unable to write to $statusfile";
88 for my $groupname (sort keys %grouplast) {
89 print STATUS
"$groupname: 1-".$grouplast{$groupname}."\n";
94 sub process_gmane_group
{
96 my ($msgcount, $msgfirst, $msglast, $groupname) = $nntp->group($group);
97 my $curmsgnum = $grouplast{$groupname};
101 print "\n$groupname: $msgfirst -> $msglast ($msgcount)\n";
103 while ($aktive && ++$curmsgnum <= $msglast) {
104 print "\n[$curmsgnum/$msglast] ============ $groupname ===========\n";
106 my $headersref = $nntp->head($curmsgnum);
107 unless ($headersref) {
108 print "**** Message does not exist. Skipping.\n";
111 my ($spam, $subject, $from) = process_header
($headersref);
113 print "From: $from\n";
114 print "Subject: $subject\n";
116 print "**** Message already flagged as spam. Ignoring.\n";
119 print "Non-spam/Spam/sKip/view Body/view Full/jump #/Help/Quit [N] ? ";
123 if ("" eq $input || "n" eq $input) {
125 } elsif ("s" eq $input) {
127 push(@spammsgs, $curmsgnum);
128 } elsif ("q" eq $input) {
130 savestatus
($statusfile);
132 } elsif ($input =~ m/^(\d+)$/) {
134 $curmsgnum = $msglast if $curmsgnum > $msglast;
135 print "Jumping to message number $1\n";
137 } elsif ("k" eq $input) {
138 # Skip this group and move to the next group
140 } elsif ("f" eq $input) {
141 # View message header and body
142 my $articleref = $nntp->article($curmsgnum);
143 list_lines
($articleref);
145 } elsif ("b" eq $input) {
147 my $bodyref = $nntp->body($curmsgnum);
148 list_lines
($bodyref);
150 } elsif ("h" eq $input) {
153 print STDERR
"error: Unhandled choice '$input'\n";
157 print "Submit changes? [yes] ";
161 if ("" eq $input || "yes" eq $input) {
162 for my $msgnum (@spammsgs) {
163 report_spam
($groupname, $msgnum);
167 $grouplast{$groupname} = --$curmsgnum;
168 print "Storing $curmsgnum as last read message in $groupname\n";
172 my $arrayref = shift;
179 my $headerref = shift;
183 for (@{$headerref}) {
184 $from = $1 if m/^From: (.*)$/i;
185 $subject = $1 if m/^Subject: (.*)$/i;
186 $spam = 1 if m/Xref: .*gmane.spam.detected.*$/;
188 return ($spam, $subject, $from)
192 my ($groupname, $msgnum) = @_;
194 $url =~ s/{group}/$groupname/g;
195 $url =~ s/{msgnum}/$msgnum/g;
196 my $response = $ua->get($url);
197 if ($response->is_success) {
198 print "Reported $groupname:$msgnum as spam.\n";
200 die $response->status_line;