Skip to content

Commit

Permalink
Merge branch 'master' into folder-subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
josaphatim authored Oct 17, 2022
2 parents af3d5bc + 18bb9aa commit 2e1c269
Show file tree
Hide file tree
Showing 20 changed files with 473 additions and 284 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ scripts/test.php
/vendor/
/.idea/
composer.lock
lib/hm3/users/
2 changes: 0 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
}
},
"scripts": {
"pre-install-cmd": "composer check-platform-reqs",
"pre-update-cmd": "composer check-platform-reqs",
"post-update-cmd": "composer suggest",
"post-package-install":"composer suggest",
"post-install-cmd": "composer suggest"
Expand Down
1 change: 1 addition & 0 deletions lib/dispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private function forward_messages($session, $request) {
* @return string
*/
public function validate_request_uri($uri) {
$uri = html_entity_decode($uri);
if ($uri === '') {
return '/';
}
Expand Down
6 changes: 3 additions & 3 deletions modules/core/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ public function process() {
$headers['Content-Type'] = 'application/json';
}
$this->out('http_headers', $headers, false);
if ($this->session->get('hm_reload_folders', false)) {
$this->session->set('hm_reload_folders', $this->session->get('hm_reload_folders') + 1);
if (array_key_exists('hm_reload_folders', $this->request->cookie)) {
$this->session->set('hm_reload_folders', $this->session->get('hm_reload_folders', 0) + 1);
}
if ($this->session->get('hm_reload_folders', false) > 3) {
if ($this->session->get('hm_reload_folders', false) > 2) {
$this->session->delete_cookie($this->request, 'hm_reload_folders');
$this->session->del('hm_reload_folders');
}
Expand Down
3 changes: 0 additions & 3 deletions modules/core/message_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ function reply_to_address($headers, $type) {
}
}
}
if (!array_key_exists('delivered-to', $headers) && array_key_exists('to', $headers)) {
list($parsed, $msg_to) = format_reply_address($headers['to'], $parsed);
}
if ($type == 'reply_all') {
if ($delivered_address) {
$parsed[] = $delivered_address;
Expand Down
3 changes: 2 additions & 1 deletion modules/core/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@
'CYPHTID' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
'hm_id' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
'hm_session' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
'hm_msgs' => FILTER_SANITIZE_FULL_SPECIAL_CHARS
'hm_msgs' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
'hm_reload_folders' => FILTER_VALIDATE_INT
),
'allowed_server' => array(
'REQUEST_URI' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
Expand Down
23 changes: 16 additions & 7 deletions modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,8 @@ function Message_List() {
};

this.prev_next_links = function(cache, class_name) {
var href;
var phref;
var nhref;
var target;
var subject;
var plink = false;
Expand All @@ -864,17 +865,18 @@ function Message_List() {
var next = current.next();
target = $('.msg_headers tr').last();
if (prev.length) {
href = prev.find('.subject').find('a').prop('href');
phref = prev.find('.subject').find('a').prop('href');
subject = new Option(prev.find('.subject').text()).innerHTML;
plink = '<a class="plink" href="'+href+'"><div class="prevnext prev_img"></div> '+subject+'</a>';
plink = '<a class="plink" href="'+phref+'"><div class="prevnext prev_img"></div> '+subject+'</a>';
$('<tr class="prev"><th colspan="2">'+plink+'</th></tr>').insertBefore(target);
}
if (next.length) {
href = next.find('.subject').find('a').prop('href');
nhref = next.find('.subject').find('a').prop('href');
subject = new Option(next.find('.subject').text()).innerHTML;
nlink = '<a class="nlink" href="'+href+'"><div class="prevnext next_img"></div> '+subject+'</a>';
nlink = '<a class="nlink" href="'+nhref+'"><div class="prevnext next_img"></div> '+subject+'</a>';
$('<tr class="next"><th colspan="2">'+nlink+'</th></tr>').insertBefore(target);
}
return [phref, nhref];
};

this.check_empty_list = function() {
Expand Down Expand Up @@ -1640,7 +1642,7 @@ var reset_default_value_checkbox = function() {
this.style.transform = "scaleX(1)";
this.parentElement.setAttribute("restore_aria_label","Restore current value");
checkbox.setAttribute("current_value", checkbox.checked);
checkbox.checked = false;
checkbox.checked = !checkbox.checked;
checkbox.disabled = true;
}
else {
Expand Down Expand Up @@ -1712,7 +1714,14 @@ var Hm_Message_List = new Message_List();

/* executes on onload, has access to other module code */
$(function() {

/* Remove disabled attribute to send checkbox */
$('.save_settings').on("click", function (e) {
$('.general_setting input[type=checkbox]').each(function () {
if (this.hasAttribute('disabled') && this.checked) {
this.removeAttribute('disabled');
}
});
})
/* setup settings and server pages */
if (hm_page_name() == 'settings') {
Hm_Utils.expand_core_settings();
Expand Down
23 changes: 20 additions & 3 deletions modules/developer/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,42 @@ public function process() {
if ($package) {
// Cypht is embedded
$branch_name = str_replace(['dev-', '-dev'], '', $package['version']);
$commit_hash = substr($package['dist']['reference'], 0, 8);
$commit_hash = substr($package['dist']['reference'], 0, 7);
$commit_url = COMMITS_URL.$commit_hash;
$commit_date = $package['time'];
} elseif (exec('git --version')) {
// Standalone cypht
$branch_name = trim(exec('git rev-parse --abbrev-ref HEAD'));
$commit_hash = trim(exec('git log --pretty="%h" -n1 HEAD'));
$commit_hash = substr(trim(exec('git log --pretty="%H" -n1 HEAD')), 0, 7);
$commit_url = COMMITS_URL.$commit_hash;
$commit_date = trim(exec('git log -n1 --pretty=%ci HEAD'));
}

if ($commit_hash != '-') {
// Get right commit date (not merge date) if not a local commit
$ch = Hm_Functions::c_init();
$res = array();
Hm_Functions::c_setopt($ch, CURLOPT_URL, 'https://api.github.com/repos/jasonmunro/cypht/commits/'.$commit_hash);
Hm_Functions::c_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
Hm_Functions::c_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
Hm_Functions::c_setopt($ch, CURLOPT_USERAGENT, $this->request->server["HTTP_USER_AGENT"]);
$curl_result = Hm_Functions::c_exec($ch);
if (trim($curl_result)) {
if (!strstr($curl_result, 'No commit found for SHA')) {
$json_commit = json_decode($curl_result);
$commit_date = $json_commit->commit->author->date;
}
}
}

$res['branch_name'] = $branch_name;
$res['commit_hash'] = $commit_hash;
$res['commit_url'] = $commit_url;

if ($commit_date != '-') {
$commit_date = new \DateTime($commit_date);
$commit_date->setTimezone(new \DateTimeZone('UTC'));
$res['commit_date'] = $commit_date->format('Y-m-d H:i:s');
$res['commit_date'] = $commit_date->format('M d, Y');
}

$this->out('server_info', $res);
Expand Down
46 changes: 25 additions & 21 deletions modules/imap/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function process() {
function pagination_links_callback($val) {
return $val;
}
process_site_setting('pagination_links', $this, 'pagination_links_callback', false, true);
process_site_setting('pagination_links', $this, 'pagination_links_callback', true, true);
}
}

Expand Down Expand Up @@ -355,6 +355,9 @@ public function process() {
}
}
}
if ($this->get('msg_next_link')) {
$this->out('redirect_url', htmlspecialchars_decode($this->get('msg_next_link')));
}
}
}

Expand Down Expand Up @@ -929,22 +932,30 @@ public function process() {
foreach ($ids as $server => $folders) {
$specials = get_special_folders($this, $server);
$trash_folder = false;
$archive_folder = false;
if ($form['action_type'] == 'delete') {
if (array_key_exists('trash', $specials) && $specials['trash']) {
$trash_folder = $specials['trash'];
}
}
if ($form['action_type'] == 'archive') {
if(array_key_exists('archive', $specials)) {
if($specials['archive']) {
$archive_folder = $specials['archive'];
}
}
}
$archive_folder = false;
$cache = Hm_IMAP_List::get_cache($this->cache, $server);
$imap = Hm_IMAP_List::connect($server, $cache);
if (imap_authed($imap)) {
$server_details = $this->user_config->get('imap_servers')[$server];
if ($form['action_type'] == 'delete') {
if (array_key_exists('trash', $specials)) {
if ($specials['trash']) {
$trash_folder = $specials['trash'];
} else {
Hm_Msgs::add(sprintf('ERRNo trash folder configured for %s', $server_details['name']));
}
}
}
if ($form['action_type'] == 'archive') {
if(array_key_exists('archive', $specials)) {
if($specials['archive']) {
$archive_folder = $specials['archive'];
} else {
Hm_Msgs::add(sprintf('ERRNo archive folder configured for %s', $server_details['name']));
}
}
}

foreach ($folders as $folder => $uids) {
if ($imap->select_mailbox(hex2bin($folder))) {
$status['imap_'.$server.'_'.$folder] = $imap->folder_state;
Expand Down Expand Up @@ -1401,7 +1412,6 @@ class Hm_Handler_load_imap_servers_from_config extends Hm_Handler_Module {
* This list is cached in the session between page loads by Hm_Handler_save_imap_servers
*/
public function process() {
$this->out('sieve_filters_enabled', $this->module_is_supported('sievefilters'));
$servers = $this->user_config->get('imap_servers', array());
$added = false;
$updated = false;
Expand Down Expand Up @@ -1801,12 +1811,6 @@ public function process() {
$this->out('msg_download_args', sprintf("page=message&amp;uid=%s&amp;list_path=imap_%s_%s&amp;imap_download_message=1", $form['imap_msg_uid'], $form['imap_server_id'], $form['folder']));
$this->out('msg_show_args', sprintf("page=message&amp;uid=%s&amp;list_path=imap_%s_%s&amp;imap_show_message=1", $form['imap_msg_uid'], $form['imap_server_id'], $form['folder']));

$server = $this->user_config->get('imap_servers')[$this->request->post['imap_server_id']];

if (array_key_exists('sieve_config_host', $server)) {
$this->out('sieve_filters_enabled', $this->module_is_supported('sievefilters'));
}

if (!$prefetch) {
clear_existing_reply_details($this->session);
if ($part == 0) {
Expand Down
22 changes: 16 additions & 6 deletions modules/imap/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,12 @@ protected function output() {
$txt .= ' | <a class="archive_link hlink" id="archive_message" href="#">'.$this->trans('Archive').'</a>';

if ($this->get('sieve_filters_enabled')) {
$txt .= ' | <a class="block_sender_link hlink" id="block_sender" href="#"><img src="'.Hm_Image_Sources::$lock.'" width="10px"></img> <span id="filter_block_txt">'.$this->trans('Block Sender').'</span></a>';
$imap_server = Hm_IMAP_List::get($this->get('msg_server_id'), false);
if ($this->get('sieve_filters_client')) {
$txt .= ' | <a class="block_sender_link hlink" id="block_sender" href="#"><img src="'.Hm_Image_Sources::$lock.'" width="10px"></img> <span id="filter_block_txt">'.$this->trans('Block Sender').'</span></a>';
} else {
$txt .= ' | <span title="This functionality requires the email server support &quot;Sieve&quot; technology which is not provided. Contact your email provider to fix it or enable it if supported."><img src="'.Hm_Image_Sources::$lock.'" width="10px"></img> <span id="filter_block_txt">'.$this->trans('Block Sender').'</span></span>';
}
}

if (isset($headers['Flags']) && stristr($headers['Flags'], 'draft')) {
Expand Down Expand Up @@ -461,8 +466,7 @@ protected function output() {
$count = sprintf($this->trans('%d configured'), $count);
return '<div class="jmap_server_setup"><div data-target=".jmap_section" class="server_section">'.
'<img alt="" src="'.Hm_Image_Sources::$env_closed.'" width="16" height="16" />'.
' '.$this->trans('JMAP Servers').'<div class="server_count">'.$count.'</div></div><div class="jmap_section"><form class="add_server" method="POST
">'.
' '.$this->trans('JMAP Servers').'<div class="server_count">'.$count.'</div></div><div class="jmap_section"><form class="add_server" method="POST">'.
'<input type="hidden" name="hm_page_key" value="'.$this->html_safe(Hm_Request_Key::generate()).'" />'.
'<div class="subtitle">'.$this->trans('Add a JMAP Server').'</div><table>'.
'<tr><td colspan="2"><label class="screen_reader" for="new_jmap_name">'.$this->trans('Account name').'</label>'.
Expand Down Expand Up @@ -912,13 +916,17 @@ protected function output() {
class Hm_Output_imap_pagination_links extends Hm_Output_Module {
protected function output() {
$checked = '';
$reset = '';
$settings = $this->get('user_settings', array());
if (!array_key_exists('pagination_links', $settings) || (array_key_exists('pagination_links', $settings) && $settings['pagination_links'])) {
$checked = ' checked="checked"';
} else {
$reset = '<span class="tooltip_restore" restore_aria_label="Restore default value"><img alt="Refresh" class="refresh_list reset_default_value_checkbox" src="'.Hm_Image_Sources::$refresh.'" /></span>';
}
return '<tr class="general_setting"><td><label for="pagination_links">'.
$res = '<tr class="general_setting"><td><label for="pagination_links">'.
$this->trans('Show next & previous emails when reading a message').'</label></td>'.
'<td><input type="checkbox" '.$checked.' id="pagination_links" name="pagination_links" value="1" /></td></tr>';
'<td><input type="checkbox"'.$checked.' id="pagination_links" name="pagination_links" value="1" />'.$reset.'</td></tr>';
return $res;
}
}

Expand Down Expand Up @@ -1023,12 +1031,14 @@ protected function output() {
class Hm_Output_original_folder_setting extends Hm_Output_Module {
protected function output() {
$checked = '';
$reset = '';
$settings = $this->get('user_settings', array());
if (array_key_exists('original_folder', $settings) && $settings['original_folder']) {
$checked = ' checked="checked"';
$reset = '<span class="tooltip_restore" restore_aria_label="Restore default value"><img alt="Refresh" class="refresh_list reset_default_value_checkbox" src="'.Hm_Image_Sources::$refresh.'" /></span>';
}
return '<tr class="general_setting"><td><label for="original_folder">'.
$this->trans('Archive to the original folder').'</label></td>'.
'<td><input type="checkbox" '.$checked.' id="original_folder" name="original_folder" value="1" /></td></tr>';
'<td><input type="checkbox" '.$checked.' id="original_folder" name="original_folder" value="1" />'.$reset.'</td></tr>';
}
}
1 change: 1 addition & 0 deletions modules/imap/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
add_output('settings', 'original_folder_setting', true, 'imap', 'imap_msg_icons_setting', 'after');
add_output('settings', 'text_only_setting', true, 'imap', 'list_style_setting', 'after');
add_output('settings', 'imap_msg_icons_setting', true, 'imap', 'msg_list_icons_setting', 'after');

add_output('settings', 'imap_simple_msg_parts', true, 'imap', 'original_folder_setting', 'after');
add_output('settings', 'imap_pagination_links', true, 'imap', 'imap_unread_on_open', 'after');
add_output('settings', 'imap_unread_on_open', true, 'imap', 'text_only_setting', 'after');
Expand Down
Loading

0 comments on commit 2e1c269

Please sign in to comment.