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 22, 2025
1 parent 9ac9f53 commit 3b4f9f1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 44 deletions.
50 changes: 32 additions & 18 deletions modules/core/site.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use strict';

/* swipe event handler */
var swipe_event = function(el, callback, direction) {
var swipe_event = function (el, callback, direction) {
var start_x, start_y, dist_x, dist_y, threshold = 150, restraint = 100,
allowed_time = 500, start_time;

el.addEventListener('touchstart', function(e) {
el.addEventListener('touchstart', function (e) {
var touchobj = e.changedTouches[0];
start_x = touchobj.pageX;
start_y = touchobj.pageY;
start_time = new Date().getTime();
}, false);

el.addEventListener('touchend', function(e) {
el.addEventListener('touchend', function (e) {
var touchobj = e.changedTouches[0];
dist_x = touchobj.pageX - start_x;
dist_y = touchobj.pageY - start_y;
Expand Down Expand Up @@ -137,8 +137,18 @@ var Hm_Ajax_Request = function () {
if (config.data) {
data = this.format_xhr_data(config.data);
}
const url = window.location.next ?? window.location.href;
xhr.open('POST', url)
const url = new URL(window.location.href);
if (window.location.next) {
url.search = window.location.next.split('?')[1];
}
for (const param of url.searchParams) {
const configItem = config.data.find(item => item.name === param[0]);
if (configItem) {
url.searchParams.set(configItem.name, configItem.value);
}
}

xhr.open('POST', url.toString())
if (config.signal) {
config.signal.addEventListener('abort', function () {
xhr.abort();
Expand Down Expand Up @@ -234,7 +244,7 @@ var Hm_Ajax_Request = function () {
messages.load().then(() => {
if (messages.count != res.folder_status[name].messages) {
messages.load(true).then(() => {
display_imap_mailbox(messages.rows, messages.links);
display_imap_mailbox(messages.rows, messages.list);
})
}
});
Expand Down Expand Up @@ -498,8 +508,8 @@ function Message_List() {
fixLtrInRtl();
};

this.update = function (msgs) {
Hm_Utils.tbody().html('');
this.update = function (msgs, id) {
Hm_Utils.tbody(id).html('');
for (const index in msgs) {
const row = msgs[index][0];
Hm_Utils.tbody(id).append(row);
Expand Down Expand Up @@ -847,8 +857,9 @@ function Message_List() {
};

this.prev_next_links = function (msgUid, lisPath = getListPathParam()) {
let phref;
let nhref;
let prevUrl;
let nextUrl;

const target = $('.msg_headers tr').last();
const messages = new Hm_MessagesStore(lisPath, Hm_Utils.get_url_page_number());
messages.load(false, true);
Expand All @@ -859,7 +870,7 @@ function Message_List() {
prevUrl = new URL(prevSubject.prop('href'));
prevUrl.searchParams.set('list_parent', lisPath);
const subject = prevSubject.text();
const plink = '<a class="plink" href="' + phref + '"><i class="prevnext bi bi-arrow-left-square-fill"></i> ' + subject + '</a>';
const plink = '<a class="plink" href="' + prevUrl.href + '"><i class="prevnext bi bi-arrow-left-square-fill"></i> ' + subject + '</a>';
$('<tr class="prev"><th colspan="2">' + plink + '</th></tr>').insertBefore(target);
}
if (next) {
Expand All @@ -868,7 +879,7 @@ function Message_List() {
nextUrl.searchParams.set('list_parent', lisPath);
const subject = nextSubject.text();

const nlink = '<a class="nlink" href="' + nhref + '"><i class="prevnext bi bi-arrow-right-square-fill"></i> ' + subject + '</a>';
const nlink = '<a class="nlink" href="' + nextUrl.href + '"><i class="prevnext bi bi-arrow-right-square-fill"></i> ' + subject + '</a>';
$('<tr class="next"><th colspan="2">' + nlink + '</th></tr>').insertBefore(target);
}

Expand Down Expand Up @@ -1062,6 +1073,7 @@ function Message_List() {
this.set_unread_state = function () { self.set_message_list_state('formatted_unread_data'); };
this.set_search_state = function () { self.set_message_list_state('formatted_search_data'); };
this.set_junk_state = function () { self.set_message_list_state('formatted_junk_data'); };
this.set_snoozed_state = function () { self.set_message_list_state('formatted_snoozed_data'); };
this.set_trash_state = function () { self.set_message_list_state('formatted_trash_data'); };
this.set_draft_state = function () { self.set_message_list_state('formatted_drafts_data'); };
this.set_tag_state = function () { self.set_message_list_state('formatted_tag_data'); };
Expand Down Expand Up @@ -1547,11 +1559,14 @@ var Hm_Utils = {
}
},

rows: function () {
return $('.message_table_body > tr').not('.inline_msg');
rows: function (id) {
return this.tbody(id).find('tr').not('.inline_msg');
},

tbody: function () {
tbody: function (id) {
if (id) {
return $('#' + id);
}
return $('.message_table_body');
},

Expand Down Expand Up @@ -1790,7 +1805,6 @@ var imap_smtp_edit_action = function (event) {
}
};


var hasLeadingOrTrailingSpaces = function (str) {
return str !== str.trim();
};
Expand Down Expand Up @@ -2008,9 +2022,9 @@ function resetQuickSetupForm() {

function handleCreateProfileCheckboxChange(checkbox) {
if (checkbox.checked) {
$('#srv_setup_stepper_profile_bloc').show();
$(checkbox).closest('.form-check').next().show();
} else {
$('#srv_setup_stepper_profile_bloc').hide();
$(checkbox).closest('.form-check').next().hide();
}
}

Expand Down
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 3b4f9f1

Please sign in to comment.