+sub CheckOnList2 ($$;$) {
+ # CheckOnList will check to see if the $sender is on the list. Return 1 if
+ # found 0 if not.
+ my ($listtype, $sender, $update) = @_;
+
+ $update //= 1;
+
+ my ($status, $rule, $sequence);
+
+ my $table = 'list';
+ my $condition = "userid='$userid' and type='$listtype'";
+
+ my ($err, $errmsg) = $db->find($table, $condition, '*', 'order by sequence');
+
+ my ($email_on_file, $rec);
+
+ while ($rec = $db->getnext) {
+ unless ($rec->{domain}) {
+ $email_on_file = $rec->{pattern};
+ } else {
+ unless ($rec->{pattern}) {
+ $email_on_file = '@' . $rec->{domain};
+ } else {
+ $email_on_file = $rec->{pattern} . '@' . $rec->{domain};
+ } # if
+ } # unless
+
+ # Escape some special characters
+ $email_on_file =~ s/\@/\\@/;
+ $email_on_file =~ s/^\*/.\*/;
+
+ # We want to terminate the search string with a "$" iff there's an
+ # "@" in there. This is because some "email_on_file" may have no
+ # domain (e.g. "mailer-daemon" with no domain). In that case we
+ # don't want to terminate the search string with a "$" rather we
+ # wish to terminate it with an "@". But in the case of say
+ # "@ti.com" if we don't terminate the search string with "$" then
+ # "@ti.com" would also match "@tixcom.com"!
+ my $search_for = $email_on_file =~ /\@/
+ ? "$email_on_file\$"
+ : !defined $rec->{domain}
+ ? "$email_on_file\@"
+ : $email_on_file;
+ if ($sender and $sender =~ /$search_for/i) {
+ $status = 1;
+
+ $rec->{hit_count} //= 0;
+
+ RecordHit(
+ userid => $userid,
+ type => $listtype,
+ sequence => $rec->{sequence},
+ hit_count => $rec->{hit_count} + 1,
+ ) if $update;
+
+ last;
+ } # if
+ } # while
+
+ return ($status, $rec);
+} # CheckOnList2
+