-
Notifications
You must be signed in to change notification settings - Fork 0
/
popfile.pl
125 lines (101 loc) · 4.09 KB
/
popfile.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/perl
# ----------------------------------------------------------------------------
#
# popfile.pl --- Message analyzer and sorter
#
# Acts as a server and client designed to sit between a real mail/news
# client and a real mail/ news server using POP3. Inserts an extra
# header X-Text-Classification: into the header to tell the client
# which category the message belongs in and much more...
#
# Copyright (c) 2001-2011 John Graham-Cumming
#
# This file is part of POPFile
#
# POPFile is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# POPFile is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with POPFile; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Modified by Sam Schinke ([email protected])
#
# ----------------------------------------------------------------------------
# Check the packing list of POPFile to ensure that all the required
# modules are present.
my $packing_list = defined($ENV{POPFILE_ROOT})?$ENV{POPFILE_ROOT}:'./';
$packing_list =~ s/[\\\/]$//;
$packing_list .= '/popfile.pck';
my $fatal = 0;
my @log;
if ( open PACKING, "<$packing_list" ) {
while (<PACKING>) {
if ( /^(REQUIRED|OPTIONAL-([^\t]+))\t([^\t]+)\t([^\r\n]+)/ ) {
my ( $required, $why, $version, $module ) = ( $1, $2, $3, $4 );
# Find the module and set $ver to the loaded version, or -1 if
# the module was not found
local $::SIG{__DIE__};
local $::SIG{__WARN__};
eval "require $module";
my $ver = ${"${module}::VERSION"} || ${"${module}::VERSION"} || 0;
$ver = ${"${module}::VERSION"} || ${"${module}::VERSION"} || 0;
$ver = -1 if $@;
if ( $ver == -1 ) {
if ( $required eq 'REQUIRED' ) {
$fatal = 1;
print STDERR "ERROR: POPFile needs Perl module $module, please install it.\n";
} else {
push @log, ("Warning: POPFile may require Perl module $module; it is needed only for \"$why\".");
}
}
}
}
close PACKING;
} else {
push @log, ("Warning: Couldn't open POPFile packing list ($packing_list) so cannot check configuration (this probably doesn't matter)");
}
use strict;
use locale;
use lib defined( $ENV{POPFILE_ROOT} ) ? $ENV{POPFILE_ROOT} : '.';
use POPFile::Loader;
# POPFile is actually loaded by the POPFile::Loader object which does all
# the work
my $POPFile = POPFile::Loader->new();
# Indicate that we should create output on STDOUT (the POPFile
# load sequence) and initialize with the version
$POPFile->debug(1);
$POPFile->CORE_loader_init();
# Redefine POPFile's signals
$POPFile->CORE_signals();
# Create the main objects that form the core of POPFile. Consists of
# the configuration modules, the classifier, the UI (currently HTML
# based), platform specific code, and the POP3 proxy. The link the
# components together, intialize them all, load the configuration from
# disk, start the modules running
$POPFile->CORE_load();
$POPFile->CORE_link_components();
$POPFile->CORE_initialize();
if ( $POPFile->CORE_config() ) {
$POPFile->CORE_start();
# If there were any log messages from the packing list check then
# log them now
if ( $#log != -1 ) {
foreach my $m (@log) {
$POPFile->get_module( 'POPFile::Logger' )->debug( 0, $m );
}
}
$POPFile->get_module( 'POPFile::Logger' )->debug( 0, "POPFile successfully started" );
# This is the main POPFile loop that services requests, it will
# exit only when we need to exit
$POPFile->CORE_service();
# Shutdown every POPFile module
$POPFile->CORE_stop();
}
# END