Skip to content

Commit

Permalink
feat(backend): change Hm_IMAP_List to Hm_Mailbox
Browse files Browse the repository at this point in the history
  • Loading branch information
amaninyumu1 committed Jan 19, 2025
1 parent 16fefa5 commit 45924cf
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions modules/smtp/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,12 @@ public function process() {
$draft_notice = array_key_exists('draft_notice', $this->request->post) ? $this->request->post['draft_notice'] : false;
$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'] : '';

$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);
return;
Expand Down Expand Up @@ -974,11 +974,11 @@ public function process() {
$ids = explode(',', $form['scheduled_msg_ids']);
foreach ($ids as $msg_part) {
list($imap_server_id, $msg_id, $folder) = explode('_', $msg_part);
$cache = Hm_IMAP_List::get_cache($this->cache, $imap_server_id);
$imap = Hm_IMAP_List::connect($imap_server_id, $cache);
if (imap_authed($imap)) {

$mailbox = new Hm_Mailbox($imap_server_id, $this->user_config, $this->session, $this->config);
if ($mailbox->connect()) {
$folder = hex2bin($folder);
if (reschedule_message_sending($this, $imap, $msg_id, $folder, $new_schedule_date, $imap_server_id)) {
if (reschedule_message_sending($this, $mailbox, $msg_id, $folder, $new_schedule_date, $imap_server_id)) {
$scheduled_msg_count++;
}
}
Expand Down Expand Up @@ -2057,19 +2057,11 @@ 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);

if (!empty($atts['schedule'])) {
$folder ='Scheduled';
if (!count($imap->get_mailbox_status($folder))) {
$imap->create_mailbox($folder);
}
$atts['schedule'] = get_scheduled_date($atts['schedule']);
} else {
$folder = $specials['draft'];
$mailbox = new Hm_Mailbox($imap_profile['id'], $mod->user_config, $session, $mod->config);
if (! $mailbox || ! $mailbox->connect()) {
return -1;
}

if (!empty($atts['schedule'])) {
$folder ='Scheduled';
if (!count($mailbox->get_folder_status($folder))) {
Expand All @@ -2080,23 +2072,19 @@ function save_imap_draft($atts, $id, $session, $mod, $mod_cache, $uploaded_files
$folder = $specials['draft'];
}


$mime = prepare_draft_mime($atts, $uploaded_files, $from, $name, $profile['id']);
$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, mb_strlen($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($folder, 'ARRIVAL', true, 'DRAFT', 0, 10);

// Remove old version from the mailbox
if ($id) {
Expand Down

0 comments on commit 45924cf

Please sign in to comment.