Skip to content

Commit

Permalink
feat(backend): refactor the code to fix the server error Uncaught Err…
Browse files Browse the repository at this point in the history
…or: Call to undefined method Hm_Mailbox::get_mailbox_status()
  • Loading branch information
amaninyumu1 committed Jan 7, 2025
1 parent 382ca1c commit 127713a
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions modules/smtp/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ public function process() {
$uploaded_files = array_key_exists('uploaded_files', $this->request->post) ? $this->request->post['uploaded_files'] : false;
$delivery_receipt = array_key_exists('compose_delivery_receipt', $this->request->post) ? $this->request->post['compose_delivery_receipt'] : false;
$schedule = array_key_exists('schedule', $this->request->post) ? $this->request->post['schedule'] : '';
if ($schedule == "undefined") {
$schedule = "";
}

if (array_key_exists('delete_uploaded_files', $this->request->post) && $this->request->post['delete_uploaded_files']) {
delete_uploaded_files($this->session, $draft_id);
Expand Down Expand Up @@ -2020,13 +2023,11 @@ function save_imap_draft($atts, $id, $session, $mod, $mod_cache, $uploaded_files
$from = false;
$name = '';
$uploaded_files = get_uploaded_files_from_array($uploaded_files);

if ($profile && $profile['type'] == 'imap' && $mod->module_is_supported('imap')) {
$from = $profile['replyto'];
$name = $profile['name'];
$imap_profile = Hm_IMAP_List::fetch($profile['user'], $profile['server']);
}

if (!$imap_profile || empty($imap_profile)) {
$imap_profile = find_imap_by_smtp(
$mod->user_config->get('imap_servers'),
Expand All @@ -2046,44 +2047,42 @@ function save_imap_draft($atts, $id, $session, $mod, $mod_cache, $uploaded_files
Hm_Msgs::add('ERRThere is no draft directory configured for this account.');
return -1;
}
$cache = Hm_IMAP_List::get_cache($mod_cache, $imap_profile['id']);
$imap = Hm_IMAP_List::connect($imap_profile['id'], $cache);

$mailbox = Hm_IMAP_List::get_connected_mailbox($imap_profile['id'], $mod_cache);
if (! $mailbox || ! $mailbox->authed()) {
return -1;
}

if (!empty($atts['schedule'])) {
$folder ='Scheduled';
if (!count($imap->get_mailbox_status($folder))) {
$imap->create_mailbox($folder);
if (!count($mailbox->get_folder_status($folder))) {
$mailbox->create_folder($folder);
}
$atts['schedule'] = get_scheduled_date($atts['schedule']);
} else {
$folder = $specials['draft'];
}
$imap->select_mailbox($folder);

$mime = prepare_draft_mime($atts, $uploaded_files, $from, $name, $profile['id']);
$mime = prepare_draft_mime($atts, $uploaded_files, $from, $name);
$res = $mime->process_attachments();

$msg = str_replace("\r\n", "\n", $mime->get_mime_msg());
$msg = str_replace("\n", "\r\n", $msg);
$msg = rtrim($msg)."\r\n";

if ($imap->append_start($folder, mb_strlen($msg), false, true)) {
$imap->append_feed($msg."\r\n");
if (!$imap->append_end()) {
Hm_Msgs::add('ERRAn error occurred saving the draft message');
return -1;
}
if (! $mailbox->store_message($folder, $msg, false, true)) {
Hm_Msgs::add('ERRAn error occurred saving the draft message');
return -1;
}

$mailbox_page = $imap->get_mailbox_page($folder, 'ARRIVAL', true, 'DRAFT', 0, 10);

$messages = $mailbox->get_messages($specials['draft'], 'ARRIVAL', true, 'DRAFT', 0, 10);
// Remove old version from the mailbox
if ($id) {
$mailbox->message_action($specials['draft'], 'DELETE', array($id));
$mailbox->message_action($specials['draft'], 'EXPUNGE', array($id));
}

foreach ($messages[1] as $mail) {
if (!empty($messages[1])) {
foreach ($messages[1] as $mail) {
$msg_header = $mailbox->get_message_headers($specials['draft'], $mail['uid']);
// Convert all header keys to lowercase
$msg_header_lower = array_change_key_case($msg_header, CASE_LOWER);
Expand All @@ -2098,8 +2097,7 @@ function save_imap_draft($atts, $id, $session, $mod, $mod_cache, $uploaded_files
return $mail['uid'];
}
}
}
return -1;
}}
}}

/**
Expand Down

0 comments on commit 127713a

Please sign in to comment.