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']); $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); } /* 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 .= '

'; } return $str; } }