Email.pm untested

filter: Statementstmt 0.0% 0 / 91 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 119 CC 4 SCAR 14.4
CC
4
Cov
0%
split_address
12.0
init
6.0
meta
2.0
CRAP 4.2
1 package VUser::Email;
2 use warnings;
3 use strict;
4  
5 # Copyright 2006 Randy Smith <perlstalker@vuser.org>
6 # $Id: Email.pm,v 1.6 2007/01/18 20:30:25 perlstalker Exp $
7  
8 use VUser::Meta;
9 use VUser::Log qw(:levels);
10 use VUser::ExtLib qw(:config);
11  
12 our $VERSION = '0.3.2';
13  
14 use Exporter;
15 our @ISA = qw(Exporter);
16 our @EXPORT = ();
17 our @EXPORT_OK = qw(split_address get_domain_directory get_home_directory);
18 our %EXPORT_TAGS = (utils => [qw(split_address
19 get_domain_directory
20 get_home_directory)]);
21  
22 our $c_sec = 'Extension Email';
23 our %meta = ('account' => VUser::Meta->new('name' => 'account',
24 'type' => 'string',
25 'description' => 'Email account'),
26 'password' => VUser::Meta->new('name' => 'password',
27 'type' => 'string',
28 'description' => 'Account password'),
29 'name' => VUser::Meta->new('name' => 'name',
30 'type' => 'string',
31 'description' => 'Real name'),
32 'quota' => VUser::Meta->new('name' => 'quota',
33 'type' => 'integer',
34 'description' => 'Mailbox quota in KB'),
35 'domain' => VUser::Meta->new('name' => 'domain',
36 'type' => 'string',
37 'description' => 'Domain name'),
38 'home' => VUser::Meta->new('name' => 'home',
39 'type' => 'string',
40 'description' => 'Home directory (overrides config setting)'),
41 'pattern' => VUser::Meta->new('name' => 'pattern',
42 'type' => 'string',
43 'description', 'Limit to pattern')
44 );
45
46 my $log;
47  
48 sub init {
49 my $eh = shift;
50 my %cfg = @_;
51  
52 if (defined $main::log) {
53 $log = $main::log;
54 } else {
55 $log = VUser::Log->new(\%cfg, 'vuser');
56 }
57  
58 # email
59 $eh->register_keyword('email', 'Manage email accounts');
60  
61 # email-add
62 $eh->register_action('email', 'add', 'Add an email account');
63 $eh->register_option('email', 'add', $meta{'account'}, 1);
64 $eh->register_option('email', 'add', $meta{'password'}, 1);
65 $eh->register_option('email', 'add', $meta{'name'});
66 $eh->register_option('email', 'add', $meta{'quota'});
67 $eh->register_option('email', 'add', $meta{'home'});
68  
69 # email-mod
70 $eh->register_action('email', 'mod', 'Modify an email account');
71 $eh->register_option('email', 'mod', $meta{'account'}, 1);
72 $eh->register_option('email', 'mod', $meta{'account'}->new('name' => 'newaccount'));
73 $eh->register_option('email', 'mod', $meta{'password'});
74 $eh->register_option('email', 'mod', $meta{'name'});
75 $eh->register_option('email', 'mod', $meta{'quota'});
76 $eh->register_option('email', 'mod', $meta{'home'});
77  
78 # email-del
79 $eh->register_action('email', 'del', 'Delete an email account');
80 $eh->register_option('email', 'del', $meta{'account'}, 1);
81  
82 # email-info
83 $eh->register_action('email', 'info', 'Get email account info');
84 $eh->register_option('email', 'info', $meta{'account'}, 1);
85  
86 # email-list
87 $eh->register_action('email', 'list', 'List email accounts');
88 $eh->register_option('email', 'list', $meta{'pattern'});
89  
90 # domain
91 $eh->register_keyword('domain');
92  
93 # domain-add
94 $eh->register_action('domain', 'add', 'Add a domain');
95 $eh->register_option('domain', 'add', $meta{'domain'}, 1);
96  
97 # domain-mod
98 $eh->register_action('domain', 'mod', 'Modify a domain');
99 $eh->register_option('domain', 'mod', $meta{'domain'}, 1);
100 $eh->register_option('domain', 'mod', $meta{'domain'}->new(name => 'newdomain'));
101  
102 # domain-del
103 $eh->register_action('domain', 'del', 'Delete a domain');
104 $eh->register_option('domain', 'del', $meta{'domain'}, 1);
105  
106 # domain-info
107 $eh->register_action('domain', 'info', 'Get domain info');
108 $eh->register_option('domain', 'info', $meta{'domain'}, 1);
109  
110 # domain-list
111 $eh->register_action('domain', 'list', 'List domains');
112 $eh->register_option('domain', 'list', $meta{'pattern'});
113  
114 };
115  
116 sub meta { return %meta; };
117 sub c_sec { return $c_sec; }
118  
119 sub get_home_directory
120 {
121 my $cfg = shift;
122 my $user = shift;
123 my $domain = shift;
124  
125 return eval( $cfg->{$c_sec}{userhomedir} );
126 }
127  
128 sub get_domain_directory
129 {
130 my $cfg = shift;
131 my $domain = shift;
132 return eval( $cfg->{$c_sec}{domaindir} );
133 }
134  
135 sub get_quotafile
136 {
137 my $cfg = shift;
138 my $user = shift;
139 my $domain = shift;
140  
141 return get_home_directory( $cfg, $user, $domain )."/Maildir/maildirsize";
142 }
143  
144 sub split_address
145 {
146 my $cfg = shift;
147 my $account = shift;
148 my $username = shift;
149 my $domain = shift;
150  
151 if ($account =~ /^(\S+)\@(\S+)$/) {
152 $$username = $1;
153 $$domain = $2;
154 } else {
155 $$username = $account;
156 $$domain = $cfg->{$c_sec}{defaultdomain};
157 $$domain =~ s/^\s*(\S+)\s*/$1/;
158 }
159  
160 $$username = lc($$username) if check_bool($cfg->{$c_sec}{'lc_user'});
161 $$domain = lc($$domain);
162
163 $log->log(LOG_DEBUG, "account: $account, user: $$username, domain: $$domain");
164 }
165  
166 sub unload { }
167  
168 1;
169  
170 __END__