Skip to content

Commit 01f3abd

Browse files
committed
fix(backend): ews enhance filename extraction for email attachments
1 parent 4068c8d commit 01f3abd

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

modules/imap/hm-ews.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public function send_message($from, $recipients, $message, $delivery_receipt = f
268268
$msg->setFrom($from);
269269
$msg->setToRecipients($recipients);
270270

271-
$message = $this->convert_utf8_to_iso88591_if_safe($message);
271+
$message = $this->use_iso_if_safe($message);
272272
$mimeContent = Type\MimeContentType::buildFromArray([
273273
'CharacterSet' => 'UTF-8',
274274
'_' => base64_encode($message)
@@ -294,7 +294,7 @@ public function send_message($from, $recipients, $message, $delivery_receipt = f
294294
* @param string $message The MIME message from Hm_MIME_Msg
295295
* @return string Modified message with ISO-8859-1 where safe
296296
*/
297-
private function convert_utf8_to_iso88591_if_safe($message) {
297+
private function use_iso_if_safe($message) {
298298
// Use regex to find and replace each text part's charset + body
299299
return preg_replace_callback(
300300
'/Content-Type:\s*text\/[^;]+;\s*charset="?UTF-8"?[^\r\n]*\r\n' .
@@ -1080,9 +1080,21 @@ protected function parse_mime_part($part, &$struct, $part_num) {
10801080
$struct[$part_num]['md5'] = '';
10811081
$struct[$part_num]['disposition'] = $part->getContentDisposition();
10821082

1083-
if ($filename = $part->getFilename()) {
1083+
$filename = $part->getFilename();
1084+
if (! $filename) {
1085+
$filename = $part->getHeaderParameter('Content-Type', 'name');
1086+
}
1087+
if (! $filename) {
1088+
$filename = $part->getHeaderParameter('Content-Disposition', 'filename');
1089+
}
1090+
if ($filename) {
10841091
$struct[$part_num]['file_attributes'] = ['filename' => $filename];
10851092

1093+
if (! isset($struct[$part_num]['attributes']) || ! is_array($struct[$part_num]['attributes'])) {
1094+
$struct[$part_num]['attributes'] = [];
1095+
}
1096+
$struct[$part_num]['attributes']['name'] = $filename;
1097+
10861098
if ($part->getContentDisposition() == 'attachment') {
10871099
$struct[$part_num]['file_attributes']['attachment'] = true;
10881100
}

0 commit comments

Comments
 (0)