diff --git a/.gitignore b/.gitignore index 2433589d0e..cd0afc66c9 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ scripts/test.php *.sublime-workspace composer.phar lib/hm3/users/ +.env diff --git a/.travis/.env b/.travis/.env index c28670b29e..676ab129df 100644 --- a/.travis/.env +++ b/.travis/.env @@ -183,6 +183,3 @@ WORDPRESS_CLIENT_URI= RECAPTCHA_SECRET= RECAPTCHA_SITE_KEY= - -#LoginPage -FANCY_LOGIN=false \ No newline at end of file diff --git a/language/en.php b/language/en.php index de1cc1cfdf..de016fda8c 100755 --- a/language/en.php +++ b/language/en.php @@ -581,6 +581,24 @@ 'Warn for unsaved changes' => false, 'We couldn\'t find the attachment you referred to. Please confirm if you attached it or provide the details again.' => false, 'attachment,file,attach,attached,attaching,enclosed,CV,cover letter' => false, + 'Connection To Sieve Server Failed' => false, + 'Step 1' => false, + 'Step 2' => false, + 'Authentication' => false, + 'Profile name' => false, + 'Email' => false, + 'Password' => false, + 'Mail server configuration' => false, + 'Sender account' => false, + 'Receiver account' => false, + 'Address' => false, + 'Enable Sieve' => false, + 'Create Profile' => false, + 'Sieve server' => false, + 'Reply to' => false, + 'Set this profile default' => false, + 'Finish' => false, + 'Add a new server' => false, 'Automatically add outgoing email addresses' => false, 'Trusted Senders' => false, 'Collected Recipients' => false, @@ -624,6 +642,6 @@ 'Send anyway' => false, 'Send anyway and don\'t warn in the future' => false, 'Are you sure you want to send this message?' => false, -); +); ?> diff --git a/modules/core/handler_modules.php b/modules/core/handler_modules.php index 6e3fc8889c..6ad7967751 100644 --- a/modules/core/handler_modules.php +++ b/modules/core/handler_modules.php @@ -961,3 +961,149 @@ function warn_for_unsaved_changes_callback($val) { process_site_setting('warn_for_unsaved_changes', $this, 'warn_for_unsaved_changes_callback'); } } + +/** + * @subpackage core/handler + */ +class Hm_Handler_quick_servers_setup extends Hm_Handler_Module { + public $smtp_server_id = null; + public $imap_server_id = null; + public $jmap_server_id = null; + + public function process() { + list($success, $form) = $this->process_form(array( + 'srv_setup_stepper_profile_name', + 'srv_setup_stepper_email', + 'srv_setup_stepper_password', + 'srv_setup_stepper_provider', + 'srv_setup_stepper_is_sender', + 'srv_setup_stepper_is_receiver', + 'srv_setup_stepper_smtp_address', + 'srv_setup_stepper_smtp_port', + 'srv_setup_stepper_smtp_tls', + 'srv_setup_stepper_imap_address', + 'srv_setup_stepper_imap_port', + 'srv_setup_stepper_imap_tls', + 'srv_setup_stepper_enable_sieve', + 'srv_setup_stepper_create_profile', + 'srv_setup_stepper_profile_is_default', + 'srv_setup_stepper_profile_signature', + 'srv_setup_stepper_profile_reply_to', + 'srv_setup_stepper_imap_sieve_host', + 'srv_setup_stepper_only_jmap', + 'srv_setup_stepper_jmap_hide_from_c_page', + 'srv_setup_stepper_jmap_address', + )); + + if ($success) { + // Destructure form array into variables + [ + 'srv_setup_stepper_profile_name' => $profileName, + 'srv_setup_stepper_email' => $email, + 'srv_setup_stepper_password' => $password, + 'srv_setup_stepper_provider' => $provider, + 'srv_setup_stepper_is_sender' => $isSender, + 'srv_setup_stepper_is_receiver' => $isReceiver, + 'srv_setup_stepper_smtp_address' => $smtpAddress, + 'srv_setup_stepper_smtp_port' => $smtpPort, + 'srv_setup_stepper_smtp_tls' => $smtpTls, + 'srv_setup_stepper_imap_address' => $imapAddress, + 'srv_setup_stepper_imap_port' => $imapPort, + 'srv_setup_stepper_imap_tls' => $imapTls, + 'srv_setup_stepper_enable_sieve' => $enableSieve, + 'srv_setup_stepper_create_profile' => $createProfile, + 'srv_setup_stepper_profile_is_default' => $profileIsDefault, + 'srv_setup_stepper_profile_signature' => $profileSignature, + 'srv_setup_stepper_profile_reply_to' => $profileReplyTo, + 'srv_setup_stepper_imap_sieve_host' => $imapSieveHost, + 'srv_setup_stepper_only_jmap' => $onlyJmap, + 'srv_setup_stepper_jmap_hide_from_c_page' => $jmapHideFromCPage, + 'srv_setup_stepper_jmap_address' => $jmapAddress, + ] = $form; + + /* + * When JMAP selected only configure JMAP + */ + if(isset($onlyJmap) && $onlyJmap) { + if (!$this->module_is_supported('jmap')) { + Hm_Msgs::add("ERRJMAP module is not enabled"); + return; + } + + $this->jmap_server_id = connect_to_imap_server( + $jmapAddress, + $profileName, + $imapPort, + $email, + $password, + $imapTls, + null, + false, + 'imap', + $this, + $jmapHideFromCPage + ); + + Hm_Msgs::add("JMAP Server saved"); + $this->out('just_saved_credentials', true); + } else { + /* + * Connect to SMTP server if user wants to send emails + */ + if($isSender){ + if (!$this->module_is_supported('smtp')) { + Hm_Msgs::add("ERRSMTP module is not enabled"); + return; + } + + $this->smtp_server_id = connect_to_smtp_server($smtpAddress, $profileName, $smtpPort, $email, $password, $smtpTls, $this); + if(!isset($this->smtp_server_id)){ + return; + } + } + + /* + * Connect to IMAP server if user wants to receive emails + */ + if($isReceiver){ + if (!$this->module_is_supported('imap')) { + Hm_Msgs::add("ERRIMAP module is not enabled"); + return; + } + + $this->imap_server_id = connect_to_imap_server( + $imapAddress, + $profileName, + $imapPort, + $email, + $password, + $imapTls, + $imapSieveHost, + $enableSieve, + 'imap', + $this + ); + + if(!isset($this->imap_server_id)) { + if($isSender && isset($this->smtp_server_id)){ + delete_smtp_server($this->smtp_server_id, $this); + } + return; + }; + } + + if($isSender && $isReceiver && $createProfile && isset($this->imap_server_id) && isset($this->smtp_server_id)) { + if (!$this->module_is_supported('profiles')) { + Hm_Msgs::add("ERRProfiles module is not enabled"); + return; + } + + add_profile($profileName, $profileSignature, $profileReplyTo, $profileIsDefault, $email, $imapAddress, $this->smtp_server_id, $this->imap_server_id, $this); + } + + Hm_Msgs::add("Server saved"); + $this->out('just_saved_credentials', true); + } + } + } +} diff --git a/modules/core/output_modules.php b/modules/core/output_modules.php index 5c2db9c974..ae001ca9a7 100644 --- a/modules/core/output_modules.php +++ b/modules/core/output_modules.php @@ -2072,3 +2072,192 @@ protected function output() { ''.$reset.''; } } + +class Hm_Output_server_config_stepper extends Hm_Output_Module { + protected function output() { + $accordionTitle = ''; + $configuredText = $this->trans('Configured') .' '; + $hasEssentialModuleActivated = false; + + $hasImapActivated = in_array('imap', $this->get('router_module_list'), true); + $hasSmtpActivated = in_array('smtp', $this->get('router_module_list'), true); + $hasJmapActivated = in_array('jmap', $this->get('router_module_list'), true); + + if($hasImapActivated){ + $imap_servers_count = count(array_filter($this->get('imap_servers', array()), function($v) { return !array_key_exists('type', $v) || $v['type'] != 'jmap'; })); + $accordionTitle .= 'IMAP'; + $configuredText .= $imap_servers_count .' IMAP'; + $hasEssentialModuleActivated = true; + } + + if($hasJmapActivated){ + $jmap_servers_count = count(array_filter($this->get('imap_servers', array()), function($v) { return array_key_exists('type', $v) && $v['type'] == 'jmap'; })); + if($accordionTitle != ''){ + $accordionTitle .= ' - '; + $configuredText .= ' / '; + } + $accordionTitle .= 'JMAP'; + $configuredText .= $jmap_servers_count .' JMAP'; + $hasEssentialModuleActivated = true; + } + + if($hasSmtpActivated){ + $smtp_servers_count = count($this->get('smtp_servers', array())); + if($accordionTitle != ''){ + $accordionTitle .= ' - '; + $configuredText .= ' / '; + } + $accordionTitle .= 'SMTP'; + $configuredText .= $smtp_servers_count .' SMTP'; + $hasEssentialModuleActivated = true; + } + + $accordionTitle .= ' Servers'; + + // When essential module is not activated, we don't display the accordion + if(!$hasEssentialModuleActivated) return ''; + + $serverList = null; + + if(class_exists('Nux_Quick_Services')){ + $serverList = Nux_Quick_Services::option_list(false, $this); + } + + $hideClass = 'd-none'; + + // Don't hide this section if at least one of the essential module is activated + if($hasImapActivated || $hasSmtpActivated || $hasJmapActivated){ + $hideClass = ''; + } + + $res = '
+
+ + + '.$accordionTitle.' + +
'.$configuredText.'
+
+
+
+
+
+
+

'.$this->trans('Step 1').'

+ ('.$this->trans('Authentication').') +
+
+
+ +
+ + + +
+
+ + + +
+
+ + + +
+
+
+
+ + +
+
+
+
+

'.$this->trans('Step 2').'

