Mailing List Archive

svn commit: r482309 - in /spamassassin/trunk: lib/Mail/SpamAssassin/ArchiveIterator.pm masses/mass-check
Author: felicity
Date: Mon Dec 4 11:34:31 2006
New Revision: 482309

URL: http://svn.apache.org/viewvc?view=rev&rev=482309
Log:
change ArchiveIterator function names to more clearly suggest what is public and what isn't. mass-check breaks into the object a lot and uses private functions and data, so change there as well...

Modified:
spamassassin/trunk/lib/Mail/SpamAssassin/ArchiveIterator.pm
spamassassin/trunk/masses/mass-check

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/ArchiveIterator.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/ArchiveIterator.pm?view=diff&rev=482309&r1=482308&r2=482309
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/ArchiveIterator.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/ArchiveIterator.pm Mon Dec 4 11:34:31 2006
@@ -265,10 +265,10 @@
}

# scan the targets and get the number and list of messages
- $self->scan_targets(\@targets,
+ $self->_scan_targets(\@targets,
sub {
my($self, $date, $class, $format, $mail) = @_;
- push(@{$self->{$class}}, index_pack($date, $class, $format, $mail));
+ push(@{$self->{$class}}, _index_pack($date, $class, $format, $mail));
}
);

@@ -289,7 +289,7 @@
my ($self, $messages) = @_;

while (my $message = shift @{$messages}) {
- my($class, undef, $date, undef, $result) = $self->run_message($message);
+ my($class, undef, $date, undef, $result) = $self->_run_message($message);
&{$self->{result_sub}}($class, $result, $date) if $result;
}
return ! $self->{access_problem};
@@ -299,26 +299,26 @@

## run_message and related functions to process a single message

-sub run_message {
+sub _run_message {
my ($self, $msg) = @_;

- my ($date, $class, $format, $mail) = index_unpack($msg);
+ my ($date, $class, $format, $mail) = _index_unpack($msg);

if ($format eq 'f') {
- return $self->run_file($class, $format, $mail, $date);
+ return $self->_run_file($class, $format, $mail, $date);
}
elsif ($format eq 'm') {
- return $self->run_mailbox($class, $format, $mail, $date);
+ return $self->_run_mailbox($class, $format, $mail, $date);
}
elsif ($format eq 'b') {
- return $self->run_mbx($class, $format, $mail, $date);
+ return $self->_run_mbx($class, $format, $mail, $date);
}
}

-sub run_file {
+sub _run_file {
my ($self, $class, $format, $where, $date) = @_;

- if (!mail_open($where)) {
+ if (!_mail_open($where)) {
$self->{access_problem} = 1;
return;
}
@@ -346,13 +346,13 @@
return($class, $format, $date, $where, &{$self->{wanted_sub}}($class, $where, $date, \@msg, $format));
}

-sub run_mailbox {
+sub _run_mailbox {
my ($self, $class, $format, $where, $date) = @_;

my ($file, $offset) = ($where =~ m/(.*)\.(\d+)$/);
my @msg;
my $header;
- if (!mail_open($file)) {
+ if (!_mail_open($file)) {
$self->{access_problem} = 1;
return;
}
@@ -381,14 +381,14 @@
return($class, $format, $date, $where, &{$self->{wanted_sub}}($class, $where, $date, \@msg, $format));
}

-sub run_mbx {
+sub _run_mbx {
my ($self, $class, $format, $where, $date) = @_;

my ($file, $offset) = ($where =~ m/(.*)\.(\d+)$/);
my @msg;
my $header;

- if (!mail_open($file)) {
+ if (!_mail_open($file)) {
$self->{access_problem} = 1;
return;
}
@@ -425,7 +425,7 @@

############################################################################

-sub scan_targets {
+sub _scan_targets {
my ($self, $targets, $bkfunc) = @_;

%class_opts = ();
@@ -476,9 +476,9 @@
foreach my $k (keys %opts) {
$self->{$k} = $opts{$k};
}
- $self->set_default_message_selection_opts();
+ $self->_set_default_message_selection_opts();

- my @locations = $self->fix_globs($rawloc);
+ my @locations = $self->_fix_globs($rawloc);

foreach my $location (@locations) {
my $method;
@@ -499,16 +499,16 @@
}

if ($format eq 'dir') {
- $method = \&scan_directory;
+ $method = \&_scan_directory;
}
elsif ($format eq 'mbox') {
- $method = \&scan_mailbox;
+ $method = \&_scan_mailbox;
}
elsif ($format eq 'file') {
- $method = \&scan_file;
+ $method = \&_scan_file;
}
elsif ($format eq 'mbx') {
- $method = \&scan_mbx;
+ $method = \&_scan_mbx;
}
else {
warn "archive-iterator: format $format unknown!";
@@ -521,7 +521,7 @@
}
}

-sub mail_open {
+sub _mail_open {
my ($file) = @_;

my $expr;
@@ -541,7 +541,7 @@
return 1;
}

-sub set_default_message_selection_opts {
+sub _set_default_message_selection_opts {
my ($self) = @_;
$self->{opt_scanprob} = 1.0 unless (defined $self->{opt_scanprob});
$self->{opt_want_date} = 1 unless (defined $self->{opt_want_date});
@@ -550,7 +550,7 @@

############################################################################

-sub message_is_useful_by_date {
+sub _message_is_useful_by_date {
my ($self, $date) = @_;

if (!$self->{opt_after} && !$self->{opt_before}) {
@@ -573,7 +573,7 @@
# make assumptions about --before, since the file may have been "touch"ed
# since the last message was appended; but we can assume that too-old
# files cannot contain messages newer than their modtime.
-sub message_is_useful_by_file_modtime {
+sub _message_is_useful_by_file_modtime {
my ($self, $date) = @_;

# better safe than sorry, if date is undef; let other stuff catch errors
@@ -587,7 +587,7 @@
}
}

-sub scanprob_says_scan {
+sub _scanprob_says_scan {
my ($self) = @_;
if (defined $self->{opt_scanprob} && $self->{opt_scanprob} < 1.0) {
if ( int( rand( 1 / $self->{opt_scanprob} ) ) != 0 ) {
@@ -606,17 +606,17 @@

# put the date in first, big-endian packed format
# this format lets cmp easily sort by date, then class, format, and path.
-sub index_pack {
+sub _index_pack {
return pack("NAAA*", @_);
}

-sub index_unpack {
+sub _index_unpack {
return unpack("NAAA*", $_[0]);
}

############################################################################

-sub scan_directory {
+sub _scan_directory {
my ($self, $class, $folder, $bkfunc) = @_;

my @files;
@@ -641,10 +641,10 @@
return;
}

- $self->create_cache('dir', $folder);
+ $self->_create_cache('dir', $folder);

foreach my $mail (@files) {
- $self->scan_file($class, $mail, $bkfunc);
+ $self->_scan_file($class, $mail, $bkfunc);
}

if (defined $AICache) {
@@ -652,13 +652,13 @@
}
}

-sub scan_file {
+sub _scan_file {
my ($self, $class, $mail, $bkfunc) = @_;

- $self->bump_scan_progress();
+ $self->_bump_scan_progress();

my @s = stat($mail);
- return unless $self->message_is_useful_by_file_modtime($s[9]);
+ return unless $self->_message_is_useful_by_file_modtime($s[9]);

my $date = AI_TIME_UNKNOWN;

@@ -680,8 +680,8 @@
}
}

- return if !$self->message_is_useful_by_date($date);
- return if !$self->scanprob_says_scan();
+ return if !$self->_message_is_useful_by_date($date);
+ return if !$self->_scanprob_says_scan();
}

&{$bkfunc}($self, $date, $class, 'f', $mail);
@@ -689,7 +689,7 @@
return;
}

-sub scan_mailbox {
+sub _scan_mailbox {
my ($self, $class, $folder, $bkfunc) = @_;
my @files;

@@ -714,7 +714,7 @@
}

foreach my $file (@files) {
- $self->bump_scan_progress();
+ $self->_bump_scan_progress();
if ($file =~ /\.(?:gz|bz2)$/) {
warn "archive-iterator: compressed mbox folders are not supported at this time\n";
$self->{access_problem} = 1;
@@ -722,12 +722,12 @@
}

my @s = stat($file);
- next unless $self->message_is_useful_by_file_modtime($s[9]);
+ next unless $self->_message_is_useful_by_file_modtime($s[9]);

my $info = {};
my $count;

- $self->create_cache('mbox', $file);
+ $self->_create_cache('mbox', $file);

if ($self->{opt_cache}) {
if ($count = $AICache->count()) {
@@ -768,7 +768,7 @@
$where = tell INPUT;
}
if ($header) {
- $self->bump_scan_progress();
+ $self->_bump_scan_progress();
$info->{$offset} = Mail::SpamAssassin::Util::receive_date($header);
}
}
@@ -781,9 +781,9 @@
}

if ($self->{determine_receive_date}) {
- next if !$self->message_is_useful_by_date($v);
+ next if !$self->_message_is_useful_by_date($v);
}
- next if !$self->scanprob_says_scan();
+ next if !$self->_scanprob_says_scan();

&{$bkfunc}($self, $v, $class, 'm', "$file.$k");
}
@@ -794,7 +794,7 @@
}
}

-sub scan_mbx {
+sub _scan_mbx {
my ($self, $class, $folder, $bkfunc) = @_;
my (@files, $fp);

@@ -819,7 +819,7 @@
}

foreach my $file (@files) {
- $self->bump_scan_progress();
+ $self->_bump_scan_progress();

if ($folder =~ /\.(?:gz|bz2)$/) {
warn "archive-iterator: compressed mbx folders are not supported at this time\n";
@@ -828,12 +828,12 @@
}

my @s = stat($file);
- next unless $self->message_is_useful_by_file_modtime($s[9]);
+ next unless $self->_message_is_useful_by_file_modtime($s[9]);

my $info = {};
my $count;

- $self->create_cache('mbx', $file);
+ $self->_create_cache('mbx', $file);

if ($self->{opt_cache}) {
if ($count = $AICache->count()) {
@@ -870,7 +870,7 @@
$header .= $_;
}

- $self->bump_scan_progress();
+ $self->_bump_scan_progress();
$info->{$offset} = Mail::SpamAssassin::Util::receive_date($header);

# go onto the next message
@@ -889,9 +889,9 @@
}

if ($self->{determine_receive_date}) {
- next if !$self->message_is_useful_by_date($v);
+ next if !$self->_message_is_useful_by_date($v);
}
- next if !$self->scanprob_says_scan();
+ next if !$self->_scanprob_says_scan();

&{$bkfunc}($self, $v, $class, 'b', "$file.$k");
}
@@ -904,7 +904,7 @@

############################################################################

-sub bump_scan_progress {
+sub _bump_scan_progress {
my ($self) = @_;
if (exists $self->{scan_progress_sub}) {
return unless ($self->{scan_progress_counter}++ % 50 == 0);
@@ -917,7 +917,7 @@
{
my $home;

- sub fix_globs {
+ sub _fix_globs {
my ($self, $path) = @_;

unless (defined $home) {
@@ -947,7 +947,7 @@
}
}

-sub create_cache {
+sub _create_cache {
my ($self, $type, $path) = @_;

if ($self->{opt_cache}) {

Modified: spamassassin/trunk/masses/mass-check
URL: http://svn.apache.org/viewvc/spamassassin/trunk/masses/mass-check?view=diff&rev=482309&r1=482308&r2=482309
==============================================================================
--- spamassassin/trunk/masses/mass-check (original)
+++ spamassassin/trunk/masses/mass-check Mon Dec 4 11:34:31 2006
@@ -949,7 +949,7 @@
exit;
}

- my($class, $format, $date, $where, $result) = $iter->run_message($line);
+ my($class, $format, $date, $where, $result) = $iter->_run_message($line);
$result ||= '';

# If determine_receive_date is not set, the original input date
@@ -957,7 +957,7 @@
# the packed version if possible ... use defined for date since
# it could == 0.
if (!$iter->{determine_receive_date} && $class && $format && defined $date && $where) {
- $line = Mail::SpamAssassin::ArchiveIterator::index_pack($date, $class, $format, $where);
+ $line = Mail::SpamAssassin::ArchiveIterator::_index_pack($date, $class, $format, $where);
}

send_line($parent,"$result\0RESULT $line");
@@ -1144,7 +1144,7 @@
send_line($gzfd, $data) || die "mass-check: error when writing to gz temp file\n";

if (!$paths_only) {
- my $msg = ($iter->run_message($data))[4];
+ my $msg = ($iter->_run_message($data))[4];
send_line($gzfd, join('', @{$msg})) ||
die "mass-check: error when writing to gz temp file\n";
}
@@ -1190,7 +1190,7 @@
# process, and we take whatever the first responder sends us.
if (exists $msgsout->{$k}) {
# the result_sub will need parts of the message data, so get it ready
- my @d = Mail::SpamAssassin::ArchiveIterator::index_unpack($msgsout->{$k}->{'data'});
+ my @d = Mail::SpamAssassin::ArchiveIterator::_index_unpack($msgsout->{$k}->{'data'});

# go ahead and do the result
&{$iter->{result_sub}}($d[1], $v, $d[0]);
@@ -1228,7 +1228,7 @@
my $total_count = 0;

while (($total_messages > $total_count) && ($message = read_line($tmpfd))) {
- my($class, undef, $date, undef, $result) = $iter->run_message($message);
+ my($class, undef, $date, undef, $result) = $iter->_run_message($message);
if ($result) {
&{$iter->{result_sub}}($class, $result, $date);
}
@@ -1261,7 +1261,7 @@
}
elsif ($line =~ /^([^\0]*)\0RESULT (.+)$/s) {
my $result = $1;
- my ($date,$class,$type) = Mail::SpamAssassin::ArchiveIterator::index_unpack($2);
+ my ($date,$class,$type) = Mail::SpamAssassin::ArchiveIterator::_index_unpack($2);
aidbg "mass-check: $class, $type, $date\n";

if (defined $opt_restart && ($total_count % $opt_restart) == 0) {
@@ -1729,10 +1729,10 @@
# this is a little tricky -- we need to process the files in the
# path and format we've created, but the original data is needed
# to create a proper result later, so deal with that here.
- my @d = Mail::SpamAssassin::ArchiveIterator::index_unpack($index);
+ my @d = Mail::SpamAssassin::ArchiveIterator::_index_unpack($index);
$real{"$tmpdir/$num"} = \@d;
send_line($tmpfd,
- Mail::SpamAssassin::ArchiveIterator::index_pack($d[0], $d[1], 'f', "$tmpdir/$num")) ||
+ Mail::SpamAssassin::ArchiveIterator::_index_pack($d[0], $d[1], 'f', "$tmpdir/$num")) ||
die "mass-check: error writing out temp file in client mode\n";
}
else {
@@ -1743,7 +1743,7 @@
# in paths_only mode, there's no kluging between formats since we're
# reading the same corpus, however we do still need to track server
# message number to message data so our results will be useable.
- my @d = Mail::SpamAssassin::ArchiveIterator::index_unpack($index);
+ my @d = Mail::SpamAssassin::ArchiveIterator::_index_unpack($index);
$real{$d[3]} = $num;
send_line($tmpfd, $index) ||
die "mass-check: error writing out temp file in client mode\n";
@@ -1864,10 +1864,10 @@
my ($targets, $tmpfd) = @_;

# scan the targets and get the number and list of messages
- $iter->scan_targets($targets,
+ $iter->_scan_targets($targets,
sub {
my($self, $date, $class, $format, $mail) = @_;
- push(@{$self->{$class}}, Mail::SpamAssassin::ArchiveIterator::index_pack($date, $class, $format, $mail));
+ push(@{$self->{$class}}, Mail::SpamAssassin::ArchiveIterator::_index_pack($date, $class, $format, $mail));
}
);