Skip to content

Commit

Permalink
Merge pull request #23 from freescout-helpdesk/analysis-XlJ1pk
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
freescout-helpdesk authored Aug 3, 2018
2 parents 4324b43 + 1858495 commit d93925c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 39 deletions.
50 changes: 28 additions & 22 deletions app/Console/Commands/FetchEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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');
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -306,6 +311,7 @@ public function formatEmailList($obj_list)
foreach ($obj_list as $item) {
$plain_list[] = $item->mail;
}

return $plain_list;
}
}
10 changes: 5 additions & 5 deletions app/Http/Controllers/ConversationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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));
}
}

Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/MailboxesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]);

Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/SecureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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,
]);
}
}
14 changes: 7 additions & 7 deletions app/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];

/**
Expand All @@ -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',
];

/**
Expand Down Expand Up @@ -380,7 +380,7 @@ public function getEmailDomain()

/**
* Get outgoing email encryption protocol.
*
*
* @return string
*/
public function getOutEncryptionName()
Expand All @@ -390,7 +390,7 @@ public function getOutEncryptionName()

/**
* Get incoming email encryption protocol.
*
*
* @return string
*/
public function getInEncryptionName()
Expand All @@ -400,7 +400,7 @@ public function getInEncryptionName()

/**
* Get incoming protocol name.
*
*
* @return string
*/
public function getInProtocolName()
Expand Down

0 comments on commit d93925c

Please sign in to comment.