Skip to content

Commit

Permalink
clean up merged PR code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmunro committed Jun 28, 2021
1 parent f12db8b commit de7a832
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 42 deletions.
40 changes: 9 additions & 31 deletions modules/smtp/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,43 +468,21 @@ public function process() {
class Hm_Handler_profile_status extends Hm_Handler_Module {
public function process() {
$profiles = $this->user_config->get('profiles');
$servers = $this->user_config->get('smtp_servers', array());
$profile_value = $this->request->post['profile_value'];
$imap_servers = $this->user_config->get('imap_servers',array());
$specials = $this->user_config->get('special_imap_folders', array());

// If profile do not exist

if (!strstr($profile_value, '.')) {
if (count(Hm_Msgs::get()) == 0) {
Hm_Msgs::add('ERRPlease create a profile for saving sent messages option');
}
Hm_Msgs::add('ERRPlease create a profile for saving sent messages');
return;
}

list($selected_smtp_id, $profile_id) = explode(".", $profile_value);
$profile = profiles_by_smtp_id($profiles, $selected_smtp_id)[0];

// Select the IMAP account from the profile info
foreach ($imap_servers as $id => $srv) {
if ($srv['user'] == $profile['user'] && $srv['server'] == $profile['server']) {
$imap_server_id = $id;
}
}

// If IMAP server can't be found just ignore the
// sent folder warning
if (!isset($imap_server_id)) {
$profile = profile_from_compose_smtp_id($profiles, $profile_value);
if (!$profile) {
Hm_Msgs::add('ERRPlease create a profile for saving sent messages');
return;
}

if (count($servers) > 0) {
if( !array_key_exists($imap_server_id, $specials) ||
!array_key_exists('sent', $specials[$imap_server_id]) ||
empty($specials[$imap_server_id]['sent'])) {
if (count(Hm_Msgs::get()) == 0) {
Hm_Msgs::add('ERRPlease configure your folder to save sent messages (Sent Folder)');
}
}
$imap_profile = Hm_IMAP_List::fetch($profile['user'], $profile['server']);
$specials = get_special_folders($this, $imap_profile['id']);
if (!array_key_exists('sent', $specials) || !$specials['sent']) {
Hm_Msgs::add('ERRPlease configure a sent folder for this IMAP account)');
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions modules/smtp/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@

add_handler('ajax_update_server_pw', 'load_smtp_servers_from_config', true, 'smtp', 'load_user_data', 'after');

add_handler('ajax_profiles_status', 'login', false, 'core');
add_handler('ajax_profiles_status', 'load_user_data', true, 'core');
add_handler('ajax_profiles_status', 'profile_status', true);
setup_base_ajax_page('ajax_profiles_status', 'core');
add_handler('ajax_profiles_status', 'load_imap_servers_from_config', true, 'imap', 'load_user_data', 'after');
add_handler('ajax_profiles_status', 'profile_status', true, 'smtp', 'load_imap_servers_from_config', 'after');

return array(
'allowed_pages' => array(
'ajax_smtp_debug',
Expand Down
14 changes: 6 additions & 8 deletions modules/smtp/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var get_smtp_profile = function(profile_value) {
}
);
}
}
};

var smtp_test_action = function(event) {
event.preventDefault();
Expand Down Expand Up @@ -267,13 +267,11 @@ $(function() {
save_compose_state();
}, 100);
}
$( document ).ready(function() {
if (document.getElementsByClassName("sys_messages")[0].textContent != 'Message Sent') {
get_smtp_profile(this.value);
}
$('.compose_server').on('change', function() {
get_smtp_profile(this.value);
});
if ($('.sys_messages').text() != 'Message Sent') {
get_smtp_profile($('.compose_server').val());
}
$('.compose_server').on('change', function() {
get_smtp_profile($('.compose_server').val());
});
}
});

0 comments on commit de7a832

Please sign in to comment.