File Coverage

blib/lib/Mail/Box/Net.pm
Criterion Covered Total %
statement 33 66 50.0
branch 0 14 0.0
condition 0 26 0.0
subroutine 11 14 78.5
pod 2 3 66.6
total 46 123 37.4


line stmt bran cond sub pod time code
1             # This code is part of Perl distribution Mail-Box version 4.01.
2             # The POD got stripped from this file by OODoc version 3.05.
3             # For contributors see file ChangeLog.
4              
5             # This software is copyright (c) 2001-2025 by Mark Overmeer.
6              
7             # This is free software; you can redistribute it and/or modify it under
8             # the same terms as the Perl 5 programming language system itself.
9             # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10              
11              
12             package Mail::Box::Net;{
13             our $VERSION = '4.01';
14             }
15              
16 2     2   628698 use parent 'Mail::Box';
  2         11  
  2         15  
17              
18 2     2   193 use strict;
  2         4  
  2         51  
19 2     2   9 use warnings;
  2         4  
  2         149  
20              
21 2     2   11 use Log::Report 'mail-box', import => [ qw/__x warning/ ];
  2         4  
  2         16  
22              
23 2     2   1860 use Mail::Box::Net::Message ();
  2         7  
  2         56  
24 2     2   14 use Mail::Message::Body::Lines ();
  2         4  
  2         32  
25 2     2   9 use Mail::Message::Body::File ();
  2         4  
  2         30  
26 2     2   574 use Mail::Message::Body::Delayed ();
  2         6  
  2         70  
27 2     2   13 use Mail::Message::Body::Multipart ();
  2         4  
  2         70  
28 2     2   12 use Mail::Message::Head ();
  2         4  
  2         56  
29 2     2   630 use Mail::Message::Head::Delayed ();
  2         5  
  2         1758  
30              
31             #--------------------
32              
33             sub init($)
34 0     0 0   { my ($self, $args) = @_;
35              
36 0   0       $args->{lock_type} ||= 'NONE';
37 0   0       $args->{body_type} ||= 'Mail::Message::Body::Lines';
38 0   0       $args->{trusted} ||= 0;
39              
40 0           my ($scheme, $s, $port, $u, $pwd, $f);
41 0 0         if(my $d = $args->{folderdir})
42             { # cannot use URI, because some scheme's are fake
43 0           ($scheme, $u, $pwd, $s, $port, $f) = $d =~ m!
44             ^ (\w+) \:// # scheme
45             (?: ( [^:\@/]+ ) # username
46             (?: \: ( [^\@/]+ ))? # password
47             \@ )?
48             ( [a-zA-Z0-9.-]+ )? # hostname
49             (?: \: ([0-9]+) )? # port
50             ( / .* )? # path
51             !x;
52              
53 0           defined && s/%([0-9a-fA-F]{2})/hex $1/ge
54 0   0       for $u, $pwd, $s, $port, $f;
55              
56 0           $args->{folderdir} =~ s!/$!!;
57             }
58              
59 0   0       $args->{folder} ||= $f || '/';
      0        
60              
61 0           $self->SUPER::init($args);
62              
63 0   0       $self->{MBN_hostname} = $args->{server_name} || $s;
64 0   0       $self->{MBN_port} = $args->{server_port} || $port;
65 0   0       $self->{MBN_username} = $args->{username} || $u;
66 0   0       $self->{MBN_password} = $args->{password} || $pwd;
67              
68             ! exists $args->{hostname}
69 0 0         or warning __x"the term 'hostname' is confusing wrt folder. You probably need 'server_name'.";
70              
71 0           $self;
72             }
73              
74              
75 0     0 1   sub create(@) { $_[0]->notImplemented }
76             sub organization() { 'REMOTE' }
77              
78             sub url()
79 0     0 1   { my $self = shift;
80 0           my ($user, $pass, $host, $port) = @$self{ qw/MBN_username MBN_password MBN_hostname MBN_port/ };
81              
82 0           my $perm = '';
83 0 0         $perm = $user if defined $user;
84 0 0         if(defined $pass)
85 0           { $pass =~ s/(\W)/sprintf "%%%02X", ord $1/ge;
  0            
86 0           $perm .= ':'.$pass;
87             }
88              
89 0 0         $perm .= '@' if length $perm;
90              
91 0           my $loc = $host;
92 0 0         $loc .= ':'.$port if length $port;
93              
94 0           my $name = $self->name;
95 0 0         $loc .= '/'.$name if $name ne '/';
96              
97 0           $self->type . '://' . $perm . $loc;
98             }
99              
100             1;