News/Article/Cancel.pm untested

filter: Statementstmt 0.0% 0 / 102 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 35 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 207 CC 22 SCAR 58.5
CC
22
Cov
0%
make_cancel
462.0
verify_resurrected
6.0
BEGIN
2.0
CRAP 347.3
1 $VERSION = '0.71';
2 package News::Article::Cancel;
3 our $VERSION = '0.71';
4  
5 # -*- Perl -*- Thu Apr 22 10:49:53 CDT 2004
6 #############################################################################
7 # Written by Tim Skirvin <tskirvin@killfile.org>.
8 # Based on a script by Chris Lewis <clewis@bnr.ca>, and relying almost
9 # exclusively on the News::Article package written by Andrew Gierth
10 # <andrew@erlenstar.demon.co.uk>. Thanks, folks.
11 #
12 # Copyright 2000-2004 Tim Skirvin. Redistribution terms are in the
13 # documentation, and I'm sure you can find them.
14 #############################################################################
15  
16 =head1 NAME
17  
18 News::Article::Cancel - a module to generate accurate cancel messages
19  
20 =head1 SYNOPSIS
21  
22 use News::Article::Cancel;
23 my $article = new News::Article::Cancel(\*STDIN);
24 next if $article->verify_resurrected($GROUP);
25  
26 my $from = $article->header('from') || "";
27 my $subject = $article->header('subject') || "";
28 my $xauth = $article->header('x-auth') || "";
29 my $mid = $article->header('message-id') || "";
30 my $cancel = $article->make_cancel( $NAME, "moder",
31 "From: $from", "Subject: $subject", "Message-ID: $mid",
32 "X-Auth: $xauth");
33  
34 =head1 DESCRIPTION
35  
36 Creates a cancel message based on a Usenet article, which may be posted
37 normally to delete a message. Also adds a verification for reposted
38 messages in moderated newsgroups.
39  
40 =head1 USAGE
41  
42 =over 2
43  
44 =item use News::Article::Cancel;
45  
46 =back
47  
48 News::Article::Cancel is class that inherits News::Article and adds two
49 new functions: make_cancel() and verify_resurrected().
50  
51 =cut
52  
53 require 5; # Requires Perl 5
54  
55 use News::Article;
56 use Exporter;
57 use strict;
58  
59 use vars qw($KILL_CANCELS @ISA @EXPORT @EXPORT_OK );
60  
61 @ISA = qw( Exporter News::Article );
62  
63 =head2 Article Methods
64  
65 =over 4
66  
67 =item make_cancel ( CANCELLER TYPE [TEXT] )
68  
69 Creates a cancel message based on the current article and the given
70 C<TYPE>. C<CANCELLER> is the email address of the poster, and is
71 required; C<TEXT> is an array of lines which will be appended to cancel
72 message's body. C<TYPE> determines several characteristics of the cancel
73 message, and must be one of the following (not case sensitive):
74  
75 =over 2
76  
77 - spam - Spam, EMP, or ECP cancel.
78  
79 - spew - Spew cancel.
80  
81 - aup - Cancel by poster's service provider.
82  
83 - personal - Original article posted by user.
84  
85 - mmf - Make.Money.Fast cancel.
86  
87 - binary - Binary in a non-binary group.
88  
89 - moderator - Cancel by group moderator.
90  
91 - retromod - Cancel by group retromoderator.
92  
93 - forgery - Forged article.
94  
95 - request - Cancel by poster's request.
96  
97 =back
98  
99 make_cancel returns a News::Article object if successful, or an error
100 message if not.
101  
102 =cut
103  
104 sub make_cancel {
105 my $self = shift;
106 my ($canceller, $type, @text) = @_;
107  
108 return "No canceller given" unless $type;
109  
110 my ($PATH, $PREFIX, @BODY);
111 my $RAND = rand(32767); # A random number for message-ids
112 $RAND =~ s/\..*//;
113  
114 my $cancel = new News::Article;
115  
116 # Decide what kind of cancel this will be, based on $type
117 if ($type =~ /^(spam|emp|ecp)/i) {
118 $PATH = "cyberspam!not-for-mail";
119 $PREFIX = "cancel.";
120 @BODY = "Spam cancelled by $canceller";
121 } elsif ($type =~ /^spew/i) {
122 $PATH = "spewcancel!cyberspam!not-for-mail";
123 $PREFIX = "cancel.";
124 @BODY = "Spew cancelled by $canceller";
125 } elsif ($type =~ /^(mmf|make-)/i) {
126 $PATH = "mmfcancel!cyberspam!not-for-mail";
127 $PREFIX = "cancel.";
128 @BODY = "Make Money Fast cancelled by $canceller.";
129 } elsif ($type =~ /^binar/i) {
130 $PATH = "bincancel!cyberspam!not-for-mail";
131 $PREFIX = "cancel.";
132 @BODY = "Binary in a non-binary group cancelled by $canceller";
133 } elsif ($type =~ /^moder/i) {
134 $PATH = "not-for-mail";
135 $PREFIX = "can.$RAND.";
136 @BODY =
137 "Moderation approval forged (or in error) cancelled by $canceller";
138 } elsif ($type =~ /^retro/i) {
139 $PATH = "retromod!cyberspam!not-for-mail";
140 $PREFIX = "cancel.";
141 @BODY = "Article cancelled from retromoderated group by $canceller";
142 } elsif ($type =~ /^forge/i) {
143 $PATH = "not-for-mail";
144 $PREFIX = "can.$RAND.";
145 @BODY = "Forged message cancelled by $canceller.";
146 } elsif ($type =~ /^personal/i) {
147 $PATH = "not-for-mail";
148 $PREFIX = "can.$RAND.";
149 @BODY = "Personal message cancelled by $canceller";
150 } elsif ($type =~ /^(aup|isp|tos)/i) {
151 $PATH = "not-for-mail";
152 $PREFIX = 'cancel.';
153 @BODY = "Post in violation of terms-of-service cancelled by $canceller";
154 } elsif ($type =~ /^request/i) {
155 $PATH = "not-for-mail";
156 $PREFIX = "can.$RAND.";
157 @BODY = "Cancelled at original poster's request by $canceller";
158 } else {
159 return "Cancel-type \"$type\" not recognized";
160 }
161
162 # Create headers for the cancel and test to make sure a cancel is allowed.
163 return "No cancel issuer" unless $canceller;
164 if (defined $self->header('control') && $self->header('control') =~/cancel/) {
165 return "Shouldn't try to cancel cancels, often loops" unless $KILL_CANCELS;
166 }
167  
168 my @GROUPS = split /\s*,+\s*/, $self->header('newsgroups') ;
169 @GROUPS = grep !/test$/, @GROUPS; # Don't post to *.test
170 @GROUPS = "news.admin.misc" unless @GROUPS; # Default group
171 return "No newsgroups for cancel" unless @GROUPS;
172  
173 my $id = $self->header('message-id');
174 my $newid = $id;
175 $newid =~ s/^\s*<(.*)>\s*$/<$PREFIX$1>/;
176 return "Missing or bad Message-ID" unless ($id && $newid);
177
178 my $from = $self->header('sender') || $self->header('from');
179 # THIS IS A HACK. Ick ick ick! - Tue Jan 25 00:57:05 CST 2000
180 $from = $self->header('from') unless ($from =~ /\S+\@\S+/);
181 # $from =~ s/\(/</g; $from =~ s/\)/>/g; # MORE HACK
182 $from =~ s/(\S+\@[^.\s]+)/$1.com/g;
183 # $from =~ s/<\s*(.*)\s*>/<$1>/g;
184 $from = "\"$from\" <nobody\@nowhere.com>" unless $from =~ /@/;
185 return "Can't find original From" unless $from;
186  
187 # Set the headers and body of the cancel
188 $cancel->set_headers('Newsgroups', join(',', @GROUPS));
189 $cancel->set_headers('Path', $PATH || "");
190 $cancel->set_headers('Message-ID', $newid || "");
191 # $cancel->set_headers('From', $canceller); # More accurate
192 $cancel->set_headers('From', $from || "");
193 $cancel->set_headers('Sender', $from || "");
194 $cancel->set_headers('Control', "cancel $id" || "");
195 $cancel->set_headers('Subject', "cmsg cancel $id" || "");
196 $cancel->set_headers('Approved', $canceller || "");
197 $cancel->set_headers('X-Cancelled-By', $canceller || "");
198 $cancel->add_date;
199  
200 $cancel->set_body(@BODY, @text);
201
202 return $cancel;
203 }
204 push @EXPORT, qw( make_cancel );
205  
206 =over 4
207  
208 =item verify_resurrected ( GROUP )
209  
210 Does the same thing as C<verify_pgpmoose()>, but reformats the message for
211 a message reposted by Dave the Resurrector.
212  
213 =back
214  
215 =cut
216  
217 sub verify_resurrected {
218 my ($self, $group) = @_;
219 my $newarticle = new News::Article;
220  
221 my ($line, @oldbody);
222 my $oldfrom = $self->header('from') || "";
223 my $oldsubject = $self->header('subject') || "";
224 $oldsubject =~ s/^\s*REPOST:\s//;
225 my $oldid = $self->header('X-Original-Message-ID') || "";
226 my $oldxauth = $self->header('X-Auth') || "";
227 my $oldgroups = $self->header('newsgroups') || "";
228  
229 foreach $line ($self->body) {
230 last if $line =~ /^========= WAS CANCELLED BY =======:$/;
231 push (@oldbody, $line);
232 }
233  
234 $newarticle->set_headers('from', $oldfrom, 'subject', $oldsubject,
235 'message-id', $oldid, 'x-auth', $oldxauth,
236 'newsgroups', $oldgroups);
237 $newarticle->set_body( @oldbody );
238  
239 $newarticle->verify_pgpmoose($group);
240 }
241 push @EXPORT, qw( verify_resurrected );
242  
243 =head1 NOTES
244  
245 Standard article manipulation information can be read in the News::Article
246 manpages.
247  
248 Cancel messages are not toys. Before using this module, all users should
249 have a good idea of how cancels work, what they are used for, and what the
250 results of their actions may be. This information can be found in the
251 Cancel Messages FAQ, posted monthly to news.answers and available on the
252 web at <URL:http://www.killfile.org/faqs/cancel.html>.
253  
254 =head1 TODO
255  
256 Make sure I've got all of the different cancel types taken care of.
257  
258 =head1 SEE ALSO
259  
260 B<pgpmoose>, at B<http://www.killfile.org/~tskirvin/software/pgpmoose/>
261  
262 =head1 AUTHOR
263  
264 Written by Tim Skirvin <tskirvin@killfile.org>, based on a shell script by
265 Chris Lewis <clewis@bnr.ca>.
266  
267 =head1 COPYRIGHT
268  
269 Copyright 2000-2004 by Tim Skirvin <tskirvin@killfile.org>. This code may
270 be redistributed under the same terms as Perl itself.
271  
272 =cut
273  
274 ###############################################################################
275 ### Version History ###########################################################
276 ###############################################################################
277 # v0.1a Thu Apr 22 13:45:25 CDT 1999
278 ### First version. Unfinished, but it needs to be here so that I can get
279 ### pgpmoose.pl working again.
280 # v0.2a Wed Jul 7 19:28:17 CDT 1999
281 # Got the documentation done and fixed stuff up in general.
282 # v0.5b Mon Feb 7 17:10:35 CST 2000
283 ### Put it up on the website, made a few cosmetic changes. Need to work on
284 ### an installation script and stuff soon.
285 # v0.6b Fri Feb 11 16:27:41 CST 2000
286 ### Added verify_resurrected. We'll see what happens.
287 # v0.61b Mon Mar 13 18:08:57 CST 2000
288 ### Made some more hacks on the "make a from line" code. Ick.
289 # v0.70b Fri Feb 13 16:22:47 CST 2004
290 ### Why was I using News::Article namespace? I suck. Oh well.
291 # v0.71 Thu Apr 22 10:48:48 CDT 2004
292 ### Cleaning up the code and comments to match my normal work. Generally
293 ### matching things to the new version of pgpmoose. Better docs.
294  
295 1;