Hi. I'm writing a series of sub-functions that expand to provides some qos capabilities to MailScanner. I'm just a beginner, but I think I'm almost there.
Sorry about the formatting. It looks fine in UltraEdit.
Anyways, Can someone tell me if this code looks correct? I'm trying to count the number of files found in $dir and the total number of lines from all $filename in $dir. Then I pass that along to the Log function which I'm using for debugging purposes, IE if it says it read 0 entries and I have at least 1, then I know something aint working right.
I'd appreciate any help.
Errol
Code:
my $PriorityDir = '/etc/MailScanner/qos';
my(%PriorityList);
use FileHandle;
sub InitMultipleQueueDir {
MailScanner::Log::InfoLog("Starting up Priority Queueing list, " .
"reading from %s", $PriorityDir);
my $list = CreatePriorityList($PriorityDir, \%PriorityList);
MailScanner::Log::InfoLog("Read a total of %d from " .
"%d files recieving priority " .
"service", $lines, $domains);
}
sub EndMultipleQueueDir {
MailScanner::Log::InfoLog("Shutting down priority domain list");
}
sub MultipleQueueDir {
my($message) = @_;
return LookupQueue($message, \%PriorityList);
}
sub CreatePriorityList {
my($dirname, $prioritydefaultlist, $prioritydomainlist) = @_;
my($dir, $filename, $fh, $lines, $domains);
$dir = new DirHandle;
$dir->open($dirname) or return 0;
$domains = 0;
$lines = 0;
while ($filename = $dir->read()) {
next if $filename =~ /^\./; #Ignore files with a preceeding .
if ($filename = /default/i) {
$fh = new FileHandle;
$fh->open("$filename");
$filename = lc($filename);
while(<$fh>) {
chomp;
s/#.*$//; # Strip comments
s/\S*:\S*//g; # Strip any words with ":" in them
s/^\s+//g; # Strip leading whitespace
s/^(\S+)\s.*$/$1/; # Use only the 1st word
s/^\*\@//; # Strip any leading "*@" they might have put in
s/^\s*\@//; #No usernames allowed here
next if /^$/; # Strip blank lines
$lines++;
$prioritydefaultlist->{$filename}{lc($_)} = 1;
}
$fh->close();
return $lines
}
$fh = new FileHandle;
$fh->open("$filename");
$filename = lc($filename);
while(<$fh>) {
chomp;
s/#.*$//; # Strip comments
s/\S*:\S*//g; # Strip any words with ":" in them
s/^\s+//g; # Strip leading whitespace
s/^(\S+)\s.*$/$1/; # Use only the 1st word
s/^\*\@//; # Strip any leading "*@" they might have put in
next if /^$/; # Strip blank lines
$lines++;
$prioritydomainlist->{$filename}{lc($_)} = 1;
}
$fh->close();
$domains++;
}
$dir->close();
return $domains;
return $lines;
}
sub LookupQueue {
my($message, $List) = @_;
return '/var/spool/mqueue' unless $message;
my($todomain, @todomain, $to, @to, $isspam);
@todomain = @{$message->{$todomain}};
$todomain = $todomain[0];
@to = @{$message->{$to}};
$to = $to[0];
$isspam = $message->{$isspam};
return '/var/spool/mqueue.priority' if $List->{$to};
return '/var/spool/mqueue.priority' if $List->{$todomain};
return '/var/spool/mqueue.spam' if $isspam;
return '/var/spool/mqueue';
}
Sorry about the formatting. It looks fine in UltraEdit.
Anyways, Can someone tell me if this code looks correct? I'm trying to count the number of files found in $dir and the total number of lines from all $filename in $dir. Then I pass that along to the Log function which I'm using for debugging purposes, IE if it says it read 0 entries and I have at least 1, then I know something aint working right.
I'd appreciate any help.
Errol