Skip to content

Commit

Permalink
Fix an issue with emails being empty when fetching from iCloud - closes
Browse files Browse the repository at this point in the history
  • Loading branch information
freescout-help-desk committed Aug 29, 2024
1 parent af2b125 commit 03c234e
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class ImapProtocol extends Protocol {
*/
protected $noun = 0;

/**
* Host is stored just to check which instruction to use
* when fetching body: BODY[TEXT] or RFC822.TEXT.
*/
public $host = '';

public static $output_debug_log = true;
public static $debug_log = '';

Expand Down Expand Up @@ -65,6 +71,9 @@ public function connect(string $host, $port = null) {
$transport = 'tcp';
$encryption = '';

// Remember host.
$this->host = $host;

if ($this->encryption) {
$encryption = strtolower($this->encryption);
if (in_array($encryption, ['ssl', 'tls'])) {
Expand Down Expand Up @@ -697,7 +706,15 @@ public function fetch($items, $from, $to = null, $uid = IMAP::ST_UID) {
* @throws RuntimeException
*/
public function content($uids, string $rfc = "RFC822", $uid = IMAP::ST_UID): array {
$result = $this->fetch(["$rfc.TEXT"], is_array($uids)?$uids:[$uids], null, $uid);
// iCloud requires BODY[TEXT] instead of RFC822.TEXT.
// https://github.com/freescout-help-desk/freescout/issues/4202#issuecomment-2315369990
if (strtolower(trim($this->host)) == 'imap.mail.me.com') {
$item = "BODY[TEXT]";
} else {
$item = "$rfc.TEXT";
}

$result = $this->fetch([$item], is_array($uids)?$uids:[$uids], null, $uid);
return is_array($result) ? $result : [];
}

Expand Down

0 comments on commit 03c234e

Please sign in to comment.