Skip to content

Commit

Permalink
Merge 469632d into eee77c0
Browse files Browse the repository at this point in the history
  • Loading branch information
yvesdaxmaz committed Oct 18, 2019
2 parents eee77c0 + 469632d commit 0fe899f
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 1 deletion.
64 changes: 63 additions & 1 deletion modules/imap/handler_modules.php
Expand Up @@ -685,6 +685,69 @@ public function process() {
}
}


/**
* Archive a message
* @subpackage imap/handler
*/
class Hm_Handler_imap_archive_message extends Hm_Handler_Module {
/**
* Use IMAP to archive the selected message uid
*/
public function process() {
list($success, $form) = $this->process_form(array('imap_msg_uid', 'imap_server_id', 'folder'));

if ($success) {
$cache = Hm_IMAP_List::get_cache($this->cache, $form['imap_server_id']);
$imap = Hm_IMAP_List::connect($form['imap_server_id'], $cache);
$archive_folder = "Archive";

if (imap_authed($imap)) {
$new_folder = $archive_folder . '/' . hex2bin($form['folder']);

if(count($imap->get_mailbox_status($archive_folder)) == 0) {
if($imap->create_mailbox($archive_folder)) {
if ($imap->create_mailbox($new_folder)) {
if ($imap->select_mailbox(hex2bin($form['folder']))) {
$imap->message_action('MOVE', array($form['imap_msg_uid']), $new_folder);
Hm_Msgs::add("Message archived");
} else {
Hm_Msgs::add('ERRAn error occurred archiving the message');
}
} else {
Hm_Msgs::add('ERRAn error occurred archiving the message');
}
} else {
Hm_Msgs::add('ERRAn error occurred archiving the message');
}
} else {
if(count($imap->get_mailbox_status($new_folder)) == 0 ){
if ($imap->create_mailbox($new_folder)) {
if ($imap->select_mailbox(hex2bin($form['folder']))) {
$imap->message_action('MOVE', array($form['imap_msg_uid']), $new_folder);
Hm_Msgs::add("Message archived");
} else {
Hm_Msgs::add('ERRAn error occurred archiving the message');
}
} else {
Hm_Msgs::add('ERRAn error occurred archiving the message');
}
} else {
if ($imap->select_mailbox(hex2bin($form['folder']))) {
$imap->message_action('MOVE', array($form['imap_msg_uid']), $new_folder);
Hm_Msgs::add("Message archived");
}
}
}
}

$msgs = Hm_Msgs::get();
Hm_Msgs::flush();
$this->session->secure_cookie($this->request, 'hm_msgs', base64_encode(json_encode($msgs)));
}
}
}

/**
* Flag a message
* @subpackage imap/handler
Expand Down Expand Up @@ -1568,4 +1631,3 @@ public function process() {
}
}
}

1 change: 1 addition & 0 deletions modules/imap/output_modules.php
Expand Up @@ -233,6 +233,7 @@ protected function output() {
$txt .= ' | <a class="delete_link hlink" id="delete_message" href="#">'.$this->trans('Delete').'</a>';
$txt .= ' | <a class="hlink" id="copy_message" href="#">'.$this->trans('Copy').'</a>';
$txt .= ' | <a class="hlink" id="move_message" href="#">'.$this->trans('Move').'</a>';
$txt .= ' | <a class="archive_link hlink" id="archive_message" href="#">'.$this->trans('Archive').'</a>';
$txt .= '<div class="move_to_location"></div></div>';
$txt .= '<input type="hidden" class="move_to_type" value="" />';
$txt .= '<input type="hidden" class="move_to_string1" value="'.$this->trans('Move to ...').'" />';
Expand Down
11 changes: 11 additions & 0 deletions modules/imap/setup.php
Expand Up @@ -190,6 +190,16 @@
add_handler('ajax_imap_delete_message', 'close_session_early', true, 'core');
add_handler('ajax_imap_delete_message', 'imap_delete_message', true);

/* archive message callback */
setup_base_ajax_page('ajax_imap_archive_message', 'core');
add_handler('ajax_imap_archive_message', 'message_list_type', true, 'core');
add_handler('ajax_imap_archive_message', 'imap_message_list_type', true);
add_handler('ajax_imap_archive_message', 'load_imap_servers_from_config', true);
add_handler('ajax_imap_archive_message', 'imap_oauth2_token_check', true);
add_handler('ajax_imap_archive_message', 'close_session_early', true, 'core');
add_handler('ajax_imap_archive_message', 'imap_archive_message', true);


/* ajax message action callback */
add_handler('ajax_message_action', 'load_imap_servers_from_config', true, 'imap', 'load_user_data', 'after');
add_handler('ajax_message_action', 'imap_oauth2_token_check', true, 'imap', 'load_imap_servers_from_config', 'after');
Expand Down Expand Up @@ -270,6 +280,7 @@
'ajax_imap_save_folder_state',
'ajax_imap_message_action',
'ajax_imap_delete_message',
'ajax_imap_archive_message',
'ajax_imap_flag_message',
'ajax_imap_update_combined_source',
'ajax_imap_mark_as_read',
Expand Down
41 changes: 41 additions & 0 deletions modules/imap/site.js
Expand Up @@ -580,6 +580,7 @@ var imap_message_view_finished = function(msg_uid, detail, skip_links) {
$('#delete_message').on("click", function() { return imap_delete_message(); });
$('#move_message').on("click", function(e) { return imap_move_copy(e, 'move', 'message');});
$('#copy_message').on("click", function(e) { return imap_move_copy(e, 'copy', 'message');});
$('#archive_message').on("click", function(e) { return imap_archive_message();});
};

var get_local_message_content = function(msg_uid, path) {
Expand Down Expand Up @@ -930,3 +931,43 @@ $(function() {
Hm_Timer.add_job(imap_prefetch_msgs, prefetch_interval, true);
setTimeout(prefetch_imap_folders, 2);
});


var imap_archive_message = function(state, supplied_uid, supplied_detail) {
var uid = hm_msg_uid();
var detail = Hm_Utils.parse_folder_path(hm_list_path(), 'imap');
if (supplied_uid) {
uid = supplied_uid;
}
if (supplied_detail) {
detail = supplied_detail;
}
if (detail && uid) {
Hm_Ajax.request(
[{'name': 'hm_ajax_hook', 'value': 'ajax_imap_archive_message'},
{'name': 'imap_msg_uid', 'value': uid},
{'name': 'imap_server_id', 'value': detail.server_id},
{'name': 'folder', 'value': detail.folder}],
function(res) {
if (!res.imap_archive_error) {
if (Hm_Utils.get_from_global('msg_uid', false)) {
return;
}
var nlink = $('.nlink');
if (nlink.length) {
window.location.href = nlink.attr('href');
}
else {
if (!hm_list_parent()) {
window.location.href = "?page=message_list&list_path="+hm_list_path();
}
else {
window.location.href = "?page=message_list&list_path="+hm_list_parent();
}
}
}
}
);
}
return false;
};

0 comments on commit 0fe899f

Please sign in to comment.