[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Webmail: auto delete draft messages from the email tracker field right...

"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68dbcc1d7ab09_2ddf1743889@gitlab-sidekiq-low-urgency-cpu-bound-v2-7845d6fdc8-77jh4.mail>

Victor Emanouilov pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
1c712c2f by Merci Jacob at 2025-09-30T12:15:09+00:00
[FIX] Webmail: auto delete draft messages from the email tracker field right after they are sent and avoid recreating the same draft email multiple times
---
* [FIX] Webmail: auto delete draft messages from the email tracker field right after they are sent and avoid recreating the same draft email multiple times

See merge request tikiwiki/tiki!8677

- - - - -


2 changed files:

- lib/cypht/modules/tiki/setup.php
- lib/cypht/modules/tiki/tracker_modules.php


Changes:

=====================================
lib/cypht/modules/tiki/setup.php
=====================================
@@ -129,7 +129,8 @@ add_handler('message_list', 'check_path_redirect', true, 'core', 'load_user_data
 add_handler('compose', 'tiki_presave_sent', true, 'smtp', 'imap_save_sent', 'before');
 add_handler('compose', 'tiki_mark_as_answered', true, 'smtp', 'process_compose_form_submit', 'after');
 add_handler('compose', 'tiki_save_sent', true, 'smtp', 'tiki_mark_as_answered', 'after');
-add_handler('compose', 'tiki_archive_replied', true, 'smtp', 'tiki_save_sent', 'after');
+add_handler('compose', 'tiki_delete_draft', true, 'tiki', 'tiki_save_sent', 'after');
+add_handler('compose', 'tiki_archive_replied', true, 'smtp', 'tiki_delete_draft', 'after');
 add_handler('compose', 'check_path_redirect_after_sent', true, 'smtp', 'tiki_archive_replied', 'after');
 add_handler('compose', 'tiki_compose_from_draft', true, 'smtp', 'load_smtp_servers_from_config', 'after');
 add_output('message_list', 'add_multiple_move_to_trackers', true, 'imap', 'imap_custom_controls', 'after');


=====================================
lib/cypht/modules/tiki/tracker_modules.php
=====================================
@@ -373,6 +373,55 @@ class Hm_Handler_tiki_save_sent extends Hm_Handler_Module
         ]);
     }
 }
+
+/**
+ * Delete a draft message from EmailFolder field when successfully sent
+ * @subpackage tiki/handler
+ */
+class Hm_Handler_tiki_delete_draft extends Hm_Handler_Module
+{
+    public $request;
+    public function process()
+    {
+        if (! $this->get('msg_sent')) {
+            return;
+        }
+
+        $path = $this->request->post['compose_msg_path'];
+        if (! str_contains($path, 'tracker_folder_')) {
+            return;
+        }
+
+        $draftId = $this->request->post['draft_id'];
+        if (! $draftId) {
+            return;
+        }
+
+        $path = str_replace('tracker_folder_', '', $path);
+        list ($itemId, $fieldId) = explode('_', $path);
+
+        $trk = TikiLib::lib('trk');
+        $item = $trk->get_item_info($itemId);
+        if (! $item) {
+            Hm_Msgs::add('Could not delete the saved draft. (Tracker item was not found)', 'danger');
+            return;
+        }
+        $field = $trk->get_field_info($fieldId);
+        if (! $field) {
+            Hm_Msgs::add('Could not delete the saved draft. (Tracker field not found)', 'danger');
+            return;
+        }
+        $field['value'] = [
+            'folder' => 'draft',
+            'delete' => $draftId,
+            'skip_trash' => true
+        ];
+        $trk->replace_item($item['trackerId'], $item['itemId'], [
+            'data' => [$field]
+        ]);
+    }
+}
+
 /**
  * Prevent saving a draft message to IMAP if it originated from a tracker
  * @subpackage tiki/handler
@@ -452,7 +501,7 @@ class Hm_Handler_tiki_save_draft extends Hm_Handler_Module
             return;
         }
 
-        $fileId = $this->request->get['draft_id'];
+        $fileId = $this->request->post['draft_id'];
 
         $headers = $mime->get_headers();
         $msg = "Flags: \Draft\r\n" . $mime->get_mime_msg();
@@ -475,6 +524,13 @@ class Hm_Handler_tiki_save_draft extends Hm_Handler_Module
             'folder' => 'draft',
             $action => $fileValue
         ];
+
+        TikiLib::events()->bind('tiki.trackeritem.update', function ($args) use ($fieldId) {
+            $drafts = json_decode($args['values'][$fieldId])->draft;
+            $currentDraft = end($drafts);
+            $this->out('draft_id', $currentDraft);
+        });
+
         $trk->replace_item($item['trackerId'], $item['itemId'], [
             'data' => [$field]
         ]);



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/1c712c2ff3a70eafcbec53c141531b050219b890

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/1c712c2ff3a70eafcbec53c141531b050219b890
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.