Skip to content

Commit

Permalink
Fix Unknown hashing algorithm crc32c error in Webklex/php-imap librar…
Browse files Browse the repository at this point in the history
…y - closes #3991
  • Loading branch information
freescout-helpdesk committed Apr 22, 2024
1 parent 8c5dbb4 commit 047111f
Showing 1 changed file with 13 additions and 3 deletions.
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 047111f

Please sign in to comment.