Skip to content

Commit

Permalink
Merge pull request #939 from Shadow243/jmap-corrections
Browse files Browse the repository at this point in the history
[FIX] JMAP Server: menu link not clickable
  • Loading branch information
kroky authored Apr 10, 2024
2 parents d7e7a3e + faadce7 commit c401139
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
44 changes: 28 additions & 16 deletions modules/imap/hm-jmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -856,22 +856,33 @@ private function normalize_headers($msg) {
private function init_session($data, $url) {
$this->state = 'authenticated';
$this->session = $data;
$this->api_url = sprintf(
'%s%s',
preg_replace("/\/$/", '', $url),
$data['apiUrl']
);
$this->api_url = $data['apiUrl'];
$this->download_url = sprintf(
'%s%s',
preg_replace("/\/$/", '', $url),
$data['downloadUrl']
);
$this->upload_url = sprintf(
'%s%s',
preg_replace("/\/$/", '', $url),
$data['uploadUrl']
);
if (!str_contains($data['apiUrl'], $url)){
$this->api_url = sprintf(
'%s%s',
preg_replace("/\/$/", '', $url),
$data['apiUrl']
);
}else{
$this->api_url = $data['apiUrl'];
}
if (!str_contains($data['downloadUrl'], $url)){
$this->download_url = sprintf(
'%s%s',
preg_replace("/\/$/", '', $url),
$data['downloadUrl']
);
}else{
$this->download_url = $data['downloadUrl'];
}
if (!str_contains($data['uploadUrl'], $url)){
$this->upload_url = sprintf(
'%s%s',
preg_replace("/\/$/", '', $url),
$data['uploadUrl']
);
}else{
$this->upload_url = $data['uploadUrl'];
}
foreach ($data['accounts'] as $account) {
$this->account_id = array_keys($data['accounts'])[0];
}
Expand Down Expand Up @@ -1101,6 +1112,7 @@ private function build_imap_folders($data) {
'name' => $vals['name'],
'type' => 'jmap',
'noselect' => false,
'clickable' => true,
'id' => $vals['id'],
'role' => $vals['role'],
'name_parts' => $vals['name_parts'],
Expand Down
4 changes: 2 additions & 2 deletions modules/profiles/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ protected function output() {
continue;
}
if (strlen(trim($smtp_vals['sig']))) {
$sigs[] = sprintf("%s: \"\\n%s\\n\"", $smtp_vals['smtp_id'].'.'.($index+1), $this->html_safe(str_replace("\r\n", "\\n", $smtp_vals['sig'])));
$sigs[] = sprintf("\"%s\": \"\\n%s\\n\"", $smtp_vals['smtp_id'].'.'.($index+1), $this->html_safe(str_replace("\r\n", "\\n", $smtp_vals['sig'])));
$used[] = $smtp_vals['id'];
}
}
Expand All @@ -230,7 +230,7 @@ protected function output() {
continue;
}
if (strlen(trim($vals['sig']))) {
$sigs[] = sprintf("%s: \"\\n%s\\n\"", $vals['smtp_id'], $this->html_safe(str_replace("\r\n", "\\n", $vals['sig'])));
$sigs[] = sprintf("\"%s\": \"\\n%s\\n\"", $vals['smtp_id'], $this->html_safe(str_replace("\r\n", "\\n", $vals['sig'])));
$used[] = $vals['id'];
}
}
Expand Down
13 changes: 9 additions & 4 deletions modules/smtp/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,7 @@ function save_imap_draft($atts, $id, $session, $mod, $mod_cache, $uploaded_files
$imap_profile = Hm_IMAP_List::fetch($profile['user'], $profile['server']);
}

if (!$imap_profile) {
if (!$imap_profile || empty($imap_profile)) {
$imap_profile = find_imap_by_smtp(
$mod->user_config->get('imap_servers'),
$mod->user_config->get('smtp_servers')[$atts['draft_smtp']]
Expand All @@ -1841,7 +1841,7 @@ function save_imap_draft($atts, $id, $session, $mod, $mod_cache, $uploaded_files
$from = $mod->user_config->get('smtp_servers')[$atts['draft_smtp']]['user'];
}
}
if (!$imap_profile) {
if (!$imap_profile || empty($imap_profile)) {
return -1;
}

Expand Down Expand Up @@ -1893,8 +1893,13 @@ function save_imap_draft($atts, $id, $session, $mod, $mod_cache, $uploaded_files

foreach ($mailbox_page[1] as $mail) {
$msg_header = $imap->get_message_headers($mail['uid']);
if ($msg_header['Message-Id'] === $mime->get_headers()['Message-Id']) {
return $mail['uid'];
// Convert all header keys to lowercase
$msg_header_lower = array_change_key_case($msg_header, CASE_LOWER);
$mime_headers_lower = array_change_key_case($mime->get_headers(), CASE_LOWER);
if (isset($msg_header_lower['message-id'], $mime_headers_lower['message-id'])) {
if ($msg_header_lower['message-id'] === $mime_headers_lower['message-id']) {
return $mail['uid'];
}
}
}
return -1;
Expand Down

0 comments on commit c401139

Please sign in to comment.