forked from cypht-org/cypht
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Review and fix the implementation of the tags feature (cypht-org#1378)
* WIP: Review and fix the tags feature * More fixes: the tags ids do not change on each reload, the folder is registered when adding a tag, & msgs are listed * Alter the tags storage structure to also save the msg uids as part of the tag rather than altering the message entry in the imap server * Move output modules to their appropriate file * Fix the tag handler called multiple times * Revert changes made to merge_imap_search_results(). It is not needed anymore * Does this hinder the selenium tests?
- Loading branch information
1 parent
b4cd0f0
commit 3163ddf
Showing
12 changed files
with
524 additions
and
490 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
<?php | ||
|
||
/** | ||
* @subpackage tags/handler | ||
*/ | ||
class Hm_Handler_mod_env extends Hm_Handler_Module { | ||
public function process() { | ||
$this->out('mod_support', array_filter(array( | ||
$this->module_is_supported('imap') ? 'imap' : false, | ||
$this->module_is_supported('feeds') ? 'feeds' : false, | ||
$this->module_is_supported('github') ? 'github' : false, | ||
$this->module_is_supported('wordpress') ? 'wordpress' : false | ||
))); | ||
} | ||
} | ||
|
||
/** | ||
* Add tag/label to message | ||
* @subpackage imap/handler | ||
*/ | ||
class Hm_Handler_add_tag_to_message extends Hm_Handler_Module { | ||
/** | ||
* Use IMAP to tag the selected message uid | ||
*/ | ||
public function process() { | ||
list($success, $form) = $this->process_form(array('tag_id', 'list_path')); | ||
if (!$success) { | ||
return; | ||
} | ||
|
||
$taged_messages = 0; | ||
$ids = explode(',', $form['list_path']); | ||
foreach ($ids as $msg_part) { | ||
list($imap_server_id, $msg_id, $folder) = explode('_', $msg_part); | ||
$folder = hex2bin($folder); | ||
$tagged = Hm_Tags::addMessage($form['tag_id'], $imap_server_id, $folder, $msg_id); | ||
if ($tagged) { | ||
$taged_messages++; | ||
} | ||
} | ||
$this->out('taged_messages', $taged_messages); | ||
if ($taged_messages == count($ids)) { | ||
$msg = 'Tag added'; | ||
} elseif ($taged_messages > 0) { | ||
$msg = 'Some messages have been taged'; | ||
} else { | ||
$msg = 'ERRFailed to tag selected messages'; | ||
} | ||
Hm_Msgs::add($msg); | ||
} | ||
} | ||
|
||
/** | ||
* @subpackage tags/handler | ||
*/ | ||
class Hm_Handler_tag_edit_data extends Hm_Handler_Module { | ||
public function process() { | ||
$id = false; | ||
if (array_key_exists('tag_id', $this->request->get)) { | ||
$id = $this->request->get['tag_id']; | ||
} | ||
$folders = $this->get('tags'); | ||
$folder = null; | ||
foreach ($folders as $f) { | ||
if ($f['id'] === $id) { | ||
$folder = $f; | ||
} | ||
} | ||
if ($id !== false) { | ||
$this->out('edit_tag', $folder); | ||
$this->out('edit_tag_id', $id); | ||
} | ||
else { | ||
$this->out('new_tag_id', count($folders)); | ||
} | ||
} | ||
} | ||
/** | ||
* @subpackage tags/handler | ||
*/ | ||
class Hm_Handler_process_tag_update extends Hm_Handler_Module { | ||
public function process() { | ||
if (array_key_exists('tag_delete', $this->request->post)) { | ||
return; | ||
} | ||
list($success, $form) = $this->process_form(array('tag_name','parent_tag','tag_id'));// 'tag_id', parent_tag | ||
if (!$success) { | ||
return; | ||
} | ||
$tag = array( | ||
'name' => html_entity_decode($form['tag_name'], ENT_QUOTES), | ||
'parent' => $form['parent_tag'] ?? null | ||
); | ||
if (!is_null($form['tag_id']) AND Hm_Tags::get($form['tag_id'])) { | ||
$tag['id'] = $form['tag_id']; | ||
Hm_Tags::edit($form['tag_id'], $tag); | ||
Hm_Msgs::add('Tag Edited'); | ||
} else { | ||
Hm_Tags::add($tag); | ||
Hm_Msgs::add('Tag Created'); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @subpackage profile/handler | ||
*/ | ||
class Hm_Handler_process_tag_delete extends Hm_Handler_Module { | ||
public function process() { | ||
list($success, $form) = $this->process_form(array('tag_delete', 'tag_id')); | ||
if (!$success) { | ||
return; | ||
} | ||
if (($tag = Hm_Tags::get($form['tag_id']))) { | ||
Hm_Tags::del($tag['id']); | ||
Hm_Msgs::add('Tag Deleted'); | ||
} else { | ||
Hm_Msgs::add('ERRTag ID not found'); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @subpackage tags/handler | ||
*/ | ||
class Hm_Handler_imap_tag_content extends Hm_Handler_Module { | ||
public function process() { | ||
$data_sources = imap_data_sources(''); | ||
$ids = array_map(function($ds) { return $ds['id']; }, $data_sources); | ||
$tag_id = $this->request->post['folder']; | ||
if ($ids && $tag_id) { | ||
try { | ||
$msg_list = []; | ||
foreach ($ids as $serverId) { | ||
$folders = Hm_Tags::getFolders($tag_id, $serverId); | ||
if (!empty($folders)) { | ||
$cache = Hm_IMAP_List::get_cache($this->cache, $serverId); | ||
$imap = Hm_IMAP_List::connect($serverId, $cache); | ||
$server_details = Hm_IMAP_List::dump($serverId); | ||
if (imap_authed($imap)) { | ||
foreach ($folders as $folder => $messageIds) { | ||
$imap->select_mailbox($folder); | ||
$messages = array_map(function($msg) use ($serverId, $folder, $server_details) { | ||
$msg['server_id'] = $serverId; | ||
$msg['folder'] = bin2hex($folder); | ||
$msg['server_name'] = $server_details['name']; | ||
return $msg; | ||
}, $imap->get_message_list($messageIds)); | ||
$msg_list = array_merge($msg_list, $messages); | ||
} | ||
} | ||
} | ||
} | ||
$limit = $this->user_config->get('tag_per_source_setting', DEFAULT_TAGS_PER_SOURCE); | ||
$date = process_since_argument($this->user_config->get('tag_since_setting', DEFAULT_TAGS_SINCE)); | ||
|
||
$msg_list = array_filter($msg_list, function($msg) use ($date) { | ||
return strtotime($msg['internal_date']) >= strtotime($date); | ||
}); | ||
$msg_list = array_slice($msg_list, 0, $limit); | ||
usort($msg_list, function($a, $b) { | ||
return strtotime($b['internal_date']) - strtotime($a['internal_date']); | ||
}); | ||
|
||
$this->out('imap_tag_data', $msg_list); | ||
} catch (\Throwable $th) { | ||
Hm_Msgs::add('ERRFailed to load tag messages: '.$th->getMessage()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Process "tag_per_source" setting for the tag page in the settings page | ||
* @subpackage core/handler | ||
*/ | ||
class Hm_Handler_process_tag_source_max_setting extends Hm_Handler_Module { | ||
/** | ||
* Allowed values are greater than zero and less than MAX_PER_SOURCE | ||
*/ | ||
public function process() { | ||
process_site_setting('tag_per_source', $this, 'max_source_setting_callback', DEFAULT_TAGS_PER_SOURCE); | ||
} | ||
} | ||
|
||
class Hm_Handler_tag_data extends Hm_Handler_Module { | ||
public function process() { | ||
Hm_Tags::init($this); | ||
$this->out('tags', Hm_Tags::getAll()); | ||
} | ||
} |
Oops, something went wrong.