Postini.pm

filter: Statementstmt 90.0% 325 / 361 Branchbran 56.9% 98 / 172 Conditioncond 43.8% 46 / 105 MC/DCmcdc 6.6% 4 / 60 Subroutinesub 100% 29 / 29 Podpod 100% 10 / 10 totaltotal 69.4% 512 / 737 CC 125 SCAR 37.5
CC
125
Cov
74%
list_messages
82.8
process_messages
56.0
get_message_info
42.5
CRAP 42.4
↑ Summary Postini/Exception.pm »
1 package WWW::Postini;
2
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 1 ▶use WWW::Postini::Assert;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use WWW::Postini::Exception::LoginFailure;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use WWW::Postini::Exception::InvalidParameter;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use WWW::Postini::Exception::UnexpectedResponse;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use WWW::Postini::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use WWW::Postini::Constants ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
12
13 1 ▶use HTML::TokeParser;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use HTTP::Status;
Subroutine BEGIN: called CC=1 SCAR=0.0
16
17 1 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
18
19 1 ▶use constant DEFAULT_LOGIN_HOST => 'login.postini.com';
Subroutine BEGIN: called CC=1 SCAR=0.0
20
21 1 ▶use constant QUARANTINE_PAGE_SIZE => 1000;
Subroutine BEGIN: called CC=1 SCAR=0.0
22
23 1 ▶use constant LOG_IN_TITLE => 'Log in';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use constant CHOOSE_SESSION_TITLE => 'Choose Session Type';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use constant ADMIN_TITLE => 'System Administration';
Subroutine BEGIN: called CC=1 SCAR=0.0
26
27 1 $VERSION = '0.01';
28
29 #################
30 ## constructor ##
31 #################
32
33 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
34
35 2 my $class = shift;
36 2 my $self = bless {}, $class;
37 2 $self->_init(@_);
38 2 $self;
39
40 }
41
42 #################
43 ## initializer ##
44 #################
45
46 2 ▶sub _init {
Subroutine _init: called CC=2 SCAR=6.9
47
48 2 my $self = shift;
49
50 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1 1 2
51
52 1 $self->login_host(shift);
53
54 } else {
55
56 1 $self->{'_login_host'} = DEFAULT_LOGIN_HOST;
57
58 }
59
60 2 $self->{'_user_agent'} = new WWW::Postini::UserAgent();
61 2 return;
62
63 }
64
65 ######################
66 ## accessor methods ##
67 ######################
68
69 # user agent
70
71 1 ▶sub user_agent {
Subroutine user_agent: called CC=3 SCAR=12.5
Pod documented
72
73 1 my $self = shift;
74
75 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
76
77 0 $self->{'_user_agent'} = shift;
78
79 }
80
81 1 ▶ return $self->{'_user_agent'} if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 1 0 1
82
83 }
84
85 # login host
86
87 4 ▶sub login_host {
Subroutine login_host: called CC=3 SCAR=11.0
Pod documented
88
89 4 my $self = shift;
90
91 4 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 2 4
92
93 2 $self->{'_login_host'} = shift;
94
95 }
96
97 4 ▶ return $self->{'_login_host'} if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 3 1 4
98
99 }
100
101 # admin host
102
103 1 ▶sub admin_host {
Subroutine admin_host: called CC=3 SCAR=12.5
Pod documented
104
105 1 my $self = shift;
106
107 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
108
109 0 $self->{'_admin_host'} = shift;
110
111 }
112
113 1 ▶ return $self->{'_admin_host'} if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 1 0 1
114
115 }
116
117 #####################
118 ## utility methods ##
119 #####################
120
121 # login
122
123 2 ▶sub login {
Subroutine login: called CC=12 SCAR=25.4
Pod documented
124
125 2 my $self = shift;
126
127 2 ▶ throw WWW::Postini::Exception::InvalidParameter('Email address not specified')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] and length $_[0] 0 2 2
Condition33%1/3
defined $_[0] and length $_[0]
!ll&&!rl&&r
002
MC/DC0%0/2
defined $_[0] and length $_[0]
defined $_[0] length $_[0]
Truth table33%1/3
A and B
A= defined $_[0]B= length $_[0]
ABresult
0X0
100
111
128 unless defined $_[0] && length $_[0]
129 ;
130 2 ▶ throw WWW::Postini::Exception::InvalidParameter('Password not specified')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] and length $_[1] 0 2 2
Condition33%1/3
defined $_[1] and length $_[1]
!ll&&!rl&&r
002
MC/DC0%0/2
defined $_[1] and length $_[1]
defined $_[1] length $_[1]
Truth table33%1/3
A and B
A= defined $_[1]B= length $_[1]
ABresult
0X0
100
111
131 unless defined $_[1] && length $_[1]
132 ;
133
134 2 my $email_address = shift;
135 2 my $password = shift;
136 2 my $response;
137
138 # try
139
140 2 eval {
141
142 # attempt to log in
143
144 2 $response = $self->{'_user_agent'}->get(
145 "https://$self->{'_login_host'}/exec/login?"
146 ."email=$email_address"
147 ."&pword=$password"
148 ."&action=login"
149 );
150
151 2 assert($response, 'Response returned');
152
153 2 my $code = $response->code();
154 2 assert($code == RC_OK, 'Response code is '.RC_OK);
155
156 2 my $content = $response->content();
157 2 my $p = new HTML::TokeParser(\$content);
158
159 # determine title
160
161 2 my $tag = $p->get_tag('title');
162 2 assert($tag, 'Title tag exists');
163
164 2 my $token = $p->get_token();
165 2 assert($token, 'Token exists');
166 2 assert($token->[0] eq 'T', 'Token is text');
167 2 ▶ assert(
Condition66%2/3
$token->[1] eq 'Log in' || $token->[1] eq 'Choose Session Type'
l!l&&r!l&&!r
110
MC/DC0%0/2
$token->[1] eq 'Log in' || $token->[1] eq 'Choose Session Type'
$token->[1] eq 'Log in' $token->[1] eq 'Choose Session Type'
Truth table66%2/3
A || B
A= $token->[1] eq 'Log in'B= $token->[1] eq 'Choose Session Type'
ABresult
1X1
011
000
168 $token->[1] eq LOG_IN_TITLE || $token->[1] eq CHOOSE_SESSION_TITLE,
169 'Title recognized'
170 );
171
172 # log in
173
174 2 ▶ if ($token->[1] eq LOG_IN_TITLE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token->[1] eq 'Log in') { } 1 1 2
elsif ($token->[1] eq 'Choose Session Type') { } 1 0 1
175
176 1 $tag = $p->get_tag('br');
177 1 assert($tag, 'Break tag exists');
178
179 1 $tag = $p->get_tag('b');
180 1 assert($tag, 'Bold tag exists');
181
182 1 my $text = $p->get_trimmed_text();
183 1 assert($text, 'Bold has text');
184
185 1 throw WWW::Postini::Exception::LoginFailure($text);
186
187 # choose session (transfer phase)
188
189 } elsif ($token->[1] eq CHOOSE_SESSION_TITLE) {
190
191 1 $tag = $p->get_tag('a');
192 1 assert($tag, 'Administration link exists');
193 1 assert($tag->[1]->{'href'}, 'Administration URL defined');
194
195 # make certain user is administrator
196
197 1 my $text = $p->get_trimmed_text();
198 1 assert($text eq ADMIN_TITLE, 'User is administrator');
199
200 # determine administration host
201
202 1 my $url = $tag->[1]->{'href'};
203 1 my ($admin_host) = $url =~ m!^https?://(.+?)/!;
204 1 assert($admin_host, 'Administration site determined');
205 1 $self->{'_admin_host'} = $admin_host;
206
207 # send transfer code
208
209 1 $response = $self->{'_user_agent'}->get($url);
210
211 1 assert($response, 'Response returned');
212
213 1 $code = $response->code();
214 1 assert($code == RC_OK, 'Response code is '.RC_OK);
215
216 }
217
218 };
219
220 # catch
221
222 2 ▶ if (defined $@ && (length $@ || ref $@)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $@ and length $@ || ref $@) 1 1 2
Condition66%4/6
defined $@ and length $@ || ref $@
!ll&&!rl&&r
011
length $@ or ref $@
l!l&&r!l&&!r
101
MC/DC33%1/3
defined $@ and length $@ || ref $@
defined $@ length $@ ref $@
Truth table50%2/4
A and B or C
A= defined $@B= length $@C= ref $@
ABCresult
0XX0
1000
11X1
1011
223
224 1 ▶ if (UNIVERSAL::isa($@, 'WWW::Postini::Exception::LoginFailure')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($@, 'WWW::Postini::Exception::LoginFailure')) { } 1 0 1
225
226 1 $@->rethrow();
227
228 } else {
229
230 0 throw WWW::Postini::Exception::UnexpectedResponse($@);
231
232 }
233
234 }
235
236 1 return 1;
237
238 }
239
240 # get user id
241
242 2 ▶sub get_user_id {
Subroutine get_user_id: called CC=7 SCAR=20.1
Pod documented
243
244 2 my $self = shift;
245
246 2 ▶ throw WWW::Postini::Exception::InvalidParameter('Email address not specified')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] and length $_[0] 0 2 2
Condition33%1/3
defined $_[0] and length $_[0]
!ll&&!rl&&r
002
MC/DC0%0/2
defined $_[0] and length $_[0]
defined $_[0] length $_[0]
Truth table33%1/3
A and B
A= defined $_[0]B= length $_[0]
ABresult
0X0
100
111
247 unless defined $_[0] && length $_[0]
248 ;
249
250 2 my $email_address = shift;
251 2 my ($response, $user_id);
252
253 # try
254
255 2 eval {
256
257 # avoid automatic redirect so user id can be ascertained
258
259 $response = $self->{'_user_agent'}->simple_request(new HTTP::Request (
260 GET =>
261 'https://'
262 2 .$self->{'_admin_host'}
263 .'/exec/adminstart?'
264 .'action=user_shortcut'
265 ."&targetAddress=$email_address"
266 .'&next_action=Quarantine'
267 ));
268
269 2 assert($response, 'Response returned');
270
271 2 my $code = $response->code();
272 2 assert($code == RC_FOUND, 'Response code is '.RC_FOUND);
273
274 1 my $location = $response->headers->header('location');
275 1 assert($location, 'Location defined');
276
277 1 ($user_id) = $location =~ /targetuserid=(\d+)/;
278 1 assert($user_id, 'User ID defined');
279
280 };
281
282 # catch
283
284 2 ▶ if (defined $@ && (length $@ || ref $@)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $@ and length $@ || ref $@) 1 1 2
Condition66%4/6
defined $@ and length $@ || ref $@
!ll&&!rl&&r
011
length $@ or ref $@
l!l&&r!l&&!r
101
MC/DC33%1/3
defined $@ and length $@ || ref $@
defined $@ length $@ ref $@
Truth table50%2/4
A and B or C
A= defined $@B= length $@C= ref $@
ABCresult
0XX0
1000
11X1
1011
285
286 1 ▶ if (UNIVERSAL::isa($@, 'WWW::Postini::Exception::UnexpectedResponse')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($@, 'WWW::Postini::Exception::UnexpectedResponse')) { } 0 1 1
287
288 0 $@->rethrow();
289
290 } else {
291
292 1 throw WWW::Postini::Exception::UnexpectedResponse($@);
293
294 }
295
296 }
297
298 1 $user_id;
299
300 }
301
302 # list messages messages from quarantine
303
304 9 ▶sub list_messages {
Subroutine list_messages: called CC=43 SCAR=44.2
Pod documented
305
306 9 my $self = shift;
307 9 my %args;
308
309 # handle arguments
310
311 9 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 9 0 9
312
313 # hash reference
314
315 9 ▶ if (defined $_[0] && UNIVERSAL::isa($_[0], 'HASH')) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_[0] and UNIVERSAL::isa($_[0], 'HASH')) { } 0 9 9
elsif (@_ == 1) { } 0 9 9
Condition33%1/3
defined $_[0] and UNIVERSAL::isa($_[0], "HASH")
!ll&&!rl&&r
090
MC/DC0%0/2
defined $_[0] and UNIVERSAL::isa($_[0], "HASH")
defined $_[0] UNIVERSAL::isa($_[0], "HASH")
Truth table33%1/3
A and B
A= defined $_[0]B= UNIVERSAL::isa($_[0], "HASH")
ABresult
0X0
100
111
316
317 0 %args = %{$_[0]};
318
319 # single parameter (user id)
320
321 } elsif (@_ == 1) {
322
323 0 $args{'user_id'} = shift;
324
325 # array of key/value pairs
326
327 } else {
328
329 9 %args = @_;
330
331 }
332
333 }
334
335 # require user id parameter
336
337 throw WWW::Postini::Exception::InvalidParameter ('User ID not specified')
338 9 ▶ unless defined $args{'user_id'} && length $args{'user_id'}
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"user_id"} and length $args{"user_id"} 0 9 9
Condition33%1/3
defined $args{"user_id"} and length $args{"user_id"}
!ll&&!rl&&r
009
MC/DC0%0/2
defined $args{"user_id"} and length $args{"user_id"}
defined $args{"user_id"} length $args{"user_id"}
Truth table33%1/3
A and B
A= defined $args{"user_id"}B= length $args{"user_id"}
ABresult
0X0
100
111
339 ;
340
341 # set argument defaults
342
343 9 ▶ $args{'show'} = SHOW_ALL unless defined $args{'show'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"show"} 4 5 9
344 9 ▶ $args{'sort'} = SORT_NONE unless defined $args{'sort'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"sort"} 9 0 9
345
346 # define which messages will be shown
347
348 9 my $show;
349
350 9 ▶ if ($args{'show'} == SHOW_ALL) {
Branch: 4 branches
BranchTrueFalseTotal
if ($args{'show'} == 0) { } 5 4 9
elsif ($args{'show'} == 1) { } 1 3 4
elsif ($args{'show'} == 2) { } 2 1 3
elsif ($args{'show'} == 3) { } 1 0 1
351
352 5 $show = 'all';
353
354 } elsif ($args{'show'} == SHOW_QUARANTINED) {
355
356 1 $show = 'visible';
357
358 } elsif ($args{'show'} == SHOW_DELIVERED) {
359
360 2 $show = 'delivered';
361
362 } elsif ($args{'show'} == SHOW_DELETED) {
363
364 1 $show = 'deleted';
365
366 } else {
367
368 0 throw WWW::Postini::Exception::InvalidParameter(
369 'Invalid "show" parameter specified'
370 );
371
372 }
373
374 # define sort method
375
376 9 my $sort;
377
378 9 ▶ if ($args{'sort'} == SORT_NONE) {
Branch: 5 branches
BranchTrueFalseTotal
if ($args{'sort'} == 0) { } 9 0 9
elsif ($args{'sort'} == 1) { } 0 0 0
elsif ($args{'sort'} == 3) { } 0 0 0
elsif ($args{'sort'} == 4) { } 0 0 0
elsif ($args{'sort'} == 5) { } 0 0 0
379
380 9 $sort = '';
381
382 } elsif ($args{'sort'} == SORT_RECIPIENT) {
383
384 0 $sort = 'recip';
385
386 } elsif ($args{'sort'} == SORT_SENDER) {
387
388 0 $sort = 'sender';
389
390 } elsif ($args{'sort'} == SORT_SUBJECT) {
391
392 0 $sort = 'subject';
393
394 } elsif ($args{'sort'} == SORT_FILTER) {
395
396 0 $sort = 'block';
397
398 } else {
399
400 0 throw WWW::Postini::Exception::InvalidParameter(
401 'Invalid "sort" parameter specified'
402 );
403
404 }
405
406 9 my $base_url = "https://$self->{'_admin_host'}/exec/admin_users?"
407 ."targetuserid=$args{'user_id'}"
408 .'&action=display_Quarantine'
409 ;
410
411 9 my %url_params = (
412 pagesize => QUARANTINE_PAGE_SIZE,
413 msgtype => $show,
414 msgsort => $sort
415 );
416
417 # search for recipient
418
419 $url_params{'filterRecip'} = $args{'recipient'}
420 9 ▶ if defined $args{'recipient'}
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"recipient"} 1 8 9
421 ;
422
423 # search for sender
424
425 $url_params{'filterSender'} = $args{'sender'}
426 9 ▶ if defined $args{'sender'}
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"sender"} 1 8 9
427 ;
428
429 # search for subject
430
431 $url_params{'filterSubject'} = $args{'subject'}
432 9 ▶ if defined $args{'subject'}
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"subject"} 1 8 9
433 ;
434
435 # limit to specified filter
436
437 $url_params{'filterBlock'} = $args{'filter'}
438 9 ▶ if defined $args{'filter'}
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"filter"} 1 8 9
439 ;
440
441 9 my $page_number = 1;
442 9 my @messages;
443
444 # try
445
446 9 eval {
447
448 9 my $response;
449
450 9 while (1) {
451
452 # retrieve current page
453
454 9 $response = $self->{'_user_agent'}->post(
455 $base_url, [
456 %url_params,
457 firstmsg => (($page_number - 1) * QUARANTINE_PAGE_SIZE)
458 ]
459 );
460
461 9 assert($response, 'Response returned');
462
463 9 my $code = $response->code();
464 9 assert($code == RC_OK, 'Response code is '.RC_OK);
465
466 9 my $content = $response->content();
467 9 my $p = new HTML::TokeParser(\$content);
468
469 9 my ($tag, $start_range, $end_range, $total_messages);
470
471 9 ▶ while (defined ($tag = $p->get_tag('td'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($tag = $p->get_tag("td"))) 18 0 18
472
473 last if defined $tag->[1]->{'width'}
474 && defined $tag->[1]->{'align'}
475 && $tag->[1]->{'width'} eq '100%'
476 18 ▶ && $tag->[1]->{'align'} eq 'right'
Branch: 1 branch
BranchTrueFalseTotal
if defined $tag->[1]{"width"} and defined $tag->[1]{"align"} and $tag->[1]{"width"} eq "100%" and $tag->[1]{"align"} eq "right" 9 9 18
Condition66%6/9
defined $tag->[1]{"width"} and defined $tag->[1]{"align"} and $tag->[1]{"width"} eq "100%" and $tag->[1]{"align"} eq "right"
!ll&&!rl&&r
909
defined $tag->[1]{"width"} and defined $tag->[1]{"align"} and $tag->[1]{"width"} eq "100%"
!ll&&!rl&&r
909
defined $tag->[1]{"width"} and defined $tag->[1]{"align"}
!ll&&!rl&&r
909
MC/DC25%1/4
defined $tag->[1]{"width"} and defined $tag->[1]{"align"} and $tag->[1]{"width"} eq "100%" and $tag->[1]{"align"} eq "right"
defined $tag->[1]{"width"} defined $tag->[1]{"align"} $tag->[1]{"width"} eq "100%" $tag->[1]{"align"} eq "right"
Truth table40%2/5
A and B and C and D
A= defined $tag->[1]{"width"}B= defined $tag->[1]{"align"}C= $tag->[1]{"width"} eq "100%"D= $tag->[1]{"align"} eq "right"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
477 ;
478
479 }
480
481 9 $tag = $p->get_tag('font');
482 9 assert($tag, 'Font tag exists');
483
484 9 my $token;
485
486 9 ▶ while (defined ($token = $p->get_token())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($token = $p->get_token)) 45 0 45
487
488 45 ▶ last if $token->[0] eq 'E' && $token->[1] eq 'font';
Branch: 1 branch
BranchTrueFalseTotal
if $token->[0] eq "E" and $token->[1] eq "font" 0 45 45
Condition66%2/3
$token->[0] eq "E" and $token->[1] eq "font"
!ll&&!rl&&r
3690
MC/DC0%0/2
$token->[0] eq "E" and $token->[1] eq "font"
$token->[0] eq "E" $token->[1] eq "font"
Truth table66%2/3
A and B
A= $token->[0] eq "E"B= $token->[1] eq "font"
ABresult
0X0
100
111
489
490 45 ▶ if ($token->[0] eq 'T') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->[0] eq "T") 27 18 45
491
492 27 ▶ next unless $token->[1] =~ /\d+ - \d+ of \d+/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $token->[1] =~ /\d+ - \d+ of \d+/s 18 9 27
493
494 9 ($start_range, $end_range, $total_messages) = $token->[1] =~ /
495 (\d+) \s - \s (\d+)
496 \s of \s
497 (\d+)
498 /x;
499 9 last;
500
501 }
502
503 }
504
505 9 assert(defined ($total_messages), 'Total messages defined');
506 9 assert(defined ($start_range), 'Start range defined');
507 9 assert($start_range <= $total_messages, 'Valid start range');
508
509 9 $tag = $p->get_tag('form');
510 9 assert($tag, 'Form tag exists');
511
512 9 $tag = $p->get_tag('tr');
513 9 assert($tag, 'TR tag exists');
514
515 9 ▶ while($tag = $p->get_tag('tr')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag = $p->get_tag("tr")) 31 9 40
516
517 next unless defined $tag->[1]->{'bgcolor'} && (
518 $tag->[1]->{'bgcolor'} eq '#EEEEEE'
519 31 ▶ || $tag->[1]->{'bgcolor'} eq '#FFFFFF'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tag->[1]{"bgcolor"} and $tag->[1]{"bgcolor"} eq "#EEEEEE" || $tag->[1]{"bgcolor"} eq "#FFFFFF" 0 31 31
Condition50%3/6
defined $tag->[1]{"bgcolor"} and $tag->[1]{"bgcolor"} eq "#EEEEEE" || $tag->[1]{"bgcolor"} eq "#FFFFFF"
!ll&&!rl&&r
0031
$tag->[1]{"bgcolor"} eq "#EEEEEE" or $tag->[1]{"bgcolor"} eq "#FFFFFF"
l!l&&r!l&&!r
14170
MC/DC0%0/3
defined $tag->[1]{"bgcolor"} and $tag->[1]{"bgcolor"} eq "#EEEEEE" || $tag->[1]{"bgcolor"} eq "#FFFFFF"
defined $tag->[1]{"bgcolor"} $tag->[1]{"bgcolor"} eq "#EEEEEE" $tag->[1]{"bgcolor"} eq "#FFFFFF"
Truth table50%2/4
A and B or C
A= defined $tag->[1]{"bgcolor"}B= $tag->[1]{"bgcolor"} eq "#EEEEEE"C= $tag->[1]{"bgcolor"} eq "#FFFFFF"
ABCresult
0XX0
1000
11X1
1011
520 );
521 31 ▶ last unless defined $p->get_tag('font');
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p->get_tag("font") 0 31 31
522
523 31 my ($date, $recipient, $sender) = (
524 $self->_get_message_field($p),
525 $self->_get_message_field($p),
526 $self->_get_message_field($p)
527 );
528
529 31 assert($date, 'Date defined');
530 31 assert($recipient, 'Recipient defined');
531 31 assert($sender, 'Sender defined');
532
533 31 $tag = $p->get_tag('font');
534 31 assert($tag, 'Font tag exists');
535
536 31 $tag = $p->get_tag('a');
537 31 assert($tag, 'Link exists');
538
539 31 my $url = $tag->[1]->{'href'};
540 31 assert($url, 'URL defined');
541
542 31 my $subject = $p->get_trimmed_text();
543 31 assert($subject, 'Subject defined');
544
545 31 my $uri = (split m!\?!, $url)[1];
546 31 assert($uri, 'URI defined');
547
548 31 my %params;
549
550 31 foreach my $pair (split /&/, $uri) {
551
552 93 my ($key, $value) = split /=/, $pair;
553 93 $params{$key} = $value;
554
555 }
556
557 31 $tag = $p->get_tag('font');
558 31 assert($tag, 'Font tag exists');
559
560 31 my $filter = $p->get_trimmed_text();
561 31 assert($filter, 'Filter defined');
562
563 push @messages, {
564 sender => $sender,
565 recipient => $recipient,
566 subject => $subject,
567 date => $date,
568 filter => $filter,
569 id => $params{'msgid'},
570 31 uid => $args{'user_id'}
571 };
572
573 }
574
575 9 ▶ last if $end_range >= $total_messages;
Branch: 1 branch
BranchTrueFalseTotal
if $end_range >= $total_messages 9 0 9
576 0 $page_number++;
577
578 }
579
580 };
581
582 # catch
583
584 9 ▶ if (defined $@ && (length $@ || ref $@)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $@ and length $@ || ref $@) 0 9 9
Condition33%2/6
defined $@ and length $@ || ref $@
!ll&&!rl&&r
090
length $@ or ref $@
l!l&&r!l&&!r
009
MC/DC0%0/3
defined $@ and length $@ || ref $@
defined $@ length $@ ref $@
Truth table25%1/4
A and B or C
A= defined $@B= length $@C= ref $@
ABCresult
0XX0
1000
11X1
1011
585
586 0 ▶ if (UNIVERSAL::isa($@, 'WWW::Postini::Exception::UnexpectedResponse')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($@, 'WWW::Postini::Exception::UnexpectedResponse')) { } 0 0 0
587
588 0 $@->rethrow();
589
590 } else {
591
592 0 throw WWW::Postini::Exception::UnexpectedResponse($@);
593
594 }
595
596 }
597
598 9 \@messages;
599
600 }
601
602 # get message info
603
604 1 ▶sub get_message_info {
Subroutine get_message_info: called CC=22 SCAR=37.5
Pod documented
605
606 1 my $self = shift;
607
608 1 ▶ throw WWW::Postini::Exception::InvalidParameter('User ID not specified')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] and length $_[0] 0 1 1
Condition33%1/3
defined $_[0] and length $_[0]
!ll&&!rl&&r
001
MC/DC0%0/2
defined $_[0] and length $_[0]
defined $_[0] length $_[0]
Truth table33%1/3
A and B
A= defined $_[0]B= length $_[0]
ABresult
0X0
100
111
609 unless defined $_[0] && length $_[0]
610 ;
611 1 ▶ throw WWW::Postini::Exception::InvalidParameter('Message ID not specified')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] and length $_[1] 0 1 1
Condition33%1/3
defined $_[1] and length $_[1]
!ll&&!rl&&r
001
MC/DC0%0/2
defined $_[1] and length $_[1]
defined $_[1] length $_[1]
Truth table33%1/3
A and B
A= defined $_[1]B= length $_[1]
ABresult
0X0
100
111
612 unless defined $_[1] && length $_[1]
613 ;
614
615 1 my $user_id = shift;
616 1 my $message_id = shift;
617 1 my ($headers, $body, @attachments);
618
619 1 eval {
620
621 1 my $response = $self->{'_user_agent'}->get(
622 "https://$self->{'_admin_host'}/exec/admin_users?"
623 ."targetuserid=$user_id"
624 .'&action=display_Message'
625 ."&msgid=$message_id"
626 .'&showheader=1'
627 );
628
629 1 assert($response, 'Response returned');
630
631 1 my $code = $response->code();
632 1 assert($code == RC_OK, 'Response code is '.RC_OK);
633
634 1 my $content = $response->content();
635 1 my $p = new HTML::TokeParser(\$content);
636
637 1 my $tag = $p->get_tag('pre');
638 1 assert($tag, 'PRE tag exists');
639
640 1 $headers = $p->get_text();
641 1 assert($headers, 'Headers exist');
642
643 1 $headers =~ s/\s+$//gs;
644
645 1 $tag = $p->get_tag('xmp');
646 1 assert($tag, 'XMP tag exists');
647
648 1 my $token;
649
650 1 ▶ while (defined ($token = $p->get_token())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($token = $p->get_token)) 2 0 2
651
652 # start tag
653
654 2 ▶ if ($token->[0] eq 'S') {
Branch: 4 branches
BranchTrueFalseTotal
if ($token->[0] eq 'S') { } 0 2 2
elsif ($token->[0] eq 'E') { } 1 1 2
elsif ($token->[0] eq 'T' or $token->[0] eq 'C' or $token->[0] eq 'D') { } 1 0 1
elsif ($token->[0] eq 'PI') { } 0 0 0
655
656 0 $body .= $token->[4];
657
658 # end tag
659
660 } elsif ($token->[0] eq 'E') {
661
662 1 ▶ last if $token->[1] eq 'xmp';
Branch: 1 branch
BranchTrueFalseTotal
if $token->[1] eq "xmp" 1 0 1
663 0 $body .= $token->[2];
664
665 # text, comment, or declaration
666
667 ▶ } elsif ($token->[0] eq 'T'
Condition33%2/6
$token->[0] eq "T" or $token->[0] eq "C" or $token->[0] eq "D"
l!l&&r!l&&!r
100
$token->[0] eq "T" or $token->[0] eq "C"
l!l&&r!l&&!r
100
MC/DC0%0/3
$token->[0] eq "T" or $token->[0] eq "C" or $token->[0] eq "D"
$token->[0] eq "T" $token->[0] eq "C" $token->[0] eq "D"
Truth table25%1/4
A or B or C
A= $token->[0] eq "T"B= $token->[0] eq "C"C= $token->[0] eq "D"
ABCresult
1XX1
01X1
0011
0000
668 || $token->[0] eq 'C'
669 || $token->[0] eq 'D'
670 ) {
671
672 1 $body .= $token->[1];
673
674 # processing instruction
675
676 } elsif ($token->[0] eq 'PI') {
677
678 0 $body .= $token->[2];
679
680 }
681
682 }
683
684 1 $body =~ s/\s+$//sg;
685
686 1 my ($text, $file);
687
688 1 ▶ while (defined ($token = $p->get_token())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($token = $p->get_token)) 8 0 8
689
690 8 ▶ last if $token->[0] eq 'E' && $token->[1] eq 'font';
Branch: 1 branch
BranchTrueFalseTotal
if $token->[0] eq "E" and $token->[1] eq "font" 1 7 8
Condition66%2/3
$token->[0] eq "E" and $token->[1] eq "font"
!ll&&!rl&&r
701
MC/DC50%1/2
$token->[0] eq "E" and $token->[1] eq "font"
$token->[0] eq "E" $token->[1] eq "font"
Truth table66%2/3
A and B
A= $token->[0] eq "E"B= $token->[1] eq "font"
ABresult
0X0
100
111
691 7 ▶ next unless $token->[0] eq 'T';
Branch: 1 branch
BranchTrueFalseTotal
unless $token->[0] eq "T" 3 4 7
692
693 4 ▶ if (($file) = $token->[1] =~ /name=\"?([^";]+?)\s*(?:"|\;|$)/s) {
Branch: 1 branch
BranchTrueFalseTotal
if (($file) = $token->[1] =~ /name=\"?([^";]+?)\s*(?:"|\;|$)/s) 2 2 4
694
695 2 push @attachments, $file;
696
697 }
698
699 }
700
701 };
702
703 # catch
704
705 1 ▶ if (defined $@ && (length $@ || ref $@)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $@ and length $@ || ref $@) 0 1 1
Condition33%2/6
defined $@ and length $@ || ref $@
!ll&&!rl&&r
010
length $@ or ref $@
l!l&&r!l&&!r
001
MC/DC0%0/3
defined $@ and length $@ || ref $@
defined $@ length $@ ref $@
Truth table25%1/4
A and B or C
A= defined $@B= length $@C= ref $@
ABCresult
0XX0
1000
11X1
1011
706
707 0 ▶ if (UNIVERSAL::isa($@, 'WWW::Postini::Exception::UnexpectedResponse')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($@, 'WWW::Postini::Exception::UnexpectedResponse')) { } 0 0 0
708
709 0 $@->rethrow();
710
711 } else {
712
713 0 throw WWW::Postini::Exception::UnexpectedResponse($@);
714
715 }
716
717 }
718
719 return {
720 1 headers => $headers,
721 body => $body,
722 attachments => \@attachments
723 };
724
725 }
726
727 # delete specified messages
728
729 1 ▶sub delete_messages {
Subroutine delete_messages: called CC=15 SCAR=32.5
Pod documented
730
731 1 my $self = shift;
732 1 my @message_ids;
733
734 1 ▶ throw WWW::Postini::Exception::InvalidParameter('User ID not specified')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] and length $_[0] 0 1 1
Condition33%1/3
defined $_[0] and length $_[0]
!ll&&!rl&&r
001
MC/DC0%0/2
defined $_[0] and length $_[0]
defined $_[0] length $_[0]
Truth table33%1/3
A and B
A= defined $_[0]B= length $_[0]
ABresult
0X0
100
111
735 unless defined $_[0] && length $_[0]
736 ;
737
738 1 my $user_id = shift;
739
740 # handle arguments
741
742 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 0 1
743
744 # array reference
745
746 1 ▶ if (defined $_[0] && UNIVERSAL::isa($_[0], 'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and UNIVERSAL::isa($_[0], 'ARRAY')) { } 0 1 1
Condition33%1/3
defined $_[0] and UNIVERSAL::isa($_[0], "ARRAY")
!ll&&!rl&&r
010
MC/DC0%0/2
defined $_[0] and UNIVERSAL::isa($_[0], "ARRAY")
defined $_[0] UNIVERSAL::isa($_[0], "ARRAY")
Truth table33%1/3
A and B
A= defined $_[0]B= UNIVERSAL::isa($_[0], "ARRAY")
ABresult
0X0
100
111
747
748 0 @message_ids = @{$_[0]};
749
750 # list of values
751
752 } else {
753
754 1 @message_ids = @_;
755
756 }
757
758 }
759
760 1 ▶ throw WWW::Postini::Exception::InvalidParameter('No messages specified')
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @message_ids 0 1 1
761 unless scalar @message_ids
762 ;
763
764 1 my $message_count;
765
766 # try
767
768 1 eval {
769
770 1 my @args = (
771 action => 'processQuarantine',
772 targetuserid => $user_id,
773 submit => 'Delete'
774 );
775
776 1 foreach my $id (@message_ids) {
777
778 1 push @args, ('msgid', $id);
779
780 }
781
782 1 my $response = $self->{'_user_agent'}->post(
783 "https://$self->{'_admin_host'}/exec/admin_users",
784 \@args
785 );
786
787 1 assert($response, 'Response returned');
788
789 1 my $code = $response->code();
790 1 assert($code == RC_OK, 'Response code is '.RC_OK);
791
792 1 my $content = $response->content();
793 1 my $p = new HTML::TokeParser(\$content);
794 1 my ($tag, $text);
795
796 1 ▶ while (defined ($tag = $p->get_tag('b'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($tag = $p->get_tag("b"))) 1 0 1
797
798 1 my $text = $p->get_trimmed_text();
799 1 ▶ last if defined $text && $text eq 'Message Results';
Branch: 1 branch
BranchTrueFalseTotal
if defined $text and $text eq "Message Results" 1 0 1
Condition33%1/3
defined $text and $text eq "Message Results"
!ll&&!rl&&r
001
MC/DC0%0/2
defined $text and $text eq "Message Results"
defined $text $text eq "Message Results"
Truth table33%1/3
A and B
A= defined $textB= $text eq "Message Results"
ABresult
0X0
100
111
800
801 }
802
803 1 $tag = $p->get_tag('font');
804 1 assert($tag, 'Font tag exists');
805
806 1 $text = $p->get_trimmed_text();
807 1 assert(
808 $text =~ /^\d+ message\(s\) marked as deleted\./,
809 'Message text recognized'
810 );
811
812 1 ($message_count) = $text =~ /^(\d+)/;
813
814 };
815
816 # catch
817
818 1 ▶ if (defined $@ && (length $@ || ref $@)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $@ and length $@ || ref $@) 0 1 1
Condition33%2/6
defined $@ and length $@ || ref $@
!ll&&!rl&&r
010
length $@ or ref $@
l!l&&r!l&&!r
001
MC/DC0%0/3
defined $@ and length $@ || ref $@
defined $@ length $@ ref $@
Truth table25%1/4
A and B or C
A= defined $@B= length $@C= ref $@
ABCresult
0XX0
1000
11X1
1011
819
820 0 ▶ if (UNIVERSAL::isa($@, 'WWW::Postini::Exception::UnexpectedResponse')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($@, 'WWW::Postini::Exception::UnexpectedResponse')) { } 0 0 0
821
822 0 $@->rethrow();
823
824 } else {
825
826 0 throw WWW::Postini::Exception::UnexpectedResponse($@);
827
828 }
829
830 }
831
832 1 $message_count;
833
834 }
835
836 # process quarantined messages
837
838 1 ▶sub process_messages {
Subroutine process_messages: called CC=24 SCAR=40.2
Pod documented
839
840 1 my $self = shift;
841 1 my %args;
842
843 # handle arguments
844
845 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 0 1
846
847 # array reference
848
849 1 ▶ if (defined $_[0] && UNIVERSAL::isa ($_[0], 'HASH')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and UNIVERSAL::isa($_[0], 'HASH')) { } 0 1 1
Condition33%1/3
defined $_[0] and UNIVERSAL::isa($_[0], "HASH")
!ll&&!rl&&r
010
MC/DC0%0/2
defined $_[0] and UNIVERSAL::isa($_[0], "HASH")
defined $_[0] UNIVERSAL::isa($_[0], "HASH")
Truth table33%1/3
A and B
A= defined $_[0]B= UNIVERSAL::isa($_[0], "HASH")
ABresult
0X0
100
111
850
851 0 %args = %{$_[0]};
852
853 # list of values
854
855 } else {
856
857 1 %args = @_;
858
859 }
860
861 }
862
863 throw WWW::Postini::Exception::InvalidParameter('User ID not specified')
864 1 ▶ unless defined $args{'user_id'} && length $args{'user_id'}
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"user_id"} and length $args{"user_id"} 0 1 1
Condition33%1/3
defined $args{"user_id"} and length $args{"user_id"}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $args{"user_id"} and length $args{"user_id"}
defined $args{"user_id"} length $args{"user_id"}
Truth table33%1/3
A and B
A= defined $args{"user_id"}B= length $args{"user_id"}
ABresult
0X0
100
111
865 ;
866
867 # set default parameters
868
869 1 ▶ $args{'recipient'} = RECIPIENT_USER unless defined $args{'recipient'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"recipient"} 0 1 1
870 1 ▶ $args{'mark'} = 1 unless defined $args{'mark'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"mark"} 0 1 1
871 1 ▶ $args{'clean'} = 1 unless defined $args{'clean'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"clean"} 0 1 1
872
873 # handle recipient parameter
874
875 1 my $recipient;
876
877 1 ▶ if ($args{'recipient'} == RECIPIENT_USER) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'recipient'} == 0) { } 1 0 1
elsif ($args{'recipient'} == 1) { } 0 0 0
878
879 1 $recipient = 'user';
880
881 } elsif ($args{'recipient'} == RECIPIENT_ADMIN) {
882
883 0 $recipient = 'admin';
884
885 } else {
886
887 0 throw WWW::Postini::Exception::InvalidParameter(
888 'Invalid "recipient" parameter specified'
889 );
890
891 }
892
893 # handle messages parameter
894
895 1 my @message_ids;
896
897 1 ▶ if (defined $args{'messages'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"messages"}) 1 0 1
898
899 1 ▶ if (UNIVERSAL::isa ($args{'messages'}, 'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($args{'messages'}, 'ARRAY')) { } 1 0 1
900
901 1 @message_ids = @{$args{'messages'}};
902
903 } else {
904
905 0 @message_ids = $args{'messages'};
906
907 }
908
909 }
910
911 # no messages passed
912
913 1 ▶ throw WWW::Postini::Exception::InvalidParameter('No messages specified')
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @message_ids 0 1 1
914 unless scalar @message_ids
915 ;
916
917 1 my $message_count;
918
919 # try
920
921 1 eval {
922
923 my @args = (
924 action => 'processQuarantine',
925 targetuserid => $args{'user_id'},
926 submit => 'Process',
927 markdeliver => ($args{'mark'} ? 1 : 0),
928 1 ▶ preclean => ($args{'clean'} ? 1 : 0),
Branch: 2 branches
BranchTrueFalseTotal
$args{'mark'} ? : 1 0 1
$args{'clean'} ? : 1 0 1
929 deliv_rcpt => $recipient
930 );
931
932 1 foreach my $id (@message_ids) {
933
934 1 push @args, ('msgid', $id);
935
936 }
937
938 1 my $response = $self->{'_user_agent'}->post(
939 "https://$self->{'_admin_host'}/exec/admin_users",
940 \@args
941 );
942
943 1 assert($response, 'Response returned');
944
945 1 my $code = $response->code();
946 1 assert($code == RC_OK, 'Response code is '.RC_OK);
947
948 1 my $content = $response->content();
949 1 my $p = new HTML::TokeParser(\$content);
950 1 my ($tag, $text);
951
952 1 ▶ while (defined ($tag = $p->get_tag('b'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($tag = $p->get_tag("b"))) 1 0 1
953
954 1 my $text = $p->get_trimmed_text();
955 1 ▶ last if defined $text && $text eq 'Message Results';
Branch: 1 branch
BranchTrueFalseTotal
if defined $text and $text eq "Message Results" 1 0 1
Condition33%1/3
defined $text and $text eq "Message Results"
!ll&&!rl&&r
001
MC/DC0%0/2
defined $text and $text eq "Message Results"
defined $text $text eq "Message Results"
Truth table33%1/3
A and B
A= defined $textB= $text eq "Message Results"
ABresult
0X0
100
111
956
957 }
958
959 1 $tag = $p->get_tag('font');
960 1 assert($tag, 'Font tag exists');
961
962 1 $text = $p->get_trimmed_text();
963 1 assert(
964 $text =~ /^\d+ message\(s\) queued for delivery/,
965 'Message text recognized'
966 );
967
968 1 ($message_count) = $text =~ /^(\d+)/;
969
970 };
971
972 # catch
973
974 1 ▶ if (defined $@ && (length $@ || ref $@)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $@ and length $@ || ref $@) 0 1 1
Condition33%2/6
defined $@ and length $@ || ref $@
!ll&&!rl&&r
010
length $@ or ref $@
l!l&&r!l&&!r
001
MC/DC0%0/3
defined $@ and length $@ || ref $@
defined $@ length $@ ref $@
Truth table25%1/4
A and B or C
A= defined $@B= length $@C= ref $@
ABCresult
0XX0
1000
11X1
1011
975
976 # unexpected response
977
978 0 ▶ if (UNIVERSAL::isa($@, 'WWW::Postini::Exception::UnexpectedResponse')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($@, 'WWW::Postini::Exception::UnexpectedResponse')) { } 0 0 0
979
980 0 $@->rethrow;
981
982 # all other exceptions
983
984 } else {
985
986 0 throw WWW::Postini::Exception::UnexpectedResponse($@);
987
988 }
989
990 }
991
992 1 $message_count;
993
994 }
995
996 # get message field
997
998 93 ▶sub _get_message_field {
Subroutine _get_message_field: called CC=1 SCAR=0.0
999
1000 93 my $self = shift;
1001 93 my $p = shift;
1002 93 my $tag = $p->get_tag ('font');
1003 93 assert ($tag, 'Font tag exists');
1004 93 $p->get_trimmed_text;
1005
1006 }
1007
1008 1 1;
1009
1010 __END__
↑ Summary Postini/Exception.pm »