/usr/share/perl5/News/Scan/Article.pm is in libnews-scan-perl 0.53-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | package News::Scan::Article;
use strict;
use vars qw( $VERSION @ISA );
use Mail::Internet;
use Mail::Address;
use Date::Parse;
$VERSION = '0.51';
@ISA = qw( Mail::Internet );
sub new {
my $class = shift;
my $group = pop;
my $self = $class->SUPER::new(@_);
bless $self, $class;
$self->group($group);
$self->calculate_sizes;
if ($self->in_period($group->period)) {
return $self;
}
else {
return undef;
}
}
sub in_period {
my $self = shift;
my $period = shift(@_) * 60 * 60 * 24;
my $date = $self->head->get('Date');
return 0 unless (defined $date and $date);
chomp $date;
my $time = str2time $date;
if ($time < ($^T - $period)) {
return 0;
}
$self->group->earliest($time);
$self->group->latest($time);
1;
}
sub group {
my $self = shift;
if (@_) {
my $old = $self->{'news_scan_article_group'};
$self->{'news_scan_article_group'} = shift;
return $old;
}
else {
return $self->{'news_scan_article_group'};
}
}
sub calculate_sizes {
my $self = shift;
my $total = 0;
my $line;
## header
my $header_size = 0;
foreach $line (@{ $self->head->header }) {
$header_size += length $line;
$self->{'news_scan_article_header_lines'}++;
}
$total += $header_size;
$self->{'news_scan_article_header_size'} = $header_size;
## add a byte for the separator
$total++;
## signature (if present)
my @body = @{ $self->body };
my $sig_start = 0;
my $found_sig = 0;
foreach $line (reverse @body) {
$sig_start--;
if ($line =~ /^-- $/) {
$found_sig++;
last;
}
}
if ($found_sig) {
my @signature = splice @body, $sig_start;
shift @signature; ## toss cutline
$self->{'news_scan_article_sig_lines'} = @signature;
my $sig_size = 0;
foreach $line (@signature) {
$sig_size += length $line;
}
$self->{'news_scan_article_sig_size'} = $sig_size;
$total += $sig_size;
}
else {
$self->{'news_scan_article_sig_lines'} = 0;
$self->{'news_scan_article_sig_size'} = 0;
}
## body
my $body_size = 0;
foreach $line (@body) {
$body_size += length $line;
}
$self->{'news_scan_article_body_size'} = $body_size;
$self->{'news_scan_article_body_lines'} = @body;
$total += $body_size;
$self->{'news_scan_article_size'} = $total;
## original
if (my $group = $self->group || 0) {
my $quote_re = $group->quote_re;
if ($quote_re) {
my @orig = grep { ! /$quote_re/o } @body;
my $orig_size = 0;
foreach $line (@orig) {
$orig_size += length $line;
}
$self->{'news_scan_article_orig_size'} = $orig_size;
$self->{'news_scan_article_orig_lines'} = @orig;
}
}
else {
$self->{'news_scan_article_orig_size'} = 0;
$self->{'news_scan_article_orig_lines'} = 0;
}
}
sub author {
my $self = shift;
my $hd = $self->head || return;
my $from = $hd->get('Reply-To')
|| $hd->get('From')
|| $hd->get('Sender')
|| "";
chomp $from;
my $addr = ( Mail::Address->parse($from) )[0];
if (exists $self->group->aliases->{lc $addr->address}) {
## XXX: Danger, Will Robinson! Broken Encapsulation Alert!!!
$addr->[1] = $self->group->aliases->{lc $addr->address};
}
unless (defined $addr and ref $addr) {
return;
}
else {
return $addr;
}
}
sub message_id {
my $self = shift;
my $hdr = $self->head->get('Message-ID');
chomp $hdr;
$hdr;
}
sub subject {
my $self = shift;
my $hdr = $self->head->get('Subject');
chomp $hdr;
$hdr;
}
sub newsgroups {
my $self = shift;
my $hdr = $self->head->get('Newsgroups') || '';
$hdr =~ s/^\s+//;
$hdr =~ s/\s+$//;
split /\s*,+\s*/, $hdr;
}
sub size { $_[0]->{'news_scan_article_size'} }
sub header_size { $_[0]->{'news_scan_article_header_size'} }
sub body_size { $_[0]->{'news_scan_article_body_size'} }
sub orig_size { $_[0]->{'news_scan_article_orig_size'} }
sub sig_size { $_[0]->{'news_scan_article_sig_size'} }
sub header_lines { $_[0]->{'news_scan_article_header_lines'} }
sub body_lines { $_[0]->{'news_scan_article_body_lines'} }
sub orig_lines { $_[0]->{'news_scan_article_orig_lines'} }
sub sig_lines { $_[0]->{'news_scan_article_sig_lines'} }
1;
__END__
=head1 NAME
News::Scan::Article - collect information about news articles
=head1 SYNOPSIS
use News::Scan::Article;
my $art = News::Scan::Article->new( ARG, [ OPTIONS, ] SCAN );
=head1 DESCRIPTION
This module provides a derived class of C<Mail::Internet> whose objects
are suitable for digesting Usenet news articles.
=head1 CONSTRUCTOR
=over 4
=item new ( ARG, [ OPTIONS, ] SCAN-OBJ )
The C<ARG> and C<OPTIONS> parameters are identical to those required by
C<Mail::Internet>, except C<ARG> is required. See L<Mail::Internet>.
The C<SCAN> parameter should be a C<News::Scan> object. See L<News::Scan>.
If the article falls into the period of interest for C<SCAN>, the object
is returned, else C<undef>.
=back
=head1 METHODS
=over 4
=item group ( [ SCAN-OBJ ] )
Sets or returns an object's group depending on whether C<SCAN-OBJ> is
present.
=item author
Returns the article's author represented as a C<Mail::Address> object.
=item message_id
Returns the article's Message-ID.
=item subject
Returns the article's subject.
=item newsgroups
Returns the list of newsgroups this article was posted to.
=item size
Returns the size of this article in bytes.
=item header_size
Returns the size of this article's header in bytes.
=item header_lines
Returns the number of lines consumed in this article by headers.
=item body_size
Returns the size of this article's body in bytes.
=item body_lines
Returns the number of lines consumed in this article by the body.
=item orig_size
Returns the size of this article's original content in bytes. See
L<News::Scan/"QuoteRE">.
=item orig_lines
Returns the number of lines consumed in this article by original content.
Keep in mind that original content is a subset of the body.
=item sig_size
Returns the size of this article'ss signature in bytes.
=item sig_lines
Returns the number of lines consumed in this article by the signature.
=back
=head1 SEE ALSO
L<News::Scan>, L<Mail::Internet>, L<Mail::Address>
=head1 AUTHOR
Greg Bacon <gbacon@cs.uah.edu>
=head1 COPYRIGHT
Copyright (c) 1997 Greg Bacon. All Rights Reserved.
This library is free software. You may distribute and/or modify it under
the same terms as Perl itself.
=cut
|