arteman (arteman) wrote in changelog,
arteman
arteman
changelog

[livejournal] r23535: LJSV-2568: Implement SupportRequest even...

Committer: azateev
LJSV-2568: Implement SupportRequest event
U   branches/esn-support/cgi-bin/LJ/NotificationMethod/Email.pm
Modified: branches/esn-support/cgi-bin/LJ/NotificationMethod/Email.pm
===================================================================
--- branches/esn-support/cgi-bin/LJ/NotificationMethod/Email.pm	2013-01-14 14:02:55 UTC (rev 23534)
+++ branches/esn-support/cgi-bin/LJ/NotificationMethod/Email.pm	2013-01-14 14:19:09 UTC (rev 23535)
@@ -3,6 +3,7 @@
 use strict;
 use Carp qw/ croak /;
 use base 'LJ::NotificationMethod';
+use Data::Dumper;
 
 use lib "$ENV{LJHOME}/cgi-bin";
 require "weblib.pl";
@@ -16,11 +17,12 @@
     croak "no args passed"
         unless @_;
 
-    my $u = shift;
-    croak "invalid user object passed"
+    my $u    = shift;
+    my $subs = shift;
+    
+    warn "No user object passed"
         unless LJ::isu($u);
-
-    my $subs = shift;
+    
     my $self = { u => $u, subs => $subs };
 
     return bless $self, $class;
@@ -62,12 +64,11 @@
 
     my $u = $self->u;
 
-    if (LJ::sysban_check('email_domain', $u->email_raw)){
+    if ($u && 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,
@@ -96,7 +97,32 @@
                 next;
             }
         }
+        
+        # we should email unauthorised person about particular event
+        if (!$u && ref($ev) =~ /SupportRequest/) {
+            warn "Prepare notification for unauthorized requester!\n\n" if $ENV{DEBUG};
+            my $plain_body = $ev->as_email_string() or next;
+            my %headers = (
+                "X-LJ-Recipient" => "Unknown",
+                %{$ev->as_email_headers() || {}},
+                %{$opts->{_debug_headers}   || {}}
+            );
 
+            my $email_subject = $ev->as_email_subject();
+            LJ::send_mail({
+                to       => $ev->sprequest->{reqemail},
+                from     => $LJ::BOGUS_EMAIL,
+                fromname => "$LJ::SITENAMESHORT Support",
+                wrap     => 1,
+                charset  => 'utf-8',
+                subject  => $email_subject,
+                headers  => \%headers,
+                body     => $plain_body,
+            }) or die "unable to send notification email";
+            warn "\n\n\nAnd it seems to be sent!!!\n\n\n" if $ENV{DEBUG};
+            return 1;
+        }
+
         if (LJ::run_hook('esn_send_email', $self, $opts, $ev)) {
             ## do nothing, hook did the job
         }
@@ -159,6 +185,9 @@
     # override requiring user to have an email specified and be active if testing
     return 1 if $LJ::_T_EMAIL_NOTIFICATION;
 
+    #email unauthorised recipient
+    return 1 unless $u;
+    
     return 0 unless length $u->email_raw;
 
     # don't send out emails unless the user's email address is active

Tags: arteman, azateev, livejournal, pm
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