line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- perl -*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Mail::Spool::Handle - adpO - Mail::Spool directory encapsulization |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# $Id: Handle.pm,v 1.1 2001/12/08 05:52:59 rhandom Exp $ |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# Copyright (C) 2001, Paul T Seamons |
8
|
|
|
|
|
|
|
# paul@seamons.com |
9
|
|
|
|
|
|
|
# http://seamons.com/ |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# This package may be distributed under the terms of either the |
12
|
|
|
|
|
|
|
# GNU General Public License |
13
|
|
|
|
|
|
|
# or the |
14
|
|
|
|
|
|
|
# Perl Artistic License |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# All rights reserved. |
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
# Please read the perldoc Mail::Spool::Handle |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
################################################################ |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
package Mail::Spool::Handle; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
25
|
1
|
|
|
1
|
|
6
|
use vars qw($AUTOLOAD $VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
501
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$VERSION = $Mail::Spool::VERSION; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
###----------------------------------------------------------------### |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
32
|
2
|
|
|
2
|
1
|
4
|
my $type = shift; |
33
|
2
|
|
50
|
|
|
11
|
my $class = ref($type) || $type || __PACKAGE__; |
34
|
2
|
50
|
33
|
|
|
16
|
my $self = @_ && ref($_[0]) ? shift() : {@_}; |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
10
|
return bless $self, $class; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
###----------------------------------------------------------------### |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
### allow for opening up a spool |
42
|
|
|
|
|
|
|
### this could be a directory, or |
43
|
|
|
|
|
|
|
### db handle, etc |
44
|
|
|
|
|
|
|
sub open_spool { |
45
|
1
|
|
|
1
|
1
|
13
|
my $msh = shift; |
46
|
1
|
50
|
33
|
|
|
6
|
die 'Usage: $msh->open_spool' |
47
|
|
|
|
|
|
|
if ! $msh || ! ref $msh; |
48
|
|
|
|
|
|
|
|
49
|
1
|
50
|
|
|
|
3
|
die 'Invalid Object: missing spool_dir property' |
50
|
|
|
|
|
|
|
unless defined $msh->spool_dir; |
51
|
|
|
|
|
|
|
|
52
|
1
|
50
|
|
|
|
7
|
die 'Invalid Object: missing wait property' |
53
|
|
|
|
|
|
|
unless defined $msh->wait; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
### get a directory handle |
56
|
1
|
|
|
|
|
2
|
my $dh = do {local *_DH}; |
|
1
|
|
|
|
|
4
|
|
57
|
1
|
50
|
|
|
|
4
|
if( ! opendir($dh, $msh->spool_dir) ){ |
58
|
0
|
|
|
|
|
0
|
die "Couldn't open directory (".$msh->spool_dir.") [$!]"; |
59
|
|
|
|
|
|
|
} |
60
|
1
|
|
|
|
|
8
|
$msh->dh( $dh ); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
### optional return |
63
|
1
|
|
|
|
|
3
|
return $dh; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub next_node { |
67
|
1
|
|
|
1
|
1
|
11
|
my $msh = shift; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
### read the next inode |
70
|
1
|
|
|
|
|
3
|
while ( defined(my $sub = readdir( $msh->dh )) ){ |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
### instantiate a new object |
73
|
1
|
|
|
|
|
2
|
my $node = eval{ $msh->mail_spool_node(msh => $msh, |
|
1
|
|
|
|
|
4
|
|
74
|
|
|
|
|
|
|
name => $sub, |
75
|
|
|
|
|
|
|
) }; |
76
|
|
|
|
|
|
|
### check for errors |
77
|
1
|
50
|
33
|
|
|
7
|
if( $@ || ! $node ){ |
78
|
|
|
|
|
|
|
# warn "Trouble creating node [$@]\n"; |
79
|
0
|
|
|
|
|
0
|
next; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
### see if this is a good node |
83
|
1
|
50
|
|
|
|
4
|
if( ! $node->can_process ){ |
84
|
0
|
|
|
|
|
0
|
next; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
### all good |
88
|
1
|
|
|
|
|
3
|
return $node; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
### exit loop |
92
|
0
|
|
|
|
|
0
|
return undef; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub mail_spool_node { |
96
|
1
|
|
|
1
|
1
|
1
|
my $self = shift; |
97
|
1
|
|
|
|
|
5
|
return Mail::Spool->mail_spool_node(@_); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
###----------------------------------------------------------------### |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub AUTOLOAD { |
103
|
4
|
|
|
4
|
|
9
|
my $msh = shift; |
104
|
4
|
|
|
|
|
20
|
my ($method) = $AUTOLOAD =~ /([^:]+)$/; |
105
|
4
|
50
|
|
|
|
10
|
die "No method found in \$AUTOLOAD \"$AUTOLOAD\"" unless defined $method; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
### allow for dynamic installation of some subs |
108
|
4
|
50
|
|
|
|
14
|
if( $method =~ /^(spool_dir|fallback_dir|wait|dh|spool)$/ ){ |
109
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
99
|
|
110
|
4
|
|
|
|
|
14
|
* { __PACKAGE__ ."::". $method } = sub { |
111
|
17
|
|
|
17
|
|
27
|
my $self = shift; |
112
|
17
|
|
|
|
|
30
|
my $val = $self->{$method}; |
113
|
17
|
100
|
|
|
|
43
|
$self->{$method} = shift if @_; |
114
|
17
|
|
|
|
|
126
|
return $val; |
115
|
4
|
|
|
|
|
14
|
}; |
116
|
1
|
|
|
1
|
|
6
|
use strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
89
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
### now that it is installed, call it again |
119
|
4
|
|
|
|
|
10
|
return $msh->$method( @_ ); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
die "Unknown method \"$method\""; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
0
|
|
|
sub DESTROY {} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__END__ |