[TikiWiki-commits] [Git][tikiwiki/tiki][24.x] [BKP] Webmail: Move emails to tracker in combined views
"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6926a8707712e_2a17b36c5151f@gitlab-sidekiq-low-urgency-cpu-bound-v2-57b49dfc9c-6grw2.mail> |
Victor Emanouilov pushed to branch 24.x at Tiki Wiki CMS Groupware / Tiki
Commits:
96bd3693 by Josaphat Imani at 2025-11-26T07:06:55+00:00
[BKP] Webmail: Move emails to tracker in combined views
---
* [BKP] Webmail: Mose emails to tracker in combined views
See merge request tikiwiki/tiki!9077
- - - - -
4 changed files:
- lib/cypht/modules/tiki/functions.php
- lib/cypht/modules/tiki/setup.php
- lib/cypht/modules/tiki/site.js
- lib/cypht/modules/tiki/tracker_modules.php
Changes:
=====================================
lib/cypht/modules/tiki/functions.php
=====================================
@@ -320,3 +320,68 @@ if (! hm_exists('tiki_move_to_tracker_dropdown')) {
return $res;
}
}
+
+/**
+ * @subpackage tiki/functions
+ * @return string ensure file was saved before removing it from remote mailbox
+ */
+if (! hm_exists('bind_tracker_item_update_event')) {
+ function bind_tracker_item_update_event($mailbox, $folder, $form, $msg_ids, $mod)
+ {
+ TikiLib::events()->bind('tiki.trackeritem.update', function ($args) {
+ $mailbox = $args['mailbox'];
+ $folder = $args['folder'];
+ $form = $args['form'];
+ $old = $args['old_values'][$form['tracker_field_id']];
+ $new = $args['values'][$form['tracker_field_id']];
+ $mod = $args['mod'];
+ if ($old != $new) {
+ // Check system preference for email-to-tracker mode
+ global $prefs;
+ $email_mode = $prefs['email_to_tracker_mode'] ?? 'move';
+
+ $trash_folder = false;
+ $specials = get_special_folders($mod, $form['imap_server_id']);
+ if (array_key_exists('trash', $specials) && $specials['trash']) {
+ $trash_folder = $specials['trash'];
+ }
+
+ if ($email_mode == 'move') {
+ foreach ($args['msg_ids'] as $msg_id) {
+ if ($trash_folder && $trash_folder != hex2bin($form['folder'])) {
+ $mailbox->message_action('MOVE', array($msg_id), $trash_folder);
+ } else {
+ if ($mailbox->message_action('DELETE', array($msg_id))) {
+ $mailbox->message_action('EXPUNGE', array($msg_id));
+ }
+ }
+ }
+ }
+ }
+ }, ['mailbox' => $mailbox, 'folder' => $folder, 'form' => $form, 'msg_ids' => $msg_ids, 'mod' => $mod]);
+ }
+}
+
+/**
+ * @subpackage tiki/functions
+ * @return string array message and headers
+ */
+if (! hm_exists('get_message_data')) {
+ function get_message_data($mailbox, $folder, $msg_id)
+ {
+ if (! $mailbox->select_mailbox($folder)) {
+ return [null, null];
+ }
+ $msg = $mailbox->get_message_content($msg_id, 0);
+ $msg = str_replace("\r\n", "\n", $msg);
+ $msg = str_replace("\n", "\r\n", $msg);
+ $msg = rtrim($msg) . "\r\n";
+
+ $headers = $mailbox->get_message_headers($msg_id);
+ if (! empty($headers['Flags'])) {
+ $msg = "Flags: " . $headers['Flags'] . "\r\n" . $msg;
+ }
+
+ return [$msg, $headers];
+ }
+}
=====================================
lib/cypht/modules/tiki/setup.php
=====================================
@@ -129,6 +129,7 @@ add_handler('compose', 'tiki_archive_replied', true, 'smtp', 'tiki_save_sent', '
add_handler('compose', 'check_path_redirect_after_sent', true, 'smtp', 'tiki_archive_replied', 'after');
add_output('ajax_imap_message_content', 'add_move_to_trackers', true, 'imap', 'filter_message_headers', 'after');
add_output('message_list', 'add_multiple_move_to_trackers', true, 'imap', 'imap_custom_controls', 'after');
+add_output('search', 'add_multiple_move_to_trackers', true, 'imap', 'search_move_copy_controls', 'after');
setup_base_ajax_page('ajax_move_to_tracker', 'core');
add_handler('ajax_move_to_tracker', 'load_imap_servers_from_config', true, 'imap');
add_handler('ajax_move_to_tracker', 'imap_oauth2_token_check', true, 'imap');
=====================================
lib/cypht/modules/tiki/site.js
=====================================
@@ -285,6 +285,7 @@ var tiki_setup_move_to_trackers = function() {
url: url,
dataType: 'json',
success: function (data) {
+ const listPath = hm_list_path() ?? hm_page_name();
$el.after(data.selector);
if (jqueryTiki.select2) {
$el.parent().find('.form-select').tiki("select2");
@@ -300,7 +301,11 @@ var tiki_setup_move_to_trackers = function() {
} else {
$('input[type=checkbox]').each(function() {
if (this.checked && this.id.search('imap') != -1) {
- ids.push(this.id.split('_')[2]);
+ if (['sent', 'unread', 'combined_inbox', 'flagged', 'search', 'drafts'].includes(listPath)) {
+ ids.push(this.id);
+ } else {
+ ids.push(this.id.split('_')[2]);
+ }
}
});
if (ids.length == 0) {
@@ -312,7 +317,7 @@ var tiki_setup_move_to_trackers = function() {
{'name': 'tracker_field_id', 'value': $el.data('field')},
{'name': 'tracker_item_id', 'value': $(this).val().replace('trackeritem:', '')},
{'name': 'imap_msg_ids', 'value': ids.join(',')},
- {'name': 'list_path', 'value': hm_list_path()},
+ {'name': 'list_path', 'value': listPath},
{'name': 'folder', 'value': $el.data('folder')}],
function(res) {
if (res.tiki_redirect_url) {
@@ -598,7 +603,7 @@ $(function() {
tiki_setup_move_to_trackers();
}
- if (hm_page_name() == 'message_list') {
+ if (hm_page_name() == 'message_list' || hm_page_name() == 'search') {
tiki_setup_move_to_trackers();
}
=====================================
lib/cypht/modules/tiki/tracker_modules.php
=====================================
@@ -189,6 +189,37 @@ class Hm_Handler_move_to_tracker extends Hm_Handler_Module
]);
}
}, ['email' => $email]);
+ } elseif (in_array($form['list_path'], ['sent', 'unread', 'combined_inbox', 'flagged', 'search', 'drafts'])) {
+ $imaps = [];
+ $ids = [];
+ foreach ($msg_ids as $msg_id) {
+ $full_path = explode('_', $msg_id);
+ $imap_server_id = $full_path[1];
+ $folder = hex2bin($full_path[3]);
+
+ if (! in_array($imap_server_id, array_keys($imaps))) {
+ $cache = Hm_IMAP_List::get_cache($this->cache, $imap_server_id);
+ $imap = Hm_IMAP_List::connect($imap_server_id, $cache);
+ if (! imap_authed($imap)) {
+ Hm_Msgs::add('ERRCould not authenticate with mail server');
+ return;
+ }
+ if (! $imap->select_mailbox($folder)) {
+ Hm_Msgs::add('ERRMailbox not found');
+ return;
+ }
+
+ $imaps[$imap_server_id] = $imap;
+ }
+
+ $mailbox = $imaps[$imap_server_id];
+
+ list($msgs[], $headers_array[]) = get_message_data($mailbox, $folder, $full_path[2]);
+ $ids[] = $full_path[2];
+ }
+ if (count($ids)) {
+ bind_tracker_item_update_event($mailbox, $folder, $form, $ids, $this);
+ }
} else {
Hm_Msgs::add('ERRMessage from this source could not be moved');
return;
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/96bd3693573c9d3a92265aed14831724d5cde3c9
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/96bd3693573c9d3a92265aed14831724d5cde3c9
You're receiving this email because of your account on gitlab.com.
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs