From 18584950947be30c1f288325b1db58a43e92134d Mon Sep 17 00:00:00 2001 From: FreeScout Date: Fri, 3 Aug 2018 18:57:50 +0000 Subject: [PATCH] Apply fixes from StyleCI --- app/Console/Commands/FetchEmails.php | 50 +++++++++++-------- .../Controllers/ConversationsController.php | 10 ++-- app/Http/Controllers/MailboxesController.php | 8 +-- app/Http/Controllers/SecureController.php | 3 +- app/Mailbox.php | 14 +++--- 5 files changed, 46 insertions(+), 39 deletions(-) diff --git a/app/Console/Commands/FetchEmails.php b/app/Console/Commands/FetchEmails.php index 7c7616c3a..505315034 100644 --- a/app/Console/Commands/FetchEmails.php +++ b/app/Console/Commands/FetchEmails.php @@ -6,9 +6,9 @@ use App\Customer; use App\Email; use App\Events\CustomerReplied; +use App\Mail\Mail; use App\Mailbox; use App\Thread; -use App\Mail\Mail; use Illuminate\Console\Command; use Webklex\IMAP\Client; @@ -53,21 +53,22 @@ public function handle() ->where('in_password', '<>', '') ->get(); - foreach ($mailboxes as $mailbox) { - $this->info('['.date('Y-m-d H:i:s').'] Mailbox: '.$mailbox->name); - try { - $this->fetch($mailbox); - } catch(\Exception $e) { - $this->error('['.date('Y-m-d H:i:s').'] Error: '.$e->getMessage().'; Line: '.$e->getLine()); - activity() + foreach ($mailboxes as $mailbox) { + $this->info('['.date('Y-m-d H:i:s').'] Mailbox: '.$mailbox->name); + + try { + $this->fetch($mailbox); + } catch (\Exception $e) { + $this->error('['.date('Y-m-d H:i:s').'] Error: '.$e->getMessage().'; Line: '.$e->getLine()); + activity() ->withProperties([ 'error' => $e->getMessage(), 'mailbox' => $mailbox->name, ]) ->useLog(\App\ActivityLog::NAME_EMAILS_FETCHING) ->log(\App\ActivityLog::DESCRIPTION_EMAILS_FETCHING_ERROR); - } } + } } public function fetch($mailbox) @@ -79,7 +80,7 @@ public function fetch($mailbox) 'validate_cert' => true, 'username' => $mailbox->in_username, 'password' => $mailbox->in_password, - 'protocol' => $mailbox->getInProtocolName() + 'protocol' => $mailbox->getInProtocolName(), ]); // Connect to the Server @@ -89,12 +90,12 @@ public function fetch($mailbox) $folder = $client->getFolder('INBOX'); if (!$folder) { - throw new \Exception("Could not get mailbox folder: INBOX", 1); + throw new \Exception('Could not get mailbox folder: INBOX', 1); } // Get unseen messages for a period $messages = $folder->query()->unseen()->since(now()->subDays(1))->leaveUnread()->get(); - + $this->line('['.date('Y-m-d H:i:s').'] Fetched: '.count($messages)); $message_index = 1; @@ -108,7 +109,7 @@ public function fetch($mailbox) $message->setFlag(['Seen']); continue; } - + if ($message->hasHTMLBody()) { // Get body and replace :cid with images URLs $body = $message->getHTMLBody(true); @@ -152,7 +153,7 @@ public function fetch($mailbox) $attachments = $message->getAttachments(); $save_result = $this->saveThread($mailbox->id, $message_id, $in_reply_to, $references, $from, $to, $cc, $bcc, $subject, $body, $attachments); - + if ($save_result) { $message->setFlag(['Seen']); $this->line('['.date('Y-m-d H:i:s').'] Processed'); @@ -173,14 +174,14 @@ public function saveThread($mailbox_id, $message_id, $in_reply_to, $references, $new = false; $conversation = null; $now = date('Y-m-d H:i:s'); - + $prev_thread = null; if ($in_reply_to) { $prev_thread = Thread::where('message_id', $in_reply_to)->first(); } elseif ($references) { if (!is_array($references)) { - $references = array_filter(preg_split("/[, <>]/", $references)); + $references = array_filter(preg_split('/[, <>]/', $references)); } $prev_thread = Thread::whereIn('message_id', $references)->first(); } @@ -249,7 +250,7 @@ public function separateReply($body, $is_html) if ($is_html) { $separator = Mail::REPLY_ABOVE_HTML; - $dom = new \DOMDocument; + $dom = new \DOMDocument(); libxml_use_internal_errors(true); $dom->loadHTML($body); libxml_use_internal_errors(false); @@ -270,14 +271,16 @@ public function separateReply($body, $is_html) if (!empty($parts)) { return $parts[0]; } + return $body; } /** * Remove mailbox email from the list of emails. - * - * @param array $list - * @param string $mailbox_email [description] + * + * @param array $list + * @param string $mailbox_email [description] + * * @return array */ public function removeMailboxEmail($list, $mailbox_email) @@ -291,13 +294,15 @@ public function removeMailboxEmail($list, $mailbox_email) break; } } + return $list; } /** * Conver email object to plain emails. - * - * @param array $obj_list + * + * @param array $obj_list + * * @return array */ public function formatEmailList($obj_list) @@ -306,6 +311,7 @@ public function formatEmailList($obj_list) foreach ($obj_list as $item) { $plain_list[] = $item->mail; } + return $plain_list; } } diff --git a/app/Http/Controllers/ConversationsController.php b/app/Http/Controllers/ConversationsController.php index 8f48a46c5..06b292fc2 100644 --- a/app/Http/Controllers/ConversationsController.php +++ b/app/Http/Controllers/ConversationsController.php @@ -4,9 +4,9 @@ use App\Conversation; use App\Customer; -use App\Events\UserReplied; use App\Events\ConversationStatusChanged; use App\Events\ConversationUserChanged; +use App\Events\UserReplied; use App\Folder; use App\Mailbox; use App\Thread; @@ -391,14 +391,14 @@ public function ajax(Request $request) } else { $customer = $conversation->customer; - if ((int)$request->status != (int)$conversation->status) { + if ((int) $request->status != (int) $conversation->status) { $status_changed = true; } } $conversation->status = $request->status; if ((int) $request->user_id != -1) { // Check if user has access to the current mailbox - if ((int)$conversation->user_id != (int)$request->user_id && $mailbox->userHasAccess($request->user_id)) { + if ((int) $conversation->user_id != (int) $request->user_id && $mailbox->userHasAccess($request->user_id)) { $conversation->user_id = $request->user_id; $user_changed = true; } @@ -414,10 +414,10 @@ public function ajax(Request $request) // Fire events if (!$new) { if ($status_changed) { - event(new ConversationStatusChanged($conversation)); + event(new ConversationStatusChanged($conversation)); } if ($user_changed) { - event(new ConversationUserChanged($conversation)); + event(new ConversationUserChanged($conversation)); } } diff --git a/app/Http/Controllers/MailboxesController.php b/app/Http/Controllers/MailboxesController.php index 7f3b8438a..170b03581 100644 --- a/app/Http/Controllers/MailboxesController.php +++ b/app/Http/Controllers/MailboxesController.php @@ -186,10 +186,10 @@ public function connectionOutgoingSave($id, Request $request) if ($request->out_method == Mailbox::OUT_METHOD_SMTP) { $validator = Validator::make($request->all(), [ - 'out_server' => 'required|string|max:255', - 'out_port' => 'required|integer', - 'out_username' => 'required|string|max:100', - 'out_password' => 'required|string|max:255', + 'out_server' => 'required|string|max:255', + 'out_port' => 'required|integer', + 'out_username' => 'required|string|max:100', + 'out_password' => 'required|string|max:255', 'out_encryption' => 'required|integer', ]); diff --git a/app/Http/Controllers/SecureController.php b/app/Http/Controllers/SecureController.php index 43d0d7f95..1e6bc9ea7 100644 --- a/app/Http/Controllers/SecureController.php +++ b/app/Http/Controllers/SecureController.php @@ -41,6 +41,7 @@ function addCol($cols, $col) if (!in_array($col, $cols)) { $cols[] = $col; } + return $cols; } $names = ActivityLog::select('log_name')->distinct()->get()->pluck('log_name'); @@ -115,7 +116,7 @@ public function system(Request $request) return view('secure/system', [ 'queued_jobs' => $queued_jobs, 'failed_jobs' => $failed_jobs, - 'php_extensions' => $php_extensions + 'php_extensions' => $php_extensions, ]); } } diff --git a/app/Mailbox.php b/app/Mailbox.php index 7af44e8b3..d402013d5 100644 --- a/app/Mailbox.php +++ b/app/Mailbox.php @@ -52,8 +52,8 @@ class Mailbox extends Model public static $out_encryptions = [ self::OUT_ENCRYPTION_NONE => '', - self::OUT_ENCRYPTION_SSL => 'ssl', - self::OUT_ENCRYPTION_TLS => 'tls', + self::OUT_ENCRYPTION_SSL => 'ssl', + self::OUT_ENCRYPTION_TLS => 'tls', ]; /** @@ -76,8 +76,8 @@ class Mailbox extends Model public static $in_encryptions = [ self::IN_ENCRYPTION_NONE => '', - self::IN_ENCRYPTION_SSL => 'ssl', - self::IN_ENCRYPTION_TLS => 'tls', + self::IN_ENCRYPTION_SSL => 'ssl', + self::IN_ENCRYPTION_TLS => 'tls', ]; /** @@ -380,7 +380,7 @@ public function getEmailDomain() /** * Get outgoing email encryption protocol. - * + * * @return string */ public function getOutEncryptionName() @@ -390,7 +390,7 @@ public function getOutEncryptionName() /** * Get incoming email encryption protocol. - * + * * @return string */ public function getInEncryptionName() @@ -400,7 +400,7 @@ public function getInEncryptionName() /** * Get incoming protocol name. - * + * * @return string */ public function getInProtocolName()