+ ('.$this->trans('Mail server configuration').') +
+
+
+
+ + +
'; + + if($hasSmtpActivated && $hasImapActivated) { + $res .= ' +
+ + +
+
+ + +
+ + '; + } + + $res .= '
'; + + return $res; + } +} + +class Hm_Output_server_config_stepper_end_part extends Hm_Output_Module { + protected function output() { + $res = '
'; + + if(in_array('profiles', $this->get('router_module_list'), true)) { + $res .= ' +
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ '; + } + + $res .= '
+
+
+
+ Loading... +
+
+
+ + + +
+
+
+ +
+
+
+
'; + + return $res; + } +} + +class Hm_Output_server_config_stepper_accordion_end_part extends Hm_Output_Module { + protected function output() { + return '
'; + } +} diff --git a/modules/core/setup.php b/modules/core/setup.php index a988270d89..3bf8111329 100644 --- a/modules/core/setup.php +++ b/modules/core/setup.php @@ -21,6 +21,9 @@ setup_base_page('servers'); add_handler('servers', 'reload_folder_cookie', true, 'core', 'save_user_data', 'after'); add_output('servers', 'server_content_start', true, 'core', 'content_section_start', 'after'); +add_output('servers', 'server_config_stepper', true, 'core', 'server_content_start', 'after'); +add_output('servers', 'server_config_stepper_end_part', true, 'core', 'server_config_stepper', 'after'); +add_output('servers', 'server_config_stepper_accordion_end_part', true, 'core', 'server_config_stepper_end_part', 'after'); add_output('servers', 'server_content_end', true, 'core', 'content_section_end', 'before'); /* compose */ @@ -166,6 +169,19 @@ add_handler('ajax_test', 'date', true, 'core'); add_handler('ajax_test', 'http_headers', true, 'core'); +/* Server setup */ +add_handler('ajax_quick_servers_setup', 'login', false, 'core'); +add_handler('ajax_quick_servers_setup', 'load_user_data', true, 'core'); +add_handler('ajax_quick_servers_setup', 'quick_servers_setup', true); +add_handler('ajax_quick_servers_setup', 'load_smtp_servers_from_config', true, 'smtp', 'quick_servers_setup', 'before'); +add_handler('ajax_quick_servers_setup', 'load_imap_servers_from_config', true, 'imap', 'quick_servers_setup', 'before'); +add_handler('ajax_quick_servers_setup', 'profile_data', true, 'profiles', 'quick_servers_setup', 'before'); +add_handler('ajax_quick_servers_setup', 'compose_profile_data', true, 'profiles'); +add_handler('ajax_quick_servers_setup', 'save_user_data', true, 'core'); +add_handler('ajax_quick_servers_setup', 'language', true, 'core'); +add_handler('ajax_quick_servers_setup', 'date', true, 'core'); +add_handler('ajax_quick_servers_setup', 'http_headers', true, 'core'); + /* allowed input */ return array( 'allowed_pages' => array( @@ -183,7 +199,8 @@ 'ajax_update_server_pw', 'ajax_no_op', 'notfound', - 'search' + 'search', + 'ajax_quick_servers_setup', ), 'allowed_output' => array( 'date' => array(FILTER_DEFAULT, false), @@ -193,7 +210,7 @@ 'formatted_message_list' => array(FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY), 'just_saved_credentials' => array(FILTER_VALIDATE_BOOLEAN, false), 'just_forgot_credentials' => array(FILTER_VALIDATE_BOOLEAN, false), - 'deleted_server_id' => array(FILTER_SANITIZE_FULL_SPECIAL_CHARS, false), + 'deleted_server_id' => array(FILTER_DEFAULT, false), 'msg_headers' => array(FILTER_UNSAFE_RAW, false), 'msg_text' => array(FILTER_UNSAFE_RAW, false), 'msg_source' => array(FILTER_UNSAFE_RAW, false), @@ -288,9 +305,30 @@ 'junk_since' => FILTER_DEFAULT, 'trash_per_source' => FILTER_VALIDATE_INT, 'trash_since' => FILTER_DEFAULT, - 'drafts_per_source' => FILTER_VALIDATE_INT, + 'drafts_per_source' => FILTER_DEFAULT, 'drafts_since' => FILTER_DEFAULT, - 'warn_for_unsaved_changes' => FILTER_VALIDATE_BOOLEAN + 'warn_for_unsaved_changes' => FILTER_VALIDATE_BOOLEAN, + 'srv_setup_stepper_profile_name' => FILTER_DEFAULT, + 'srv_setup_stepper_email' => FILTER_DEFAULT, + 'srv_setup_stepper_password' => FILTER_UNSAFE_RAW, + 'srv_setup_stepper_provider' => FILTER_DEFAULT, + 'srv_setup_stepper_is_sender' => FILTER_VALIDATE_BOOLEAN, + 'srv_setup_stepper_is_receiver' => FILTER_VALIDATE_BOOLEAN, + 'srv_setup_stepper_smtp_address' => FILTER_DEFAULT, + 'srv_setup_stepper_smtp_port' => FILTER_DEFAULT, + 'srv_setup_stepper_smtp_tls' => FILTER_VALIDATE_BOOLEAN, + 'srv_setup_stepper_imap_address' => FILTER_DEFAULT, + 'srv_setup_stepper_imap_port' => FILTER_DEFAULT, + 'srv_setup_stepper_imap_tls' => FILTER_VALIDATE_BOOLEAN, + 'srv_setup_stepper_enable_sieve' => FILTER_VALIDATE_BOOLEAN, + 'srv_setup_stepper_create_profile' => FILTER_VALIDATE_BOOLEAN, + 'srv_setup_stepper_profile_is_default' => FILTER_VALIDATE_BOOLEAN, + 'srv_setup_stepper_profile_signature' => FILTER_DEFAULT, + 'srv_setup_stepper_profile_reply_to' => FILTER_DEFAULT, + 'srv_setup_stepper_imap_sieve_host' => FILTER_DEFAULT, + 'srv_setup_stepper_only_jmap' => FILTER_VALIDATE_BOOLEAN, + 'srv_setup_stepper_jmap_hide_from_c_page' => FILTER_VALIDATE_BOOLEAN, + 'srv_setup_stepper_jmap_address' => FILTER_DEFAULT ) ); diff --git a/modules/core/site.css b/modules/core/site.css index f012a643ff..dfcef2e416 100644 --- a/modules/core/site.css +++ b/modules/core/site.css @@ -325,3 +325,34 @@ div.unseen, .unseen .subject { font-weight: 700; } .drag_target { background-color: #888 !important; } + +.step_config-title {display: flex;align-items: center;gap: 10px;} +.step_config-title > span {font-size: small;} +.step_config-title > h2 {color: #777} +.stepper_input {width: 350px;height: 20px;padding: 4px 8px 4px 8px;background: #FFFFFF; border-color: #232323;border-width: 1px;border-style: solid;border-radius: 3px 3px 3px 3px;font-family: "Helvetica";font-weight: 400;font-size: 14px;text-align: left;} + +.step_config-form_item {margin: 10px 0px;} +.step_config-form_item.nested {margin-left: 20px !important;} +.step_config-form_item-checkbox {} +.step_config-form_item > label {color: #232323;font-family: "Helvetica";font-weight: 400;font-size: 14px;text-align: left;} +.step_config-form_item > textarea {width: 350px;height: 32px;padding: 4px 8px 4px 8px;background: #FFFFFF; border-color: #232323;border-width: 1px;border-style: solid;border-radius: 3px 3px 3px 3px;font-family: "Helvetica";font-weight: 400;font-size: 14px;text-align: left;} +.step_config-form_item > select {height: 32px;} +.step_config-actions {display: flex;justify-content: space-between;margin-top: 15px;} +.stepper {display: flex;overflow: hidden;padding: 10px 30px 100px 30px;} +.step_config {width: 100%;transition: transform 0.5s;display: none;} +.current_config_step {display: block;} +.step-container {display: flex;width: 400px;} + +.step_config-smtp_imap_bloc { padding: 15px; background: #EBEBEB; } + +.step_config-smtp_imap_port_bloc {display: flex; font-size: 10px;} + +.step_config-smtp_imap_port_bloc > input { width: 100px;} +.step_config-smtp_bloc {margin-bottom: 10px;} +.step_config-imap_bloc {margin-bottom: 10px;} +.server_config_section { display: none; } +.error-message {color: red; font-size: small;} +.hide {display: none;} +.server_type_tag {background-color: teal;border-radius: 5px;padding: 0px 5px;color: white;font-size: x-small;width: max-content;font-weight: 900;} +input[type="submit"], button {cursor: pointer; min-width: 70px;} +input[type="submit"]:hover, button:hover {background-color: rgba(139, 137, 137, 0.16);} diff --git a/modules/core/site.js b/modules/core/site.js index 7ea6637336..4206341542 100644 --- a/modules/core/site.js +++ b/modules/core/site.js @@ -1597,11 +1597,11 @@ var Hm_Utils = { * Shows pending messages added with the add_sys_message method */ show_sys_messages: function() { - $('.sys_messages').removeClass('d-none'); + $('.sys_messages').removeClass('d-none'); }, /** - * + * * @param {*} msg : The alert message to display * @param {*} type : The type of message to display, depending on the type of boostrap5 alert (primary, secondary, success, danger, warning, info, light, dark ) */ @@ -2125,4 +2125,303 @@ if(tableBody && !hm_mobile()) { }; observer.observe(folderList, config); -} \ No newline at end of file +} + +function submitSmtpImapServer() { + $('#srv_setup_stepper_form_loader').removeClass('hide'); + $('.step_config-actions').addClass('hide'); + + var requestData = [ + { name: 'hm_ajax_hook', value: 'ajax_quick_servers_setup' }, + { name: 'srv_setup_stepper_profile_name', value: $('#srv_setup_stepper_profile_name').val() }, + { name: 'srv_setup_stepper_email', value: $('#srv_setup_stepper_email').val() }, + { name: 'srv_setup_stepper_password', value: $('#srv_setup_stepper_password').val() }, + { name: 'srv_setup_stepper_provider', value: $('#srv_setup_stepper_provider').val() }, + { name: 'srv_setup_stepper_is_sender', value: $('#srv_setup_stepper_is_sender').prop('checked') }, + { name: 'srv_setup_stepper_is_receiver', value: $('#srv_setup_stepper_is_receiver').prop('checked') }, + { name: 'srv_setup_stepper_smtp_address', value: $('#srv_setup_stepper_smtp_address').val() }, + { name: 'srv_setup_stepper_smtp_port', value: $('#srv_setup_stepper_smtp_port').val() }, + { name: 'srv_setup_stepper_smtp_tls', value: $('input[name="srv_setup_stepper_smtp_tls"]:checked').val() }, + { name: 'srv_setup_stepper_imap_address', value: $('#srv_setup_stepper_imap_address').val() }, + { name: 'srv_setup_stepper_imap_port', value: $('#srv_setup_stepper_imap_port').val() }, + { name: 'srv_setup_stepper_imap_tls', value: $('input[name="srv_setup_stepper_imap_tls"]:checked').val() }, + { name: 'srv_setup_stepper_enable_sieve', value: $('#srv_setup_stepper_enable_sieve').prop('checked') }, + { name: 'srv_setup_stepper_create_profile', value: $('#srv_setup_stepper_create_profile').prop('checked') }, + { name: 'srv_setup_stepper_profile_is_default', value: $('#srv_setup_stepper_profile_is_default').prop('checked') }, + { name: 'srv_setup_stepper_profile_signature', value: $('#srv_setup_stepper_profile_signature').val() }, + { name: 'srv_setup_stepper_profile_reply_to', value: $('#srv_setup_stepper_profile_reply_to').val() }, + { name: 'srv_setup_stepper_imap_sieve_host', value: $('#srv_setup_stepper_imap_sieve_host').val() }, + { name: 'srv_setup_stepper_only_jmap', value: $('input[name="srv_setup_stepper_only_jmap"]:checked').val() }, + { name: 'srv_setup_stepper_jmap_hide_from_c_page', value: $('input[name="srv_setup_stepper_jmap_hide_from_c_page"]:checked').val() }, + { name: 'srv_setup_stepper_jmap_address', value: $('#srv_setup_stepper_jmap_address').val() }, + ]; + + Hm_Ajax.request(requestData, function(res) { + $('#srv_setup_stepper_form_loader').addClass('hide'); + $('.step_config-actions').removeClass('hide'); + Hm_Notices.show(res.router_user_msgs); + + if (res.just_saved_credentials) { + $('#srv_setup_stepper_stepper').find('form').trigger('reset'); + display_config_step(0); + + //Initialize the form + $("#srv_setup_stepper_profile_reply_to").val(''); + $("#srv_setup_stepper_profile_signature").val(''); + $("#srv_setup_stepper_profile_name").val(''); + $("#srv_setup_stepper_email").val(''); + $("#srv_setup_stepper_password").val(''); + $("#srv_setup_stepper_profile_is_default").prop('checked', true); + $("#srv_setup_stepper_is_sender").prop('checked', true); + $("#srv_setup_stepper_is_receiver").prop('checked', true); + $("#srv_setup_stepper_enable_sieve").prop('checked', false); + $("#srv_setup_stepper_only_jmap").prop('checked', false); + $('#step_config-imap_bloc').show(); + $('#step_config-smtp_bloc').show(); + $('#srv_setup_stepper_profile_bloc').show(); + + Hm_Utils.set_unsaved_changes(1); + Hm_Folders.reload_folders(true); + location.reload(); + } + }, null, null, function (res) { + $('#srv_setup_stepper_form_loader').addClass('hide'); + $('.step_config-actions').removeClass('hide'); + }); +} + +function handleCreateProfileCheckboxChange(checkbox) { + if(checkbox.checked) { + $('#srv_setup_stepper_profile_bloc').show(); + }else{ + $('#srv_setup_stepper_profile_bloc').hide(); + } +} + +function handleSieveStatusChange (checkbox) { + if(checkbox.checked) { + $('#srv_setup_stepper_imap_sieve_host_bloc').show(); + }else{ + $('#srv_setup_stepper_imap_sieve_host_bloc').hide(); + } +} +function handleSmtpImapCheckboxChange(checkbox) { + $(".step_config-smtp_imap_bloc").show(); + + if (checkbox.id === 'srv_setup_stepper_is_receiver') { + if(checkbox.checked) $('#step_config-imap_bloc').show(); + else $('#step_config-imap_bloc').hide(); + } + + if (checkbox.id === 'srv_setup_stepper_is_sender') { + console.log("checkbox.checked", checkbox.checked) + if(checkbox.checked) $('#step_config-smtp_bloc').show(); + else $('#step_config-smtp_bloc').hide(); + } + + if($('#srv_setup_stepper_is_sender').prop('checked') && + $('#srv_setup_stepper_is_receiver').prop('checked')){ + $('#srv_setup_stepper_profile_bloc').show(); + $('#srv_setup_stepper_profile_checkbox_bloc').show(); + $('#srv_setup_stepper_jmap_select_box').show(); + $("#srv_setup_stepper_only_jmap").show(); + }else{ + $("#srv_setup_stepper_only_jmap").prop('checked', false); + + $('#srv_setup_stepper_profile_bloc').hide(); + $('#srv_setup_stepper_profile_checkbox_bloc').hide(); + $('#srv_setup_stepper_jmap_select_box').hide(); + $("#srv_setup_stepper_only_jmap").hide(); + + if(!$('#srv_setup_stepper_is_sender').prop('checked') && + !$('#srv_setup_stepper_is_receiver').prop('checked')){ + $(".step_config-smtp_imap_bloc").hide(); + } + } +} + +function handleJmapCheckboxChange(checkbox) { + if(checkbox.checked){ + $('#step_config-jmap_bloc').show(); + $('#step_config-smtp_bloc').hide(); + $('#step_config-imap_bloc').hide(); + $('#srv_setup_stepper_profile_bloc').hide(); + $('#srv_setup_stepper_profile_checkbox_bloc').hide(); + }else { + $('#step_config-jmap_bloc').hide(); + $('#step_config-smtp_bloc').show(); + $('#step_config-imap_bloc').show(); + $('#srv_setup_stepper_profile_bloc').show(); + $('#srv_setup_stepper_profile_checkbox_bloc').show(); + } +} + +function handleProviderChange(select) { + let providerKey = select.value; + if(providerKey) { + getServiceDetails(providerKey); + }else{ + $("#srv_setup_stepper_smtp_address").val(''); + $("#srv_setup_stepper_smtp_port").val(465); + $("#srv_setup_stepper_imap_address").val(''); + $("#srv_setup_stepper_imap_port").val(993); + } +} +function display_config_step(stepNumber) { + if(stepNumber == 2) { + + var isValid = true; + + [ {key: 'srv_setup_stepper_profile_name', value: $('#srv_setup_stepper_profile_name').val()}, + {key: 'srv_setup_stepper_email', value: $('#srv_setup_stepper_email').val()}, + {key: 'srv_setup_stepper_password', value: $('#srv_setup_stepper_password').val()}].forEach((item) => { + if(!item.value) { + $(`#${item.key}-error`).text('Required'); + isValid = false; + } + else $(`#${item.key}-error`).text(''); + }) + + if (!isValid) { + return + } + + let providerKey = getEmailProviderKey($('#srv_setup_stepper_email').val()); + getServiceDetails(providerKey); + } + + if(stepNumber == 3) { + var requiredFields = []; + var isValid = true; + + if(!$('#srv_setup_stepper_is_sender').is(':checked') && !$('#srv_setup_stepper_is_receiver').is(':checked')){ + $('#srv_setup_stepper_serve_type-error').text('Required'); + return; + } + + if($('#srv_setup_stepper_is_sender').is(':checked') && + $('#srv_setup_stepper_is_receiver').is(':checked') && + $('#srv_setup_stepper_only_jmap').is(':checked')){ + requiredFields.push( + {key: 'srv_setup_stepper_jmap_address', value: $('#srv_setup_stepper_jmap_address').val()}, + ) + }else { + if($('#srv_setup_stepper_is_sender').is(':checked')){ + requiredFields.push( + {key: 'srv_setup_stepper_smtp_address', value: $('#srv_setup_stepper_smtp_address').val()}, + {key: 'srv_setup_stepper_smtp_port', value: $('#srv_setup_stepper_smtp_port').val()}, + ) + } + + if($('#srv_setup_stepper_is_receiver').is(':checked')) { + requiredFields.push( + {key: 'srv_setup_stepper_imap_address', value: $('#srv_setup_stepper_imap_address').val()}, + {key: 'srv_setup_stepper_imap_port', value: $('#srv_setup_stepper_imap_port').val()}, + ) + } + } + + if($('#srv_setup_stepper_enable_sieve').is(':checked')) { + requiredFields.push( + {key: 'srv_setup_stepper_imap_sieve_host', value: $('#srv_setup_stepper_imap_sieve_host').val()}, + ) + } + + requiredFields.forEach((item) => { + if(!item.value) { + $(`#${item.key}-error`).text('Required'); + isValid = false; + } + else $(`#${item.key}-error`).text(''); + }) + + + if(!isValid) return + + submitSmtpImapServer(); + return + } + // Hide all step elements + var steps = document.querySelectorAll('.step_config'); + for (var i = 0; i < steps.length; i++) { + steps[i].style.display = 'none'; + } + + // Show the selected step + var selectedStep = document.getElementById('step_config_' + stepNumber); + + if (selectedStep) { + selectedStep.style.display = 'block'; + if(stepNumber === 0) $('.srv_setup_stepper_btn').show(); + } +} + +function getServiceDetails(providerKey){ + if(providerKey) { + $("#srv_setup_stepper_provider").val(providerKey); + + Hm_Ajax.request( + [ + {'name': 'hm_ajax_hook', 'value': 'ajax_get_nux_service_details'}, + {'name': 'nux_service', 'value': providerKey},], + function(res) { + if(res.service_details){ + let serverConfig = JSON.parse(res.service_details) + + $("#srv_setup_stepper_smtp_address").val(serverConfig.smtp.server); + $("#srv_setup_stepper_smtp_port").val(serverConfig.smtp.port); + + if(serverConfig.smtp.tls)$("input[name='srv_setup_stepper_smtp_tls'][value='true']").prop("checked", true); + else $("input[name='srv_setup_stepper_smtp_tls'][value='false']").prop("checked", true); + + $("#srv_setup_stepper_imap_address").val(serverConfig.server); + $("#srv_setup_stepper_imap_port").val(serverConfig.port); + + if(serverConfig.tls)$("input[name='srv_setup_stepper_imap_tls'][value='true']").prop("checked", true); + else $("input[name='srv_setup_stepper_imap_tls'][value='false']").prop("checked", true); + } + }, + [], + false + ); + } +} + +function getEmailProviderKey(email) { + const emailProviderMap = { + "all-inkl": ["all-inkl.de", "all-inkl.com"], + "aol": ["aol.com"], + "fastmail": ["fastmail.com"], + "gandi": ["gandi.net"], + "gmail": ["gmail.com"], + "gmx": ["gmx.com", "gmx.de"], + "icloud": ["icloud.com"], + "inbox": ["inbox.com"], + "kolabnow": ["kolabnow.com"], + "mailcom": ["mail.com"], + "mailbox": ["mailbox.org"], + "migadu": ["migadu.com"], + "office365": ["office365.com"], + "outlook": ["outlook.com", "outlook.fr"], + "postale": ["postale.io"], + "yahoo": ["yahoo.com", "yahoo.fr"], + "yandex": ["yandex.com", "yandex.ru"], + "zoho": ["zoho.com"] + }; + + const emailParts = email.split("@"); + + if(emailParts.length !== 2) return ""; + + const provider = emailParts[1].toLowerCase(); + + for (const providerKey in emailProviderMap) { + if (emailProviderMap[providerKey].some(p => p.includes(provider))) { + return providerKey; + } + } + + return ""; +} + + diff --git a/modules/imap/functions.php b/modules/imap/functions.php index fceaaaf87b..5ef3c7d522 100644 --- a/modules/imap/functions.php +++ b/modules/imap/functions.php @@ -1425,3 +1425,51 @@ function parse_sieve_config_host($host) { // $host = '$scheme://'.$host; return [$host, $port, $tls]; }} + +if (!hm_exists('connect_to_imap_server')) { + function connect_to_imap_server($address, $name, $port, $user, $pass, $tls, $imap_sieve_host, $enableSieve, $type, $context, $hidden = false) { + $imap_list = array( + 'name' => $name, + 'server' => $address, + 'hide' => false, + 'port' => $port, + 'user' => $user, + 'pass' => $pass, + 'tls' => $tls); + + if ($type === 'jmap') { + $imap_list['type'] = 'jmap'; + $imap_list['hide'] = $hidden; + $imap_list['port'] = false; + $imap_list['tls'] = false; + } + + if (isset($imap_sieve_host) && $imap_sieve_host) { + $imap_list['sieve_config_host'] = $imap_sieve_host; + } + + $imap_server_id = Hm_IMAP_List::add($imap_list); + $server = Hm_IMAP_List::get($imap_server_id, false); + + if ($enableSieve && + isset($imap_sieve_host) && + $context->module_is_supported('sievefilters') && + $context->user_config->get('enable_sieve_filter_setting', true)) { + try { + + include APP_PATH.'modules/sievefilters/hm-sieve.php'; + $sieveClientFactory = new Hm_Sieve_Client_Factory(); + $client = $sieveClientFactory::init(null, $server); + + if (!$client) { + Hm_Msgs::add("ERRFailed to authenticate to the Sieve host"); + } + } catch (Exception $e) { + Hm_Msgs::add("ERRFailed to authenticate to the Sieve host"); + return; + } + } + + return Hm_IMAP_List::service_connect($imap_server_id, $server, $user, $pass, false); + } +} diff --git a/modules/imap/handler_modules.php b/modules/imap/handler_modules.php index 34fa43f050..9c6fa1e526 100644 --- a/modules/imap/handler_modules.php +++ b/modules/imap/handler_modules.php @@ -688,7 +688,7 @@ public function process() { } } } - + } } } @@ -899,7 +899,7 @@ public function process() { $imap = Hm_IMAP_List::connect($form['imap_server_id'], $cache); $archive_folder = false; $errors = 0; - + $specials = get_special_folders($this, $form['imap_server_id']); if (array_key_exists('archive', $specials) && $specials['archive']) { $archive_folder = $specials['archive']; @@ -917,13 +917,13 @@ public function process() { } $form_folder = hex2bin($form['folder']); - + /* select source folder */ if ($errors || !$imap->select_mailbox($form_folder)) { Hm_Msgs::add('ERRAn error occurred archiving the message'); $errors++; } - + /* path according to original option setting */ if ($this->user_config->get('original_folder_setting', false)) { $archive_folder .= '/'.$form_folder; @@ -931,7 +931,7 @@ public function process() { $imap->create_mailbox($archive_folder); } } - + /* try to move the message */ if (!$errors && $imap->message_action('MOVE', array($form['imap_msg_uid']), $archive_folder)) { Hm_Msgs::add("Message archived"); @@ -1063,7 +1063,7 @@ public function process() { } /** - * Perform an IMAP message action + * Perform an IMAP message action * @subpackage imap/handler */ class Hm_Handler_imap_message_action extends Hm_Handler_Module { @@ -1082,7 +1082,7 @@ public function process() { foreach ($ids as $server => $folders) { $specials = get_special_folders($this, $server); $trash_folder = false; - $archive_folder = false; + $archive_folder = false; $cache = Hm_IMAP_List::get_cache($this->cache, $server); $imap = Hm_IMAP_List::connect($server, $cache); if (imap_authed($imap)) { @@ -1554,7 +1554,7 @@ public function process() { else { $name = $this->config->get('imap_auth_name', 'Default'); } - $imap_details = array( + $imap_details = array( 'name' => $name, 'default' => true, 'server' => $auth_server['server'], diff --git a/modules/imap/output_modules.php b/modules/imap/output_modules.php index fb0ec57cc0..c5250498e8 100644 --- a/modules/imap/output_modules.php +++ b/modules/imap/output_modules.php @@ -422,11 +422,19 @@ protected function output() { if ($this->get('single_server_mode')) { return ''; } - $res = ''; - foreach ($this->get('imap_servers', array()) as $index => $vals) { + $list = $this->get('imap_servers', array()); + + if (empty($list)) { + return ''; + } + + $res = '
Imap & JMAP Serves
'; + foreach ($list as $index => $vals) { $server_id = $vals['id']; + $type = 'IMAP'; + if (array_key_exists('type', $vals) && $vals['type'] == 'jmap') { - continue; + $type = 'JMAP'; } if (array_key_exists('user', $vals) && !array_key_exists('nopass', $vals)) { @@ -452,33 +460,43 @@ protected function output() { $disabled = ''; $pass_value = ''; } - $res .= '
'; - $res .= sprintf('
%s
%s/%d %s
', - $this->html_safe($vals['name']), $this->html_safe($vals['server']), $this->html_safe($vals['port']), - $vals['tls'] ? 'TLS' : '' ); - + $res .= '
'; $res .= '
'; $res .= ''; $res .= ''; - + $res .= ' + + + + + +
'; + $res .= sprintf(' +
+
%s
+
%s/%d %s
+
', + $this->html_safe($vals['name']), $this->html_safe($vals['server']), $this->html_safe($vals['port']), + $vals['tls'] ? 'TLS' : '' ); + $res .= '
'; + // IMAP Username $res .= '
'; $res .= ''; $res .= '
'; - + $res .= '
'; // IMAP Password $res .= '
'; $res .= ''; $res .= '
'; - + $res .= '
'; + // Sieve Host (Conditional) if ($this->get('sieve_filters_enabled') && isset($vals['sieve_config_host'])) { $default_value = $vals['sieve_config_host']; $res .= '
'; $res .= ''; $res .= '
'; + $res .= '
'; } - + // Buttons if (!isset($vals['user']) || !$vals['user']) { $res .= ''; @@ -488,19 +506,25 @@ protected function output() { $res .= ''; $res .= ''; } - + // Hide/Unhide Buttons $hidden = array_key_exists('hide', $vals) && $vals['hide']; $res .= ''; $res .= ''; - + + + $res .= '
'; + $res .= ''; $res .= '
'; - - $res .= '
'; + + $res .= '
'; } - $res .= '
'; + $res .= '
'; return $res; } } @@ -531,54 +555,9 @@ protected function output() { ''; } - return '
'. - ''. - ' '.$this->trans('IMAP Servers').''. - '
'.$count.'
-
-
-
-
'. - ''. - '
'.$this->trans('Add an IMAP Server').'
'. - - // Account Name Field - '
'. - ''. - '
'. - - // Server Address Field - '
'. - ''. - '
'. - - // IMAP Port Field - '
'. - ''. - '
'. - - $sieve_extra. - - // Checkbox for Hide From Combined Pages - '
'. - ''. - '
'. - - $sieve_extra2. - - // TLS Radio Button - '
'. - ''. - '
'. - - '
'. - ''. - '
'. - - ''. - '
-
'; - + return '
'. + ''. + ' '.$this->trans('IMAP Servers').'
'.$count.'
'; } } @@ -1308,4 +1287,92 @@ protected function output() { $res .= '
'; return $res; } -} \ No newline at end of file +} +/** + * @subpackage jmap/output + */ +class Hm_Output_stepper_setup_server_jmap extends Hm_Output_Module { + protected function output() { + if(!in_array('jmap', $this->get('router_module_list'), true)) return ''; + return ' +
+ + +
+
+ +
+ + + +
+
+ + +
+
+ '; + } +} + +/** + * @subpackage imap/output + */ +class Hm_Output_stepper_setup_server_imap extends Hm_Output_Module { + protected function output() { + $res = ' +
+ +
+ + + +
+
+
+
+ + + +
+ +
+
+
+ + +
+
+ + +
+
+
+ '; + + if (!$this->get('sieve_filters_enabled')) { + $default_value = ''; + $res .= ' + +
+ + +
+
+ + + +
'; + } + $res .= '
'; + return $res; + } +} diff --git a/modules/imap/setup.php b/modules/imap/setup.php index e2981862f7..e6ba612d08 100644 --- a/modules/imap/setup.php +++ b/modules/imap/setup.php @@ -21,11 +21,10 @@ add_handler('servers', 'process_add_imap_server', true, 'imap', 'message_list_type', 'after'); add_handler('servers', 'process_add_jmap_server', true, 'imap', 'process_add_imap_server', 'after'); add_handler('servers', 'save_imap_servers', true, 'imap', 'process_add_jmap_server', 'after'); -add_output('servers', 'add_imap_server_dialog', true, 'imap', 'server_content_start', 'after'); -add_output('servers', 'display_configured_imap_servers', true, 'imap', 'add_imap_server_dialog', 'after'); -add_output('servers', 'add_jmap_server_dialog', true, 'imap', 'display_configured_imap_servers', 'after'); -add_output('servers', 'display_configured_jmap_servers', true, 'imap', 'add_jmap_server_dialog', 'after'); +add_output('servers', 'display_configured_imap_servers', true, 'imap', 'server_config_stepper_accordion_end_part', 'before'); add_output('servers', 'imap_server_ids', true, 'imap', 'page_js', 'before'); +add_output('servers', 'stepper_setup_server_jmap', true, 'imap', 'server_config_stepper_end_part', 'before'); +add_output('servers', 'stepper_setup_server_imap', true, 'imap', 'server_config_stepper_end_part', 'before'); /* settings page data */ add_handler('settings', 'process_sent_since_setting', true, 'imap', 'date', 'after'); diff --git a/modules/imap/site.css b/modules/imap/site.css index ffd3fc4e01..7b2f4d7339 100644 --- a/modules/imap/site.css +++ b/modules/imap/site.css @@ -8,11 +8,11 @@ .hl { padding-right: 5px; color: #666; } .dl { color: #888; } .empty_list { text-align: center; color: #ccc; font-size: 2em; font-style: italic; padding: 30px; padding-bottom: 100px; } -/* .credentials { width: 205px; margin-bottom: 15px !important; } */ -/* .add_server .txt_fld { width: 205px; } */ -/* .add_server .port_fld { width: 50px; } */ -/* .server_title { font-size: 110%; margin-bottom: 0px; color: #666; } */ -.server_subtitle { margin-bottom: 20px; color: #666; overflow: hidden; text-overflow: ellipsis} +.credentials { width: 205px; margin-bottom: 15px !important; } +.add_server .txt_fld { width: 205px; } +.add_server .port_fld { width: 50px; } +.server_title { font-size: 110%; margin-bottom: 0px; color: #666; } +.server_subtitle {font-size: x-small; color: teal; overflow: hidden; text-overflow: ellipsis} .msg_text { min-height: 600px; background-color: #fff; height: 100%; } .msg_text_inner { min-height: 300px; font-family: monospace; width: 90%; padding: 30px; padding-left: 40px; } /* .msg_headers { max-width: 100%; border-bottom: solid 1px #ddd; color: #777; padding: 0px; padding-bottom: 10px; padding-top: 10px; } */ diff --git a/modules/ldap_contacts/modules.php b/modules/ldap_contacts/modules.php index c4bdc5edbe..d4cf70c7e8 100644 --- a/modules/ldap_contacts/modules.php +++ b/modules/ldap_contacts/modules.php @@ -317,7 +317,7 @@ class Hm_Handler_load_ldap_settings extends Hm_Handler_Module { public function process() { $connections = array(); foreach (ldap_config($this->config) as $name => $vals) { - if (array_key_exists('auth', $vals) && $vals['auth']) { + if (is_array($vals) && array_key_exists('auth', $vals) && $vals['auth']) { if ((!array_key_exists('user', $vals) || !$vals['user']) && (!array_key_exists('pass', $vals) || !$vals['pass'])) { $connections[$name] = $vals; diff --git a/modules/nux/modules.php b/modules/nux/modules.php index e4b474d354..1142a6ad1f 100644 --- a/modules/nux/modules.php +++ b/modules/nux/modules.php @@ -251,6 +251,23 @@ public function process() { } } +/** + * @subpackage nux/handler + */ +class Hm_Handler_get_nux_service_details extends Hm_Handler_Module { + public function process() { + list($success, $form) = $this->process_form(array('nux_service')); + if ($success) { + if (Nux_Quick_Services::exists($form['nux_service'])) { + $details = Nux_Quick_Services::details($form['nux_service']); + + $this->out('nux_add_service_details', $details); + $this->session->set('nux_add_service_details', $details); + } + } + } +} + /** * @subpackage nux/output */ @@ -298,6 +315,16 @@ protected function output() { } } +/** + * @subpackage nux/output + */ +class Hm_Output_service_details extends Hm_Output_Module { + protected function output() { + $details = $this->get('nux_add_service_details', array()); + $this->out('service_details', json_encode($details)); + } +} + /** * @subpackage nux/output */ diff --git a/modules/nux/services.php b/modules/nux/services.php index 2ba0401f02..1bdc3dc8da 100644 --- a/modules/nux/services.php +++ b/modules/nux/services.php @@ -41,17 +41,17 @@ )); Nux_Quick_Services::add('outlook', array( - 'server' => 'imap.live.com', + 'server' => 'outlook.office365.com', 'type' => 'imap', 'tls' => true, 'port' => 993, 'name' => 'Outlook.com', 'scope' => 'wl.imap', - /*'smtp' => array( - 'server' => 'smtp.live.com', + 'smtp' => array( + 'server' => 'smtp.office365.com', 'port' => 587, - 'tls'=> 'yes' - )*/ + 'tls'=> false + ) )); Nux_Quick_Services::add('office365', array( @@ -77,7 +77,7 @@ 'auth' => 'login', 'smtp' => array( 'server' => 'smtp.mail.yahoo.com', - 'port' => 587, + 'port' => 465, 'tls' => true ) )); diff --git a/modules/nux/setup.php b/modules/nux/setup.php index b5baa213e0..2a3e519cfb 100644 --- a/modules/nux/setup.php +++ b/modules/nux/setup.php @@ -6,7 +6,7 @@ output_source('nux'); /* servers page */ -add_output('servers', 'quick_add_section', true, 'nux', 'server_content_start', 'after'); +add_output('servers', 'quick_add_section', true, 'nux', 'server_config_stepper_accordion_end_part', 'after'); add_output('servers', 'quick_add_dialog', true, 'nux', 'quick_add_section', 'after'); add_handler('ajax_nux_service_select', 'login', false, 'core'); @@ -18,6 +18,14 @@ add_handler('ajax_nux_service_select', 'http_headers', true, 'core'); add_output('ajax_nux_service_select', 'filter_service_select', true); +add_handler('ajax_get_nux_service_details', 'login', false, 'core'); +add_handler('ajax_get_nux_service_details', 'load_user_data', true, 'core'); +add_handler('ajax_get_nux_service_details', 'get_nux_service_details', true); +add_handler('ajax_get_nux_service_details', 'language', true, 'core'); +add_handler('ajax_get_nux_service_details', 'date', true, 'core'); +add_handler('ajax_get_nux_service_details', 'http_headers', true, 'core'); +add_output('ajax_get_nux_service_details', 'service_details', true); + add_handler('ajax_nux_add_service', 'login', false, 'core'); add_handler('ajax_nux_add_service', 'load_user_data', true, 'core'); add_handler('ajax_nux_add_service', 'setup_nux', true); @@ -45,7 +53,8 @@ return array( 'allowed_pages' => array( 'ajax_nux_service_select', - 'ajax_nux_add_service', + 'ajax_get_nux_service_details', + 'ajax_nux_add_service' ), 'allowed_get' => array( 'code' => FILTER_DEFAULT, @@ -55,6 +64,7 @@ ), 'allowed_output' => array( 'nux_service_step_two' => array(FILTER_UNSAFE_RAW, false), + 'service_details' => array(FILTER_UNSAFE_RAW, false), 'nux_account_added' => array(FILTER_VALIDATE_BOOLEAN, false), 'nux_server_id' => array(FILTER_VALIDATE_INT, false), 'nux_service_name' => array(FILTER_DEFAULT, false) diff --git a/modules/nux/site.js b/modules/nux/site.js index f8441d8f2f..3cae10a145 100644 --- a/modules/nux/site.js +++ b/modules/nux/site.js @@ -57,7 +57,7 @@ var display_final_nux_step = function(res) { } ); } - + window.location.href = "?page=servers"; } }; diff --git a/modules/profiles/functions.php b/modules/profiles/functions.php new file mode 100644 index 0000000000..2f33deea87 --- /dev/null +++ b/modules/profiles/functions.php @@ -0,0 +1,21 @@ + $name, + 'sig' => $signature, + 'smtp_id' => $smtp_server_id, + 'replyto' => $reply_to, + 'default' => $is_default, + 'address' => $email, + 'server' => $server_mail, + 'user' => $email, + 'type' => 'imap' + ); + + Hm_Profiles::add($profile); + } +} \ No newline at end of file diff --git a/modules/profiles/modules.php b/modules/profiles/modules.php index c1fb2a52a9..35b1013c51 100644 --- a/modules/profiles/modules.php +++ b/modules/profiles/modules.php @@ -9,6 +9,7 @@ if (!defined('DEBUG_MODE')) { die(); } require_once APP_PATH.'modules/profiles/hm-profiles.php'; +require APP_PATH.'modules/profiles/functions.php'; /** * @subpackage profile/handler @@ -262,9 +263,9 @@ protected function output() { foreach ($profiles as $id => $profile) { $smtp = ''; - if ($profile['smtp_id'] !== false && array_key_exists($profile['smtp_id'], $smtp_servers)) { + if (isset($profile['smtp_id']) && is_scalar($profile['smtp_id']) && array_key_exists($profile['smtp_id'], $smtp_servers)) { $smtp = $smtp_servers[$profile['smtp_id']]['name']; - } + } $res .= ''. ''.$this->html_safe($profile['name']).''. ''.$this->html_safe($profile['server']).''. diff --git a/modules/sievefilters/functions.php b/modules/sievefilters/functions.php new file mode 100644 index 0000000000..2b36b22dc7 --- /dev/null +++ b/modules/sievefilters/functions.php @@ -0,0 +1,447 @@ + +
+

