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 22, 2024
2 parents 0ecfa24 + d18cc23 commit 17024f8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 27 deletions.
23 changes: 11 additions & 12 deletions app/Console/Commands/FetchEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ public function handle()

$this->line('['.date('Y-m-d H:i:s').'] Fetching '.($this->option('unseen') ? 'UNREAD' : 'ALL').' emails for the last '.$this->option('days').' days.');

$this->extra_import = [];

if (Mailbox::getInProtocols() === Mailbox::$in_protocols) {
$this->mailboxes = Mailbox::get();
} else {
Expand Down Expand Up @@ -124,24 +122,25 @@ function ($mailboxId) {
$this->info('['.date('Y-m-d H:i:s').'] Mailbox: '.$mailbox->name);

$this->mailbox = $mailbox;

$this->extra_import = [];

try {
$this->fetch($mailbox);
} catch (\Exception $e) {
$successfully = false;
$this->logError('Error: '.$e->getMessage().'; File: '.$e->getFile().' ('.$e->getLine().')').')';
}

usleep($sleep);
}

// Import emails sent to several mailboxes at once.
if (count($this->extra_import)) {
$this->line('['.date('Y-m-d H:i:s').'] Importing emails sent to several mailboxes at once: '.count($this->extra_import));
foreach ($this->extra_import as $i => $extra_import) {
$this->line('['.date('Y-m-d H:i:s').'] '.($i+1).') '.$extra_import['message']->getSubject());
$this->processMessage($extra_import['message'], $extra_import['message_id'], $extra_import['mailbox'], [], true);
// Import emails sent to several mailboxes at once.
if (count($this->extra_import)) {
$this->line('['.date('Y-m-d H:i:s').'] Importing emails sent to several mailboxes at once: '.count($this->extra_import));
foreach ($this->extra_import as $i => $extra_import) {
$this->line('['.date('Y-m-d H:i:s').'] '.($i+1).') '.$extra_import['message']->getSubject());
$this->processMessage($extra_import['message'], $extra_import['message_id'], $extra_import['mailbox'], [], true);
}
}

usleep($sleep);
}

if ($successfully && count($this->mailboxes)) {
Expand Down
26 changes: 19 additions & 7 deletions app/Conversation.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,9 @@ public function getNearby($mode = 'closest', $folder_id = null, $status = null,

$query = \Eventy::filter('conversation.get_nearby_query', $query, $this, $mode, $folder);

if ($status) {
$status_applied = \Eventy::filter('conversation.get_nearby_status', false, $query, $status, $this, $folder);

if (!$status_applied && $status) {
$query->where('status', $status);
}

Expand Down Expand Up @@ -1092,11 +1094,13 @@ public static function getQueryByFolder($folder, $user_id)
{
// Get conversations from personal folder
if ($folder->type == Folder::TYPE_MINE) {
$query_conversations = self::where('user_id', $user_id)
->where('mailbox_id', $folder->mailbox_id)
$query_conversations = self::where('mailbox_id', $folder->mailbox_id)
->whereIn('status', [self::STATUS_ACTIVE, self::STATUS_PENDING])
->where('state', self::STATE_PUBLISHED);

// Applied below.
//where('user_id', $user_id)

// Assigned - do not show my conversations.
} elseif ($folder->type == Folder::TYPE_ASSIGNED) {
$query_conversations = $folder->conversations()
Expand Down Expand Up @@ -1128,23 +1132,31 @@ public static function getQueryByFolder($folder, $user_id)
$query_conversations = $folder->conversations()->where('state', self::STATE_PUBLISHED);
}

$assignee_condition_applied = false;

// If show only assigned to the current user conversations.
if (!\Helper::isConsole()
&& $user_id
&& $user = auth()->user()
) {
if ($user->id == $user_id
&& $user->hasManageMailboxPermission($folder->mailbox_id, Mailbox::ACCESS_PERM_ASSIGNED)
) {
if ($user->id == $user_id && $user->canSeeOnlyAssignedConversations()) {
if ($folder->type != Folder::TYPE_DRAFTS) {
$query_conversations->where('user_id', '=', $user_id);
$assignee_condition_applied = \Eventy::filter('folder.only_assigned_condition', false, $query_conversations, $user_id);
if (!$assignee_condition_applied) {
$query_conversations->where('user_id', '=', $user_id);
$assignee_condition_applied = true;
}
} else {
$query_conversations->where('user_id', '=', $user_id)
->orWhere('created_by_user_id', '=', $user_id);
}
}
}

if ($folder->type == Folder::TYPE_MINE && !$assignee_condition_applied) {
$query_conversations->where('user_id', $user_id);
}

return \Eventy::filter('folder.conversations_query', $query_conversations, $folder, $user_id);
}

Expand Down
9 changes: 5 additions & 4 deletions app/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,12 @@ public static function processEvents()
$thread_id = self::chooseThread($notify_info['threads'])->id;

foreach ($notify_info['users'] as $user) {
$broadcast_id = $thread_id.'_'.$user->id;
$mediums = [$medium];
if (!empty($broadcasts[$thread_id]['mediums'])) {
$mediums = array_unique(array_merge($mediums, $broadcasts[$thread_id]['mediums']));
if (!empty($broadcasts[$broadcast_id]['mediums'])) {
$mediums = array_unique(array_merge($mediums, $broadcasts[$broadcast_id]['mediums']));
}
$broadcasts[$thread_id] = [
$broadcasts[$broadcast_id] = [
'user' => $user,
'conversation' => $notify_info['conversation'],
'threads' => $notify_info['threads'],
Expand All @@ -422,7 +423,7 @@ public static function processEvents()
}
}
// \Notification::sendNow($notify_info['users'], new BroadcastNotification($notify_info['conversation'], $notify_info['threads'][0]));
foreach ($broadcasts as $thread_id => $to_broadcast) {
foreach ($broadcasts as $broadcast_id => $to_broadcast) {
$broadcast_notification = new BroadcastNotification($to_broadcast['conversation'], self::chooseThread($to_broadcast['threads']), $to_broadcast['mediums']);
$broadcast_notification->delay($delay);
$to_broadcast['user']->notify($broadcast_notification);
Expand Down
2 changes: 1 addition & 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.136',
'version' => '1.8.137',

/*
|--------------------------------------------------------------------------
Expand Down
16 changes: 13 additions & 3 deletions overrides/webklex/php-imap/src/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,13 @@ protected function fetch() {
// php < 8.1. crc32c is the next fastest and is compatible with php >= 5.1. sha256 is the slowest, but is compatible
// with php >= 5.1 and is the most likely to be unique. crc32c is the best compromise between speed and uniqueness.
// Unique enough for our purposes, but not so slow that it could be a bottleneck.
$this->hash = hash("crc32c", $this->part->getHeader()->raw."\r\n\r\n".$this->part->content);
//$this->hash = hash("crc32c", $this->part->getHeader()->raw."\r\n\r\n".$this->part->content);
// https://github.com/freescout-helpdesk/freescout/issues/3991

if (($id = $this->part->id) !== null) {
$this->id = str_replace(['<', '>'], '', $id);
}else{
$this->id = $this->hash;
$this->id = $this->getHash();
}

$this->size = $this->part->bytes;
Expand Down Expand Up @@ -279,14 +280,23 @@ protected function fetch() {
$this->attributes = array_merge($this->part->getHeader()->getAttributes(), $this->attributes);

if (!$this->filename) {
$this->filename = $this->hash;
$this->filename = $this->getHash();
}

if (!$this->name && $this->filename != "") {
$this->name = $this->filename;
}
}

public function getHash()
{
if (!$this->hash) {
$this->hash = substr(md5($this->part->getHeader()->raw."\r\n\r\n".$this->part->content), 0, 8);
}

return $this->hash;
}

/**
* Save the attachment content to your filesystem
* @param string $path
Expand Down

0 comments on commit 17024f8

Please sign in to comment.