diff --git a/app/Console/Commands/FetchEmails.php b/app/Console/Commands/FetchEmails.php index 778746648..df872977e 100644 --- a/app/Console/Commands/FetchEmails.php +++ b/app/Console/Commands/FetchEmails.php @@ -31,7 +31,7 @@ class FetchEmails extends Command * * @var string */ - protected $signature = 'freescout:fetch-emails {--days=3} {--unseen=1} {--identifier=dummy}'; + protected $signature = 'freescout:fetch-emails {--days=3} {--unseen=1} {--identifier=dummy} {--mailboxes=0}'; /** * The console command description. @@ -97,10 +97,24 @@ public function handle() // Microseconds: 1 second = 1 000 000 microseconds. $sleep = 20000; + // Fetches specific mailboxes only, in case the corresponding id is greater than zero. + $mailboxIds = array_filter( + array_map( + 'intval', + explode(',', $this->option('mailboxes')) + ), + function ($mailboxId) { + return $mailboxId > 0; + } + ); + foreach ($this->mailboxes as $mailbox) { if (!$mailbox->isInActive()) { continue; } + if ($mailboxIds !== [] && !in_array($mailbox->id, $mailboxIds, true)) { + continue; + } $sleep += 20000; if ($sleep > 500000) { diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 8d17ea9f8..e61803ca2 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -100,8 +100,11 @@ protected function schedule(Schedule $schedule) } } + $fetch_unseen = (int)config('app.fetch_unseen'); $fetch_command_identifier = \Helper::getWorkerIdentifier('freescout:fetch-emails'); - $fetch_command_name = 'freescout:fetch-emails --identifier='.$fetch_command_identifier; + $fetch_command_name = 'freescout:fetch-emails' + . ' --identifier='.$fetch_command_identifier + . ' --unseen='.$fetch_unseen; // Kill fetch commands running for too long. // In shedule:run this code is executed every time $schedule->command() in this function is executed. diff --git a/app/Http/Controllers/ConversationsController.php b/app/Http/Controllers/ConversationsController.php index be4152921..c457d21fe 100755 --- a/app/Http/Controllers/ConversationsController.php +++ b/app/Http/Controllers/ConversationsController.php @@ -823,6 +823,7 @@ public function ajax(Request $request) // Check max. message size. if (!$response['msg']) { + $max_message_size = (int)config('app.max_message_size'); if ($max_message_size) { // Todo: take into account conversation history. @@ -830,6 +831,7 @@ public function ajax(Request $request) // Calculate attachments size. $attachments_ids = array_merge($request->attachments ?? [], $request->embeds ?? []); + $attachments_ids = $this->decodeAttachmentsIds($attachments_ids); if (count($attachments_ids)) { $attachments_to_check = Attachment::select('size')->whereIn('id', $attachments_ids)->get(); @@ -3152,7 +3154,12 @@ public function processReplyAttachments($request) public function decodeAttachmentsIds($attachments_list) { foreach ($attachments_list as $i => $attachment_id) { - $attachments_list[$i] = \Helper::decrypt($attachment_id); + $attachment_id_decrypted = \Helper::decrypt($attachment_id); + if ($attachment_id_decrypted == $attachment_id) { + unset($attachments_list[$i]); + } else { + $attachments_list[$i] = $attachment_id_decrypted; + } } return $attachments_list; diff --git a/app/Http/Controllers/MailboxesController.php b/app/Http/Controllers/MailboxesController.php index 75d4377d3..311928f7d 100755 --- a/app/Http/Controllers/MailboxesController.php +++ b/app/Http/Controllers/MailboxesController.php @@ -719,22 +719,23 @@ public function ajax(Request $request) if (count($response['folders'])) { + // https://github.com/freescout-helpdesk/freescout/issues/3933 // Exclude duplicate INBOX.Name and Name folders. - $folder_excluded = false; - foreach ($response['folders'] as $i => $folder_name) { - if (\Str::startsWith($folder_name, 'INBOX.')) { - foreach ($response['folders'] as $folder_name2) { - if ($folder_name != $folder_name2 && $folder_name == 'INBOX.'.$folder_name2) { - unset($response['folders'][$i]); - $folder_excluded = true; - continue 2; - } - } - } - } - if ($folder_excluded) { - $response['folders'] = array_values($response['folders']); - } + // $folder_excluded = false; + // foreach ($response['folders'] as $i => $folder_name) { + // if (\Str::startsWith($folder_name, 'INBOX.')) { + // foreach ($response['folders'] as $folder_name2) { + // if ($folder_name != $folder_name2 && $folder_name == 'INBOX.'.$folder_name2) { + // unset($response['folders'][$i]); + // $folder_excluded = true; + // continue 2; + // } + // } + // } + // } + // if ($folder_excluded) { + // $response['folders'] = array_values($response['folders']); + // } $response['msg_success'] = __('IMAP folders retrieved: '.implode(', ', $response['folders'])); } else { @@ -822,15 +823,15 @@ public function ajax(Request $request) } // Recursively interate over folders. - public function interateFolders($response, $imap_folders) { + public function interateFolders($response, $imap_folders, $subfolder = false) { foreach ($imap_folders as $imap_folder) { - if (!empty($imap_folder->name)) { + if (!empty($imap_folder->name) && !$subfolder) { $response['folders'][] = $imap_folder->name; } // Check for children and recurse. if (!empty($imap_folder->children)) { - $response = $this->interateFolders($response, $imap_folder->children); + $response = $this->interateFolders($response, $imap_folder->children, true); } // Old library. diff --git a/app/Jobs/SendReplyToCustomer.php b/app/Jobs/SendReplyToCustomer.php index 7b56b1f9e..d2ed6d9d8 100644 --- a/app/Jobs/SendReplyToCustomer.php +++ b/app/Jobs/SendReplyToCustomer.php @@ -367,14 +367,18 @@ public function handle() $client->connect(); - $mail_from = $mailbox->getMailFrom(null, $this->conversation); + $mail_from = $mailbox->getMailFrom($this->last_thread->created_by_user ?? null, $this->conversation); if (!empty($mail_from['name'])) { $envelope['from'] = '"'.$mail_from['name'].'" <'.$mail_from['address'].'>'; } else { $envelope['from'] = $mail_from['address']; } - $envelope['to'] = $this->customer_email; + if (is_array($to) && !empty($to[0]) && !empty($to[0]['name']) && !empty($to[0]['email'])) { + $envelope['to'] = '"'.$to[0]['name'].'" <'.$to[0]['email'].'>'; + } else { + $envelope['to'] = $this->customer_email; + } $envelope['subject'] = $subject; $envelope['date'] = now()->toRfc2822String(); $envelope['message_id'] = $this->message_id; @@ -402,7 +406,9 @@ public function handle() if ($this->last_thread->has_attachments) { $multipart = []; $multipart["type"] = TYPEMULTIPART; - $multipart["subtype"] = "alternative"; + $multipart["subtype"] = "mixed"; + // https://github.com/freescout-helpdesk/freescout/issues/3934 + //$multipart["subtype"] = "alternative"; $parts[] = $multipart; } diff --git a/app/Misc/Helper.php b/app/Misc/Helper.php index e8259b131..f52984569 100644 --- a/app/Misc/Helper.php +++ b/app/Misc/Helper.php @@ -2070,7 +2070,7 @@ public static function setCurlDefaultOptions($ch) curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, config('app.curl_ssl_verifypeer')); } - public static function setGuzzleDefaultOptions($params) + public static function setGuzzleDefaultOptions($params = []) { $default_params = [ 'timeout' => config('app.curl_timeout'), diff --git a/config/app.php b/config/app.php index 25ec1ecc0..81533b8a2 100644 --- a/config/app.php +++ b/config/app.php @@ -18,7 +18,7 @@ | or any other location as required by the application or its packages. */ - 'version' => '1.8.130', + 'version' => '1.8.131', /* |-------------------------------------------------------------------------- @@ -219,6 +219,7 @@ |------------------------------------------------------------------------- */ 'fetch_schedule' => env('APP_FETCH_SCHEDULE', 1), + 'fetch_unseen' => env('APP_FETCH_UNSEEN', 1), /* |-------------------------------------------------------------------------- diff --git a/resources/lang/pl.json b/resources/lang/pl.json index 7928d7bb7..d11700671 100644 --- a/resources/lang/pl.json +++ b/resources/lang/pl.json @@ -2,6 +2,7 @@ "\":name\" module successfully Deactivated!": "\\”:name\\” - moduł pomyślnie Zdezaktywowany!", "\":name\" module successfully activated!": "\\”:name\\” - moduł pomyślnie aktywowany!", "\":name\" module successfully updated!": "\\”:name\\” - moduł pomyślnie zaktualizowany!", + "%identifier% added": "%identifier% dodano", "(no subject)": "(brak tematu)", "(optional)": "(opcjonalny)", ".env file": "plik .env", @@ -194,6 +195,7 @@ "Custom": "Własne", "Custom From Name": "Niestandardowy Nadawca", "Custom Name": "Niestandardowa Nazwa", + "Custom conversation": "Niestandardowa rozmowa", "Customer": "Klient", "Customer Name": "Nazwa Klienta", "Customer Profile": "Profil Klienta",