lib/EMDIS/ECS/FileBackedMessage.pm

filter: Statementstmt 48.0% 176 / 366 Branchbran 27.3% 71 / 260 Conditioncond 14.5% 7 / 48 MC/DCmcdc 10.3% 3 / 29 Subroutinesub 88.8% 24 / 27 Podpod 0.0% 0 / 19 totaltotal 37.5% 281 / 749 CC 149 SCAR 81.5
CC
149
Cov
38%
send_this_message
7140.0
new
86.6
inspect_fml
9.1
CRAP 3447.1
↑ Summary lib/EMDIS/ECS.pm »
1 #!/usr/bin/perl -w
2 #
3 # Copyright (C) 2010-2021 National Marrow Donor Program. All rights reserved.
4 #
5 # For a description of this module, please refer to the POD documentation
6 # embedded at the bottom of the file (e.g. perldoc EMDIS::ECS::FileBackedMessage).
7  
8 package EMDIS::ECS::FileBackedMessage;
9  
10 1 ▶use EMDIS::ECS qw($ECS_CFG $ECS_NODE_TBL $FILEMODE $VERSION ecs_is_configured
Subroutine BEGIN: called CC=1 SCAR=0.0
11 format_datetime format_doc_filename format_msg_filename
12 log_debug log_info log_warn log_error log_fatal
13 send_amqp_message send_encrypted_message send_email
14 1 dequote trim is_yes);
15 1 ▶use Fcntl qw(:DEFAULT :flock);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use File::Spec::Functions qw(catdir catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use File::Temp qw(tempfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 # ----------------------------------------------------------------------
23 # Constructor.
24 # If error encountered, returns error message instead of object reference.
25 sub new
26 29 ▶{
Subroutine new: called CC=38 SCAR=44.6
Pod undocumented
27 29 my $arg1 = shift;
28 29 my $this;
29 29 ▶ if(ref $arg1)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg1) { } 0 29 29
30 {
31 # invoked as instance method
32 0 $this = $arg1;
33 }
34 else
35 {
36 # invoked as class method
37 29 $this = {};
38 29 bless $this, $arg1;
39 }
40  
41 29 my $err = '';
42 29 my ($sender_node_id, $seq_num, $filename);
43 29 my $argc = scalar(@_);
44 29 ▶ if($argc <= 1)
Branch: 2 branches
BranchTrueFalseTotal
if ($argc <= 1) { } 20 9 29
elsif ($argc == 3) { } 9 0 9
45 {
46 20 $filename = shift;
47 }
48 elsif($argc == 3)
49 {
50 9 ($sender_node_id, $seq_num, $filename) = @_;
51 9 ▶ $this->{sender_node_id} = $sender_node_id if $sender_node_id;
Branch: 1 branch
BranchTrueFalseTotal
if $sender_node_id 8 1 9
52 9 ▶ $this->{seq_num} = $seq_num if $seq_num;
Branch: 1 branch
BranchTrueFalseTotal
if $seq_num 2 7 9
53 }
54 else
55 {
56 0 return "Illegal usage -- expected 0, 1, or 3 parameters: " .
57 "[filename] or <sender_node_id>, <seq_num>, <filename>";
58 }
59  
60 # set presumed message type flags - can be overridden by email headers or subject
61 29 $this->{is_ecs_message} = 1;
62 29 $this->{is_meta_message} = '';
63 29 $this->{is_document} = '';
64 29 ▶ if(defined $filename and $filename =~ /(\.doc|\.doc\.xml)$/io)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $filename and $filename =~ /(\.doc|\.doc\.xml)$/io) 2 27 29
Condition66%2/3
defined $filename and $filename =~ /(\.doc|\.doc\.xml)$/io
!ll&&!rl&&r
0272
MC/DC50%1/2
defined $filename and $filename =~ /(\.doc|\.doc\.xml)$/io
defined $filename $filename =~ /(\.doc|\.doc\.xml)$/io
Truth table66%2/3
A and B
A= defined $filenameB= $filename =~ /(\.doc|\.doc\.xml)$/io
ABresult
0X0
100
111
65 {
66 # filename ending in .doc or .doc.xml indicates document (not message)
67 2 $this->{is_ecs_message} = '';
68 2 $this->{is_meta_message} = '';
69 2 $this->{is_document} = 1;
70 }
71  
72 29 $this->{temp_files} = [];
73 29 $this->{is_closed} = 0;
74  
75 # if $filename not specified, read input from stdin
76 29 ▶ if(not $filename)
Branch: 1 branch
BranchTrueFalseTotal
unless ($filename) 0 29 29
77 {
78 # read from stdin, create temp file
79 0 my $template = sprintf('%s_XXXX', format_datetime(time,
80 '%04d%02d%02d_%02d%02d%02d'));
81 0 ▶ return "Unable to create temp file from stdin: ECS is not configured!"
Branch: 1 branch
BranchTrueFalseTotal
unless ecs_is_configured() 0 0 0
82 unless ecs_is_configured();
83 0 my $fh;
84 0 ($fh, $filename) = tempfile($template,
85 DIR => catdir($ECS_CFG->ECS_TMP_DIR),
86 SUFFIX => '.msg');
87 0 binmode(STDIN);
88 0 binmode($fh);
89 0 while(1)
90 {
91 0 my $buffer;
92  
93 0 my $readlen = read STDIN, $buffer, 65536;
94 0 ▶ if(not defined $readlen)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $readlen) 0 0 0
95 {
96 0 $err = "Unexpected problem reading STDIN: $!";
97 0 last;
98 }
99  
100 0 ▶ last if $readlen == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $readlen == 0 0 0 0
101  
102 0 ▶ if(not print $fh $buffer)
Branch: 1 branch
BranchTrueFalseTotal
unless (print $fh $buffer) 0 0 0
103 {
104 0 $err = "Unexpected problem writing file $filename: $!";
105 0 last;
106 }
107 }
108 0 close $fh;
109 0 ▶ if($err)
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
110 {
111 0 unlink $filename;
112 0 return $err;
113 }
114 0 push @{$this->{temp_files}}, $filename;
115 }
116  
117 29 $this->{filename} = $filename;
118 29 my $file_handle;
119 29 ▶ return "Unable to open input file $filename: $!"
Branch: 1 branch
BranchTrueFalseTotal
unless open $file_handle, "+< $filename" 0 29 29
120 unless open $file_handle, "+< $filename";
121 29 $this->{file_handle} = $file_handle;
122 29 binmode $file_handle;
123  
124 # get exclusive lock (with retry loop)
125 # protects against reading a file while another process is writing it
126 29 my $locked = '';
127 29 for my $retry (1..5)
128 {
129 29 $locked = flock $file_handle, LOCK_EX | LOCK_NB;
130 29 ▶ last if $locked;
Branch: 1 branch
BranchTrueFalseTotal
if $locked 29 0 29
131 }
132 29 ▶ if(!$locked)
Branch: 1 branch
BranchTrueFalseTotal
unless ($locked) 0 29 29
133 {
134 0 $err = "Unable to lock input file $filename: $!";
135 0 close $file_handle;
136 0 return $err;
137 }
138  
139 29 my $email_headers = '';
140 29 my $data_offset = 0;
141  
142 # attempt to read email headers only if sender_node_id not yet defined
143 29 ▶ if(not exists $this->{sender_node_id})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $this->{"sender_node_id"}) 21 8 29
144 {
145 # attempt to read email headers from file, determine data offset
146 21 my $buf;
147 21 while(1)
148 {
149 5170 my $bytecount = read $file_handle, $buf, 1;
150  
151 5170 ▶ if(not defined $bytecount)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bytecount) 0 5170 5170
152 {
153 0 $err = "Unexpected problem reading from file $filename: $!";
154 0 last;
155 }
156  
157 5170 ▶ if($bytecount > 0)
Branch: 2 branches
BranchTrueFalseTotal
if ($bytecount > 0) { } 5170 0 5170
elsif ($bytecount == 0 or $data_offset >= 1048576) { } 0 0 0
158 {
159 5170 $email_headers .= $buf;
160 5170 $data_offset++;
161  
162 # first empty line ends potential email header
163 5170 ▶ last if $email_headers =~ /\r?\n\r?\n$/so;
Branch: 1 branch
BranchTrueFalseTotal
if $email_headers =~ /\r?\n\r?\n$/so 21 5149 5170
164 }
165 ▶ elsif($bytecount == 0 or $data_offset >= 1048576)
Condition0%0/3
$bytecount == 0 or $data_offset >= 1048576
l!l&&r!l&&!r
000
MC/DC0%0/2
$bytecount == 0 or $data_offset >= 1048576
$bytecount == 0 $data_offset >= 1048576
Truth table0%0/3
A or B
A= $bytecount == 0B= $data_offset >= 1048576
ABresult
1X1
011
000
166 {
167 # assume file does not contain email header
168 # if EOF encountered or no empty line found in first X bytes
169 0 $data_offset = 0;
170 0 last;
171 }
172 }
173 21 ▶ if($err)
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 21 21
174 {
175 0 close $file_handle;
176 0 return $err;
177 }
178 }
179  
180 29 ▶ if($data_offset > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($data_offset > 0) 21 8 29
181 {
182 # convert headers to more easily parseable format, store in this obj
183 21 $email_headers =~ s/\r?\n/\n/go;
184  
185 # look for "Subject" line
186 21 ▶ if($email_headers =~ /^Subject:\s*(.+?)$/imo)
Branch: 1 branch
BranchTrueFalseTotal
if ($email_headers =~ /^Subject:\s*(.+?)$/imo) 20 1 21
187 {
188 20 $this->{subject} = $1;
189 20 $this->{email_headers} = $email_headers;
190 20 $this->{data_offset} = $data_offset;
191 }
192 }
193  
194 # absence of "Subject" line indicates file contains data only
195 29 ▶ if(not exists $this->{subject})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $this->{"subject"}) 9 20 29
196 {
197 9 $this->{data_offset} = 0;
198 9 return $this;
199 }
200  
201 # parse "Subject" into MAIL_MRK:sender_node_id[:seqnum]
202 20 my $mail_mrk = 'EMDIS';
203 20 ▶ if(ecs_is_configured())
Branch: 1 branch
BranchTrueFalseTotal
if (ecs_is_configured()) { } 0 20 20
204 {
205 0 $mail_mrk = $ECS_CFG->MAIL_MRK;
206 }
207 else
208 {
209 20 warn "ECS not configured, using MAIL_MRK = '$mail_mrk'\n";
210 }
211 20 ▶ if($this->{subject} =~ /$mail_mrk:(\S+?):(\d+)(:(\d+)\/(\d+))?\s*$/i)
Branch: 3 branches
BranchTrueFalseTotal
if ($this->{'subject'} =~ m[$mail_mrk:(\S+?):(\d+)(:(\d+)/(\d+))?\s*$]i) { } 10 10 20
elsif ($this->{'subject'} =~ /$mail_mrk:(\S+?):(\d+):DOC\s*$/io) { } 1 9 10
elsif ($this->{'subject'} =~ /$mail_mrk:(\S+)\s*$/i) { } 4 5 9
212 {
213 # regular message
214 10 $this->{is_ecs_message} = 1;
215 10 $this->{is_meta_message} = '';
216 10 $this->{is_document} = '';
217 10 $this->{sender_node_id} = $1;
218 10 $this->{seq_num} = $2;
219 10 ▶ $this->{part_num} = $4 if defined $4;
Branch: 1 branch
BranchTrueFalseTotal
if defined $4 6 4 10
220 10 ▶ $this->{num_parts} = $5 if defined $5;
Branch: 1 branch
BranchTrueFalseTotal
if defined $5 6 4 10
221 10 ▶ if(exists $this->{part_num} and exists $this->{num_parts}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $this->{"part_num"} and exists $this->{"num_parts"} and $this->{"part_num"} > $this->{"num_parts"}) 1 9 10
Condition83%5/6
exists $this->{"part_num"} and exists $this->{"num_parts"} and $this->{"part_num"} > $this->{"num_parts"}
!ll&&!rl&&r
451
exists $this->{"part_num"} and exists $this->{"num_parts"}
!ll&&!rl&&r
406
MC/DC66%2/3
exists $this->{"part_num"} and exists $this->{"num_parts"} and $this->{"part_num"} > $this->{"num_parts"}
exists $this->{"part_num"} exists $this->{"num_parts"} $this->{"part_num"} > $this->{"num_parts"}
Truth table75%3/4
A and B and C
A= exists $this->{"part_num"}B= exists $this->{"num_parts"}C= $this->{"part_num"} > $this->{"num_parts"}
ABCresult
0XX0
10X0
1100
1111
222 and $this->{part_num} > $this->{num_parts})
223 {
224 1 close $file_handle;
225 1 return "part_num is greater than num_parts: " . $this->{subject};
226 }
227 }
228 elsif($this->{subject} =~ /$mail_mrk:(\S+?):(\d+):DOC\s*$/io) {
229 # document
230 1 $this->{sender_node_id} = $1;
231 1 $this->{is_ecs_message} = '';
232 1 $this->{is_meta_message} = '';
233 1 $this->{is_document} = 1;
234 1 $this->{seq_num} = $2;
235 }
236 elsif($this->{subject} =~ /$mail_mrk:(\S+)\s*$/i)
237 {
238 # meta-message
239 4 $this->{sender_node_id} = $1;
240 4 $this->{is_ecs_message} = 1;
241 4 $this->{is_meta_message} = 1;
242 4 $this->{is_document} = '';
243 }
244 else
245 {
246 # subject line indicates this is not an ECS message or document
247 5 $this->{is_ecs_message} = '';
248 5 $this->{is_meta_message} = '';
249 5 $this->{is_document} = '';
250 }
251  
252 19 ▶ return $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 19 19
253  
254 19 return $this;
255 }
256  
257 # ----------------------------------------------------------------------
258 # prepare for object destruction: close $this->{file_handle}, delete
259 # temp files
260 sub cleanup
261 29 ▶{
Subroutine cleanup: called CC=4 SCAR=14.6
Pod undocumented
262 29 my $this = shift;
263 29 ▶ die "cleanum() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 29 29
264 unless ref $this;
265 close $this->{file_handle}
266 29 ▶ if exists $this->{file_handle};
Branch: 1 branch
BranchTrueFalseTotal
if exists $this->{"file_handle"} 29 0 29
267 29 foreach my $temp_file (@{$this->{temp_files}})
268 {
269 0 unlink $temp_file;
270 }
271 29 $this->{is_closed} = 1;
272 }
273  
274 # ----------------------------------------------------------------------
275 # Accessor method (read-only).
276 sub data_offset
277 4 ▶{
Subroutine data_offset: called CC=2 SCAR=7.1
Pod undocumented
278 4 my $this = shift;
279 4 ▶ die "data_offset() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 4 4
280 unless ref $this;
281 4 return $this->{data_offset};
282 }
283  
284 # ----------------------------------------------------------------------
285 # Accessor method (read-only).
286 sub email_headers
287 4 ▶{
Subroutine email_headers: called CC=2 SCAR=7.1
Pod undocumented
288 4 my $this = shift;
289 4 ▶ die "email_headers() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 4 4
290 unless ref $this;
291 4 return $this->{email_headers};
292 }
293  
294 # ----------------------------------------------------------------------
295 # Accessor method (read-only).
296 sub filename
297 1 ▶{
Subroutine filename: called CC=2 SCAR=7.1
Pod undocumented
298 1 my $this = shift;
299 1 ▶ die "filename() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 1 1
300 unless ref $this;
301 1 return $this->{filename};
302 }
303  
304 # ----------------------------------------------------------------------
305 # Accessor method (read-only).
306 sub hub_rcv
307 2 ▶{
Subroutine hub_rcv: called CC=2 SCAR=7.1
Pod undocumented
308 2 my $this = shift;
309 2 ▶ die "hub_rcv() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 2 2
310 unless ref $this;
311 2 return $this->{hub_rcv};
312 }
313  
314 # ----------------------------------------------------------------------
315 # Accessor method (read-only).
316 sub hub_snd
317 2 ▶{
Subroutine hub_snd: called CC=2 SCAR=7.1
Pod undocumented
318 2 my $this = shift;
319 2 ▶ die "hub_snd() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 2 2
320 unless ref $this;
321 2 return $this->{hub_snd};
322 }
323  
324 # ----------------------------------------------------------------------
325 # Accessor method (read-only).
326 sub is_ecs_message
327 20 ▶{
Subroutine is_ecs_message: called CC=2 SCAR=7.1
Pod undocumented
328 20 my $this = shift;
329 20 ▶ die "is_ecs_message() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 20 20
330 unless ref $this;
331 20 return $this->{is_ecs_message};
332 }
333  
334 # ----------------------------------------------------------------------
335 # Accessor method (read-only).
336 sub is_meta_message
337 16 ▶{
Subroutine is_meta_message: called CC=2 SCAR=7.1
Pod undocumented
338 16 my $this = shift;
339 16 ▶ die "is_meta_message() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 16 16
340 unless ref $this;
341 16 return $this->{is_meta_message};
342 }
343  
344 # ----------------------------------------------------------------------
345 # Accessor method (read-only).
346 sub is_document
347 3 ▶{
Subroutine is_document: called CC=2 SCAR=7.1
Pod undocumented
348 3 my $this = shift;
349 3 ▶ die "is_document() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 3 3
350 unless ref $this;
351 3 return $this->{is_document};
352 }
353  
354 # ----------------------------------------------------------------------
355 # Accessor method (read-only).
356 sub num_parts
357 3 ▶{
Subroutine num_parts: called CC=2 SCAR=7.1
Pod undocumented
358 3 my $this = shift;
359 3 ▶ die "num_parts() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 3 3
360 unless ref $this;
361 3 return $this->{num_parts};
362 }
363  
364 # ----------------------------------------------------------------------
365 # Accessor method (read-only).
366 sub part_num
367 3 ▶{
Subroutine part_num: called CC=2 SCAR=7.1
Pod undocumented
368 3 my $this = shift;
369 3 ▶ die "part_num() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 3 3
370 unless ref $this;
371 3 return $this->{part_num};
372 }
373  
374 # ----------------------------------------------------------------------
375 # Accessor method (read-only).
376 sub sender
377 0 ▶{
Subroutine sender: not called CC=2 SCAR=17.9
Pod undocumented
378 0 my $this = shift;
379 0 ▶ die "sender() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 0 0
380 unless ref $this;
381 0 return $this->{sender_node_id};
382 }
383  
384 # ----------------------------------------------------------------------
385 # Accessor method (read-only).
386 sub sender_node_id
387 14 ▶{
Subroutine sender_node_id: called CC=2 SCAR=7.1
Pod undocumented
388 14 my $this = shift;
389 14 ▶ die "sender_node_id() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 14 14
390 unless ref $this;
391 14 return $this->{sender_node_id};
392 }
393  
394 # ----------------------------------------------------------------------
395 # Accessor method (read-only).
396 sub seq_num
397 10 ▶{
Subroutine seq_num: called CC=2 SCAR=7.1
Pod undocumented
398 10 my $this = shift;
399 10 ▶ die "seq_num() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 10 10
400 unless ref $this;
401 10 return $this->{seq_num};
402 }
403  
404 # ----------------------------------------------------------------------
405 # Accessor method (read-only).
406 sub subject
407 8 ▶{
Subroutine subject: called CC=2 SCAR=7.1
Pod undocumented
408 8 my $this = shift;
409 8 ▶ die "subject() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 8 8
410 unless ref $this;
411 8 return $this->{subject};
412 }
413  
414 # ----------------------------------------------------------------------
415 # Accessor method (read only)
416 sub temp_files
417 0 ▶{
Subroutine temp_files: not called CC=2 SCAR=17.9
Pod undocumented
418 0 my $this = shift;
419 0 ▶ die "temp_files() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 0 0
420 unless ref $this;
421 0 return @{$this->{temp_files}};
422 }
423  
424 # ----------------------------------------------------------------------
425 # object destructor, called by perl garbage collector
426 sub DESTROY
427 56 ▶{
Subroutine DESTROY: called CC=3 SCAR=11.1
428 56 my $this = shift;
429 56 ▶ die "DESTROY() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 56 56
430 unless ref $this;
431 56 ▶ $this->cleanup unless $this->{is_closed};
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"is_closed"} 29 27 56
432 }
433  
434 # ----------------------------------------------------------------------
435 # read first portion of message, attempt to extract HUB_SND and HUB_RCV
436 # (deprecated -- may be called explicitly, but is no longer used by FileBackedMessage constructor)
437 sub inspect_fml
438 6 ▶{
Subroutine inspect_fml: called CC=9 SCAR=22.1
Pod undocumented
439 6 my $this = shift;
440 6 ▶ return "inspect_fml() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 6 6
441 unless ref $this;
442 return "inspect_fml(): this FileBackedMessage object is closed!"
443 6 ▶ if $this->{is_closed};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"is_closed"} 0 6 6
444  
445 # read first part of FML payload, look for HUB_SND, HUB_RCV
446  
447 return "Unable to position file pointer for file $this->{filename}" .
448 " to position $this->{data_offset}: $!"
449 6 ▶ unless seek $this->{file_handle}, $this->{data_offset}, 0;
Branch: 1 branch
BranchTrueFalseTotal
unless seek $this->{"file_handle"}, $this->{"data_offset"}, 0 0 6 6
450 6 my $fml;
451 6 my $bytecount = read $this->{file_handle}, $fml, 65536;
452 6 ▶ return "Unable to read from file " . $this->{filename} . ": $!"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytecount 0 6 6
453 unless defined $bytecount;
454  
455 # compute is_ecs_message and is_meta_message
456 6 ▶ if($fml =~ /^\s*(BLOCK_BEGIN\s+\w+\s*;\s*)?\w+\s*:/iso)
Branch: 2 branches
BranchTrueFalseTotal
if ($fml =~ /^\s*(BLOCK_BEGIN\s+\w+\s*;\s*)?\w+\s*:/iso) { } 4 2 6
elsif ($fml =~ /^\s*msg_type\s*=\s*\S+/imos) { } 1 1 2
457 {
458 4 $this->{is_ecs_message} = 1;
459 4 $this->{is_meta_message} = '';
460 4 $this->{is_document} = '';
461 }
462 elsif($fml =~ /^\s*msg_type\s*=\s*\S+/isom)
463 {
464 1 $this->{is_ecs_message} = 1;
465 1 $this->{is_meta_message} = 1;
466 1 $this->{is_document} = '';
467 1 return '';
468 }
469 else
470 {
471 1 $this->{is_ecs_message} = '';
472 1 $this->{is_meta_message} = '';
473 1 $this->{is_document} = '';
474 1 return '';
475 }
476  
477 # Note: this code only understands the simple forms of FML assignments
478 # (not the extended /FIELDS form)
479  
480 # look for HUB_RCV
481 4 ▶ if($fml =~ /HUB_RCV\s*=\s*([^,;]+)/iso) # presumes [^,;] in HUB_RCV
Branch: 1 branch
BranchTrueFalseTotal
if ($fml =~ /HUB_RCV\s*=\s*([^,;]+)/iso) 3 1 4
482 {
483 3 $this->{hub_rcv} = dequote(trim($1));
484 }
485  
486 # look for HUB_SND
487 4 ▶ if($fml =~ /HUB_SND\s*=\s*([^,;]+)/iso) # presumes [^,;] in HUB_SND
Branch: 1 branch
BranchTrueFalseTotal
if ($fml =~ /HUB_SND\s*=\s*([^,;]+)/iso) 3 1 4
488 {
489 3 $this->{hub_snd} = dequote(trim($1));
490 }
491  
492 4 return '';
493 }
494  
495 # ----------------------------------------------------------------------
496 sub send_this_message
497 0 ▶{
Subroutine send_this_message: not called CC=84 SCAR=88.7
Pod undocumented
498 0 my $this = shift;
499 0 ▶ return "send_this_message() must only be called as an instance method!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $this 0 0 0
500 unless ref $this;
501 return "send_this_message(): this FileBackedMessage object is closed!"
502 0 ▶ if $this->{is_closed};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"is_closed"} 0 0 0
503 return "send_this_message(): this FileBackedMessage object represents " .
504 "only a partial message!"
505 0 ▶ if defined $this->{num_parts} and $this->{num_parts} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $this->{"num_parts"} and $this->{"num_parts"} > 1 0 0 0
Condition0%0/3
defined $this->{"num_parts"} and $this->{"num_parts"} > 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $this->{"num_parts"} and $this->{"num_parts"} > 1
defined $this->{"num_parts"} $this->{"num_parts"} > 1
Truth table0%0/3
A and B
A= defined $this->{"num_parts"}B= $this->{"num_parts"} > 1
ABresult
0X0
100
111
506  
507 # initialize
508 0 my $rcv_node_id = shift;
509 0 my $is_re_send = shift;
510 0 my $part_num = shift;
511 0 ▶ return "send_this_message(): ECS has not been configured."
Branch: 1 branch
BranchTrueFalseTotal
unless ecs_is_configured() 0 0 0
512 unless ecs_is_configured();
513 0 my $cfg = $ECS_CFG;
514 0 my $node_tbl = $ECS_NODE_TBL;
515 0 my $err = '';
516  
517 0 ▶ return "send_this_message(): Missing \$rcv_node_id!"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rcv_node_id and $rcv_node_id 0 0 0
Condition0%0/3
defined $rcv_node_id and $rcv_node_id
!ll&&!rl&&r
000
MC/DC0%0/2
defined $rcv_node_id and $rcv_node_id
defined $rcv_node_id $rcv_node_id
Truth table0%0/3
A and B
A= defined $rcv_node_idB= $rcv_node_id
ABresult
0X0
100
111
518 unless defined $rcv_node_id and $rcv_node_id;
519  
520 # lock node_tbl, look up $rcv_node_id
521 0 my $was_locked = $node_tbl->LOCK;
522 0 ▶ if(not $was_locked)
Branch: 1 branch
BranchTrueFalseTotal
unless ($was_locked) 0 0 0
523 {
524 0 ▶ $node_tbl->lock() # lock node_tbl
Branch: 1 branch
BranchTrueFalseTotal
$node_tbl->lock or return 'send_this_message(): unable to lock node_tbl: ' . $node_tbl->ERROR 0 0 0
525 or return "send_this_message(): unable to lock node_tbl: " .
526 $node_tbl->ERROR;
527 }
528 0 my $node = $node_tbl->read($rcv_node_id);
529 0 ▶ if(not $node)
Branch: 1 branch
BranchTrueFalseTotal
unless ($node) 0 0 0
530 {
531 0 ▶ $node_tbl->unlock() unless $was_locked; # unlock node_tbl if needed
Branch: 1 branch
BranchTrueFalseTotal
unless $was_locked 0 0 0
532 0 return "send_this_message(): node not found: $rcv_node_id";
533 }
534 0 ▶ if(not $node->{addr})
Branch: 1 branch
BranchTrueFalseTotal
unless ($node->{"addr"}) 0 0 0
535 {
536 0 ▶ $node_tbl->unlock() unless $was_locked; # unlock node_tbl if needed
Branch: 1 branch
BranchTrueFalseTotal
unless $was_locked 0 0 0
537 0 return "send_this_message(): addr not defined for node: $rcv_node_id";
538 }
539  
540 # compute or assign message seq_num
541 0 my $seq_num = '';
542 0 ▶ if($is_re_send and not $this->{is_document})
Branch: 4 branches
BranchTrueFalseTotal
if ($is_re_send and not $this->{'is_document'}) { } 0 0 0
elsif ($is_re_send and $this->{'is_document'}) { } 0 0 0
elsif ($this->{'is_document'}) { } 0 0 0
elsif (not $this->{'is_meta_message'}) { } 0 0 0
Condition0%0/3
$is_re_send and not $this->{"is_document"}
!ll&&!rl&&r
000
MC/DC0%0/2
$is_re_send and not $this->{"is_document"}
$is_re_send not $this->{"is_document"}
Truth table0%0/3
A and not(B)
A= $is_re_sendB= not $this->{"is_document"}
ABresult
0X0
100
111
543 {
544 # sanity checks
545 0 ▶ if(not defined $this->{seq_num})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $this->{"seq_num"}) 0 0 0
546 {
547 0 ▶ $node_tbl->unlock() unless $was_locked; # unlock node_tbl if needed
Branch: 1 branch
BranchTrueFalseTotal
unless $was_locked 0 0 0
548 0 return "send_this_message(): seq_num not defined for RE_SEND";
549 }
550 0 ▶ if($this->{seq_num} > $node->{out_seq})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"seq_num"} > $node->{"out_seq"}) 0 0 0
551 {
552 0 ▶ $node_tbl->unlock() unless $was_locked; # unlock node_tbl if needed
Branch: 1 branch
BranchTrueFalseTotal
unless $was_locked 0 0 0
553 return "send_this_message(): seq_num for RE_SEND (" .
554 $this->{seq_num} . ") is greater than out_seq for node " .
555 0 "$rcv_node_id (" . $node->{out_seq} . ")!";
556 }
557 0 $seq_num = $this->{seq_num};
558 }
559 ▶ elsif($is_re_send and $this->{is_document})
Condition0%0/3
$is_re_send and $this->{"is_document"}
!ll&&!rl&&r
000
MC/DC0%0/2
$is_re_send and $this->{"is_document"}
$is_re_send $this->{"is_document"}
Truth table0%0/3
A and B
A= $is_re_sendB= $this->{"is_document"}
ABresult
0X0
100
111
560 {
561 # sanity checks
562 0 ▶ if(not defined $this->{seq_num})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $this->{"seq_num"}) 0 0 0
563 {
564 0 ▶ $node_tbl->unlock() unless $was_locked; # unlock node_tbl if needed
Branch: 1 branch
BranchTrueFalseTotal
unless $was_locked 0 0 0
565 0 return "send_this_message(): seq_num not defined for DOC_RE_SEND";
566 }
567 0 ▶ if($this->{seq_num} > $node->{doc_out_seq})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"seq_num"} > $node->{"doc_out_seq"}) 0 0 0
568 {
569 0 ▶ $node_tbl->unlock() unless $was_locked; # unlock node_tbl if needed
Branch: 1 branch
BranchTrueFalseTotal
unless $was_locked 0 0 0
570 return "send_this_message(): seq_num for DOC_RE_SEND (" .
571 $this->{seq_num} . ") is greater than doc_out_seq for node " .
572 0 "$rcv_node_id (" . $node->{doc_out_seq} . ")!";
573 }
574 0 $seq_num = $this->{seq_num};
575 }
576 elsif($this->{is_document})
577 {
578 # automatically get next (doc) sequence number
579 0 $node->{doc_out_seq}++;
580 0 $seq_num = $node->{doc_out_seq};
581 }
582 elsif(not $this->{is_meta_message})
583 {
584 # only allow $part_num to be specified if this is a RE_SEND request
585 0 ▶ if($part_num)
Branch: 1 branch
BranchTrueFalseTotal
if ($part_num) 0 0 0
586 {
587 0 ▶ $node_tbl->unlock() unless $was_locked; # unlock node_tbl if needed
Branch: 1 branch
BranchTrueFalseTotal
unless $was_locked 0 0 0
588 0 return "send_this_message(): part_num specified ($part_num), for " .
589 "non- RE_SEND request!";
590 }
591 # automatically get next (msg) sequence number
592 0 $node->{out_seq}++;
593 0 $seq_num = $node->{out_seq};
594 }
595  
596 # compute message part size
597 0 my $msg_part_size = $cfg->MSG_PART_SIZE_DFLT;
598 0 ▶ if(defined $node->{msg_part_size} and $node->{msg_part_size} > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node->{"msg_part_size"} and $node->{"msg_part_size"} > 0) 0 0 0
Condition0%0/3
defined $node->{"msg_part_size"} and $node->{"msg_part_size"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $node->{"msg_part_size"} and $node->{"msg_part_size"} > 0
defined $node->{"msg_part_size"} $node->{"msg_part_size"} > 0
Truth table0%0/3
A and B
A= defined $node->{"msg_part_size"}B= $node->{"msg_part_size"} > 0
ABresult
0X0
100
111
599 {
600 0 $msg_part_size = $node->{msg_part_size};
601 }
602  
603 # compute data size
604 0 my $file_size = (stat $this->{file_handle})[7];
605 0 my $data_size = $file_size - $this->{data_offset};
606 0 ▶ if($data_size <= 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($data_size <= 0) 0 0 0
607 {
608 0 ▶ $node_tbl->unlock() unless $was_locked; # unlock node_tbl if needed
Branch: 1 branch
BranchTrueFalseTotal
unless $was_locked 0 0 0
609 0 return "send_this_message(): data_size is <= 0 ($data_size)!";
610 }
611  
612 # for document, force num_parts = 1
613 0 ▶ if($this->{is_document})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"is_document"}) 0 0 0
614 {
615 0 $msg_part_size = $data_size;
616 }
617  
618 # compute num_parts
619 0 my $num_parts = int($data_size / $msg_part_size);
620 0 ▶ $num_parts++ if ($data_size % $msg_part_size) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $data_size % $msg_part_size > 0 0 0 0
621 # num_parts should be 1 for meta message
622 0 ▶ if($this->{is_meta_message} and $num_parts > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"is_meta_message"} and $num_parts > 1) 0 0 0
Condition0%0/3
$this->{"is_meta_message"} and $num_parts > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$this->{"is_meta_message"} and $num_parts > 1
$this->{"is_meta_message"} $num_parts > 1
Truth table0%0/3
A and B
A= $this->{"is_meta_message"}B= $num_parts > 1
ABresult
0X0
100
111
623 {
624 0 ▶ $node_tbl->unlock() unless $was_locked; # unlock node_tbl if needed
Branch: 1 branch
BranchTrueFalseTotal
unless $was_locked 0 0 0
625 0 return "send_this_message(): num_parts cannot be > 1 for meta message!";
626 }
627 # $part_num cannot be greater than $num_parts
628 0 ▶ if(defined $part_num and $part_num and $part_num > $num_parts)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $part_num and $part_num and $part_num > $num_parts) 0 0 0
Condition0%0/6
defined $part_num and $part_num and $part_num > $num_parts
!ll&&!rl&&r
000
defined $part_num and $part_num
!ll&&!rl&&r
000
MC/DC0%0/3
defined $part_num and $part_num and $part_num > $num_parts
defined $part_num $part_num $part_num > $num_parts
Truth table0%0/4
A and B and C
A= defined $part_numB= $part_numC= $part_num > $num_parts
ABCresult
0XX0
10X0
1100
1111
629 {
630 0 ▶ $node_tbl->unlock() unless $was_locked; # unlock node_tbl if needed
Branch: 1 branch
BranchTrueFalseTotal
unless $was_locked 0 0 0
631 0 return "send_this_message(): part_num ($part_num) cannot be greater " .
632 "than num_parts ($num_parts)!";
633 }
634  
635 # compute base subject
636 0 my $subject = $cfg->MAIL_MRK . ':' . $cfg->THIS_NODE;
637 0 ▶ $subject .= ":$seq_num" if $seq_num;
Branch: 1 branch
BranchTrueFalseTotal
if $seq_num 0 0 0
638 0 ▶ $subject .= ":DOC" if $this->{is_document};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"is_document"} 0 0 0
639  
640 0 ▶ if($is_re_send)
Branch: 1 branch
BranchTrueFalseTotal
if ($is_re_send) { } 0 0 0
641 {
642 # to save disk space, don't copy message to file for RE_SEND
643 0 ▶ log_info("send_this_message(): transmitting $rcv_node_id RE_SEND " .
Branch: 1 branch
BranchTrueFalseTotal
$part_num ? : 0 0 0
644 "message $seq_num" . ($part_num ? ":$part_num" : '') . "\n");
645 }
646 else
647 {
648 # copy message to file (for non- RE_SEND)
649  
650 0 my $filename;
651  
652 0 ▶ if($this->{is_meta_message})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'is_meta_message'}) { } 0 0 0
653 {
654 # copy meta message to mboxes/out subdirectory
655 0 $filename = sprintf("%s_%s_%s.msg",
656 $cfg->THIS_NODE, $rcv_node_id, "META");
657 0 my $dirname = $cfg->ECS_MBX_OUT_DIR;
658 # create directory if it doesn't already exist
659 0 ▶ mkdir $dirname unless -e $dirname;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dirname 0 0 0
660 0 $filename = catfile($dirname, $filename);
661 }
662 else
663 {
664 # copy regular message or document file to mboxes/out_NODE subdirectory
665 0 ▶ if($this->{is_document})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'is_document'}) { } 0 0 0
666 {
667 0 $filename = format_doc_filename($rcv_node_id, $seq_num);
668 }
669 else
670 {
671 0 $filename = format_msg_filename($rcv_node_id, $seq_num);
672 }
673 # create directory if it doesn't already exist
674 0 my $dirname = dirname($filename);
675 0 ▶ mkdir $dirname unless -e $dirname;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dirname 0 0 0
676 }
677  
678 # don't overwrite $filename file if it already exists
679 0 my $fh;
680 0 ▶ if(-e $filename)
Branch: 1 branch
BranchTrueFalseTotal
if (-e $filename) { } 0 0 0
681 {
682 0 my $template = $filename . "_XXXXXX";
683 0 ($fh, $filename) = tempfile($template);
684 0 ▶ return "send_this_message(): unable to open _XXXX file: " .
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 0 0 0
685 "$filename"
686 unless $fh;
687 }
688 else
689 {
690 0 $fh = new IO::File;
691 0 ▶ return "send_this_message(): unable to open file: " .
Branch: 1 branch
BranchTrueFalseTotal
unless $fh->open("> $filename") 0 0 0
692 "$filename"
693 unless $fh->open("> $filename");
694 }
695  
696 0 print $fh "Subject: $subject\n";
697 0 print $fh "To: $node->{addr}\n";
698 0 print $fh "From: " . $cfg->SMTP_FROM . "\n\n";
699 # copy data to $fh
700 $err = "Unable to position file pointer for file $this->{filename}" .
701 " to position $this->{data_offset}: $!"
702 0 ▶ unless seek $this->{file_handle}, $this->{data_offset}, 0;
Branch: 1 branch
BranchTrueFalseTotal
unless seek $this->{"file_handle"}, $this->{"data_offset"}, 0 0 0 0
703 0 my $buffer;
704 0 while(1)
705 {
706 0 ▶ if($err)
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
707 {
708 0 ▶ $node_tbl->unlock() unless $was_locked; # unlock if needed
Branch: 1 branch
BranchTrueFalseTotal
unless $was_locked 0 0 0
709 0 close $fh;
710 0 unlink $filename;
711 0 return $err;
712 }
713  
714 0 my $bytecount = read $this->{file_handle}, $buffer, 65536;
715 0 ▶ if(not defined $bytecount)
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $bytecount) { } 0 0 0
elsif ($bytecount == 0) { } 0 0 0
716 {
717 0 $err = "send_this_message(): Problem reading input file " .
718 "$this->{filename}: $!";
719 }
720 elsif($bytecount == 0)
721 {
722 0 last; # EOF
723 }
724 else
725 {
726 0 ▶ print $fh $buffer
Branch: 1 branch
BranchTrueFalseTotal
print $fh $buffer or $err = 'send_this_message(): Problem writing output ' . "file ${filename}: $!" 0 0 0
727 or $err = "send_this_message(): Problem writing output " .
728 "file $filename: $!";
729 }
730 }
731 0 close $fh;
732 0 chmod $FILEMODE, $filename;
733 }
734  
735 0 my $custom_headers = {};
736 0 $custom_headers->{'x-emdis-hub-rcv'} = $rcv_node_id;
737 0 $custom_headers->{'x-emdis-hub-snd'} = $cfg->THIS_NODE;
738  
739 0 ▶ if($num_parts == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($num_parts == 1) { } 0 0 0
740 {
741 # read all data, send single email message
742 $err = "send_this_message(): Unable to position file pointer for " .
743 "file $this->{filename} to position $this->{data_offset}: $!"
744 0 ▶ unless seek $this->{file_handle}, $this->{data_offset}, 0;
Branch: 1 branch
BranchTrueFalseTotal
unless seek $this->{"file_handle"}, $this->{"data_offset"}, 0 0 0 0
745  
746 0 ▶ if(not $err)
Branch: 1 branch
BranchTrueFalseTotal
unless ($err) 0 0 0
747 {
748 0 my $all_data;
749 0 my $bytecount = read $this->{file_handle}, $all_data, $data_size;
750  
751 0 ▶ if(not defined $bytecount)
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $bytecount) { } 0 0 0
elsif ($bytecount != $data_size) { } 0 0 0
elsif ($this->{'is_meta_message'} and not $node->{'encr_meta'} =~ /true/io) { } 0 0 0
752 {
753 0 $err = "send_this_message(): Problem reading input file " .
754 "$this->{filename}: $!";
755 }
756 elsif($bytecount != $data_size)
757 {
758 0 $err = "send_this_message(): Problem reading from input file " .
759 "$this->{filename}: expected $msg_part_size bytes, " .
760 "found $bytecount bytes.";
761 }
762 ▶ elsif($this->{is_meta_message}
Condition0%0/3
$this->{"is_meta_message"} and not $node->{"encr_meta"} =~ /true/io
!ll&&!rl&&r
000
MC/DC0%0/2
$this->{"is_meta_message"} and not $node->{"encr_meta"} =~ /true/io
$this->{"is_meta_message"} not $node->{"encr_meta"} =~ /true/io
Truth table0%0/3
A and not(B)
A= $this->{"is_meta_message"}B= not $node->{"encr_meta"} =~ /true/io
ABresult
0X0
100
111
763 and ($node->{encr_meta} !~ /true/io))
764 {
765 # don't encrypt meta-message
766 0 ▶ if(is_yes($cfg->ENABLE_AMQP) and exists $node->{amqp_addr_meta} and $node->{amqp_addr_meta}) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_yes($cfg->ENABLE_AMQP) and exists $node->{'amqp_addr_meta'} and $node->{'amqp_addr_meta'}) { } 0 0 0
elsif (is_yes($node->{'amqp_only'})) { } 0 0 0
Condition0%0/6
is_yes($cfg->ENABLE_AMQP) and exists $node->{"amqp_addr_meta"} and $node->{"amqp_addr_meta"}
!ll&&!rl&&r
000
is_yes($cfg->ENABLE_AMQP) and exists $node->{"amqp_addr_meta"}
!ll&&!rl&&r
000
MC/DC0%0/3
is_yes($cfg->ENABLE_AMQP) and exists $node->{"amqp_addr_meta"} and $node->{"amqp_addr_meta"}
is_yes($cfg->ENABLE_AMQP) exists $node->{"amqp_addr_meta"} $node->{"amqp_addr_meta"}
Truth table0%0/4
A and B and C
A= is_yes($cfg->ENABLE_AMQP)B= exists $node->{"amqp_addr_meta"}C= $node->{"amqp_addr_meta"}
ABCresult
0XX0
10X0
1100
1111
767 # send meta-message via AMQP (if indicated by node config)
768 $err = send_amqp_message(
769 $node->{amqp_addr_meta},
770 0 $subject,
771 $node,
772 $custom_headers,
773 $all_data);
774 }
775 elsif(is_yes($node->{amqp_only})) {
776 0 $err = "send_this_message(): Unable to send email META message " .
777 "to node $rcv_node_id: amqp_only selected.";
778 }
779 else {
780 0 $err = send_email($node->{addr}, $subject, undef, $all_data);
781 }
782 }
783 else
784 {
785 # send encrypted message
786 $err = send_encrypted_message(
787 $node->{encr_typ},
788 $node->{addr_r},
789 $node->{addr},
790 $node->{encr_out_keyid},
791 $node->{encr_out_passphrase},
792 0 $node,
793 $subject,
794 $custom_headers,
795 $all_data);
796 }
797 }
798 }
799 else
800 {
801 # process message parts ...
802  
803 0 my $min_part_num = 1;
804 0 my $max_part_num = $num_parts;
805 0 ▶ if($part_num)
Branch: 1 branch
BranchTrueFalseTotal
if ($part_num) 0 0 0
806 {
807 # if $part_num specified, limit to that $part_num
808 0 $min_part_num = $part_num;
809 0 $max_part_num = $part_num;
810 }
811  
812 # iterate through message part(s), send email message(s)
813 0 my $parts_sent = 0;
814 0 ▶ for($part_num = $min_part_num; $part_num <= $max_part_num; $part_num++)
Branch: 1 branch
BranchTrueFalseTotal
if ($part_num <= $max_part_num) 0 0 0
815 {
816 my $part_offset = $this->{data_offset} +
817 0 ($part_num -1) * $msg_part_size;
818 $err = "send_this_message(): Unable to position file pointer for " .
819 "file $this->{filename} to position $this->{data_offset}: $!"
820 0 ▶ unless seek $this->{file_handle}, $part_offset, 0;
Branch: 1 branch
BranchTrueFalseTotal
unless seek $this->{"file_handle"}, $part_offset, 0 0 0 0
821  
822 0 ▶ if(not $err)
Branch: 1 branch
BranchTrueFalseTotal
unless ($err) 0 0 0
823 {
824 0 my $part_data;
825 0 my $bytecount = read $this->{file_handle}, $part_data,
826 $msg_part_size;
827  
828 0 ▶ if(not defined $bytecount)
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $bytecount) { } 0 0 0
elsif ($part_num < $num_parts and $bytecount != $msg_part_size) { } 0 0 0
elsif ($bytecount <= 0) { } 0 0 0
829 {
830 0 $err = "send_this_message(): Problem reading input file " .
831 "$this->{filename}: $!";
832 }
833 ▶ elsif($part_num < $num_parts and $bytecount != $msg_part_size)
Condition0%0/3
$part_num < $num_parts and $bytecount != $msg_part_size
!ll&&!rl&&r
000
MC/DC0%0/2
$part_num < $num_parts and $bytecount != $msg_part_size
$part_num < $num_parts $bytecount != $msg_part_size
Truth table0%0/3
A and B
A= $part_num < $num_partsB= $bytecount != $msg_part_size
ABresult
0X0
100
111
834 {
835 0 $err = "send_this_message(): Problem reading $rcv_node_id " .
836 "message part $part_num/$num_parts from input file " .
837 "$this->{filename}: expected $msg_part_size bytes, " .
838 "found $bytecount bytes.";
839 }
840 elsif($bytecount <= 0)
841 {
842 0 $err = "send_this_message(): Problem reading $rcv_node_id " .
843 "message part $part_num/$num_parts from input file " .
844 "$this->{filename}: found $bytecount bytes.";
845 }
846 else
847 {
848 # send encrypted email message
849 $err = send_encrypted_message(
850 $node->{encr_typ},
851 $node->{addr_r},
852 $node->{addr},
853 $node->{encr_out_keyid},
854 $node->{encr_out_passphrase},
855 0 $node,
856 "$subject:$part_num/$num_parts",
857 $custom_headers,
858 $part_data);
859 }
860 }
861  
862 0 ▶ if($err)
Branch: 1 branch
BranchTrueFalseTotal
if ($err) { } 0 0 0
863 {
864 0 ▶ if($parts_sent == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($parts_sent == 0) { } 0 0 0
865 {
866 # nothing sent yet, so quit now (possible smtp problem?)
867 0 last;
868 }
869 else
870 {
871 # part of message was sent, so log error and continue
872 0 log_error($err);
873 0 $err = '';
874 }
875 }
876 else
877 {
878 0 $parts_sent++;
879 }
880 }
881 }
882  
883 0 ▶ if(not $err)
Branch: 1 branch
BranchTrueFalseTotal
unless ($err) 0 0 0
884 {
885 # update node last_out, possibly out_seq
886 0 $node->{last_out} = time();
887 0 ▶ $err = $node_tbl->ERROR
Branch: 1 branch
BranchTrueFalseTotal
unless $node_tbl->write($rcv_node_id, $node) 0 0 0
888 unless $node_tbl->write($rcv_node_id, $node);
889 }
890 $node_tbl->unlock() # unlock node_tbl if needed
891 0 ▶ unless $was_locked;
Branch: 1 branch
BranchTrueFalseTotal
unless $was_locked 0 0 0
892  
893 0 return $err;
894 }
895  
896 1 1;
897  
898 __DATA__
↑ Summary lib/EMDIS/ECS.pm »