Skip to content

Commit

Permalink
FIX: Logging fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mellisa Hankins committed Jun 17, 2015
1 parent acc2ad2 commit 120717e
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 11 deletions.
2 changes: 1 addition & 1 deletion code/listeners/Logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion code/listeners/mandrill/Tracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
Expand Down
70 changes: 67 additions & 3 deletions code/logs/SendThis_Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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)
{
Expand All @@ -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']) ? '<img src="' . $tracker['Icon'] . '" alt="" class="icon-tiny" /> ' . $this->getClientFromTracker($value, $tracker) : $this->getClientFromTracker($value, $tracker);

if(isset($tracker['ClientLink'])) {
$formattedValue = '<a href="' . $tracker['ClientLink'] . '" target="_blank">' . $formattedValue . '</a>';
}

$output->push(
ArrayData::create(
array(
'Title' => _t('SendThis_Log.LABEL-Client', 'Client'),
'FormattedValue' => isset($tracker['Icon']) ? '<img src="' . $tracker['Icon'] . '" alt="" class="icon-tiny" /> ' . $value : $value
'FormattedValue' => $formattedValue,
)
)
);
Expand Down Expand Up @@ -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;
}
}
13 changes: 8 additions & 5 deletions code/transports/AmazonSES.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion code/transports/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions code/transports/Mandrill.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 120717e

Please sign in to comment.