Article.pm

filter: Statementstmt 93.1% 27 / 29 Branchbran 16.6% 1 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 74.4% 35 / 47 CC 5 SCAR 15.8
CC
5
Cov
76%
new
8.7
BEGIN
1.0
BEGIN
1.0
CRAP 4.9
« FormArticle.pm ↑ Summary FormReply.pm »
1 # -*- Perl -*-
2 ###########################################################################
3 # Written and maintained by Andrew Gierth <andrew@erlenstar.demon.co.uk>
4 # Thanks to Russ Allbery <rra@stanford.edu> 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<new> method.
45  
46 =cut
47  
48 package News::Article;
49  
50 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 4 ▶use SelfLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 4 ▶use vars qw($VERSION @SENDMAIL %SPECIAL %UNIQUE);
Subroutine BEGIN: called CC=1 SCAR=0.0
54 4 ▶use subs qw(canonical fix_envelope source_init);
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 4 ($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 4 @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 4 %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 4 %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<SOURCE>
147 as for C<read>.
148  
149 =cut
150  
151 sub new
152 1 ▶{
Subroutine new: called CC=5 SCAR=21.6
Pod documented
153 1 my $proto = shift;
154 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
155 1 my $self = {
156 Headers => {},
157 RawHeaders => [],
158 Envelope => undef,
159 Sendmail => [ @SENDMAIL ],
160 Body => [],
161 };
162 1 bless $self,$class;
163  
164 1 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
165 {
166 0 ▶ return undef unless defined ($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 0 0
167 0 ▶ $self->read(@_) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->read(@_) or return undef 0 0 0
168 }
169  
170 1 $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 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
178  
179 4 SelfLoader->load_stubs();
180  
181 4 1;
182  
183 __DATA__
« FormArticle.pm ↑ Summary FormReply.pm »