+# load the forward table
+sub load_forward
+{
+ my @out;
+ do "$forwardfn" if -e "$forwardfn";
+ push @out, $@ if $@;
+ return @out;
+}
+
+# load the bad message table
+sub load_badmsg
+{
+ my @out;
+ do "$badmsgfn" if -e "$badmsgfn";
+ push @out, $@ if $@;
+ return @out;
+}
+
+#
+# forward that message or not according to the forwarding table
+# returns 1 for forward, 0 - to ignore
+#
+
+sub forward_it
+{
+ my $ref = shift;
+ my $call = shift;
+ my $i;
+
+ for ($i = 0; $i < @forward; $i += 5) {
+ my ($sort, $field, $pattern, $action, $bbs) = @forward[$i..($i+4)];
+ my $tested;
+
+ # are we interested?
+ last if $ref->{private} && $sort ne 'P';
+ last if !$ref->{private} && $sort ne 'B';
+
+ # select field
+ $tested = $ref->{to} if $field eq 'T';
+ $tested = $ref->{from} if $field eq 'F';
+ $tested = $ref->{origin} if $field eq 'O';
+ $tested = $ref->{subject} if $field eq 'S';
+
+ if (!$pattern || $tested =~ m{$pattern}i) {
+ return 0 if $action eq 'I';
+ return 1 if !$bbs || grep $_ eq $call, @{$bbs};
+ }
+ }
+ return 0;
+}
+