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-help-desk committed Aug 14, 2024
2 parents c4a6585 + b33fb5e commit 223b4d1
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/Http/Controllers/MailboxesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,8 @@ public function oauth(Request $request)
// Set username and password for the oppozite in_out.
if ($in_out == 'in') {
if (empty($mailbox->out_server)
|| trim($mailbox->out_server) == \MailHelper::OAUTH_MICROSOFT_SMTP
|| (trim($mailbox->out_server) == \MailHelper::OAUTH_MICROSOFT_SMTP
&& (!$mailbox->out_username || $mailbox->out_username == $username))
) {
$mailbox->out_username = $username;
$mailbox->out_password = $password;
Expand Down
2 changes: 1 addition & 1 deletion app/Misc/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Mail
const FETCH_SCHEDULE_HOURLY = 60;

const OAUTH_PROVIDER_MICROSOFT = 'ms';
const OAUTH_MICROSOFT_SMTP = 'outlook.office365.com';
const OAUTH_MICROSOFT_SMTP = 'smtp.office365.com';

/**
* If reply is not extracted properly from the incoming email, add here a new separator.
Expand Down
9 changes: 8 additions & 1 deletion app/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,14 @@ public function getFromName($mailbox = null)
$name = $mailbox->name;

if ($mailbox->from_name == Mailbox::FROM_NAME_CUSTOM && $mailbox->from_name_custom) {
$name = $mailbox->from_name_custom;
$data = [
'mailbox' => $mailbox,
'mailbox_from_name' => '', // To avoid recursion.
'conversation' => $this->conversation,
// If we reach here it means the thread has been created by user.
'user' => $this->getCreatedBy(),
];
$name = \MailHelper::replaceMailVars($mailbox->from_name_custom, $data, false, true);
} elseif ($mailbox->from_name == Mailbox::FROM_NAME_USER && $this->getCreatedBy()) {
$name = $this->getCreatedBy()->getFirstName(true);
}
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.148',
'version' => '1.8.149',

/*
|--------------------------------------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions overrides/webklex/php-imap/src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ public function hasTextBody(): bool {
* @return mixed
*/
public function getTextBody() {
if (!$this->structure) {
$this->parseRawBody($this->tmp_raw_body);
}
if (!isset($this->bodies['text'])) {
return null;
}
Expand All @@ -385,6 +388,9 @@ public function getTextBody() {
* @return bool
*/
public function hasHTMLBody(): bool {
if (!$this->structure) {
$this->parseRawBody($this->tmp_raw_body);
}
return isset($this->bodies['html']) && $this->bodies['html'] !== "";
}

Expand All @@ -394,6 +400,9 @@ public function hasHTMLBody(): bool {
* @return string|null
*/
public function getHTMLBody() {
if (!$this->structure) {
$this->parseRawBody($this->tmp_raw_body);
}
if (!isset($this->bodies['html'])) {
return null;
}
Expand Down
3 changes: 3 additions & 0 deletions overrides/webklex/php-imap/src/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ public function generate_query(): string {
} else {
if (is_numeric($statement[1])) {
$query .= $statement[0] . ' ' . $statement[1];
} else if ($statement[0] == 'SINCE' && preg_match("#^[0-9]\-[a-zA-Z]\-[0-9]$#", $statement[1])) {
// https://github.com/freescout-help-desk/freescout/issues/4175
$query .= $statement[0] . ' ' . $statement[1];
} else {
$query .= $statement[0] . ' "' . $statement[1] . '"';
}
Expand Down
34 changes: 31 additions & 3 deletions overrides/webklex/php-imap/src/Structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,37 @@ private function parsePart(string $context, int $part_number = 0): array {
* @throws InvalidMessageDateException
*/
private function detectParts(string $boundary, string $context, int $part_number = 0): array {
$base_parts = explode( $boundary, $context);
// Below we get rid of exlode() as it consumes extra memory.
// https://github.com/freescout-help-desk/freescout/issues/3956#issuecomment-2284592925
//$base_parts = explode( $boundary, $context);

$final_parts = [];
foreach($base_parts as $ctx) {
$ctx = substr($ctx, 2);
//foreach($base_parts as $ctx) {

$boundary_len = strlen($boundary);
$last_pos = 0;
$positions = [];
while (($last_pos = strpos($context, $boundary, $last_pos)) !== false) {
$positions[] = $last_pos;
$last_pos = $last_pos + $boundary_len;
}
if (!count($positions) || $positions[0] != 0) {
array_unshift($positions, 0);
}

foreach ($positions as $pos_i => $pos) {
if ($pos == 0) {
// First.
$ctx = substr($context, 0+2, $positions[$pos_i+1]-2);
} elseif ($pos_i == count($positions)-1) {
// Last.
$ctx = substr($context, $pos+$boundary_len+2);
} else {
$ctx = substr($context, $pos+$boundary_len+2, $positions[$pos_i+1]-$pos-$boundary_len-2);
}

//$ctx = substr($ctx, 2);

if ($ctx !== "--" && $ctx != "" && $ctx != "\r\n") {
$parts = $this->parsePart($ctx, $part_number);
foreach ($parts as $part) {
Expand All @@ -140,6 +167,7 @@ private function detectParts(string $boundary, string $context, int $part_number
$part_number++;
}
}

return $final_parts;
}

Expand Down

0 comments on commit 223b4d1

Please sign in to comment.