ContactForm.pm

filter: Statementstmt 11.1% 33 / 296 Branchbran 1.2% 2 / 162 Conditioncond 0.0% 0 / 98 MC/DCmcdc 0.0% 0 / 55 Subroutinesub 26.4% 9 / 34 Podpod 0.0% 0 / 18 totaltotal 6.6% 44 / 663 CC 127 SCAR 51.6
CC
127
Cov
6%
arguments
420.0
reformat
420.0
mailsend
240.0
CRAP 174.9
↑ Summary ContactForm/MHonArc.pm »
1 package CGI::ContactForm;
2  
3 1 $VERSION = '1.53';
4 # $Id: ContactForm.pm,v 1.76 2009/03/03 22:46:53 gunnarh Exp $
5  
6 =head1 NAME
7  
8 CGI::ContactForm - Generate a web contact form
9  
10 =head1 SYNOPSIS
11  
12 use CGI::ContactForm;
13  
14 contactform (
15 recname => 'John Smith',
16 recmail => 'john.smith@example.com',
17 styleurl => '/style/ContactForm.css',
18 );
19  
20 =head1 DESCRIPTION
21  
22 This module generates a contact form for the web when the routine C<contactform()>
23 is called from a CGI script. Arguments are passed to the module as a list of
24 key/value pairs.
25  
26 C<CGI::ContactForm> sends a well formated (plain text format=flowed in accordance
27 with RFC 2646) email message, with the sender's address in the C<From:> header.
28  
29 By default the sender gets a C<bcc> copy. If the email address stated by the
30 sender is invalid, by default the failure message is sent to the recipient address,
31 through which you know that you don't need to bother with a reply, at least not to
32 that address... However, by setting the C<nocopy> argument you can prevent the
33 sender copy from being sent.
34  
35 =head2 Arguments
36  
37 C<CGI::ContactForm> takes the following arguments:
38  
39 Default value
40 =============
41 Compulsory
42 ----------
43 recname (none)
44 recmail (none)
45  
46 Optional
47 --------
48 smtp 'localhost'
49 styleurl (none)
50 returnlinktext 'Main Page'
51 returnlinkurl '/'
52 subject (none)
53 nocopy 0
54 bouncetosender 0
55 formtmplpath (none)
56 resulttmplpath (none)
57 maxsize 100 (KiB)
58 maxperhour 5 (messages per hour per host)
59 tempdir (none)
60 spamfilter '(?is:</a>|\[/url]|https?:/(?:.+https?:/){3})' (Perl regex)
61  
62 Additional arguments, intended for forms at non-English sites
63 -------------------------------------------------------------
64 title 'Send email to'
65 namelabel 'Your name:'
66 emaillabel 'Your email:'
67 subjectlabel 'Subject:'
68 msglabel 'Message:'
69 reset 'Reset'
70 send 'Send'
71 erroralert 'Fields with %s need to be filled or corrected.'
72 marked 'marked labels'
73 thanks 'Thanks for your message!'
74 sent_to 'The message was sent to %s with a copy to %s.'
75 sent_to_short 'The message was sent to %s.'
76 encoding 'ISO-8859-1'
77  
78 =head2 Customization
79  
80 There are only two compulsory arguments. The example CGI script
81 C<contact.pl>, that is included in the distribution, also uses the C<styleurl>
82 argument, assuming the use of the enclosed style sheet C<ContactForm.css>.
83 That results in a decently styled form with a minimum of effort.
84  
85 If the default value C<localhost> isn't sufficient to identify the local SMTP
86 server, you may need to explicitly state its host name or IP address via the
87 C<smtp> argument.
88  
89 As you can see from the list over available arguments, all the text strings
90 can be changed, and as regards the presentation, you can of course edit the
91 style sheet to your liking.
92  
93 If you want to modify the HTML markup, you can have C<CGI::ContactForm> make
94 use of one or two templates. The enclosed example templates
95 C<ContactForm_form.tmpl> and C<ContactForm_result.tmpl> can be activated via
96 the C<formtmplpath> respective C<resulttmplpath> arguments, and used as a
97 starting point for a customized markup.
98  
99 =head2 Spam prevention
100  
101 Behind the scenes C<CGI::ContactForm> performs a few checks aiming to complicate
102 and/or discourage abuse in the form of submitted spam messages.
103  
104 =over 4
105  
106 =item *
107  
108 The number of messages that can be sent from the same host is restricted. The
109 default is 5 messages per hour.
110  
111 =item *
112  
113 A customizable spamfilter is applied to the body of the message. By default it
114 allows max 3 URLs that start with C<http://> or C<https://>, and it rejects
115 submissions with C<E<lt>/aE<gt>> or C<[/url]> in the message body.
116  
117 =item *
118  
119 When sending a message, the request must include a cookie.
120  
121 =back
122  
123 The thought is that normal use, i.e. establishing contact with somebody,
124 should typically not be affected by those checks.
125  
126 =head1 INSTALLATION
127  
128 =head2 Installation with Makefile.PL
129  
130 Type the following:
131  
132 perl Makefile.PL
133 make
134 make install
135  
136 =head2 Manual Installation
137  
138 =over 4
139  
140 =item *
141  
142 Download the distribution file and extract the contents.
143  
144 =item *
145  
146 Designate a directory as your local library for Perl modules, for instance
147  
148 /www/username/cgi-bin/lib
149  
150 =item *
151  
152 Create the directory C</www/username/cgi-bin/lib/CGI>, and upload
153 C<ContactForm.pm> to that directory.
154  
155 =item *
156  
157 Create the directory C</www/username/cgi-bin/lib/CGI/ContactForm>, and
158 upload C<MHonArc.pm> to that directory.
159  
160 =item *
161  
162 In the CGI scripts that use this module, include a line that tells Perl
163 to look for modules also in your local library, such as
164  
165 use lib '/www/username/cgi-bin/lib';
166  
167 =back
168  
169 =head2 Other Installation Matters
170  
171 If you have previous experience from installing CGI scripts, making
172 C<contact.pl> (or whichever name you choose) work should be easy.
173 Otherwise, this is a B<very> short lesson:
174  
175 =over 4
176  
177 =item 1.
178  
179 Upload the CGI file in ASCII transfer mode to your C<cgi-bin>.
180  
181 =item 2.
182  
183 Set the file permission 755 (chmod 755).
184  
185 =back
186  
187 If that doesn't do it, there are many CGI tutorials for beginners
188 available on the web. This is one example:
189  
190 http://my.execpc.com/~keithp/bdlogcgi.htm
191  
192 On some servers, the CGI file must be located in the C<cgi-bin> directory
193 (or in a C<cgi-bin> subdirectory). At the same time it's worth noting,
194 that the style sheet typically needs to be located somewhere outside the
195 C<cgi-bin>.
196  
197 =head1 DEPENDENCIES
198  
199 C<CGI::ContactForm> requires the non-standard modules L<CGI.pm|CGI> and
200 L<Mail::Sender|Mail::Sender>.
201  
202 =head1 AUTHENTICATION
203  
204 If you have access to a mail server that is configured to automatically
205 accept sending messages from a CGI script to any address, you don't need
206 to worry about authentication. Otherwise you need to somehow authenticate
207 to the server, for instance by adding something like this right after the
208 C<use CGI::ContactForm;> line in C<contact.pl>:
209  
210 %Mail::Sender::default = (
211 auth => 'LOGIN',
212 authid => 'username',
213 authpwd => 'password',
214 );
215  
216 C<auth> is the SMTP authentication protocol. Common protocols are C<LOGIN>
217 and C<PLAIN>. You may need help from the mail server's administrator to
218 find out which protocol and username/password pair to use.
219  
220 If there are multiple forms, a more convenient way to deal with a need
221 for authentication may be to make use of the C<Sender.config> file that
222 is included in the distribution. You just edit it and upload it to the
223 same directory as the one where C<Sender.pm> is located.
224  
225 See the L<Mail::Sender|Mail::Sender> documentation for further guidance.
226  
227 =head1 AUTHOR, COPYRIGHT AND LICENSE
228  
229 Copyright (c) 2003-2019 Gunnar Hjalmarsson
230 http://www.gunnar.cc/cgi-bin/contact.pl
231  
232 This module is free software; you can redistribute it and/or modify it
233 under the same terms as Perl itself.
234  
235 =head1 SEE ALSO
236  
237 L<CGI::ContactForm::MHonArc|CGI::ContactForm::MHonArc>,
238 L<Mail::Sender|Mail::Sender>
239  
240 =cut
241  
242 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
243 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
244 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
245 1 ▶use Fcntl qw(:DEFAULT :flock);
Subroutine BEGIN: called CC=1 SCAR=0.0
246 1 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
247 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
248 1 @ISA = 'Exporter';
249 1 @EXPORT = 'contactform';
250 1 @EXPORT_OK = 'CFdie';
251  
252 1 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=14.5
253 0 ▶ sub CFdie($) {
Subroutine CFdie: not called CC=3 SCAR=24.8
Pod undocumented
254 0 print "Status: 400 Bad Request\n";
255 0 print "Content-type: text/html\n\n<h1>Error</h1>\n<tt>", shift;
256 0 ▶ if ( $ENV{MOD_PERL} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"MOD_PERL"}) 0 0 0
257 0 ▶ if ( $] < 5.006 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.006") 0 0 0
258 0 require Apache;
259 0 Apache::exit();
260 }
261 }
262 0 exit 1;
263 }
264  
265 1 ▶ eval "use CGI 'escapeHTML'";
Subroutine BEGIN: called CC=1 SCAR=0.0
266 1 ▶ CFdie($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
267 1 ▶ eval "use Mail::Sender";
Subroutine BEGIN: called CC=1 SCAR=0.0
268 1 ▶ CFdie($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
269 }
270  
271 0 ▶sub contactform {
Subroutine contactform: not called CC=5 SCAR=34.0
Pod undocumented
272 0 local $^W = 1; # enables warnings
273 0 my ($error, $in) = {};
274 0 my $time = time;
275 0 ▶ my $host = $ENV{'REMOTE_ADDR'} or die "REMOTE_ADDR not set\n";
Branch: 1 branch
BranchTrueFalseTotal
my $host = $ENV{"REMOTE_ADDR"} or die "REMOTE_ADDR not set\n" 0 0 0
276 0 umask 0;
277 0 my $args = &arguments;
278 0 ▶ if ($ENV{REQUEST_METHOD} eq 'POST') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'REQUEST_METHOD'} eq 'POST') { } 0 0 0
279 0 checktimestamp( $args->{tempdir}, $time );
280 0 $in = formdata( $args->{maxsize} );
281 0 ▶ if (formcheck($in, $args->{subject}, $error) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (formcheck($in, $args->{"subject"}, $error) == 0) 0 0 0
282 0 checkspamfilter( $in->{message}, $args->{spamfilter} );
283 0 checkmaxperhour($args, $time, $host);
284 0 eval { mailsend($args, $in, $host) };
285 0 ▶ CFdie( escapeHTML(my $msg = $@) ) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
286 0 return;
287 }
288 } else {
289 0 settimestamp( $args->{tempdir}, $time );
290 }
291 0 formprint($args, $in, $error);
292 }
293  
294 0 ▶sub arguments {
Subroutine arguments: not called CC=20 SCAR=60.4
Pod undocumented
295 0 my %defaults = (
296 recname => '',
297 recmail => '',
298 smtp => 'localhost',
299 styleurl => '',
300 returnlinktext => 'Main Page',
301 returnlinkurl => '/',
302 subject => '',
303 nocopy => 0,
304 bouncetosender => 0,
305 formtmplpath => '',
306 resulttmplpath => '',
307 maxsize => 100,
308 maxperhour => 5,
309 tempdir => '',
310 spamfilter => '(?is:</a>|\[/url]|https?:/(?:.+https?:/){3})',
311 title => 'Send email to',
312 namelabel => 'Your name:',
313 emaillabel => 'Your email:',
314 subjectlabel => 'Subject:',
315 msglabel => 'Message:',
316 reset => 'Reset',
317 send => 'Send',
318 erroralert => 'Fields with %s need to be filled or corrected.',
319 marked => 'marked labels',
320 thanks => 'Thanks for your message!',
321 sent_to => 'The message was sent to %s with a copy to %s.',
322 sent_to_short => 'The message was sent to %s.',
323 encoding => 'ISO-8859-1',
324 );
325 0 my $error;
326 0 ▶ if ( @_ % 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2) 0 0 0
327 0 $error .= "Odd number of elements in argument list:\n"
328 . " The contactform() function expects a number of key/value pairs.\n";
329 }
330 0 my %args = ( %defaults, @_ );
331 0 for (qw/recname recmail/) {
332 0 ▶ $error .= "The compulsory argument '$_' is missing.\n" unless $args{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{$_} 0 0 0
333 }
334 0 for (keys %args) {
335 0 ▶ $error .= "Unknown argument: '$_'\n" unless defined $defaults{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $defaults{$_} 0 0 0
336 }
337 0 ▶ if ($args{recmail} and emailsyntax($args{recmail})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"recmail"} and emailsyntax($args{"recmail"})) 0 0 0
Condition0%0/3
$args{"recmail"} and emailsyntax($args{"recmail"})
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"recmail"} and emailsyntax($args{"recmail"})
$args{"recmail"} emailsyntax($args{"recmail"})
Truth table0%0/3
A and B
A= $args{"recmail"}B= emailsyntax($args{"recmail"})
ABresult
0X0
100
111
338 0 $error .= "'$args{recmail}' is not a valid email address.\n";
339 }
340 0 ▶ unless ($args{tempdir}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'tempdir'}) { } 0 0 0
if (do { not -d $args{"tempdir"} && -w _ && -x _ }) 0 0 0
341 0 ▶ unless (-d $CGITempFile::TMPDIRECTORY and -w _ and -x _) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $CGITempFile::TMPDIRECTORY and -w _ and -x _) 0 0 0
Condition0%0/6
-d $CGITempFile::TMPDIRECTORY and -w _ and -x _
!ll&&!rl&&r
000
-d $CGITempFile::TMPDIRECTORY and -w _
!ll&&!rl&&r
000
MC/DC0%0/3
-d $CGITempFile::TMPDIRECTORY and -w _ and -x _
-d $CGITempFile::TMPDIRECTORY -w _ -x _
Truth table0%0/4
A and B and C
A= -d $CGITempFile::TMPDIRECTORYB= -w _C= -x _
ABCresult
0XX0
10X0
1100
1111
342 0 $error .= "You need to state a temporary directory via the 'tempdir' argument.\n";
343 }
344 0 ▶ } elsif (!(-d $args{tempdir} and -w _ and -x _)) {
Condition0%0/6
-d $args{'tempdir'} && -w _ && -x _
!ll&&!rl&&r
000
-d $args{"tempdir"} and -w _
!ll&&!rl&&r
000
MC/DC0%0/3
-d $args{'tempdir'} && -w _ && -x _
-d $args{"tempdir"} -w _ -x _
Truth table0%0/4
A and B && C
A= -d $args{"tempdir"}B= -w _C= -x _
ABCresult
0XX0
10X0
1100
1111
345 0 $error .= "'$args{tempdir}' is not a writable directory.\n";
346 }
347 0 for ('formtmplpath', 'resulttmplpath') {
348 0 ▶ if ($args{$_} and !-f $args{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{$_} and not -f $args{$_}) 0 0 0
Condition0%0/3
$args{$_} and not -f $args{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{$_} and not -f $args{$_}
$args{$_} not -f $args{$_}
Truth table0%0/3
A and not(B)
A= $args{$_}B= not -f $args{$_}
ABresult
0X0
100
111
349 0 $error .= "Argument '$_': Can't find the file $args{$_}\n";
350 }
351 }
352 {
353 0 ▶ local $SIG{__WARN__} = sub { die $_[0] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
354 0 eval { $args{spamfilter} = qr($args{spamfilter}) };
355 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
356 0 my $mod_path = $INC{'CGI/ContactForm.pm'};
357 0 $@ =~ s/ at $mod_path.+//;
358 0 $error .= "Argument 'spamfilter': " . escapeHTML(my $err = $@);
359 }
360 }
361  
362 0 ▶ CFdie("<pre>$error" . <<'EXAMPLE'
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
363  
364 Example:
365  
366 contactform (
367 recname => 'John Smith',
368 recmail => 'john.smith@example.com',
369 );
370 EXAMPLE
371  
372 ) if $error;
373  
374 0 \%args;
375 }
376  
377 0 ▶sub formdata {
Subroutine formdata: not called CC=3 SCAR=24.8
Pod undocumented
378 0 my $max = shift;
379 0 ▶ if ($ENV{CONTENT_LENGTH} > 1024 * $max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"CONTENT_LENGTH"} > 1024 * $max) 0 0 0
380 0 CFdie("The message size exceeds the $max KiB limit.\n"
381 . '<p><a href="javascript:history.back(1)">Back</a>');
382 }
383  
384 # create hash reference to the form data
385 0 my $in = new CGI->Vars;
386  
387 # trim whitespace in message headers
388 0 for (qw/name email subject/) {
389 0 $in->{$_} =~ s/^\s+//;
390 0 $in->{$_} =~ s/\s+$//;
391 0 $in->{$_} =~ s/\s+/ /g;
392 }
393  
394 0 $in;
395 }
396  
397 0 ▶sub formcheck {
Subroutine formcheck: not called CC=7 SCAR=40.3
Pod undocumented
398 0 my ($in, $defaultsubject, $error) = @_;
399 0 ▶ for (qw/name message/) { $error->{$_} = ' class="error"' unless $in->{$_} }
Branch: 1 branch
BranchTrueFalseTotal
unless $in->{$_} 0 0 0
400 0 ▶ $error->{subject} = ' class="error"' unless $in->{subject} or $defaultsubject;
Branch: 1 branch
BranchTrueFalseTotal
unless $in->{"subject"} or $defaultsubject 0 0 0
Condition0%0/3
$in->{"subject"} or $defaultsubject
l!l&&r!l&&!r
000
MC/DC0%0/2
$in->{"subject"} or $defaultsubject
$in->{"subject"} $defaultsubject
Truth table0%0/3
A or B
A= $in->{"subject"}B= $defaultsubject
ABresult
1X1
011
000
401 0 ▶ $error->{email} = ' class="error"' if emailsyntax( $in->{email} );
Branch: 1 branch
BranchTrueFalseTotal
if emailsyntax($in->{"email"}) 0 0 0
402 0 ▶ %$error ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
%$error ? : 0 0 0
403 }
404  
405 0 ▶sub emailsyntax {
Subroutine emailsyntax: not called CC=4 SCAR=30.0
Pod undocumented
406 0 ▶ return 1 unless my ($localpart, $domain) = shift =~ /^(.+)@(.+)/;
Branch: 1 branch
BranchTrueFalseTotal
unless () = (shift()) =~ /^(.+)@(.+)/ 0 0 0
407 0 my $atom = '[^[:cntrl:] "(),.:;<>@\[\\\\\]]+';
408 0 my $qstring = '"(?:\\\\.|[^"\\\\\s]|[ \t])*"';
409 0 my $word = qr($atom|$qstring);
410 0 ▶ return 1 unless $localpart =~ /^$word(?:\.$word)*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $localpart =~ /^$word(?:\.$word)*$/ 0 0 0
411 0 ▶ $domain =~ /^$atom(?:\.$atom)+$/ ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$domain =~ /^$atom(?:\.$atom)+$/ ? : 0 0 0
412 }
413  
414 0 ▶sub mailsend {
Subroutine mailsend: not called CC=15 SCAR=54.8
Pod undocumented
415 0 my ($args, $in, $host) = @_;
416  
417 # Extra headers
418 0 my @extras = "X-Originating-IP: [$host]";
419 0 ▶ if ( my $agent = $ENV{'HTTP_USER_AGENT'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $agent = $ENV{"HTTP_USER_AGENT"}) 0 0 0
420 0 my @lines;
421 0 ▶ while ( $agent =~ /(.{1,66})(?:\s+|$)/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($agent =~ /(.{1,66})(?:\s+|$)/g) 0 0 0
422 0 push @lines, $1;
423 }
424 0 push @extras, 'User-Agent: ' . join("\r\n\t", @lines);
425 }
426 0 ▶ push @extras, "Referer: $ENV{'HTTP_REFERER'}" if $ENV{'HTTP_REFERER'};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"HTTP_REFERER"} 0 0 0
427 0 push @extras, "X-Mailer: CGI::ContactForm $VERSION at $ENV{HTTP_HOST}";
428  
429 # Make message format=flowed (RFC 2646)
430 0 eval "use Encode 2.23 ()";
431 0 ▶ my $convert = $@ ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 0 0
432 0 ▶ $in->{message} = Encode::decode( $args->{encoding}, $in->{message} ) if $convert;
Branch: 1 branch
BranchTrueFalseTotal
if $convert 0 0 0
433 0 $in->{message} = reformat( $in->{message}, { max_length => 66, opt_length => 66 } );
434 0 ▶ $in->{message} = Encode::encode( $args->{encoding}, $in->{message} ) if $convert;
Branch: 1 branch
BranchTrueFalseTotal
if $convert 0 0 0
435 0 push @extras, "Content-type: text/plain; charset=$args->{encoding}; format=flowed";
436  
437 # Send message
438 0 $Mail::Sender::NO_X_MAILER = 1;
439 0 $Mail::Sender::SITE_HEADERS = join "\r\n", @extras;
440 ref (new Mail::Sender -> MailMsg( {
441 smtp => $args->{smtp},
442 encoding => ( $in->{message} =~ /[[:^ascii:]]/ ? 'quoted-printable' : '7bit' ),
443 from => ( $args->{bouncetosender} ? $in->{email} : $args->{recmail} ),
444 fake_from => namefix( $in->{name}, $args->{encoding} ) . " <$in->{email}>",
445 to => namefix( $args->{recname}, $args->{encoding} ) . " <$args->{recmail}>",
446 bcc => ( $args->{nocopy} ? '' : $in->{email} ),
447 subject => mimeencode( $in->{subject}, $args->{encoding} ),
448 msg => $in->{message},
449 0 ▶ } )) or die "Cannot send mail. $Mail::Sender::Error\n";
Branch: 4 branches
BranchTrueFalseTotal
ref "Mail::Sender"->new->MailMsg({"smtp", $args->{"smtp"}, "encoding", $in->{"message"} =~ /[[:^ascii:]]/ ? "quoted-printable" : "7bit", "from", $args->{"bouncetosender"} ? $in->{"email"} : $args->{"recmail"}, "fake_from", namefix($in->{"name"}, $args->{"encoding"}) . qq[ <$in->{"email"}>], "to", namefix($args->{"recname"}, $args->{"encoding"}) . qq[ <$args->{"recmail"}>], "bcc", $args->{"nocopy"} ? "" : $in->{"email"}, "subject", mimeencode($in->{"subject"}, $args->{"encoding"}), "msg", $in->{"message"}}) or die "Cannot send mail. $Mail::Sender::Error\n" 0 0 0
$in->{'message'} =~ /[[:^ascii:]]/ ? : 0 0 0
$args->{'bouncetosender'} ? : 0 0 0
$args->{'nocopy'} ? : 0 0 0
450  
451 # Print resulting page
452 0 my @resultargs = qw/recname returnlinktext returnlinkurl title thanks/;
453 0 $args->{$_} = escapeHTML( $args->{$_} ) for @resultargs;
454 my $sent_to = sprintf escapeHTML( $args->{nocopy} ? $args->{sent_to_short} : $args->{sent_to} ),
455 0 ▶ "<b>$args->{recname}</b>", '<b>' . escapeHTML( $in->{email} ) . '</b>';
Branch: 1 branch
BranchTrueFalseTotal
$args->{'nocopy'} ? : 0 0 0
456 0 $args->{returnlinkurl} =~ s/ /%20/g;
457 0 ▶ if ( $args->{resulttmplpath} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'resulttmplpath'}) { } 0 0 0
458 0 my %result_vars;
459 0 $result_vars{style} = stylesheet( $args->{styleurl} );
460 0 $result_vars{sent_to} = \$sent_to;
461 0 $result_vars{$_} = \$args->{$_} for @resultargs;
462 0 templateprint($args->{resulttmplpath}, $args->{encoding}, %result_vars);
463 } else {
464 0 headprint($args);
465  
466 0 print <<RESULT;
467 <h1>$args->{thanks}</h1>
468 <p>$sent_to</p>
469 <p class="returnlink"><a href="$args->{returnlinkurl}">$args->{returnlinktext}</a></p>
470 </body>
471 </html>
472 RESULT
473 }
474 }
475  
476 0 ▶sub formprint {
Subroutine formprint: not called CC=14 SCAR=53.5
Pod undocumented
477 0 my ($args, $in, $error) = @_;
478 0 ▶ my $scriptname = basename( $0 or $ENV{SCRIPT_FILENAME} );
Condition0%0/3
$0 || $ENV{'SCRIPT_FILENAME'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$0 || $ENV{'SCRIPT_FILENAME'}
$0 $ENV{'SCRIPT_FILENAME'}
Truth table0%0/3
A || B
A= $0B= $ENV{'SCRIPT_FILENAME'}
ABresult
1X1
011
000
479 my $erroralert = %$error ? '<p class="erroralert">'
480 . sprintf( escapeHTML( $args->{erroralert} ), '<span class="error">'
481 0 ▶ . "\n" . escapeHTML( $args->{marked} ) . '</span>' ) . '</p>' : '';
Branch: 1 branch
BranchTrueFalseTotal
%$error ? : 0 0 0
482 0 my @formargs = qw/recname returnlinktext returnlinkurl title namelabel
483 emaillabel subjectlabel msglabel reset send/;
484 0 $args->{$_} = escapeHTML( $args->{$_} ) for @formargs;
485 0 $args->{returnlinkurl} =~ s/ /%20/g;
486 0 ▶ $in->{subject} ||= $args->{subject};
Condition0%0/3
$in->{"subject"} ||= $args->{"subject"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$in->{"subject"} ||= $args->{"subject"}
$in->{"subject"} $args->{"subject"}
Truth table0%0/3
A ||= B
A= $in->{"subject"}B= $args->{"subject"}
ABresult
1X1
011
000
487 0 for (qw/name email subject message/) {
488 0 ▶ $in->{$_} = $in->{$_} ? escapeHTML( $in->{$_} ) : '';
Branch: 1 branch
BranchTrueFalseTotal
$in->{$_} ? : 0 0 0
489 0 ▶ $error->{$_} ||= '';
Condition0%0/2
$error->{$_} ||= ""
l!l
00
MC/DC0%0/1
$error->{$_} ||= ""
$error->{$_}
Truth table0%0/2
A
A= $error->{$_}
Aresult
11
00
490 }
491  
492 # Prevent horizontal scrolling in NS4
493 my $softwrap = ($ENV{HTTP_USER_AGENT} and $ENV{HTTP_USER_AGENT} =~ /Mozilla\/[34]/
494 0 ▶ and $ENV{HTTP_USER_AGENT} !~ /MSIE|Opera/) ? ' wrap="soft"' : '';
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'HTTP_USER_AGENT'} && $ENV{'HTTP_USER_AGENT'} =~ m[Mozilla/[34]] && !($ENV{'HTTP_USER_AGENT'} =~ /MSIE|Opera/) ? : 0 0 0
Condition0%0/6
$ENV{"HTTP_USER_AGENT"} and $ENV{"HTTP_USER_AGENT"} =~ m[Mozilla/[34]] and not $ENV{"HTTP_USER_AGENT"} =~ /MSIE|Opera/
!ll&&!rl&&r
000
$ENV{"HTTP_USER_AGENT"} and $ENV{"HTTP_USER_AGENT"} =~ m[Mozilla/[34]]
!ll&&!rl&&r
000
MC/DC0%0/3
$ENV{"HTTP_USER_AGENT"} and $ENV{"HTTP_USER_AGENT"} =~ m[Mozilla/[34]] and not $ENV{"HTTP_USER_AGENT"} =~ /MSIE|Opera/
$ENV{"HTTP_USER_AGENT"} $ENV{"HTTP_USER_AGENT"} =~ m[Mozilla/[34]] not $ENV{"HTTP_USER_AGENT"} =~ /MSIE|Opera/
Truth table0%0/4
A and B and not(C)
A= $ENV{"HTTP_USER_AGENT"}B= $ENV{"HTTP_USER_AGENT"} =~ m[Mozilla/[34]]C= not $ENV{"HTTP_USER_AGENT"} =~ /MSIE|Opera/
ABCresult
0XX0
10X0
1100
1111
495  
496 0 ▶ if ( $args->{formtmplpath} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'formtmplpath'}) { } 0 0 0
497 0 my %form_vars;
498 0 $form_vars{style} = stylesheet( $args->{styleurl} );
499 0 $form_vars{scriptname} = \$scriptname;
500 0 $form_vars{erroralert} = \$erroralert;
501 0 $form_vars{$_} = \$args->{$_} for @formargs;
502 0 for (qw/name email subject message/) {
503 0 $form_vars{$_} = \$in->{$_};
504 0 $form_vars{$_.'error'} = \$error->{$_};
505 }
506 0 $form_vars{softwrap} = \$softwrap;
507 0 templateprint($args->{formtmplpath}, $args->{encoding}, %form_vars);
508 } else {
509 0 headprint($args);
510  
511 0 print <<FORM;
512 <form action="$scriptname" method="post">
513 <table cellpadding="3">
514 <tr>
515 <td colspan="4"><h1 class="halign">$args->{title} $args->{recname}</h1></td>
516 </tr><tr>
517 <td><p$error->{name}>$args->{namelabel}</p></td><td><input type="text" name="name"
518 value="$in->{name}" size="20" />&nbsp;</td>
519 <td><p$error->{email}>$args->{emaillabel}</p></td><td><input type="text" name="email"
520 value="$in->{email}" size="20" /></td>
521 </tr><tr>
522 <td><p$error->{subject}>$args->{subjectlabel}</p></td>
523 <td colspan="3"><input type="text" name="subject" value="$in->{subject}" size="55" /></td>
524 </tr><tr>
525 <td colspan="4"><p$error->{message}>$args->{msglabel}</p></td>
526 </tr><tr>
527 <td colspan="4">
528 <textarea name="message" rows="8" cols="65"$softwrap>$in->{message}</textarea>
529 </td>
530 </tr><tr>
531 <td colspan="4" class="halign">
532 $erroralert
533 <input class="button" type="reset" value="$args->{reset}" />&nbsp;&nbsp;
534 <input class="button" type="submit" value="$args->{send}" /></td>
535 </tr><tr>
536 <td colspan="4"><p class="returnlink"><a href="$args->{returnlinkurl}">
537 $args->{returnlinktext}</a></p></td>
538 </tr>
539 </table>
540 </form>
541 </body>
542 </html>
543 FORM
544 }
545 }
546  
547 0 ▶sub headprint {
Subroutine headprint: not called CC=1 SCAR=6.9
Pod undocumented
548 0 my $args = shift;
549 0 print "Content-type: text/html; charset=$args->{encoding}\n\n";
550 0 print <<HEAD;
551 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
552 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
553 <html xmlns="http://www.w3.org/1999/xhtml">
554 <head>
555 <title>$args->{title} $args->{recname}</title>
556 <style type="text/css">
557 .error { font-weight: bold }
558 </style>
559 0 ${ stylesheet( $args->{styleurl} ) }
560 </head>
561 <body>
562 HEAD
563 }
564  
565 0 ▶sub stylesheet {
Subroutine stylesheet: not called CC=2 SCAR=17.9
Pod undocumented
566 0 ▶ my $url = shift || return \'';
Condition0%0/2
shift() || (return \'')
l!l
00
MC/DC0%0/1
shift() || (return \'')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
567 0 $url =~ s/ /%20/g;
568 0 \('<link rel="stylesheet" type="text/css" href="' . $url . '" />');
569 }
570  
571 0 ▶sub templateprint {
Subroutine templateprint: not called CC=4 SCAR=30.0
Pod undocumented
572 0 my ($template, $encode, %tmpl_vars) = @_;
573 0 my $error;
574 0 ▶ open FH, "< $template" or die "Can't open $template\n$!";
Branch: 1 branch
BranchTrueFalseTotal
open FH, "< $template" or die "Can't open $template\n$!" 0 0 0
575 0 my $output = do { local $/; <FH> };
576 0 close FH;
577 0 $output =~ s[<(?:!--\s*)?tmpl_var\s*(?:name\s*=\s*)?
578 (?:"([^">]*)"|'([^'>]*)'|([^\s=>]*))
579 \s*(?:--)?>][
580 0 ▶ if ( $tmpl_vars{lc $+} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmpl_vars{lc $+}) { } 0 0 0
581 0 ${ $tmpl_vars{lc $+} };
582 } else {
583 0 $error .= "Unknown template variable: '$+'\n";
584 }
585 ]egix;
586 0 ▶ CFdie("<pre>$error") if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
587 0 print "Content-type: text/html; charset=$encode\n\n";
588 0 print $output;
589 }
590  
591 0 ▶sub namefix {
Subroutine namefix: not called CC=3 SCAR=24.8
Pod undocumented
592 0 my $name = $_[0];
593 0 ▶ if ($name =~ /[[:^ascii:]]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /[[:^ascii:]]/) 0 0 0
594 0 return &mimeencode;
595 }
596 0 ▶ if ($name =~ /[^ \w]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /[^ \w]/) 0 0 0
597 0 $name =~ tr/"/'/;
598 0 $name = qq{"$name"};
599 }
600 0 $name;
601 }
602  
603 0 ▶sub mimeencode {
Subroutine mimeencode: not called CC=3 SCAR=24.8
Pod undocumented
604 0 my ($str, $enc) = @_;
605 0 ▶ return $str unless $str =~ /[[:^ascii:]]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $str =~ /[[:^ascii:]]/ 0 0 0
606 0 my @parts;
607 0 ▶ while ( $str =~ /(.{1,40}.*?(?:\s|$))/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /(.{1,40}.*?(?:\s|$))/g) 0 0 0
608 0 my $part = $1;
609 0 push @parts, MIME::QuotedPrint::encode($part, '');
610 }
611 0 join "\r\n\t", map { "=?$enc?Q?$_?=" } @parts;
612 }
613  
614 0 ▶sub reformat {
Subroutine reformat: not called CC=20 SCAR=60.4
Pod undocumented
615 # This subroutine was initially copied from Text::Flowed v0.14, written by
616 # Philip Mak. It has undergone a couple of changes since.
617  
618 # Help functions in Text::Flowed nested into this copy of reformat()
619 0 ▶ sub _num_quotes { $_[0] =~ /^(>*)/; length $1 }
Subroutine _num_quotes: not called CC=1 SCAR=6.9
620 0 ▶ sub _unquote { my $line = shift; $line =~ s/^(>+)//g; $line }
Subroutine _unquote: not called CC=1 SCAR=6.9
621 0 ▶ sub _flowed {
Subroutine _flowed: not called CC=2 SCAR=17.9
622 0 my $line = shift;
623 # Lines with only spaces in them are not considered flowed
624 # (heuristic to recover from sloppy user input)
625 0 ▶ return 0 if $line =~ /^ *$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^ *$/ 0 0 0
626 0 $line =~ / $/;
627 }
628 0 ▶ sub _trim { local *_ = \shift; s/ +$//g; $_ }
Subroutine _trim: not called CC=1 SCAR=6.9
629 0 ▶ sub _stuff {
Subroutine _stuff: not called CC=5 SCAR=34.0
630 0 my ($text, $num_quotes) = @_;
631 0 ▶ if ($text =~ /^ / || $text =~ /^>/ || $text =~ /^From / || $num_quotes > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /^ / or $text =~ /^>/ or $text =~ /^From / or $num_quotes > 0) 0 0 0
Condition0%0/9
$text =~ /^ / or $text =~ /^>/ or $text =~ /^From / or $num_quotes > 0
l!l&&r!l&&!r
000
$text =~ /^ / or $text =~ /^>/ or $text =~ /^From /
l!l&&r!l&&!r
000
$text =~ /^ / or $text =~ /^>/
l!l&&r!l&&!r
000
MC/DC0%0/4
$text =~ /^ / or $text =~ /^>/ or $text =~ /^From / or $num_quotes > 0
$text =~ /^ / $text =~ /^>/ $text =~ /^From / $num_quotes > 0
Truth table0%0/5
A or B or C or D
A= $text =~ /^ /B= $text =~ /^>/C= $text =~ /^From /D= $num_quotes > 0
ABCDresult
1XXX1
01XX1
001X1
00011
00000
632 0 return " $text";
633 }
634 0 $text;
635 }
636 0 ▶ sub _unstuff { local *_ = \shift; s/^ //; $_ }
Subroutine _unstuff: not called CC=1 SCAR=6.9
637  
638 0 my @input = split "\n", $_[0];
639 0 my $args = $_[1];
640 0 ▶ $args->{max_length} ||= 79;
Condition0%0/2
$args->{"max_length"} ||= 79
l!l
00
MC/DC0%0/1
$args->{"max_length"} ||= 79
$args->{"max_length"}
Truth table0%0/2
A
A= $args->{"max_length"}
Aresult
11
00
641 0 ▶ $args->{opt_length} ||= 72;
Condition0%0/2
$args->{"opt_length"} ||= 72
l!l
00
MC/DC0%0/1
$args->{"opt_length"} ||= 72
$args->{"opt_length"}
Truth table0%0/2
A
A= $args->{"opt_length"}
Aresult
11
00
642 0 my @output = ();
643  
644 # Process message line by line
645 0 ▶ while (@input) {
Branch: 1 branch
BranchTrueFalseTotal
if (@input) 0 0 0
646 # Count and strip quote levels
647 0 my $line = shift @input;
648 0 my $num_quotes = _num_quotes($line);
649 0 $line = _unquote($line);
650  
651 # Should we interpret this line as flowed?
652 0 ▶ if ( !$args->{fixed} || ( $args->{fixed} == 1 && $num_quotes ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $args->{"fixed"} or $args->{"fixed"} == 1 and $num_quotes) 0 0 0
Condition0%0/6
not $args->{"fixed"} or $args->{"fixed"} == 1 and $num_quotes
l!l&&r!l&&!r
000
$args->{"fixed"} == 1 and $num_quotes
!ll&&!rl&&r
000
MC/DC0%0/3
not $args->{"fixed"} or $args->{"fixed"} == 1 and $num_quotes
not $args->{"fixed"} $args->{"fixed"} == 1 $num_quotes
Truth table0%0/4
not(A) or B and C
A= not $args->{"fixed"}B= $args->{"fixed"} == 1C= $num_quotes
ABCresult
1XX1
0111
00X0
0100
653 0 $line = _unstuff($line);
654 # While line is flowed, and there is a next line, and the
655 # next line has the same quote depth
656 0 ▶ while (_flowed($line) && @input && _num_quotes($input[0]) == $num_quotes) {
Branch: 1 branch
BranchTrueFalseTotal
if (_flowed($line) and @input and _num_quotes($input[0]) == $num_quotes) 0 0 0
Condition0%0/6
_flowed($line) and @input and _num_quotes($input[0]) == $num_quotes
!ll&&!rl&&r
000
_flowed($line) and @input
!ll&&!rl&&r
000
MC/DC0%0/3
_flowed($line) and @input and _num_quotes($input[0]) == $num_quotes
_flowed($line) @input _num_quotes($input[0]) == $num_quotes
Truth table0%0/4
A and B and C
A= _flowed($line)B= @inputC= _num_quotes($input[0]) == $num_quotes
ABCresult
0XX0
10X0
1100
1111
657 # Join the next line
658 0 $line .= _unstuff(_unquote(shift @input));
659 }
660 }
661 # Ensure line is fixed, since we joined all flowed lines
662 0 $line = _trim($line);
663  
664 # Increment quote depth if we're quoting
665 0 ▶ $num_quotes++ if $args->{quote};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"quote"} 0 0 0
666  
667 0 ▶ if ( !( defined $line and length $line ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $line && length $line) { } 0 0 0
elsif (length($line) + $num_quotes <= $args->{'max_length'} - 1) { } 0 0 0
Condition0%0/3
defined $line && length $line
!ll&&!rl&&r
000
MC/DC0%0/2
defined $line && length $line
defined $line length $line
Truth table0%0/3
A && B
A= defined $lineB= length $line
ABresult
0X0
100
111
668 # Line is empty
669 0 push @output, '>' x $num_quotes;
670 } elsif (length($line) + $num_quotes <= $args->{max_length} - 1) {
671 # Line does not require rewrapping
672 0 push @output, '>' x $num_quotes . _stuff($line, $num_quotes);
673 } else {
674 # Rewrap this paragraph
675 0 ▶ while ( defined $line and length $line ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line and length $line) 0 0 0
Condition0%0/3
defined $line and length $line
!ll&&!rl&&r
000
MC/DC0%0/2
defined $line and length $line
defined $line length $line
Truth table0%0/3
A and B
A= defined $lineB= length $line
ABresult
0X0
100
111
676 # Stuff and re-quote the line
677 0 $line = '>' x $num_quotes . _stuff($line, $num_quotes);
678  
679 # Set variables used in regexps
680 0 my $min = $num_quotes + 1;
681 0 my $opt1 = $args->{opt_length} - 1;
682 0 my $max1 = $args->{max_length} - 1;
683 0 ▶ if ( length($line) <= $args->{opt_length} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $line <= $args->{'opt_length'}) { } 0 0 0
elsif ($line =~ /^(.{$min,$opt1}) (.*)/ or $line =~ /^(.{$min,$max1}) (.*)/ or $line =~ /^(.{$min,}) (.*)/) { } 0 0 0
684 # Remaining section of line is short enough
685 0 push @output, $line;
686 0 last;
687 ▶ } elsif ( $line =~ /^(.{$min,$opt1}) (.*)/ ||
Condition0%0/6
$line =~ /^(.{$min,$opt1}) (.*)/ or $line =~ /^(.{$min,$max1}) (.*)/ or $line =~ /^(.{$min,}) (.*)/
l!l&&r!l&&!r
000
$line =~ /^(.{$min,$opt1}) (.*)/ or $line =~ /^(.{$min,$max1}) (.*)/
l!l&&r!l&&!r
000
MC/DC0%0/3
$line =~ /^(.{$min,$opt1}) (.*)/ or $line =~ /^(.{$min,$max1}) (.*)/ or $line =~ /^(.{$min,}) (.*)/
$line =~ /^(.{$min,$opt1}) (.*)/ $line =~ /^(.{$min,$max1}) (.*)/ $line =~ /^(.{$min,}) (.*)/
Truth table0%0/4
A or B or C
A= $line =~ /^(.{$min,$opt1}) (.*)/B= $line =~ /^(.{$min,$max1}) (.*)/C= $line =~ /^(.{$min,}) (.*)/
ABCresult
1XX1
01X1
0011
0000
688 $line =~ /^(.{$min,$max1}) (.*)/ || $line =~ /^(.{$min,}) (.*)/ ) {
689 # 1. Try to find a string as long as opt_length.
690 # 2. Try to find a string as long as max_length.
691 # 3. Take the first word.
692 0 push @output, "$1 ";
693 0 $line = $2;
694 } else {
695 # One excessively long word left on line
696 0 push @output, $line;
697 0 last;
698 }
699 }
700 }
701 }
702  
703 0 join("\n", @output)."\n";
704 }
705  
706 0 ▶sub checktimestamp {
Subroutine checktimestamp: not called CC=8 SCAR=42.8
Pod undocumented
707 0 my ($tempdir, $time) = @_;
708 0 ▶ $tempdir ||= $CGITempFile::TMPDIRECTORY;
Condition0%0/3
$tempdir ||= $CGITempFile::TMPDIRECTORY
l!l&&r!l&&!r
000
MC/DC0%0/2
$tempdir ||= $CGITempFile::TMPDIRECTORY
$tempdir $CGITempFile::TMPDIRECTORY
Truth table0%0/3
A ||= B
A= $tempdirB= $CGITempFile::TMPDIRECTORY
ABresult
1X1
011
000
709 0 my $cookie;
710 0 ▶ unless ( $ENV{HTTP_COOKIE} and ($cookie) = $ENV{HTTP_COOKIE} =~ /\bContactForm_time=(\d+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"HTTP_COOKIE"} and ($cookie) = $ENV{"HTTP_COOKIE"} =~ /\bContactForm_time=(\d+)/) 0 0 0
Condition0%0/3
$ENV{"HTTP_COOKIE"} and ($cookie) = $ENV{"HTTP_COOKIE"} =~ /\bContactForm_time=(\d+)/
!ll&&!rl&&r
000
MC/DC0%0/2
$ENV{"HTTP_COOKIE"} and ($cookie) = $ENV{"HTTP_COOKIE"} =~ /\bContactForm_time=(\d+)/
$ENV{"HTTP_COOKIE"} ($cookie) = $ENV{"HTTP_COOKIE"} =~ /\bContactForm_time=(\d+)/
Truth table0%0/3
A and B
A= $ENV{"HTTP_COOKIE"}B= ($cookie) = $ENV{"HTTP_COOKIE"} =~ /\bContactForm_time=(\d+)/
ABresult
0X0
100
111
711 0 CFdie("Your browser is set to refuse cookies.<br>\n"
712 . "Change that setting to accept at least session cookies, and try again.\n");
713 }
714 0 ▶ open FH, File::Spec->catfile( $tempdir, 'ContactForm_time' )
Branch: 1 branch
BranchTrueFalseTotal
open FH, "File::Spec"->catfile($tempdir, "ContactForm_time") or die "Couldn't open timestamp file: $!" 0 0 0
715 or die "Couldn't open timestamp file: $!";
716 0 chomp( my @timestamps = <FH> );
717 0 ▶ close FH or die $!;
Branch: 1 branch
BranchTrueFalseTotal
close FH or die $! 0 0 0
718 0 ▶ if ( $cookie + 7200 < $time or ! grep $cookie eq $_, @timestamps ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cookie + 7200 < $time or not grep(($cookie eq $_), @timestamps)) 0 0 0
Condition0%0/3
$cookie + 7200 < $time or not grep(($cookie eq $_), @timestamps)
l!l&&r!l&&!r
000
MC/DC0%0/2
$cookie + 7200 < $time or not grep(($cookie eq $_), @timestamps)
$cookie + 7200 < $time not grep(($cookie eq $_), @timestamps)
Truth table0%0/3
A or not(B)
A= $cookie + 7200 < $timeB= not grep(($cookie eq $_), @timestamps)
ABresult
1X1
011
000
719 0 settimestamp($tempdir, $time);
720 0 CFdie("Timeout due to more than an hour of inactivity.\n"
721 . '<p><a href="javascript:history.back(1)">Go back one page</a> and try again.');
722 }
723 }
724  
725 0 ▶sub settimestamp {
Subroutine settimestamp: not called CC=12 SCAR=50.5
Pod undocumented
726 0 my ($tempdir, $time) = @_;
727 0 ▶ $tempdir ||= $CGITempFile::TMPDIRECTORY;
Condition0%0/3
$tempdir ||= $CGITempFile::TMPDIRECTORY
l!l&&r!l&&!r
000
MC/DC0%0/2
$tempdir ||= $CGITempFile::TMPDIRECTORY
$tempdir $CGITempFile::TMPDIRECTORY
Truth table0%0/3
A ||= B
A= $tempdirB= $CGITempFile::TMPDIRECTORY
ABresult
1X1
011
000
728  
729 0 ▶ sysopen FH, File::Spec->catfile( $tempdir, 'ContactForm_time' ), O_RDWR|O_CREAT
Branch: 1 branch
BranchTrueFalseTotal
sysopen FH, "File::Spec"->catfile($tempdir, "ContactForm_time"), 66 or die "Couldn't open timestamp file: $!" 0 0 0
730 or die "Couldn't open timestamp file: $!";
731 0 ▶ flock FH, LOCK_EX or die $!;
Branch: 1 branch
BranchTrueFalseTotal
flock FH, 2 or die $! 0 0 0
732 0 chomp( my @timestamps = <FH> );
733 0 ▶ sysseek FH, 0, 0 or die $!;
Branch: 1 branch
BranchTrueFalseTotal
sysseek FH, 0, 0 or die $! 0 0 0
734 0 ▶ if ( @timestamps == 2 && $time > $timestamps[0] + 3600 or @timestamps == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@timestamps == 2 and $time > $timestamps[0] + 3600 or @timestamps == 1) { } 0 0 0
elsif (@timestamps == 0) { } 0 0 0
Condition0%0/6
@timestamps == 2 and $time > $timestamps[0] + 3600 or @timestamps == 1
l!l&&r!l&&!r
000
@timestamps == 2 and $time > $timestamps[0] + 3600
!ll&&!rl&&r
000
MC/DC0%0/3
@timestamps == 2 and $time > $timestamps[0] + 3600 or @timestamps == 1
@timestamps == 2 $time > $timestamps[0] + 3600 @timestamps == 1
Truth table0%0/5
A and B or C
A= @timestamps == 2B= $time > $timestamps[0] + 3600C= @timestamps == 1
ABCresult
11X1
0X11
1011
0X00
1000
735 0 ▶ truncate FH, 0 or die $!;
Branch: 1 branch
BranchTrueFalseTotal
truncate FH, 0 or die $! 0 0 0
736 0 print FH join( "\n", $time, $timestamps[0] ), "\n";
737 0 print "Set-cookie: ContactForm_time=$time\n";
738 } elsif ( @timestamps == 0 ) {
739 0 ▶ truncate FH, 0 or die $!;
Branch: 1 branch
BranchTrueFalseTotal
truncate FH, 0 or die $! 0 0 0
740 0 print FH "$time\n";
741 0 print "Set-cookie: ContactForm_time=$time\n";
742 } else {
743 0 print "Set-cookie: ContactForm_time=$timestamps[0]\n";
744 }
745 0 ▶ close FH or die $!;
Branch: 1 branch
BranchTrueFalseTotal
close FH or die $! 0 0 0
746 }
747  
748 0 ▶sub checkspamfilter {
Subroutine checkspamfilter: not called CC=3 SCAR=24.8
Pod undocumented
749 0 my ($msg, $filter) = @_;
750 0 ▶ if ( $filter and $msg =~ /$filter/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filter and $msg =~ /$filter/) 0 0 0
Condition0%0/3
$filter and $msg =~ /$filter/
!ll&&!rl&&r
000
MC/DC0%0/2
$filter and $msg =~ /$filter/
$filter $msg =~ /$filter/
Truth table0%0/3
A and B
A= $filterB= $msg =~ /$filter/
ABresult
0X0
100
111
751 0 CFdie("The message was trapped in a spam filter and not sent.\n"
752 . "You may want to try again with a modified message body.\n"
753 . '<p><a href="javascript:history.back(1)">Back</a>');
754 }
755 }
756  
757 0 ▶sub checkmaxperhour {
Subroutine checkmaxperhour: not called CC=10 SCAR=47.0
Pod undocumented
758 0 my ($args, $time, $host) = @_;
759 0 ▶ my $tempdir = $args->{tempdir} || $CGITempFile::TMPDIRECTORY;
Condition0%0/3
$args->{'tempdir'} || $CGITempFile::TMPDIRECTORY
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'tempdir'} || $CGITempFile::TMPDIRECTORY
$args->{'tempdir'} $CGITempFile::TMPDIRECTORY
Truth table0%0/3
A || B
A= $args->{'tempdir'}B= $CGITempFile::TMPDIRECTORY
ABresult
1X1
011
000
760 0 my (@senders, %senders);
761  
762 0 ▶ sysopen FH, File::Spec->catfile( $tempdir, 'ContactForm_sent' ), O_RDWR|O_CREAT
Branch: 1 branch
BranchTrueFalseTotal
sysopen FH, "File::Spec"->catfile($tempdir, "ContactForm_sent"), 66 or die "Couldn't open request file: $!" 0 0 0
763 or die "Couldn't open request file: $!";
764 0 ▶ flock FH, LOCK_EX or die $!;
Branch: 1 branch
BranchTrueFalseTotal
flock FH, 2 or die $! 0 0 0
765 0 ▶ while ( <FH> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FH)) 0 0 0
766 0 my ($timestamp, $ip) = /^(\d+)\t(.+)/;
767 0 ▶ next if $timestamp < $time - 3600;
Branch: 1 branch
BranchTrueFalseTotal
if $timestamp < $time - 3600 0 0 0
768 0 push @senders, $_;
769 0 $senders{$ip}++;
770 }
771 0 push @senders, "$time\t$host\n";
772 0 $senders{$host}++;
773 0 ▶ seek FH, 0, 0 or die $!;
Branch: 1 branch
BranchTrueFalseTotal
seek FH, 0, 0 or die $! 0 0 0
774 0 ▶ truncate FH, 0 or die $!;
Branch: 1 branch
BranchTrueFalseTotal
truncate FH, 0 or die $! 0 0 0
775 0 print FH @senders;
776 0 ▶ close FH or die $!;
Branch: 1 branch
BranchTrueFalseTotal
close FH or die $! 0 0 0
777  
778 0 ▶ if ( $senders{$host} > $args->{maxperhour} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($senders{$host} > $args->{"maxperhour"}) 0 0 0
779 0 CFdie('Too many send attempts from the same host. You may want to try later.');
780 }
781 }
782  
783 1 1;
784  
↑ Summary ContactForm/MHonArc.pm »