From 120717e58846fd87cf43f729111988d1c8a20c08 Mon Sep 17 00:00:00 2001 From: Mellisa Hankins Date: Wed, 17 Jun 2015 13:53:39 +1000 Subject: [PATCH] FIX: Logging fixes --- code/listeners/Logging.php | 2 +- code/listeners/mandrill/Tracking.php | 2 +- code/logs/SendThis_Log.php | 70 ++++++++++++++++++++++++++-- code/transports/AmazonSES.php | 13 ++++-- code/transports/Mail.php | 4 +- code/transports/Mandrill.php | 1 + 6 files changed, 81 insertions(+), 11 deletions(-) diff --git a/code/listeners/Logging.php b/code/listeners/Logging.php index 15d9b2f..7109220 100644 --- a/code/listeners/Logging.php +++ b/code/listeners/Logging.php @@ -113,7 +113,7 @@ public function bounced(Event $e, $messageId = '', $email = '', $params = [], $r $e->mailer()->eventful()->fire( Event::named('sendthis:spam', $e->mailer()), - $messageId, + $messageId , $email, array_merge($params, ['message' => $message, 'valid_email' => false]), $response diff --git a/code/listeners/mandrill/Tracking.php b/code/listeners/mandrill/Tracking.php index 3d705b3..ad24555 100644 --- a/code/listeners/mandrill/Tracking.php +++ b/code/listeners/mandrill/Tracking.php @@ -93,7 +93,7 @@ function getTrackerData($response) 'ClientLink' => $this->checkIfKeyExistsAndReturnValue('ua_url', $response['user_agent_parsed']), 'ClientCompany' => $this->checkIfKeyExistsAndReturnValue('ua_company', $response['user_agent_parsed']), 'ClientCompanyLink' => $this->checkIfKeyExistsAndReturnValue('ua_company_url', $response['user_agent_parsed']), - 'ClientIcon' => $this->checkIfKeyExistsAndReturnValue('ua_icon', $response['user_agent_parsed']), + 'Icon' => $this->checkIfKeyExistsAndReturnValue('ua_icon', $response['user_agent_parsed']), 'OperatingSystemBrand' => $this->checkIfKeyExistsAndReturnValue('os_family', $response['user_agent_parsed']), 'OperatingSystem' => $this->checkIfKeyExistsAndReturnValue('os_name', $response['user_agent_parsed']), diff --git a/code/logs/SendThis_Log.php b/code/logs/SendThis_Log.php index 91d06d2..4afe652 100644 --- a/code/logs/SendThis_Log.php +++ b/code/logs/SendThis_Log.php @@ -79,6 +79,22 @@ class SendThis_Log extends DataObject { private static $default_sort = 'Created DESC'; + protected $excludeFromTrackerReports = [ + 'Icon', + 'ClientBrand', + 'ClientIcon', + 'ClientLink', + 'ClientCompany', + 'ClientCompanyLink', + 'CountryCode', + + 'OperatingSystemIcon', + 'OperatingSystemBrand', + 'OperatingSystemLink', + 'OperatingSystemCompany', + 'OperatingSystemCompanyLink', + ]; + /** * Find the recent emails sent by a member and/or email * @@ -350,7 +366,7 @@ function Tracker_ForTemplate($includeContent = true, $full = false) if (($tracker = $this->Tracker) && count($tracker)) { - $exclude = array('OperatingSystem', 'Client', 'Icon', 'OperatingSystemIcon'); + $exclude = $this->excludeFromTrackerReports; if (! $full) { @@ -359,13 +375,19 @@ function Tracker_ForTemplate($includeContent = true, $full = false) foreach ($tracker as $title => $value) { - if ($title == 'ClientFull') + if ($title == 'Client') { + $formattedValue = isset($tracker['Icon']) ? ' ' . $this->getClientFromTracker($value, $tracker) : $this->getClientFromTracker($value, $tracker); + + if(isset($tracker['ClientLink'])) { + $formattedValue = '' . $formattedValue . ''; + } + $output->push( ArrayData::create( array( 'Title' => _t('SendThis_Log.LABEL-Client', 'Client'), - 'FormattedValue' => isset($tracker['Icon']) ? ' ' . $value : $value + 'FormattedValue' => $formattedValue, ) ) ); @@ -463,4 +485,46 @@ function canView($member = null) { return Permission::check('CAN_VIEW_SEND_LOGS'); } + + protected function getClientFromTracker($client, $tracked = null) { + if(!$tracked) + $tracked = $this->Tracker; + + if(strtolower($client) == 'gmail image proxy') { + return _t('SendThis_Log.WEB_CLIENT-GMAIL', 'Gmail'); + } + if (isset($tracked['Type']) && strtolower($tracked['Type']) == 'email client') + { + $client = $tracked['Client']; + } elseif (isset($tracked['Type']) && strtolower($tracked['Type']) == 'browser' || strtolower($tracked['Type']) == 'mobile browser') + { + if (isset($tracked['ClientFull']) && ! preg_match('/.*[0-9]$/', $tracked['ClientFull'])) + { + $client = _t( + 'SendThis_Log.EMAIL_CLIENT-MAC', + 'Mac Client (Apple Mail or Microsoft Entourage)' + ); + } elseif (isset($tracked['Referrer'])) + { + foreach ($this->config()->web_based_clients as $name => $url) + { + if (preg_match("/$url/", $tracked['Referrer'])) + { + $client = _t( + 'SendThis_Log.WEB_CLIENT-' . strtoupper(str_replace(' ', '_', $name)), + $name + ); + break; + } + } + } + + if (! $client) + { + $client = _t('SendThis_Log.BROWSER_BASED', 'Web Browser'); + } + } + + return $client; + } } \ No newline at end of file diff --git a/code/transports/AmazonSES.php b/code/transports/AmazonSES.php index db615bd..cb3ce5b 100644 --- a/code/transports/AmazonSES.php +++ b/code/transports/AmazonSES.php @@ -66,16 +66,19 @@ public function handleResponse(\GuzzleHttp\Message\ResponseInterface $response, } } + $messageId = ''; + + if(($result = $results->SendRawEmailResult) && isset($result['MessageId'])) + $messageId = $result['MessageId']; + if($message) { $message .= 'Status Code: ' . $response->getStatusCode() . "\n"; $message .= 'Message: ' . $response->getReasonPhrase(); - throw new Exception($message); - } - $messageId = ''; + $this->mailer->eventful()->fire(Event::named('sendthis:failed', $this->mailer), $messageId ? $messageId : $messenger->getLastMessageID(), $messenger->getToAddresses(), $results, $results, $log); - if(($result = $results->SendRawEmailResult) && isset($result['MessageId'])) - $messageId = $result['MessageId']; + throw new Exception($message); + } $this->mailer->eventful()->fire(Event::named('sendthis:sent', $this->mailer), $messageId, $messenger->getToAddresses(), $results, $results, $log); diff --git a/code/transports/Mail.php b/code/transports/Mail.php index c1b0b7e..0d56fc4 100644 --- a/code/transports/Mail.php +++ b/code/transports/Mail.php @@ -27,8 +27,10 @@ function start(\PHPMailer $messenger, \ViewableData $log = null) if($success) $this->mailer->eventful()->fire(Event::named('sendthis:sent', $this->mailer), $messenger->getLastMessageID(), $to, $response, $response, $log); - else + else { + $this->mailer->eventful()->fire(Event::named('sendthis:failed', $this->mailer), $messenger->getLastMessageID(), $to, $response, $response, $log); throw new Exception('Message not successfully sent' . "\n\n" . nl2br(print_r($response, true))); + } }; $messenger->send(); diff --git a/code/transports/Mandrill.php b/code/transports/Mandrill.php index 8d0464a..7c32f11 100644 --- a/code/transports/Mandrill.php +++ b/code/transports/Mandrill.php @@ -70,6 +70,7 @@ public function handleResponse(\GuzzleHttp\Message\ResponseInterface $response, $message .= 'Status Code: ' . $response->getStatusCode() . "\n"; $message .= 'Message: ' . $response->getReasonPhrase(); + $this->mailer->eventful()->fire(Event::named('sendthis:failed', $this->mailer), $messageId, $email, $results, $results, $log); throw new Exception($message); }