vadvs (vadvs) wrote in changelog,
vadvs
vadvs
changelog

[livejournal] r18255: LJSUP-7922: Respect "email_domain" sysba...

Committer: vsukhanov
LJSUP-7922: Respect "email_domain" sysban when sending emails
U   trunk/cgi-bin/LJ/DoSendEmail.pm
U   trunk/cgi-bin/LJ/NotificationMethod/Email.pm
U   trunk/cgi-bin/sysban.pl
Modified: trunk/cgi-bin/LJ/DoSendEmail.pm
===================================================================
--- trunk/cgi-bin/LJ/DoSendEmail.pm	2011-02-10 08:39:58 UTC (rev 18254)
+++ trunk/cgi-bin/LJ/DoSendEmail.pm	2011-02-10 08:46:54 UTC (rev 18255)
@@ -80,6 +80,13 @@
     my $class = shift;
     my ($rcpt, $opts) = @_;
 
+    ## temp hack, I Gariev, 17.01.2011
+    return CONNECTION_FAILED if $rcpt =~ /xrock\.co\.cc$/;
+    return CONNECTION_FAILED if $rcpt =~ /egor\.mail\.ua$/;
+
+    ## do not issuing banned emails
+    return NO_SUPPORTED_RCPT if LJ::sysban_check('email_domain', $rcpt);
+
     ## read params
     my $from         = $opts->{from}; # Envelope From
     my $data         = $opts->{data};

Modified: trunk/cgi-bin/LJ/NotificationMethod/Email.pm
===================================================================
--- trunk/cgi-bin/LJ/NotificationMethod/Email.pm	2011-02-10 08:39:58 UTC (rev 18254)
+++ trunk/cgi-bin/LJ/NotificationMethod/Email.pm	2011-02-10 08:46:54 UTC (rev 18255)
@@ -61,6 +61,11 @@
         unless ref $self eq __PACKAGE__;
 
     my $u = $self->u;
+    
+    if (LJ::sysban_check('email_domain', $u->email_raw)){
+        warn "Not issuing job for " . $u->email_raw . " [banned]";
+        return 1;
+    }
 
     my $lang = $u->prop('browselang');
     my $vars = { sitenameshort => $LJ::SITENAMESHORT, sitename => $LJ::SITENAME, siteroot => $LJ::SITEROOT };

Modified: trunk/cgi-bin/sysban.pl
===================================================================
--- trunk/cgi-bin/sysban.pl	2011-02-10 08:39:58 UTC (rev 18254)
+++ trunk/cgi-bin/sysban.pl	2011-02-10 08:46:54 UTC (rev 18255)
@@ -54,10 +54,10 @@
 
         # return value to user
         return $LJ::IP_BANNED{$value};
+    
     }
-
     # cache if uniq ban
-    if ($what eq 'uniq') {
+    elsif ($what eq 'uniq') {
 
         # check memcache first if not loaded
         unless ($LJ::UNIQ_BANNED_LOADED) {
@@ -88,9 +88,8 @@
         # return value to user
         return $LJ::UNIQ_BANNED{$value};
     }
-
     # cache if contentflag ban
-    if ($what eq 'contentflag') {
+    elsif ($what eq 'contentflag') {
 
         # check memcache first if not loaded
         unless ($LJ::CONTENTFLAG_BANNED_LOADED) {
@@ -123,7 +122,44 @@
                 ($LJ::CONTENTFLAG_BANNED{$value} == 0 ||     # forever
                  $LJ::CONTENTFLAG_BANNED{$value} > time())); # not-expired
     }
+    # cache if email_domain
+    elsif ($what eq 'email_domain'){
+        
+        $value =~ s/^.*@//; ## in case $value is a full email address.
 
+        # check memcache first if not loaded
+        unless ($LJ::EMAIL_DOMAIN_BANNED_LOADED) {
+            my $memval = LJ::MemCache::get("sysban:email_domain");
+            if ($memval) {
+                $LJ::EMAIL_DOMAIN_BANNED = $memval;
+                $LJ::EMAIL_DOMAIN_BANNED_LOADED++;
+            }
+        }
+
+        # is it already cached in memory?
+        if ($LJ::EMAIL_DOMAIN_BANNED_LOADED) {
+            return (defined $LJ::EMAIL_DOMAIN_BANNED{$value} &&
+                    ($LJ::EMAIL_DOMAIN_BANNED{$value} == 0 ||     # forever
+                     $LJ::EMAIL_DOMAIN_BANNED{$value} > time())); # not-expired
+        }
+
+        # set this now before the query
+        $LJ::EMAIL_DOMAIN_BANNED_LOADED++;
+
+        LJ::sysban_populate(\%LJ::EMAIL_DOMAIN_BANNED, "email_domain")
+            or return undef $LJ::EMAIL_DOMAIN_BANNED_LOADED;
+
+        # set in memcache
+        my $exp = 60*15; # 15 minutes
+        LJ::MemCache::set("sysban:email_domain", \%LJ::EMAIL_DOMAIN_BANNED, $exp);
+
+        # return value to user
+        return (defined $LJ::EMAIL_DOMAIN_BANNED{$value} &&
+                ($LJ::EMAIL_DOMAIN_BANNED{$value} == 0 ||     # forever
+                 $LJ::EMAIL_DOMAIN_BANNED{$value} > time())); # not-expired
+       
+    }
+
     # need the db below here
     my $dbr = LJ::get_db_reader();
     return undef unless $dbr;
@@ -180,9 +216,12 @@
     my ($where, $what) = @_;
 
     # call normally if no gearman/not wanted
+    return LJ::_db_sysban_populate($where, $what) 
+        unless LJ::conf_test($LJ::LOADSYSBAN_USING_GEARMAN);
+    
     my $gc = LJ::gearman_client();
-    return LJ::_db_sysban_populate($where, $what)
-        unless $gc && LJ::conf_test($LJ::LOADSYSBAN_USING_GEARMAN);
+    return LJ::_db_sysban_populate($where, $what) 
+        unless $gc;
 
     # invoke gearman
     my $args = Storable::nfreeze({what => $what});

Tags: livejournal, pl, pm, vadvs
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments