/** * **/ function saveMail($backend) { $settings = array(); $old_settings = getSettingsTable(); $val = CAT_Helper_Validate::getInstance(); global $groups, $err_msg; foreach ($groups['mail'] as $key) { $settings[$key] = $val->sanitizePost($key); } // email should be validated by core // Work-out which mailer routine should be checked if (isset($settings['server_email']) && !$val->validate_email($settings['server_email'])) { $err_msg[] = $backend->lang()->translate('Invalid default sender eMail address!'); } $catmailer_default_sendername = isset($settings['catmailer_default_sendername']) ? $settings['catmailer_default_sendername'] : $old_settings['catmailer_default_sendername']; if ($catmailer_default_sendername != '') { $settings['catmailer_default_sendername'] = $catmailer_default_sendername; } else { $err_msg[] = $backend->lang()->translate('This field is required') . ': ' . $backend->lang()->translate('Default Sender Name'); } $catmailer_routine = isset($settings['catmailer_routine']) ? $settings['catmailer_routine'] : $old_settings['catmailer_routine']; if ($catmailer_routine == 'smtp') { $pattern = '#https?://([A-Z0-9][^:][A-Z.0-9_-]+[a-z]{2,6})#ix'; $catmailer_smtp_host = isset($settings['catmailer_smtp_host']) ? $settings['catmailer_smtp_host'] : $old_settings['catmailer_smtp_host']; if (preg_match($pattern, $catmailer_smtp_host, $array)) { $catmailer_smtp_host = $array[0]; } if (isset($catmailer_smtp_host)) { if (isset($catmailer_smtp_host) && $catmailer_smtp_host != '') { $settings['catmailer_smtp_host'] = $catmailer_smtp_host; } else { $err_msg[] = $backend->lang()->translate('You must enter details for the following fields') . ': ' . $backend->lang()->translate('SMTP Host'); } } // timeout if (isset($settings['catmailer_smtp_timeout'])) { // silently catch invalid values if (!$settings['catmailer_smtp_timeout'] > 10 && !$settings['catmailer_smtp_timeout'] < 120) { $settings['catmailer_smtp_timeout'] = 30; } } // Work-out if SMTP authentification should be checked $settings['catmailer_smtp_auth'] = !isset($settings['catmailer_smtp_auth']) || $settings['catmailer_smtp_auth'] == '' ? 'false' : 'true'; if ($settings['catmailer_smtp_auth'] == 'true') { $pattern = '/^[a-zA-Z0-9_]{4,30}$/'; $catmailer_smtp_username = isset($settings['catmailer_smtp_username']) ? $settings['catmailer_smtp_username'] : $old_settings['catmailer_smtp_username']; if ($catmailer_smtp_username == '' && !preg_match($pattern, $catmailer_smtp_username)) { $err_msg[] = $backend->lang()->translate('SMTP') . ': ' . $backend->lang()->translate('Username or password incorrect'); } else { $settings['catmailer_smtp_username'] = $catmailer_smtp_username; } $current_password = $val->sanitizePost('catmailer_smtp_password'); $current_password = $current_password == null ? '' : $current_password; if ($current_password == '') { $err_msg[] = $backend->lang()->translate('SMTP') . ': ' . $backend->lang()->translate('Username or password incorrect'); } elseif (!CAT_Users::validatePassword($current_password)) { $err_msg[] = $backend->lang()->translate('Invalid password') . ': ' . CAT_Users::getPasswordError(); } } else { $settings['catmailer_smtp_username'] = ''; $settings['catmailer_smtp_password'] = ''; } } if (!count($err_msg)) { saveSettings($settings); } }