+
+ # Do NOT check IP addresses against the Spamhaus DBL list.
+
+ # If SURBL checks are enabled and the IP is
+ # not in the SURBL list, add it.
+ if (! grep(/^$spamcheckdomain$/i,@surbl_list) &&
+ ($surbl_enable == 1)) {
+ push(@surbl_list,$spamcheckdomain);
+ }
+ # If URIBL checks are enabled and the IP is
+ # not in the URIBL list, add it.
+ if (! grep(/^$spamcheckdomain$/i,@uribl_list) &&
+ ($uribl_enable == 1)) {
+ push(@uribl_list,$spamcheckdomain);
+ }
+ } else {
+ # Domain is not an IP address.
+ # Check if the last three elements of the domain are
+ # in the three-level TLD list.
+ $three_checkdomain = mkaddress(@domain,3);
+ $two_checkdomain = mkaddress(@domain,2);
+ if (grep(/^$three_checkdomain$/i,@threetlds)) {
+ # Set $spamcheckdomain to four elements.
+ $spamcheckdomain = mkaddress(@domain,4);
+ # Check if $spamcheckdomain is not in the whitelist.
+ if ((! grep(/^$spamcheckdomain$/i,@whitelist)) &&
+ (! grep(/^three_checkdomain$/i,@whitelist)) &&
+ (! grep(/^two_checkdomain$/i,@whitelist))) {
+ # If SURBL checks are enabled and the domain is
+ # not in the SURBL list, add it.
+ if (! grep(/^$spamcheckdomain$/i,@surbl_list) &&
+ ($surbl_enable == 1)) {
+ push(@surbl_list,$spamcheckdomain);
+ }
+ # If URIBL checks are enabled and the domain is
+ # not in the URIBL list, add it.
+ if (! grep(/^$spamcheckdomain$/i,@uribl_list) &&
+ ($uribl_enable == 1)) {
+ push(@uribl_list,$spamcheckdomain);
+ }
+ # If DBL checks are enabled and the domain is
+ # not in the DBL list, add it.
+ if (! grep(/^$spamcheckdomain$/i,@dbl_list) &&
+ ($dbl_enable == 1)) {
+ push(@dbl_list,$spamcheckdomain);
+ }
+ }
+ }
+
+ # Check if the last two elements of the domain are
+ # in the two-level TLD list.
+ elsif (grep(/^$two_checkdomain$/i,@twotlds)) {
+ # Reset $spamcheckdomain to three elements.
+ $spamcheckdomain = mkaddress(@domain,3);
+ # Check if $spamcheckdomain is not in the whitelist.
+ if ((! grep(/^$spamcheckdomain$/i,@whitelist)) &&
+ (! grep(/^two_checkdomain$/i,@whitelist))) {
+ # If SURBL checks are enabled and the domain is
+ # not in the SURBL list, add it.
+ if (! grep(/^$spamcheckdomain$/i,@surbl_list) &&
+ ($surbl_enable == 1)) {
+ push(@surbl_list,$spamcheckdomain);
+ }
+ # If URIBL checks are enabled and the domain is
+ # not in the URIBL list, add it.
+ if (! grep(/^$spamcheckdomain$/i,@uribl_list) &&
+ ($uribl_enable == 1)) {
+ push(@uribl_list,$spamcheckdomain);
+ }
+ # If DBL checks are enabled and the domain is
+ # not in the DBL list, add it.
+ if (! grep(/^$spamcheckdomain$/i,@dbl_list) &&
+ ($dbl_enable == 1)) {
+ push(@dbl_list,$spamcheckdomain);
+ }
+ }
+
+ # Reset $spamcheckdomain to four elements.
+ $spamcheckdomain = mkaddress(@domain,4);
+ # Check if $spamcheckdomain is not in the whitelist.
+ if ((! grep(/^$spamcheckdomain$/i,@whitelist)) &&
+ (! grep(/^three_checkdomain$/i,@whitelist)) &&
+ (! grep(/^two_checkdomain$/i,@whitelist))) {
+ # If SURBL checks are enabled and the domain is
+ # not in the SURBL list, add it.
+ if (! grep(/^$spamcheckdomain$/i,@surbl_list) &&
+ ($surbl_enable == 1)) {
+ push(@surbl_list,$spamcheckdomain);
+ }
+ # If URIBL checks are enabled and the domain is
+ # not in the URIBL list, add it.
+ if (! grep(/^$spamcheckdomain$/i,@uribl_list) &&
+ ($uribl_enable == 1)) {
+ push(@uribl_list,$spamcheckdomain);
+ }
+ # If DBL checks are enabled and the domain is
+ # not in the DBL list, add it.
+ if (! grep(/^$spamcheckdomain$/i,@dbl_list) &&
+ ($dbl_enable == 1)) {
+ push(@dbl_list,$spamcheckdomain);
+ }
+ }
+
+ } else {
+ # Set $spamcheckdomain to two elements
+ $spamcheckdomain = mkaddress(@domain,2);
+ # Check if $spamcheckdomain is not in the whitelist.
+ if (! grep(/^$spamcheckdomain$/i,@whitelist)) {
+ # If SURBL checks are enabled and the domain is
+ # not in the SURBL list, add it.
+ if (! grep(/^$spamcheckdomain$/i,@surbl_list) &&
+ ($surbl_enable == 1)) {
+ push(@surbl_list,$spamcheckdomain);
+ }
+ # If URIBL checks are enabled and the domain is
+ # not in the URIBL list, add it.
+ if (! grep(/^$spamcheckdomain$/i,@uribl_list) &&
+ ($uribl_enable == 1)) {
+ push(@uribl_list,$spamcheckdomain);
+ }
+ # If DBL checks are enabled and the domain is
+ # not in the DBL list, add it.
+ if (! grep(/^$spamcheckdomain$/i,@dbl_list) &&
+ ($dbl_enable == 1)) {
+ push(@dbl_list,$spamcheckdomain);
+ }
+ }
+ # Reset $spamcheckdomain to three elements
+ $spamcheckdomain = mkaddress(@domain,3);
+ # Check if $spamcheckdomain is not in the whitelist.
+ if ((! grep(/^$spamcheckdomain$/i,@whitelist)) &&
+ (! grep(/^$two_checkdomain$/i,@whitelist))) {
+ # If URIBL checks are enabled and the domain is
+ # not in the URIBL list, add it.
+ if (! grep(/^$spamcheckdomain$/i,@uribl_list) &&
+ ($uribl_enable == 1)) {
+ push(@uribl_list,$spamcheckdomain);
+ }
+ # If DBL checks are enabled and the domain is
+ # not in the DBL list, add it.
+ if (! grep(/^$spamcheckdomain$/i,@dbl_list) &&
+ ($dbl_enable == 1)) {
+ push(@dbl_list,$spamcheckdomain);
+ }
+ }
+ # Set $spamcheckdomain to four elements
+ $spamcheckdomain = mkaddress(@domain,4);
+ # Check if $spamcheckdomain is not in the whitelist.
+ if ((! grep(/^$spamcheckdomain$/i,@whitelist)) &&
+ (! grep(/^$three_checkdomain$/i,@whitelist)) &&
+ (! grep(/^$two_checkdomain$/i,@whitelist))) {
+ # If URIBL checks are enabled and the domain is
+ # not in the URIBL list, add it.
+ if (! grep(/^$spamcheckdomain$/i,@uribl_list) &&
+ ($uribl_enable == 1)) {
+ push(@uribl_list,$spamcheckdomain);
+ }
+ # If DBL checks are enabled and the domain is
+ # not in the DBL list, add it.
+ if (! grep(/^$spamcheckdomain$/i,@dbl_list) &&
+ ($dbl_enable == 1)) {
+ push(@dbl_list,$spamcheckdomain);
+ }
+ }
+ }
+ } # End: if ($domain[-1] =~ /^(\d){1,3}$/)
+ } # End: if (scalar(@domain) == 4)
+ } # End: if (scalar(@domain) >=2)
+ } # End: for ($i=1; $i < scalar(@parts); $i++)
+
+ # If there are items in the SURBL list and the SURBL check
+ # is enabled then perform lookups on them.
+ if ((scalar(@surbl_list) > 0) &&
+ ($surbl_enable == 1)) {
+ foreach $i (@surbl_list) {
+ # DEBUG statement.
+ #warn ("CHECKING DOMAIN ($mime_filename): $i in SURBL list.\n");
+ $return_result = surbllookup($i);
+ if ($return_result ne "") {
+ return $return_result;