Skip to content

Commit

Permalink
Merge branch 'master' of github.com:freescout-helpdesk/freescout into…
Browse files Browse the repository at this point in the history
… dist
  • Loading branch information
freescout-helpdesk committed Apr 5, 2024
2 parents 2c39ba9 + 7cf3c67 commit c15278d
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 26 deletions.
16 changes: 15 additions & 1 deletion app/Console/Commands/FetchEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion app/Http/Controllers/ConversationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -823,13 +823,15 @@ 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.
$message_size = mb_strlen($body, '8bit');

// 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();
Expand Down Expand Up @@ -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;
Expand Down
37 changes: 19 additions & 18 deletions app/Http/Controllers/MailboxesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 9 additions & 3 deletions app/Jobs/SendReplyToCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion app/Misc/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
3 changes: 2 additions & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
| or any other location as required by the application or its packages.
*/

'version' => '1.8.130',
'version' => '1.8.131',

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -219,6 +219,7 @@
|-------------------------------------------------------------------------
*/
'fetch_schedule' => env('APP_FETCH_SCHEDULE', 1),
'fetch_unseen' => env('APP_FETCH_UNSEEN', 1),

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit c15278d

Please sign in to comment.