diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php
index ee018d391ac4..b3eaa66b7e1f 100644
--- a/app/Http/Controllers/ClientController.php
+++ b/app/Http/Controllers/ClientController.php
@@ -5,6 +5,8 @@ namespace App\Http\Controllers;
use App\Http\Requests\ClientRequest;
use App\Http\Requests\CreateClientRequest;
use App\Http\Requests\UpdateClientRequest;
+use App\Jobs\LoadPostmarkHistory;
+use App\Jobs\ReactivatePostmarkEmail;
use App\Models\Account;
use App\Models\Client;
use App\Models\Credit;
@@ -276,39 +278,15 @@ class ClientController extends BaseController
public function getEmailHistory()
{
- $str = '';
+ $history = dispatch(new LoadPostmarkHistory(request()->email));
- if (config('services.postmark')) {
- $email = request()->email;
- $account = auth()->user()->account;
- $postmark = new \Postmark\PostmarkClient(config('services.postmark'));
- $response = $postmark->getOutboundMessages(5, 0, $email, null, $account->account_key);
+ return response()->json($history);
+ }
- foreach ($response['messages'] as $message) {
- $details = $postmark->getOutboundMessageDetails($message['MessageID']);
- $str .= sprintf('%s
', $details['subject']);
+ public function reactivateEmail()
+ {
+ $result = dispatch(new ReactivatePostmarkEmail(request()->bounce_id));
- if (count($details['messageevents'])) {
- $event = $details['messageevents'][0];
- $str .= sprintf('%s | %s
', $event['Type'], $account->getDateTime($event['ReceivedAt'], true));
- if ($message = $event['Details']['DeliveryMessage']) {
- $str .= sprintf('%s
', $message);
- }
- if ($server = $event['Details']['DestinationServer']) {
- $str .= sprintf('%s
', $server);
- }
- } else {
- $str .= trans('texts.processing') . '...';
- }
-
- $str .= '
';
- }
- }
-
- if (! $str) {
- $str = trans('texts.no_messages_found');
- }
-
- return $str;
+ return response()->json($result);
}
}
diff --git a/app/Jobs/LoadPostmarkHistory.php b/app/Jobs/LoadPostmarkHistory.php
new file mode 100644
index 000000000000..5708e10e2b9e
--- /dev/null
+++ b/app/Jobs/LoadPostmarkHistory.php
@@ -0,0 +1,88 @@
+email = $email;
+ $this->bounceId = false;
+ }
+
+ /**
+ * Execute the job.
+ *
+ * @return void
+ */
+ public function handle()
+ {
+ $str = '';
+
+ if (config('services.postmark')) {
+ $this->account = auth()->user()->account;
+ $this->postmark = new PostmarkClient(config('services.postmark'));
+
+ $str .= $this->loadBounceEvents();
+ $str .= $this->loadEmailEvents();
+ }
+
+ if (! $str) {
+ $str = trans('texts.no_messages_found');
+ }
+
+ $response = new stdClass;
+ $response->str = $str;
+ $response->bounce_id = $this->bounceId;
+
+ return $response;
+ }
+
+ private function loadBounceEvents() {
+ $str = '';
+ $response = $this->postmark->getBounces(5, 0, null, null, $this->email, $this->account->account_key);
+
+ foreach ($response['bounces'] as $bounce) {
+ if (! $bounce['inactive'] || ! $bounce['canactivate']) {
+ continue;
+ }
+
+ $str .= sprintf('%s
', $bounce['subject']);
+ $str .= sprintf('%s | %s
', $bounce['type'], $this->account->getDateTime($bounce['bouncedat'], true));
+ $str .= sprintf('%s %s', $bounce['description'], $bounce['details']);
+
+ $this->bounceId = $bounce['id'];
+ }
+
+ return $str;
+ }
+
+ private function loadEmailEvents() {
+ $str = '';
+ $response = $this->postmark->getOutboundMessages(5, 0, $this->email, null, $this->account->account_key);
+
+ foreach ($response['messages'] as $message) {
+ $details = $this->postmark->getOutboundMessageDetails($message['MessageID']);
+ $str .= sprintf('%s
', $details['subject']);
+
+ if (count($details['messageevents'])) {
+ $event = $details['messageevents'][0];
+ $str .= sprintf('%s | %s
', $event['Type'], $this->account->getDateTime($event['ReceivedAt'], true));
+ if ($message = $event['Details']['DeliveryMessage']) {
+ $str .= sprintf('%s
', $message);
+ }
+ if ($server = $event['Details']['DestinationServer']) {
+ $str .= sprintf('%s
', $server);
+ }
+ } else {
+ $str .= trans('texts.processing') . '...';
+ }
+
+ $str .= '';
+ }
+ }
+}
diff --git a/app/Jobs/ReactivatePostmarkEmail.php b/app/Jobs/ReactivatePostmarkEmail.php
new file mode 100644
index 000000000000..891619d99e28
--- /dev/null
+++ b/app/Jobs/ReactivatePostmarkEmail.php
@@ -0,0 +1,29 @@
+bounceId = $bounceId;
+ }
+
+ /**
+ * Execute the job.
+ *
+ * @return void
+ */
+ public function handle()
+ {
+ if (! config('services.postmark')) {
+ return false;
+ }
+
+ $postmark = new PostmarkClient(config('services.postmark'));
+ $response = $postmark->activateBounce($this->bounceId);
+ }
+}
diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php
index 96545e900458..1d5558455190 100644
--- a/resources/lang/en/texts.php
+++ b/resources/lang/en/texts.php
@@ -2750,6 +2750,8 @@ $LANG = array(
'loading' => 'Loading',
'no_messages_found' => 'No messages found',
'processing' => 'Processing',
+ 'reactivate' => 'Reactivate',
+ 'reactivated_email' => 'The email address has been reactivated',
);
diff --git a/resources/views/clients/show.blade.php b/resources/views/clients/show.blade.php
index a10eff553c0b..dea131c7367c 100644
--- a/resources/views/clients/show.blade.php
+++ b/resources/views/clients/show.blade.php
@@ -337,6 +337,7 @@
@@ -397,10 +398,21 @@
}
function showEmailHistory(email) {
+ window.emailBounceId = false;
$('#emailHistoryModal .panel-body').html("{{ trans('texts.loading') }}...");
+ $('#reactivateButton').hide();
$('#emailHistoryModal').modal('show');
$.post('{{ url('/email_history') }}', {email: email}, function(data) {
- $('#emailHistoryModal .panel-body').html(data);
+ $('#emailHistoryModal .panel-body').html(data.str);
+ window.emailBounceId = data.bounce_id;
+ $('#reactivateButton').toggle(!! window.emailBounceId);
+ })
+ }
+
+ function onReactivateClick() {
+ $.post('{{ url('/reactivate_email') }}/' + window.emailBounceId, function(data) {
+ $('#emailHistoryModal').modal('hide');
+ swal("{{ trans('texts.reactivated_email') }}")
})
}
diff --git a/routes/web.php b/routes/web.php
index 2c9ddd55deb7..9ba3648d2845 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -141,12 +141,13 @@ Route::group(['middleware' => ['lookup:user', 'auth:user']], function () {
Route::get('settings/enable_two_factor', 'TwoFactorController@setupTwoFactor');
Route::post('settings/enable_two_factor', 'TwoFactorController@enableTwoFactor');
- Route::post('email_history', 'ClientController@getEmailHistory');
Route::resource('clients', 'ClientController');
Route::get('api/clients', 'ClientController@getDatatable');
Route::get('api/activities/{client_id?}', 'ActivityController@getDatatable');
Route::post('clients/bulk', 'ClientController@bulk');
Route::get('clients/statement/{client_id}/{status_id?}/{start_date?}/{end_date?}', 'ClientController@statement');
+ Route::post('email_history', 'ClientController@getEmailHistory');
+ Route::post('reactivate_email/{bounce_id}', 'ClientController@reactivateEmail');
Route::get('time_tracker', 'TimeTrackerController@index');
Route::get('tasks/kanban/{client_id?}/{project_id?}', 'TaskKanbanController@index');