Skip to content

Commit

Permalink
[FIX]add special folders migadu
Browse files Browse the repository at this point in the history
  • Loading branch information
christer77 committed Aug 8, 2024
1 parent 3d7022f commit 38e025a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
6 changes: 6 additions & 0 deletions modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,12 @@ var Hm_Utils = {
Hm_Ajax.request(
[{'name': 'hm_ajax_hook', 'value': 'ajax_test'}],
false, [], false, false, false);
},
redirect: function (path) {
if (! path) {
path = window.location.href;
}
window.location.href = path;
}
};

Expand Down
2 changes: 1 addition & 1 deletion modules/imap/hm-imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public function get_capability() {
*/
public function get_special_use_mailboxes($type=false) {
$folders = array();
$types = array('trash', 'sent', 'flagged', 'all', 'junk');
$types = array('trash', 'sent', 'flagged', 'all', 'junk', 'archive', 'drafts');
$command = 'LIST (SPECIAL-USE) "" "*"'."\r\n";
$this->send_command($command);
$res = $this->get_response(false, true);
Expand Down
19 changes: 12 additions & 7 deletions modules/imap_folders/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function process() {
class Hm_Handler_process_accept_special_folders extends Hm_Handler_Module {
public function process() {
list($success, $form) = $this->process_form(array('imap_server_id', 'imap_service_name'));
if ($success) {
if ($success) {
$cache = Hm_IMAP_List::get_cache($this->cache, $form['imap_server_id']);
$imap = Hm_IMAP_List::connect($form['imap_server_id'], $cache);

Expand All @@ -141,17 +141,23 @@ public function process() {

$specials = $this->user_config->get('special_imap_folders', array());
if ($exposed = $imap->get_special_use_mailboxes()) {
$specials[$form['imap_server_id']] = array('sent' => $exposed['sent'], 'draft' => '', 'trash' => $exposed['trash'], 'archive' => '', 'junk' => '');
$specials[$form['imap_server_id']] = array(
'sent' => $exposed['sent'] ?? '',
'draft' => $exposed['drafts'] ?? '',
'trash' => $exposed['trash'] ?? '',
'archive' => $exposed['archive'] ?? '',
'junk' => $exposed['junk'] ?? ''
);
} else if ($form['imap_service_name'] == 'gandi') {
$specials[$form['imap_server_id']] = array('sent' => 'Sent', 'draft' => 'Drafts', 'trash' => 'Trash', 'archive' => 'Archive', 'junk' => 'Junk');
} else {
$specials[$form['imap_server_id']] = array('sent' => '', 'draft' => '', 'trash' => '', 'archive' => '', 'junk' => '');
}
}
$this->user_config->set('special_imap_folders', $specials);

$user_data = $this->user_config->dump();
$this->session->set('user_data', $user_data);

Hm_Msgs::add('Special folders assigned');
$this->session->record_unsaved('Special folders assigned');
$this->session->close_early();
Expand Down Expand Up @@ -225,7 +231,6 @@ function ($value) use($old_folder) {
foreach ($script_names as $script_name) {
$script_parsed = $client->getScript($script_name);
$script_parsed = str_replace('"'.$old_folder.'"', '"'.$new_folder.'"', $script_parsed);

$old_actions = base64_decode(preg_split('#\r?\n#', $script_parsed, 0)[2]);
$new_actions = base64_encode(str_replace('"'.$old_folder.'"', '"'.$new_folder.'"', $old_actions));
$script_parsed = str_replace(base64_encode($old_actions), $new_actions, $script_parsed);
Expand Down Expand Up @@ -269,7 +274,7 @@ public function process() {
if (is_mailbox_linked_with_filters($del_folder, $form['imap_server_id'], $this)) {
Hm_Msgs::add('ERRThis folder can\'t be deleted because it is used in a filter.');
return;
}
}
}
if ($del_folder && $imap->delete_mailbox($del_folder)) {
Hm_Msgs::add('Folder deleted');
Expand Down Expand Up @@ -639,6 +644,6 @@ function is_mailbox_linked_with_filters ($mailbox, $imap_server_id, $module) {
$linked_mailboxes = get_sieve_linked_mailbox($imap_account, $module);
return in_array($mailbox, $linked_mailboxes);
}
return false;
return false;
}
}
3 changes: 1 addition & 2 deletions modules/nux/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ var display_final_nux_step = function(res) {
[{'name': 'hm_ajax_hook', 'value': 'ajax_imap_accept_special_folders'},
{'name': 'imap_server_id', value: res.nux_server_id},
{'name': 'imap_service_name', value: res.nux_service_name}],
function(res) {
function() {
window.location.href = "?page=servers";
}
);
}

window.location.href = "?page=servers";
}
};
Expand Down

0 comments on commit 38e025a

Please sign in to comment.