line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- Perl -*- |
2
|
|
|
|
|
|
|
########################################################################### |
3
|
|
|
|
|
|
|
# Written and maintained by Andrew Gierth |
4
|
|
|
|
|
|
|
# Thanks to Russ Allbery for comment and significant |
5
|
|
|
|
|
|
|
# contributions. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# Copyright 1997 Andrew Gierth. Redistribution terms at end of file. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# $Id: Article.pm 1.27 2002/08/11 22:51:38 andrew Exp $ |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# TODO: |
12
|
|
|
|
|
|
|
# - better way of handling the system-dependent configuration |
13
|
|
|
|
|
|
|
# - reformat source for 80 columns :-) |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
########################################################################### |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# Envelope, n. The coffin of a document; the scabbard of a bill; the husk |
18
|
|
|
|
|
|
|
# of a remittance; the bed-gown of a love-letter. |
19
|
|
|
|
|
|
|
# -- Ambrose Bierce |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
News::Article - Object for handling Usenet articles in mail or news form. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use News::Article; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
See below for functions available. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
An object for representing a Usenet article (or a mail |
35
|
|
|
|
|
|
|
message). Primarily written for use with mail2news and/or moderation |
36
|
|
|
|
|
|
|
programs. (Not really intended for transit use.) |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 USAGE |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
use News::Article; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Article exports nothing. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Article objects must be created with the I method. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
package News::Article; |
49
|
|
|
|
|
|
|
|
50
|
4
|
|
|
4
|
|
7124
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
135
|
|
51
|
4
|
|
|
4
|
|
7815
|
use SelfLoader; |
|
4
|
|
|
|
|
70413
|
|
|
4
|
|
|
|
|
293
|
|
52
|
|
|
|
|
|
|
|
53
|
4
|
|
|
4
|
|
41
|
use vars qw($VERSION @SENDMAIL %SPECIAL %UNIQUE); |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
265
|
|
54
|
4
|
|
|
4
|
|
4761
|
use subs qw(canonical fix_envelope source_init); |
|
4
|
|
|
|
|
97
|
|
|
4
|
|
|
|
|
23
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
($VERSION = (split (' ', q$Revision: 1.27 $ ))[1]) =~ s/\.(\d)$/.0$1/; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
########################################################################### |
59
|
|
|
|
|
|
|
# System-dependent configuration |
60
|
|
|
|
|
|
|
# |
61
|
|
|
|
|
|
|
# How to mail an article. The code assumes that this is a |
62
|
|
|
|
|
|
|
# sendmail-workalike; i.e. can accept envelope recipients as arguments |
63
|
|
|
|
|
|
|
# or -t to parse the headers for recipients. Also uses -f to set the |
64
|
|
|
|
|
|
|
# envelope sender (this may cause problems on pre-V8 sendmails if |
65
|
|
|
|
|
|
|
# used by an untrusted user). |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
@SENDMAIL = ((grep { -x $_ } |
68
|
|
|
|
|
|
|
qw(/usr/sbin/sendmail /usr/lib/sendmail /bin/false))[0], |
69
|
|
|
|
|
|
|
qw(-oi -oem)); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# End of system-dependent configuration |
72
|
|
|
|
|
|
|
########################################################################### |
73
|
|
|
|
|
|
|
# Constant data |
74
|
|
|
|
|
|
|
# |
75
|
|
|
|
|
|
|
# Words to treat specially when canonifying header names |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
%SPECIAL = map { lc $_ => $_ } |
78
|
|
|
|
|
|
|
qw(- _ ID PGP UIDL MIME NNTP SMTP IP URL HTTP WWW MimeOLE); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# RFC1036 (and news generally) is much less tolerant of multiple |
81
|
|
|
|
|
|
|
# fields than RFC822. 822 allows for multiple message-ids, which is |
82
|
|
|
|
|
|
|
# arguably seriously broken, so we ignore that. We list here only the |
83
|
|
|
|
|
|
|
# most significant news fields; handling the rest sensibly is up to |
84
|
|
|
|
|
|
|
# the caller. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
%UNIQUE = map { $_ => 1 } |
87
|
|
|
|
|
|
|
qw(date followup-to from message-id newsgroups path reply-to |
88
|
|
|
|
|
|
|
subject sender); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# Description of internal storage: |
91
|
|
|
|
|
|
|
# |
92
|
|
|
|
|
|
|
# $self->{Headers} |
93
|
|
|
|
|
|
|
# |
94
|
|
|
|
|
|
|
# A hash of header names to values. The value stored |
95
|
|
|
|
|
|
|
# is always a reference to an array of values. The value stored |
96
|
|
|
|
|
|
|
# always includes embedded newlines and whitespace, but not the |
97
|
|
|
|
|
|
|
# header name or leading whitespace after the colon. There is no |
98
|
|
|
|
|
|
|
# trailing newline on the value. |
99
|
|
|
|
|
|
|
# |
100
|
|
|
|
|
|
|
# $self->{RawHeaders} |
101
|
|
|
|
|
|
|
# |
102
|
|
|
|
|
|
|
# Array of headers as read from external source. One header per |
103
|
|
|
|
|
|
|
# element, with embedded newlines preserved (but trailing ones |
104
|
|
|
|
|
|
|
# removed). |
105
|
|
|
|
|
|
|
# |
106
|
|
|
|
|
|
|
# $self->{HeaderSeq} |
107
|
|
|
|
|
|
|
# |
108
|
|
|
|
|
|
|
# Only set if headers have been read in; array of canonical header |
109
|
|
|
|
|
|
|
# names, in the order they were read in. Used to derive this from |
110
|
|
|
|
|
|
|
# RawHeaders, but that's wrong if read_headers has been called more |
111
|
|
|
|
|
|
|
# than once. |
112
|
|
|
|
|
|
|
# |
113
|
|
|
|
|
|
|
# $self->{Envelope} |
114
|
|
|
|
|
|
|
# |
115
|
|
|
|
|
|
|
# Envelope From address. Set from a Unix-style "From " header on |
116
|
|
|
|
|
|
|
# read. When sending mail, the value here is used (unless undefined) |
117
|
|
|
|
|
|
|
# as the envelope sender. |
118
|
|
|
|
|
|
|
# |
119
|
|
|
|
|
|
|
# $self->{Body} |
120
|
|
|
|
|
|
|
# |
121
|
|
|
|
|
|
|
# Array of text lines forming the body. Never contains embedded |
122
|
|
|
|
|
|
|
# newlines. |
123
|
|
|
|
|
|
|
# |
124
|
|
|
|
|
|
|
# $self->{Sendmail} |
125
|
|
|
|
|
|
|
# |
126
|
|
|
|
|
|
|
# What to use to send mail. |
127
|
|
|
|
|
|
|
# |
128
|
|
|
|
|
|
|
# $self->{HdrsFirst}, $self->{HdrsEnd}, $self->{HdrsLast} |
129
|
|
|
|
|
|
|
# |
130
|
|
|
|
|
|
|
# settings of headers_first, headers_next and headers_last |
131
|
|
|
|
|
|
|
# |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
########################################################################### |
134
|
|
|
|
|
|
|
# CONSTRUCTION |
135
|
|
|
|
|
|
|
########################################################################### |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 Article Methods |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=over 4 |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item new () |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item new ( SOURCE [,MAXSIZE [,MAXHEADS]] ) |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Use this to create a new Article object. Makes an empty article if no |
146
|
|
|
|
|
|
|
parameters are specified, otherwise reads in an article from C |
147
|
|
|
|
|
|
|
as for C. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub new |
152
|
|
|
|
|
|
|
{ |
153
|
1
|
|
|
1
|
1
|
128
|
my $proto = shift; |
154
|
1
|
|
33
|
|
|
43
|
my $class = ref($proto) || $proto; |
155
|
1
|
|
|
|
|
12
|
my $self = { |
156
|
|
|
|
|
|
|
Headers => {}, |
157
|
|
|
|
|
|
|
RawHeaders => [], |
158
|
|
|
|
|
|
|
Envelope => undef, |
159
|
|
|
|
|
|
|
Sendmail => [ @SENDMAIL ], |
160
|
|
|
|
|
|
|
Body => [], |
161
|
|
|
|
|
|
|
}; |
162
|
1
|
|
|
|
|
4
|
bless $self,$class; |
163
|
|
|
|
|
|
|
|
164
|
1
|
50
|
|
|
|
4
|
if (@_) |
165
|
|
|
|
|
|
|
{ |
166
|
0
|
0
|
|
|
|
0
|
return undef unless defined ($_[0]); |
167
|
0
|
0
|
|
|
|
0
|
$self->read(@_) or return undef; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
1
|
|
|
|
|
5
|
$self; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# this shouldn't be needed. But SelfLoader tries to load it in derived |
174
|
|
|
|
|
|
|
# modules if it's not found here, and those modules may not have __DATA__ |
175
|
|
|
|
|
|
|
# tokens, leading to rude error messages. |
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
0
|
|
|
sub DESTROY {} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
SelfLoader->load_stubs(); |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
1; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
__DATA__ |