General

+ Input a name and order for your filter. In filters, the order of execution is important. You can define an order value (or priority value) for your filter. Filters will run from lowest to highest priority value. +
+
+ + +
+
+ + +
+
+

Sieve Script

+ Paste the Sieve script in the field below. Manually added scripts cannot be edited with the filters interface. +
+
+ +
+
'; + } +} + + +if (!hm_exists('get_classic_filter_modal_content')) { + function get_classic_filter_modal_content() + { + return '
+
+

General

+ Input a name and order for your filter. In filters, the order of execution is important. You can define an order value (or priority value) for your filter. Filters will run from lowest to highest priority value. +
+
+ + +
+
+ + +
+
+ + +
+
+

Conditions & Actions

+ Filters must have at least one action and one condition +
+
+
+
+
+
Conditions
+
+
+ +
+
+
+ +
+
+
+
+
+
+
+
Actions
+
+
+ +
+
+
+ +
+
+
+
+
'; + } +} + +if (!hm_exists('get_mailbox_filters')) { + function get_mailbox_filters($mailbox, $site_config, $user_config, $html=false) + { + $factory = get_sieve_client_factory($site_config); + try { + $client = $factory->init($user_config, $mailbox); + $scripts = []; + foreach ($client->listScripts() as $script) { + if (strstr($script, 'cypht')) { + $scripts[] = $script; + } + } + } catch (Exception $e) { + Hm_Msgs::add("ERRSieve: {$e->getMessage()}"); + return !$html ? []: ''; + } + + if ($html == false) { + return $scripts; + } + + $scripts_sorted = []; + foreach ($scripts as $script_name) { + $exp_name = explode('-', $script_name); + if (end($exp_name) == 'cypht') { + $base_class = 'script'; + } + else if (end($exp_name) == 'cyphtfilter') { + $base_class = 'filter'; + } + else { + continue; + } + $parsed_name = str_replace('_', ' ', $exp_name[0]); + $scripts_sorted[$script_name] = $exp_name[sizeof($exp_name) - 2]; + } + asort($scripts_sorted); + + $script_list = ''; + foreach ($scripts_sorted as $script_name => $sc) { + $exp_name = explode('-', $script_name); + $parsed_name = str_replace('_', ' ', $exp_name[0]); + $script_list .= ' + + '. $exp_name[sizeof($exp_name) - 2] .' + ' . str_replace('_', ' ', implode('-', array_slice($exp_name, 0, count($exp_name) - 2))) . ' + + + + + + + + + + '; + } + return $script_list; + } +} + +if (!hm_exists('generate_main_script')) { + function generate_main_script($script_list) + { + $sorted_list = []; + foreach ($script_list as $script_name) { + if ($script_name == 'main_script') { + continue; + } + + if (strstr($script_name, 'cypht')) { + $ex_name = explode('-', $script_name); + $sorted_list[$script_name] = $ex_name[1]; + } + } + asort($sorted_list); + $include_header = 'require ["include"];'."\n\n"; + $include_body = ''; + + // Block List MUST be the first script executed + $include_body .= 'include :personal "blocked_senders";'."\n"; + + foreach ($sorted_list as $script_name => $include_script) { + $include_body .= 'include :personal "'.$script_name.'";'."\n"; + } + return $include_header.$include_body; + } +} + +if (!hm_exists('generate_script_name')) { + function generate_script_name($name, $priority) + { + return str_replace(' ', '_', strtolower($name)).'-'.$priority.'-cypht'; + } +} + +if (!hm_exists('generate_filter_name')) { + function generate_filter_name($name, $priority) + { + return str_replace(' ', '_', strtolower($name)).'-'.$priority.'-cyphtfilter'; + } +} + +if (!hm_exists('get_sieve_client_factory')) { + function get_sieve_client_factory($site_config) + { + if (!is_null($site_config) && isset($site_config) && $factory_class = $site_config->get('sieve_client_factory')) { + return new $factory_class; + } else { + return new Hm_Sieve_Client_Factory; + } + } +} + +if (!hm_exists('get_domain')) { + function get_domain($email) + { + $domain = explode('@', $email)[1]; + if (preg_match('/(?P[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) { + return $regs['domain']; + } + return false; + } +} + +if (!hm_exists('default_reject_message')) { + function default_reject_message($user_config, $imap_server_id) + { + $reject_message = ''; + if ($user_config->get('sieve_block_default_reject_message')) { + if (array_key_exists($imap_server_id, $user_config->get('sieve_block_default_reject_message'))) { + $reject_message = $user_config->get('sieve_block_default_reject_message')[$imap_server_id]; + } + } + return $reject_message; + } +} + +if (!hm_exists('block_filter')) { + function block_filter($filter, $user_config, $action, $imap_server_id, $sender, $custom_reject_message = '') + { + $ret = ['action' => $action]; + + if (explode('@', $sender)[0] == '*') { + $filter->addRequirement('regex'); + } + $custom_condition = new \PhpSieveManager\Filters\Condition( + "", 'anyof' + ); + $cond = \PhpSieveManager\Filters\FilterCriteria::if('header'); + $cond->contains('"From" ["'.$sender.'"]'); + + if ($action == 'default') { + $default_behaviour = 'Discard'; + if ($user_config->get('sieve_block_default_behaviour')) { + if (array_key_exists($imap_server_id, $user_config->get('sieve_block_default_behaviour'))) { + $default_behaviour = $user_config->get('sieve_block_default_behaviour')[$imap_server_id]; + if ($default_behaviour == 'Reject') { + $reject_message = default_reject_message($user_config, $imap_server_id); + } + } + } + } elseif ($action == 'discard') { + $default_behaviour = 'Discard'; + } elseif ($action == 'reject_default') { + $default_behaviour = 'Reject'; + $reject_message = default_reject_message($user_config, $imap_server_id); + $ret['reject_message'] = $reject_message; + } elseif ($action == 'reject_with_message') { + $default_behaviour = 'Reject'; + $reject_message = $custom_reject_message; + $ret['reject_message'] = $custom_reject_message; + } elseif ($action == 'blocked') { + $default_behaviour = 'Move'; + } + + $custom_condition->addCriteria($cond); + + if ($default_behaviour == 'Discard') { + $custom_condition->addAction( + new \PhpSieveManager\Filters\Actions\DiscardFilterAction() + ); + } + elseif ($default_behaviour == 'Reject') { + $filter->addRequirement('reject'); + $custom_condition->addAction( + new \PhpSieveManager\Filters\Actions\RejectFilterAction([$reject_message]) + ); + } + elseif ($default_behaviour == 'Move') { + $filter->addRequirement('fileinto'); + $custom_condition->addAction( + new \PhpSieveManager\Filters\Actions\FileIntoFilterAction(['Blocked']) + ); + } + + $custom_condition->addAction( + new \PhpSieveManager\Filters\Actions\StopFilterAction() + ); + + $filter->setCondition($custom_condition); + + return $ret; + } +} + +if (!hm_exists('block_filter_dropdown')) { + function block_filter_dropdown($mod, $with_scope = true, $submit_id = 'block_sender', $submit_title = 'Block') { + $ret = ''; + return $ret; + } +} + +if (!hm_exists('get_blocked_senders_array')) { + function get_blocked_senders_array($mailbox, $site_config, $user_config) + { + $factory = get_sieve_client_factory($site_config); + try { + $client = $factory->init($user_config, $mailbox); + $scripts = $client->listScripts(); + + if (array_search('blocked_senders', $scripts, true) === false) { + return []; + } + + $blocked_senders = []; + $current_script = $client->getScript('blocked_senders'); + if ($current_script != '') { + $base64_obj = str_replace("# ", "", preg_split('#\r?\n#', $current_script, 0)[1]); + $blocked_list = json_decode(base64_decode($base64_obj)); + if (!$blocked_list) { + return []; + } + foreach ($blocked_list as $blocked_sender) { + if (explode('@', $blocked_sender)[0] == '') { + $blocked_sender = '*' . $blocked_sender; + } + $blocked_senders[] = $blocked_sender; + } + } + return $blocked_senders; + } catch (Exception $e) { + Hm_Msgs::add("ERRSieve: {$e->getMessage()}"); + return []; + } + } +} + +if (!hm_exists('get_blocked_senders')){ + function get_blocked_senders($mailbox, $mailbox_id, $icon_svg, $icon_block_domain_svg, $site_config, $user_config, $module) { + $factory = get_sieve_client_factory($site_config); + try { + $client = $factory->init($user_config, $mailbox); + $scripts = $client->listScripts(); + if (array_search('blocked_senders', $scripts, true) === false) { + return ''; + } + $current_script = $client->getScript('blocked_senders'); + $blocked_list_actions = []; + if ($current_script != '') { + $script_split = preg_split('#\r?\n#', $current_script, 0); + if (!isset($script_split[1])) { + return ''; + } + $base64_obj = str_replace("# ", "", $script_split[1]); + $blocked_list = json_decode(base64_decode($base64_obj)); + if (!$blocked_list) { + return ''; + } + if (isset($script_split[2])) { + $base64_obj_actions = str_replace("# ", "", $script_split[2]); + $blocked_list_actions = json_decode(base64_decode($base64_obj_actions), true); + } + foreach ($blocked_list as $blocked_sender) { + if (explode('@', $blocked_sender)[0] == '') { + $blocked_sender = '*'.$blocked_sender; + } + $blocked_senders[] = $blocked_sender; + } + } + + $actions_map = [ + 'blocked' => $module->trans('Move To Blocked'), + 'reject_with_message' => $module->trans('Reject With Message'), + 'reject_default' => $module->trans('Reject'), + 'discard' => $module->trans('Discard'), + 'default' => $module->trans('Default'), + ]; + $ret = ''; + foreach ($blocked_senders as $sender) { + $reject_message = $blocked_list_actions[$sender]['reject_message']; + $ret .= ''.$sender.''; + if (is_array($blocked_list_actions) && array_key_exists($sender, $blocked_list_actions)) { + $action = $blocked_list_actions[$sender]['action'] ?: 'default'; + $ret .= $actions_map[$action]; + if ($action == 'reject_with_message') { + $ret .= ' - '.$reject_message; + } + } else { + $action = 'default'; + $ret .= 'Default'; + } + $ret .= ' '; + $ret .= ''; + if (!strstr($sender, '*')) { + $ret .= ' '; + } + $ret .= ''; + } + return $ret; + } catch (Exception $e) { + Hm_Msgs::add("ERRSieve: {$e->getMessage()}"); + return ''; + } + } +} + +if (!hm_exists('initialize_sieve_client_factory')) { + function initialize_sieve_client_factory($site_config, $user_config, $imapServer) + { + $factory = get_sieve_client_factory($site_config); + return $factory->init($user_config, $imapServer); + } + +} \ No newline at end of file diff --git a/modules/sievefilters/hm-sieve.php b/modules/sievefilters/hm-sieve.php new file mode 100644 index 0000000000..c2a0a71ea2 --- /dev/null +++ b/modules/sievefilters/hm-sieve.php @@ -0,0 +1,21 @@ + +connect($imap_account['user'], $imap_account['pass'], $sieve_tls, "", "PLAIN"); + return $client; + } else { + $errorMsg = 'Invalid config host'; + if (isset($imap_account['name'])) { + $errorMsg .= ' for ' . $imap_account['name']; + } + throw new Exception($errorMsg); + } + } +} + diff --git a/modules/sievefilters/modules.php b/modules/sievefilters/modules.php index 097a414309..be18178774 100644 --- a/modules/sievefilters/modules.php +++ b/modules/sievefilters/modules.php @@ -12,6 +12,8 @@ require_once APP_PATH.'modules/imap/functions.php'; require_once APP_PATH.'modules/imap/hm-imap.php'; +require_once APP_PATH.'modules/sievefilters/hm-sieve.php'; +require_once APP_PATH.'modules/sievefilters/functions.php'; /** * @subpackage sievefilters/handler @@ -202,74 +204,6 @@ public function process() { } } -function get_blocked_senders($mailbox, $mailbox_id, $icon_svg, $icon_block_domain_svg, $site_config, $user_config, $module) { - $factory = get_sieve_client_factory($site_config); - try { - $client = $factory->init($user_config, $mailbox); - $scripts = $client->listScripts(); - if (array_search('blocked_senders', $scripts, true) === false) { - return ''; - } - $current_script = $client->getScript('blocked_senders'); - $blocked_list_actions = []; - if ($current_script != '') { - $script_split = preg_split('#\r?\n#', $current_script, 0); - if (!isset($script_split[1])) { - return ''; - } - $base64_obj = str_replace("# ", "", $script_split[1]); - $blocked_list = json_decode(base64_decode($base64_obj)); - if (!$blocked_list) { - return ''; - } - if (isset($script_split[2])) { - $base64_obj_actions = str_replace("# ", "", $script_split[2]); - $blocked_list_actions = json_decode(base64_decode($base64_obj_actions), true); - } - foreach ($blocked_list as $blocked_sender) { - if (explode('@', $blocked_sender)[0] == '') { - $blocked_sender = '*'.$blocked_sender; - } - $blocked_senders[] = $blocked_sender; - } - } - - $actions_map = [ - 'blocked' => $module->trans('Move To Blocked'), - 'reject_with_message' => $module->trans('Reject With Message'), - 'reject_default' => $module->trans('Reject'), - 'discard' => $module->trans('Discard'), - 'default' => $module->trans('Default'), - ]; - $ret = ''; - foreach ($blocked_senders as $sender) { - $reject_message = $blocked_list_actions[$sender]['reject_message']; - $ret .= ''.$sender.''; - if (is_array($blocked_list_actions) && array_key_exists($sender, $blocked_list_actions)) { - $action = $blocked_list_actions[$sender]['action'] ?: 'default'; - $ret .= $actions_map[$action]; - if ($action == 'reject_with_message') { - $ret .= ' - '.$reject_message; - } - } else { - $action = 'default'; - $ret .= 'Default'; - } - $ret .= ' '; - $ret .= ''; - if (!strstr($sender, '*')) { - $ret .= ' '; - } - $ret .= ''; - } - return $ret; - } catch (Exception $e) { - Hm_Msgs::add("ERRSieve: {$e->getMessage()}"); - return ''; - } -} - - /** * @subpackage sievefilters/handler */ @@ -1228,39 +1162,6 @@ protected function output() { } } -function get_blocked_senders_array($mailbox, $site_config, $user_config) { - $factory = get_sieve_client_factory($site_config); - try { - $client = $factory->init($user_config, $mailbox); - $scripts = $client->listScripts(); - - if (array_search('blocked_senders', $scripts, true) === false) { - return []; - } - - $blocked_senders = []; - $current_script = $client->getScript('blocked_senders'); - if ($current_script != '') { - $base64_obj = str_replace("# ", "", preg_split('#\r?\n#', $current_script, 0)[1]); - $blocked_list = json_decode(base64_decode($base64_obj)); - if (!$blocked_list) { - return []; - } - foreach ($blocked_list as $blocked_sender) { - if (explode('@', $blocked_sender)[0] == '') { - $blocked_sender = '*'.$blocked_sender; - } - $blocked_senders[] = $blocked_sender; - } - } - return $blocked_senders; - } catch (Exception $e) { - Hm_Msgs::add("ERRSieve: {$e->getMessage()}"); - return []; - } -} - - /** * @subpackage sievefilters/handler */ @@ -1437,8 +1338,9 @@ public function process() { $this->out('sieve_server_capabilities', self::$capabilities[$imap_account['sieve_config_host']]); continue; } - $clientFactory = new Hm_Sieve_Client_Factory(); - $client = $clientFactory->init(null, $imap_account); + + $client = initialize_sieve_client_factory(null, null, $imap_account); + if ($client) { $this->out('sieve_server_capabilities', $client->getCapabilities()); self::$capabilities[$imap_account['sieve_config_host']] = $client->getCapabilities(); @@ -1447,351 +1349,4 @@ public function process() { } } } -} - -if (!hm_exists('get_script_modal_content')) { - function get_script_modal_content() - { - return '
-
-

General

- Input a name and order for your filter. In filters, the order of execution is important. You can define an order value (or priority value) for your filter. Filters will run from lowest to highest priority value. -
-
- - -
-
- - -
-
-

Sieve Script

- Paste the Sieve script in the field below. Manually added scripts cannot be edited with the filters interface. -
-
- -
-
'; - } -} - - -if (!hm_exists('get_classic_filter_modal_content')) { - function get_classic_filter_modal_content() - { - return '
-
-

General

- Input a name and order for your filter. In filters, the order of execution is important. You can define an order value (or priority value) for your filter. Filters will run from lowest to highest priority value. -
-
- - -
-
- - -
-
- - -
-
-

Conditions & Actions

- Filters must have at least one action and one condition -
-
-
-
-
-
Conditions
-
-
- -
-
-
- -
-
-
-
-
-
-
-
Actions
-
-
- -
-
-
- -
-
-
-
-
'; - } -} - -if (!hm_exists('get_mailbox_filters')) { - function get_mailbox_filters($mailbox, $site_config, $user_config, $html=false) - { - $factory = get_sieve_client_factory($site_config); - try { - $client = $factory->init($user_config, $mailbox); - $scripts = []; - foreach ($client->listScripts() as $script) { - if (strstr($script, 'cypht')) { - $scripts[] = $script; - } - } - } catch (Exception $e) { - Hm_Msgs::add("ERRSieve: {$e->getMessage()}"); - return !$html ? []: ''; - } - - if ($html == false) { - return $scripts; - } - - $scripts_sorted = []; - foreach ($scripts as $script_name) { - $exp_name = explode('-', $script_name); - if (end($exp_name) == 'cypht') { - $base_class = 'script'; - } - else if (end($exp_name) == 'cyphtfilter') { - $base_class = 'filter'; - } - else { - continue; - } - $parsed_name = str_replace('_', ' ', $exp_name[0]); - $scripts_sorted[$script_name] = $exp_name[sizeof($exp_name) - 2]; - } - asort($scripts_sorted); - - $script_list = ''; - foreach ($scripts_sorted as $script_name => $sc) { - $exp_name = explode('-', $script_name); - $parsed_name = str_replace('_', ' ', $exp_name[0]); - $script_list .= ' - - '. $exp_name[sizeof($exp_name) - 2] .' - ' . str_replace('_', ' ', implode('-', array_slice($exp_name, 0, count($exp_name) - 2))) . ' - - - - - - - - - - '; - } - return $script_list; - } -} - -if (!hm_exists('generate_main_script')) { - function generate_main_script($script_list) - { - $sorted_list = []; - foreach ($script_list as $script_name) { - if ($script_name == 'main_script') { - continue; - } - - if (strstr($script_name, 'cypht')) { - $ex_name = explode('-', $script_name); - $sorted_list[$script_name] = $ex_name[1]; - } - } - asort($sorted_list); - $include_header = 'require ["include"];'."\n\n"; - $include_body = ''; - - // Block List MUST be the first script executed - $include_body .= 'include :personal "blocked_senders";'."\n"; - - foreach ($sorted_list as $script_name => $include_script) { - $include_body .= 'include :personal "'.$script_name.'";'."\n"; - } - return $include_header.$include_body; - } -} - -if (!hm_exists('generate_script_name')) { - function generate_script_name($name, $priority) - { - return str_replace(' ', '_', strtolower($name)).'-'.$priority.'-cypht'; - } -} - -if (!hm_exists('generate_filter_name')) { - function generate_filter_name($name, $priority) - { - return str_replace(' ', '_', strtolower($name)).'-'.$priority.'-cyphtfilter'; - } -} - -if (!hm_exists('get_sieve_client_factory')) { - function get_sieve_client_factory($site_config) - { - if ($factory_class = $site_config->get('sieve_client_factory')) { - return new $factory_class; - } else { - return new Hm_Sieve_Client_Factory; - } - } -} - -if (!hm_exists('get_domain')) { - function get_domain($email) - { - $domain = explode('@', $email)[1]; - if (preg_match('/(?P[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) { - return $regs['domain']; - } - return false; - } -} - -if (!hm_exists('default_reject_message')) { - function default_reject_message($user_config, $imap_server_id) - { - $reject_message = ''; - if ($user_config->get('sieve_block_default_reject_message')) { - if (array_key_exists($imap_server_id, $user_config->get('sieve_block_default_reject_message'))) { - $reject_message = $user_config->get('sieve_block_default_reject_message')[$imap_server_id]; - } - } - return $reject_message; - } -} - -if (!hm_exists('block_filter')) { - function block_filter($filter, $user_config, $action, $imap_server_id, $sender, $custom_reject_message = '') - { - $ret = ['action' => $action]; - - if (explode('@', $sender)[0] == '*') { - $filter->addRequirement('regex'); - } - $custom_condition = new \PhpSieveManager\Filters\Condition( - "", 'anyof' - ); - $cond = \PhpSieveManager\Filters\FilterCriteria::if('header'); - $cond->contains('"From" ["'.$sender.'"]'); - - if ($action == 'default') { - $default_behaviour = 'Discard'; - if ($user_config->get('sieve_block_default_behaviour')) { - if (array_key_exists($imap_server_id, $user_config->get('sieve_block_default_behaviour'))) { - $default_behaviour = $user_config->get('sieve_block_default_behaviour')[$imap_server_id]; - if ($default_behaviour == 'Reject') { - $reject_message = default_reject_message($user_config, $imap_server_id); - } - } - } - } elseif ($action == 'discard') { - $default_behaviour = 'Discard'; - } elseif ($action == 'reject_default') { - $default_behaviour = 'Reject'; - $reject_message = default_reject_message($user_config, $imap_server_id); - $ret['reject_message'] = $reject_message; - } elseif ($action == 'reject_with_message') { - $default_behaviour = 'Reject'; - $reject_message = $custom_reject_message; - $ret['reject_message'] = $custom_reject_message; - } elseif ($action == 'blocked') { - $default_behaviour = 'Move'; - } - - $custom_condition->addCriteria($cond); - - if ($default_behaviour == 'Discard') { - $custom_condition->addAction( - new \PhpSieveManager\Filters\Actions\DiscardFilterAction() - ); - } - elseif ($default_behaviour == 'Reject') { - $filter->addRequirement('reject'); - $custom_condition->addAction( - new \PhpSieveManager\Filters\Actions\RejectFilterAction([$reject_message]) - ); - } - elseif ($default_behaviour == 'Move') { - $filter->addRequirement('fileinto'); - $custom_condition->addAction( - new \PhpSieveManager\Filters\Actions\FileIntoFilterAction(['Blocked']) - ); - } - - $custom_condition->addAction( - new \PhpSieveManager\Filters\Actions\StopFilterAction() - ); - - $filter->setCondition($custom_condition); - - return $ret; - } -} - -if (!hm_exists('block_filter_dropdown')) { - function block_filter_dropdown($mod, $with_scope = true, $submit_id = 'block_sender', $submit_title = 'Block') { - $ret = ''; - return $ret; - } -} - -class Hm_Sieve_Client_Factory { - public function init($user_config = null, $imap_account = null) - { - if ($imap_account && ! empty($imap_account['sieve_config_host'])) { - list($sieve_host, $sieve_port, $sieve_tls) = parse_sieve_config_host($imap_account['sieve_config_host']); - $client = new PhpSieveManager\ManageSieve\Client($sieve_host, $sieve_port); - $client->connect($imap_account['user'], $imap_account['pass'], $sieve_tls, "", "PLAIN"); - return $client; - } else { - $errorMsg = 'Invalid config host'; - if (isset($imap_account['name'])) { - $errorMsg .= ' for ' . $imap_account['name']; - } - throw new Exception($errorMsg); - } - } } \ No newline at end of file diff --git a/modules/smtp/functions.php b/modules/smtp/functions.php new file mode 100644 index 0000000000..f9e9852119 --- /dev/null +++ b/modules/smtp/functions.php @@ -0,0 +1,30 @@ + $name, + 'server' => $address, + 'hide' => false, + 'port' => $port, + 'user' => $user, + 'pass' => $pass, + 'tls' => $tls); + + $smtp_server_id = Hm_SMTP_List::add($smtp_list); + $server = Hm_SMTP_List::get($smtp_server_id, false); + + $result = Hm_SMTP_List::service_connect($smtp_server_id, $server, $user, $pass, false); + + return $result; + } +} + +if (!hm_exists('delete_smtp_server')) { + function delete_smtp_server($smtp_server_id) { + Hm_SMTP_List::del($smtp_server_id); + } +} \ No newline at end of file diff --git a/modules/smtp/modules.php b/modules/smtp/modules.php index b15f9327d6..14432a235a 100644 --- a/modules/smtp/modules.php +++ b/modules/smtp/modules.php @@ -11,6 +11,7 @@ use League\CommonMark\GithubFlavoredMarkdownConverter; define('MAX_RECIPIENT_WARNING', 20); +require_once APP_PATH.'modules/smtp/functions.php'; require APP_PATH.'modules/smtp/hm-smtp.php'; require APP_PATH.'modules/smtp/hm-mime-message.php'; @@ -59,9 +60,9 @@ public function process() { if (!array_key_exists('From', $msg_header) || count($msg_header) == 0) { return; } - + # Attachment Download - # Draft attachments must be redownloaded and added to the file cache to prevent + # Draft attachments must be redownloaded and added to the file cache to prevent # attachments from being deleted when editing a previously saved draft. $attached_files = []; $this->session->set('uploaded_files', array()); @@ -118,7 +119,7 @@ public function process() { if (!$this->module_is_supported('imap')) { return; } - + if (array_key_exists('forward', $this->request->get)) { $path = explode('_', $this->request->get['list_path']); $imap = Hm_IMAP_List::connect($path[1]); @@ -228,26 +229,26 @@ public function process() { Hm_Msgs::add('ERRerror '.$file['error'].' in file '.$this->request->get['resumableFilename']); continue; } - + if(isset($this->request->get['resumableIdentifier']) && trim($this->request->get['resumableIdentifier'])!=''){ $temp_dir = $filepath.'/'.$userpath.'/chunks-'.$this->request->get['resumableIdentifier']; } $dest_file = $temp_dir.'/'.$this->request->get['resumableFilename'].'.part'.$this->request->get['resumableChunkNumber']; - + // create the temporary directory if (!is_dir($temp_dir)) { mkdir($temp_dir, 0777, true); } - + // move the temporary file if (!move_uploaded_file($file['tmp_name'], $dest_file)) { Hm_Msgs::add('ERRError saving (move_uploaded_file) chunk '.$this->request->get['resumableChunkNumber'].' for file '.$this->request->get['resumableFilename']); } else { // check if all the parts present, and create the final destination file $result = createFileFromChunks($temp_dir, $this->request->get['resumableFilename'], - $this->request->get['resumableChunkSize'], + $this->request->get['resumableChunkSize'], $this->request->get['resumableTotalSize'], - $this->request->get['resumableTotalChunks']); + $this->request->get['resumableTotalChunks']); } } } @@ -273,7 +274,7 @@ public function process() { delete_uploaded_files($this->session, $draft_id); return; } - + if ($this->module_is_supported('imap')) { $uploaded_files = explode(',', $uploaded_files); $userpath = md5($this->session->get('username', false)); @@ -347,7 +348,7 @@ public function process() { if ($draft_id <= 0 && array_key_exists('uid', $this->request->get)) { $draft_id = $this->request->get['uid']; } - + $this->out('uploaded_files', get_uploaded_files($draft_id, $this->session)); $compose_type = $this->user_config->get('smtp_compose_type_setting', 0); if ($this->get('is_mobile', false)) { @@ -388,6 +389,7 @@ public function process() { 'server' => $form['new_smtp_address'], 'port' => $form['new_smtp_port'], 'tls' => $tls)); + Hm_Msgs::add('Added SMTP server!'); $this->session->record_unsaved('SMTP server added'); } @@ -539,11 +541,11 @@ class Hm_Handler_profile_status extends Hm_Handler_Module { public function process() { $profiles = $this->user_config->get('profiles'); $profile_value = $this->request->post['profile_value']; - + if (!strstr($profile_value, '.')) { Hm_Msgs::add('ERRPlease create a profile for saving sent messages'); return; - } + } $profile = profile_from_compose_smtp_id($profiles, $profile_value); if (!$profile) { Hm_Msgs::add('ERRPlease create a profile for saving sent messages'); @@ -635,7 +637,7 @@ function get_mime_type($filename) * @subpackage smtp/handler */ class Hm_Handler_process_compose_form_submit extends Hm_Handler_Module { - public function process() { + public function process() { /* not sending */ if (!array_key_exists('smtp_send', $this->request->post)) { $this->out('enable_attachment_reminder', $this->user_config->get('enable_attachment_reminder_setting', false)); @@ -759,7 +761,7 @@ public function process() { if ($form['post_archive']) { $msg_path = explode('_', $this->request->post['compose_msg_path']); $msg_uid = $this->request->post['compose_msg_uid']; - + $imap = Hm_IMAP_List::connect($msg_path[1]); if ($imap->select_mailbox(hex2bin($msg_path[2]))) { $specials = get_special_folders($this, $msg_path[1]); @@ -863,19 +865,19 @@ protected function output() { $size_in_kbs = 0; $num_chunks = 0; $rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->get('attachment_dir'))); - $files = array(); - + $files = array(); + foreach ($rii as $file) { if ($file->getFilename() == '.' || $file->getFilename() == '..') { continue; } - if ($file->isDir()){ + if ($file->isDir()){ continue; } if (strpos($file->getPathname(), '.part') !== False) { $num_chunks++; $size_in_kbs += filesize($file->getPathname()); - $files[] = $file->getPathname(); + $files[] = $file->getPathname(); } } if ($size_in_kbs > 0) { @@ -998,7 +1000,7 @@ protected function output() { $msg_path = $this->get('list_path', ''); $msg_uid = $this->get('uid', ''); $from = $this->get('compose_from'); - + if (!$msg_path) { $msg_path = $this->get('compose_msg_path', ''); } @@ -1063,13 +1065,13 @@ protected function output() { } $draft_id = $msg_uid; } - + // User clicked on compose if ($reply_type) { $imap_server_id = explode('_', $msg_path)[1]; $imap_server = Hm_IMAP_List::get($imap_server_id, false); $reply_from = process_address_fld($reply['msg_headers']['From']); - + if ($reply_type == 'reply_all' && $reply_from[0]['email'] != $imap_server['user'] && strpos($to, $reply_from[0]['email']) === false) { $to .= ', '.$reply_from[0]['label'].' '.$reply_from[0]['email']; } @@ -1350,8 +1352,15 @@ protected function output() { if ($this->get('single_server_mode')) { return ''; } - $res = ''; - foreach ($this->get('smtp_servers', array()) as $index => $vals) { + + $list = $this->get('smtp_servers', array()); + + if (empty($list)) { + return ''; + } + + $res = '
SMTP Servers
'; + foreach ($list as $index => $vals) { $no_edit = false; @@ -1373,24 +1382,34 @@ protected function output() { $disabled = ''; $pass_value = ''; } - $res .= '
'; - $res .= sprintf('
%s
%s/%d %s
', - $this->html_safe($vals['name']), $this->html_safe($vals['server']), $this->html_safe($vals['port']), $vals['tls'] ? 'TLS' : '' ); - + $res .= '
'; + $res .= '
'; $res .= ''; $res .= ''; - + $res .= ' + + + + + +
'; + $res .= sprintf('
+
%s
+
%s/%d %s
+
', + $this->html_safe($vals['name']), $this->html_safe($vals['server']), $this->html_safe($vals['port']), $vals['tls'] ? 'TLS' : '' ); + $res .= '
'; + // SMTP Username - $res .= '
'; + $res .= '
'; $res .= ''; $res .= '
'; - + $res .= '
'; + // SMTP Password - $res .= '
'; + $res .= '
'; $res .= ''; $res .= '
'; - + $res .= '
'; + // Buttons if (!$no_edit) { if (!isset($vals['user']) || !$vals['user']) { @@ -1404,11 +1423,16 @@ protected function output() { } $res .= ''; } - $res .= ''; - $res .= ''; + $res .= '
+ '; + + $res .= '
'; } - $res .= '
'; + $res .= '
'; return $res; } } @@ -1431,6 +1455,48 @@ protected function output() { } } +/** + * @subpackage + */ +class Hm_Output_stepper_setup_server_smtp extends Hm_Output_Module { + protected function output() { + return ' +
+ +
+ + + +
+
+
+
+ + + +
+ +
+
+
+ + +
+
+ + +
+
+
+
+ '; + } +} + /** * @subpackage smtp/functions */ @@ -1584,7 +1650,7 @@ function save_uploaded_file($id, $atts, $session) { function format_attachment_row($file, $output_mod) { $unique_identifier = str_replace(' ', '_', $output_mod->html_safe($file['name'])); return ''. - $output_mod->html_safe($file['name']).''.$output_mod->html_safe($file['type']).' ' .$output_mod->html_safe(round($file['size']/1024, 2)). 'KB '. + $output_mod->html_safe($file['name']).''.$output_mod->html_safe($file['type']).' ' .$output_mod->html_safe(round($file['size']/1024, 2)). 'KB '. ''. 'Remove'. '