Skip to content

Commit 6b293d7

Browse files
committed
fix(backend): update message header retrieval to use base64 encoding for item IDs
1 parent 0a6cabb commit 6b293d7

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

modules/imap/hm-ews.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ public function message_action($action, $itemIds, $folder=false, $keyword=false)
695695
}
696696

697697
public function get_message_headers($itemId) {
698+
$base64Id = $this->get_item_id_base64($itemId);
698699
$request = array(
699700
'ItemShape' => array(
700701
'BaseShape' => 'AllProperties',
@@ -713,7 +714,7 @@ public function get_message_headers($itemId) {
713714
],
714715
),
715716
'ItemIds' => [
716-
'ItemId' => ['Id' => hex2bin($itemId)],
717+
'ItemId' => ['Id' => $base64Id],
717718
],
718719
);
719720
$request = Type::buildFromArray($request);
@@ -838,13 +839,14 @@ public function get_structured_message($itemId, $part, $text_only) {
838839
}
839840

840841
public function get_mime_message_by_id($itemId) {
842+
$base64Id = $this->get_item_id_base64($itemId);
841843
$request = array(
842844
'ItemShape' => array(
843845
'BaseShape' => 'IdOnly',
844846
'IncludeMimeContent' => true,
845847
),
846848
'ItemIds' => [
847-
'ItemId' => ['Id' => hex2bin($itemId)],
849+
'ItemId' => ['Id' => $base64Id],
848850
],
849851
);
850852
$request = Type::buildFromArray($request);
@@ -858,6 +860,25 @@ public function get_mime_message_by_id($itemId) {
858860
return $parser->parse($content, false);
859861
}
860862

863+
protected function get_item_id_base64($itemId) {
864+
if (is_string($itemId) && strlen($itemId) > 0) {
865+
// Check if it's hex encoded (internal format) - convert to base64 first
866+
if (ctype_xdigit($itemId)) {
867+
return hex2bin($itemId);
868+
}
869+
870+
// Check if it's already base64
871+
if (base64_encode(base64_decode($itemId, true)) === $itemId) {
872+
return $itemId;
873+
}
874+
875+
// If it's binary, encode to base64
876+
return base64_encode($itemId);
877+
}
878+
879+
return $itemId;
880+
}
881+
861882
protected function parse_mime_part($part, &$struct, $part_num) {
862883
$struct[$part_num] = [];
863884
list($struct[$part_num]['type'], $struct[$part_num]['subtype']) = explode('/', $part->getContentType());

0 commit comments

Comments
 (0)