summaryrefslogtreecommitdiff
path: root/Postman/Postman-Configuration
diff options
context:
space:
mode:
Diffstat (limited to 'Postman/Postman-Configuration')
-rw-r--r--Postman/Postman-Configuration/PostmanConfigurationController.php694
-rw-r--r--Postman/Postman-Configuration/PostmanImportableConfiguration.php576
-rw-r--r--Postman/Postman-Configuration/PostmanRegisterConfigurationSettings.php407
-rw-r--r--Postman/Postman-Configuration/PostmanSmtpDiscovery.php233
-rw-r--r--Postman/Postman-Configuration/postman_manual_config.js78
-rw-r--r--Postman/Postman-Configuration/postman_wizard.js569
6 files changed, 2557 insertions, 0 deletions
diff --git a/Postman/Postman-Configuration/PostmanConfigurationController.php b/Postman/Postman-Configuration/PostmanConfigurationController.php
new file mode 100644
index 0000000..58d26d7
--- /dev/null
+++ b/Postman/Postman-Configuration/PostmanConfigurationController.php
@@ -0,0 +1,694 @@
+<?php
+require_once ('PostmanRegisterConfigurationSettings.php');
+class PostmanConfigurationController {
+ const CONFIGURATION_SLUG = 'postman/configuration';
+ const CONFIGURATION_WIZARD_SLUG = 'postman/configuration_wizard';
+
+ // logging
+ private $logger;
+ private $options;
+ private $settingsRegistry;
+
+ // Holds the values to be used in the fields callbacks
+ private $rootPluginFilenameAndPath;
+
+ /**
+ * Constructor
+ *
+ * @param unknown $rootPluginFilenameAndPath
+ */
+ public function __construct($rootPluginFilenameAndPath) {
+ assert ( ! empty ( $rootPluginFilenameAndPath ) );
+ assert ( PostmanUtils::isAdmin () );
+ assert ( is_admin () );
+
+ $this->logger = new PostmanLogger ( get_class ( $this ) );
+ $this->rootPluginFilenameAndPath = $rootPluginFilenameAndPath;
+ $this->options = PostmanOptions::getInstance ();
+ $this->settingsRegistry = new PostmanSettingsRegistry ();
+
+ PostmanUtils::registerAdminMenu ( $this, 'addConfigurationSubmenu' );
+ PostmanUtils::registerAdminMenu ( $this, 'addSetupWizardSubmenu' );
+
+ // hook on the init event
+ add_action ( 'init', array (
+ $this,
+ 'on_init'
+ ) );
+
+ // initialize the scripts, stylesheets and form fields
+ add_action ( 'admin_init', array (
+ $this,
+ 'on_admin_init'
+ ) );
+ }
+
+ /**
+ * Functions to execute on the init event
+ *
+ * "Typically used by plugins to initialize. The current user is already authenticated by this time."
+ * ref: http://codex.wordpress.org/Plugin_API/Action_Reference#Actions_Run_During_a_Typical_Request
+ */
+ public function on_init() {
+ // register Ajax handlers
+ new PostmanGetHostnameByEmailAjaxController ();
+ new PostmanManageConfigurationAjaxHandler ();
+ new PostmanImportConfigurationAjaxController ( $this->options );
+ }
+
+ /**
+ * Fires on the admin_init method
+ */
+ public function on_admin_init() {
+ //
+ $this->registerStylesAndScripts ();
+ $this->settingsRegistry->on_admin_init ();
+ }
+
+ /**
+ * Register and add settings
+ */
+ private function registerStylesAndScripts() {
+ if ($this->logger->isTrace ()) {
+ $this->logger->trace ( 'registerStylesAndScripts()' );
+ }
+ // register the stylesheet and javascript external resources
+ $pluginData = apply_filters ( 'postman_get_plugin_metadata', null );
+ wp_register_script ( 'postman_manual_config_script', plugins_url ( 'Postman/Postman-Configuration/postman_manual_config.js', $this->rootPluginFilenameAndPath ), array (
+ PostmanViewController::JQUERY_SCRIPT,
+ 'jquery_validation',
+ PostmanViewController::POSTMAN_SCRIPT
+ ), $pluginData ['version'] );
+ wp_register_script ( 'postman_wizard_script', plugins_url ( 'Postman/Postman-Configuration/postman_wizard.js', $this->rootPluginFilenameAndPath ), array (
+ PostmanViewController::JQUERY_SCRIPT,
+ 'jquery_validation',
+ 'jquery_steps_script',
+ PostmanViewController::POSTMAN_SCRIPT,
+ 'sprintf'
+ ), $pluginData ['version'] );
+ }
+
+ /**
+ */
+ private function addLocalizeScriptsToPage() {
+ $warning = __ ( 'Warning', Postman::TEXT_DOMAIN );
+ /* translators: where %s is the name of the SMTP server */
+ wp_localize_script ( 'postman_wizard_script', 'postman_smtp_mitm', sprintf ( '%s: %s', $warning, __ ( 'connected to %1$s instead of %2$s.', Postman::TEXT_DOMAIN ) ) );
+ /* translators: where %d is a port number */
+ wp_localize_script ( 'postman_wizard_script', 'postman_wizard_bad_redirect_url', __ ( 'You are about to configure OAuth 2.0 with an IP address instead of a domain name. This is not permitted. Either assign a real domain name to your site or add a fake one in your local host file.', Postman::TEXT_DOMAIN ) );
+
+ // user input
+ wp_localize_script ( PostmanViewController::POSTMAN_SCRIPT, 'postman_input_sender_email', '#input_' . PostmanOptions::MESSAGE_SENDER_EMAIL );
+ wp_localize_script ( PostmanViewController::POSTMAN_SCRIPT, 'postman_input_sender_name', '#input_' . PostmanOptions::MESSAGE_SENDER_NAME );
+ wp_localize_script ( PostmanViewController::POSTMAN_SCRIPT, 'postman_port_element_name', '#input_' . PostmanOptions::PORT );
+ wp_localize_script ( PostmanViewController::POSTMAN_SCRIPT, 'postman_hostname_element_name', '#input_' . PostmanOptions::HOSTNAME );
+
+ // the enc input
+ wp_localize_script ( PostmanViewController::POSTMAN_SCRIPT, 'postman_enc_for_password_el', '#input_enc_type_password' );
+ // these are the ids for the <option>s in the encryption <select>
+
+ // the password inputs
+ wp_localize_script ( PostmanViewController::POSTMAN_SCRIPT, 'postman_input_basic_username', '#input_' . PostmanOptions::BASIC_AUTH_USERNAME );
+ wp_localize_script ( PostmanViewController::POSTMAN_SCRIPT, 'postman_input_basic_password', '#input_' . PostmanOptions::BASIC_AUTH_PASSWORD );
+
+ // the auth input
+ wp_localize_script ( PostmanViewController::POSTMAN_SCRIPT, 'postman_redirect_url_el', '#input_oauth_redirect_url' );
+ wp_localize_script ( PostmanViewController::POSTMAN_SCRIPT, 'postman_input_auth_type', '#input_' . PostmanOptions::AUTHENTICATION_TYPE );
+
+ // the transport modules scripts
+ foreach ( PostmanTransportRegistry::getInstance ()->getTransports () as $transport ) {
+ $transport->enqueueScript ();
+ }
+
+ // we need data from port test
+ PostmanConnectivityTestController::addLocalizeScriptForPortTest ();
+
+ }
+
+ /**
+ * Register the Configuration screen
+ */
+ public function addConfigurationSubmenu() {
+ $page = add_submenu_page ( null, sprintf ( __ ( '%s Setup', Postman::TEXT_DOMAIN ), __ ( 'Postman SMTP', Postman::TEXT_DOMAIN ) ), __ ( 'Postman SMTP', Postman::TEXT_DOMAIN ), Postman::MANAGE_POSTMAN_CAPABILITY_NAME, PostmanConfigurationController::CONFIGURATION_SLUG, array (
+ $this,
+ 'outputManualConfigurationContent'
+ ) );
+ // When the plugin options page is loaded, also load the stylesheet
+ add_action ( 'admin_print_styles-' . $page, array (
+ $this,
+ 'enqueueConfigurationResources'
+ ) );
+ }
+
+ /**
+ */
+ function enqueueConfigurationResources() {
+ $this->addLocalizeScriptsToPage ();
+ wp_enqueue_style ( PostmanViewController::POSTMAN_STYLE );
+ wp_enqueue_style ( 'jquery_ui_style' );
+ wp_enqueue_script ( 'postman_manual_config_script' );
+ wp_enqueue_script ( 'jquery-ui-tabs' );
+ }
+
+ /**
+ * Register the Setup Wizard screen
+ */
+ public function addSetupWizardSubmenu() {
+ $page = add_submenu_page ( null, sprintf ( __ ( '%s Setup', Postman::TEXT_DOMAIN ), __ ( 'Postman SMTP', Postman::TEXT_DOMAIN ) ), __ ( 'Postman SMTP', Postman::TEXT_DOMAIN ), Postman::MANAGE_POSTMAN_CAPABILITY_NAME, PostmanConfigurationController::CONFIGURATION_WIZARD_SLUG, array (
+ $this,
+ 'outputWizardContent'
+ ) );
+ // When the plugin options page is loaded, also load the stylesheet
+ add_action ( 'admin_print_styles-' . $page, array (
+ $this,
+ 'enqueueWizardResources'
+ ) );
+ }
+
+ /**
+ */
+ function enqueueWizardResources() {
+ $this->addLocalizeScriptsToPage ();
+ $this->importableConfiguration = new PostmanImportableConfiguration ();
+ $startPage = 1;
+ if ($this->importableConfiguration->isImportAvailable ()) {
+ $startPage = 0;
+ }
+ wp_localize_script ( PostmanViewController::POSTMAN_SCRIPT, 'postman_setup_wizard', array (
+ 'start_page' => $startPage
+ ) );
+ wp_enqueue_style ( 'jquery_steps_style' );
+ wp_enqueue_style ( PostmanViewController::POSTMAN_STYLE );
+ wp_enqueue_script ( 'postman_wizard_script' );
+ wp_localize_script ( PostmanViewController::POSTMAN_SCRIPT, '$jq', 'jQuery.noConflict(true)' );
+ $shortLocale = substr ( get_locale (), 0, 2 );
+ if ($shortLocale != 'en') {
+ $url = plugins_url ( sprintf ( 'script/jquery-validate/localization/messages_%s.js', $shortLocale ), $this->rootPluginFilenameAndPath );
+ wp_enqueue_script ( sprintf ( 'jquery-validation-locale-%s', $shortLocale ), $url );
+ }
+ }
+
+ /**
+ */
+ public function outputManualConfigurationContent() {
+ print '<div class="wrap">';
+
+ PostmanViewController::outputChildPageHeader ( __ ( 'Settings', Postman::TEXT_DOMAIN ), 'advanced_config' );
+ print '<div id="config_tabs"><ul>';
+ print sprintf ( '<li><a href="#account_config">%s</a></li>', __ ( 'Account', Postman::TEXT_DOMAIN ) );
+ print sprintf ( '<li><a href="#message_config">%s</a></li>', __ ( 'Message', Postman::TEXT_DOMAIN ) );
+ print sprintf ( '<li><a href="#logging_config">%s</a></li>', __ ( 'Logging', Postman::TEXT_DOMAIN ) );
+ print sprintf ( '<li><a href="#advanced_options_config">%s</a></li>', __ ( 'Advanced', Postman::TEXT_DOMAIN ) );
+ print '</ul>';
+ print '<form method="post" action="options.php">';
+ // This prints out all hidden setting fields
+ settings_fields ( PostmanAdminController::SETTINGS_GROUP_NAME );
+ print '<section id="account_config">';
+ if (sizeof ( PostmanTransportRegistry::getInstance ()->getTransports () ) > 1) {
+ do_settings_sections ( 'transport_options' );
+ } else {
+ printf ( '<input id="input_%2$s" type="hidden" name="%1$s[%2$s]" value="%3$s"/>', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::TRANSPORT_TYPE, PostmanSmtpModuleTransport::SLUG );
+ }
+ print '<div id="smtp_config" class="transport_setting">';
+ do_settings_sections ( PostmanAdminController::SMTP_OPTIONS );
+ print '</div>';
+ print '<div id="password_settings" class="authentication_setting non-oauth2">';
+ do_settings_sections ( PostmanAdminController::BASIC_AUTH_OPTIONS );
+ print '</div>';
+ print '<div id="oauth_settings" class="authentication_setting non-basic">';
+ do_settings_sections ( PostmanAdminController::OAUTH_AUTH_OPTIONS );
+ print '</div>';
+ print '<div id="mandrill_settings" class="authentication_setting non-basic non-oauth2">';
+ do_settings_sections ( PostmanMandrillTransport::MANDRILL_AUTH_OPTIONS );
+ print '</div>';
+ print '<div id="sendgrid_settings" class="authentication_setting non-basic non-oauth2">';
+ do_settings_sections ( PostmanSendGridTransport::SENDGRID_AUTH_OPTIONS );
+ print '</div>';
+ print '</section>';
+ print '<section id="message_config">';
+ do_settings_sections ( PostmanAdminController::MESSAGE_SENDER_OPTIONS );
+ do_settings_sections ( PostmanAdminController::MESSAGE_FROM_OPTIONS );
+ do_settings_sections ( PostmanAdminController::EMAIL_VALIDATION_OPTIONS );
+ do_settings_sections ( PostmanAdminController::MESSAGE_OPTIONS );
+ do_settings_sections ( PostmanAdminController::MESSAGE_HEADERS_OPTIONS );
+ print '</section>';
+ print '<section id="logging_config">';
+ do_settings_sections ( PostmanAdminController::LOGGING_OPTIONS );
+ print '</section>';
+ /*
+ * print '<section id="logging_config">';
+ * do_settings_sections ( PostmanAdminController::MULTISITE_OPTIONS );
+ * print '</section>';
+ */
+ print '<section id="advanced_options_config">';
+ do_settings_sections ( PostmanAdminController::NETWORK_OPTIONS );
+ do_settings_sections ( PostmanAdminController::ADVANCED_OPTIONS );
+ print '</section>';
+ submit_button ();
+ print '</form>';
+ print '</div>';
+ print '</div>';
+ }
+
+ /**
+ */
+ public function outputWizardContent() {
+ // Set default values for input fields
+ $this->options->setMessageSenderEmailIfEmpty ( wp_get_current_user ()->user_email );
+ $this->options->setMessageSenderNameIfEmpty ( wp_get_current_user ()->display_name );
+
+ // construct Wizard
+ print '<div class="wrap">';
+
+ PostmanViewController::outputChildPageHeader ( __ ( 'Setup Wizard', Postman::TEXT_DOMAIN ) );
+
+ print '<form id="postman_wizard" method="post" action="options.php">';
+
+ // account tab
+
+ // message tab
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::PREVENT_MESSAGE_SENDER_EMAIL_OVERRIDE, $this->options->isPluginSenderEmailEnforced () );
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::PREVENT_MESSAGE_SENDER_NAME_OVERRIDE, $this->options->isPluginSenderNameEnforced () );
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::REPLY_TO, $this->options->getReplyTo () );
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::FORCED_TO_RECIPIENTS, $this->options->getForcedToRecipients () );
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::FORCED_CC_RECIPIENTS, $this->options->getForcedCcRecipients () );
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::FORCED_BCC_RECIPIENTS, $this->options->getForcedBccRecipients () );
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::ADDITIONAL_HEADERS, $this->options->getAdditionalHeaders () );
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::DISABLE_EMAIL_VALIDAITON, $this->options->isEmailValidationDisabled () );
+
+ // logging tab
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::MAIL_LOG_ENABLED_OPTION, $this->options->getMailLoggingEnabled () );
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::MAIL_LOG_MAX_ENTRIES, $this->options->getMailLoggingMaxEntries () );
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::TRANSCRIPT_SIZE, $this->options->getTranscriptSize () );
+
+ // advanced tab
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::CONNECTION_TIMEOUT, $this->options->getConnectionTimeout () );
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::READ_TIMEOUT, $this->options->getReadTimeout () );
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::LOG_LEVEL, $this->options->getLogLevel () );
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::RUN_MODE, $this->options->getRunMode () );
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::STEALTH_MODE, $this->options->isStealthModeEnabled () );
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::TEMPORARY_DIRECTORY, $this->options->getTempDirectory () );
+
+ // display the setting text
+ settings_fields ( PostmanAdminController::SETTINGS_GROUP_NAME );
+
+ // Wizard Step 0
+ printf ( '<h5>%s</h5>', _x ( 'Import Configuration', 'Wizard Step Title', Postman::TEXT_DOMAIN ) );
+ print '<fieldset>';
+ printf ( '<legend>%s</legend>', _x ( 'Import configuration from another plugin?', 'Wizard Step Title', Postman::TEXT_DOMAIN ) );
+ printf ( '<p>%s</p>', __ ( 'If you had a working configuration with another Plugin, the Setup Wizard can begin with those settings.', Postman::TEXT_DOMAIN ) );
+ print '<table class="input_auth_type">';
+ printf ( '<tr><td><input type="radio" id="import_none" name="input_plugin" value="%s" checked="checked"></input></td><td><label> %s</label></td></tr>', 'none', __ ( 'None', Postman::TEXT_DOMAIN ) );
+
+ if ($this->importableConfiguration->isImportAvailable ()) {
+ foreach ( $this->importableConfiguration->getAvailableOptions () as $options ) {
+ printf ( '<tr><td><input type="radio" name="input_plugin" value="%s"/></td><td><label> %s</label></td></tr>', $options->getPluginSlug (), $options->getPluginName () );
+ }
+ }
+ print '</table>';
+ print '</fieldset>';
+
+ // Wizard Step 1
+ printf ( '<h5>%s</h5>', _x ( 'Sender Details', 'Wizard Step Title', Postman::TEXT_DOMAIN ) );
+ print '<fieldset>';
+ printf ( '<legend>%s</legend>', _x ( 'Who is the mail coming from?', 'Wizard Step Title', Postman::TEXT_DOMAIN ) );
+ printf ( '<p>%s</p>', __ ( 'Enter the email address and name you\'d like to send mail as.', Postman::TEXT_DOMAIN ) );
+ printf ( '<p>%s</p>', __ ( 'Please note that to prevent abuse, many email services will <em>not</em> let you send from an email address other than the one you authenticate with.', Postman::TEXT_DOMAIN ) );
+ printf ( '<label for="postman_options[sender_email]">%s</label>', __ ( 'Email Address', Postman::TEXT_DOMAIN ) );
+ print $this->settingsRegistry->from_email_callback ();
+ print '<br/>';
+ printf ( '<label for="postman_options[sender_name]">%s</label>', __ ( 'Name', Postman::TEXT_DOMAIN ) );
+ print $this->settingsRegistry->sender_name_callback ();
+ print '</fieldset>';
+
+ // Wizard Step 2
+ printf ( '<h5>%s</h5>', __ ( 'Outgoing Mail Server Hostname', Postman::TEXT_DOMAIN ) );
+ print '<fieldset>';
+ foreach ( PostmanTransportRegistry::getInstance ()->getTransports () as $transport ) {
+ $transport->printWizardMailServerHostnameStep ();
+ }
+ print '</fieldset>';
+
+ // Wizard Step 3
+ printf ( '<h5>%s</h5>', __ ( 'Connectivity Test', Postman::TEXT_DOMAIN ) );
+ print '<fieldset>';
+ printf ( '<legend>%s</legend>', __ ( 'How will the connection to the mail server be established?', Postman::TEXT_DOMAIN ) );
+ printf ( '<p>%s</p>', __ ( 'Your connection settings depend on what your email service provider offers, and what your WordPress host allows.', Postman::TEXT_DOMAIN ) );
+ printf ( '<p id="connectivity_test_status">%s: <span id="port_test_status">%s</span></p>', __ ( 'Connectivity Test', Postman::TEXT_DOMAIN ), _x ( 'Ready', 'TCP Port Test Status', Postman::TEXT_DOMAIN ) );
+ printf ( '<p class="ajax-loader" style="display:none"><img src="%s"/></p>', plugins_url ( 'postman-smtp/style/ajax-loader.gif' ) );
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]">', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::TRANSPORT_TYPE );
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]">', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::PORT );
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]">', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::SECURITY_TYPE );
+ printf ( '<input type="hidden" id="input_%2$s" name="%1$s[%2$s]">', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::AUTHENTICATION_TYPE );
+ print '<p id="wizard_recommendation"></p>';
+ /* Translators: Where %1$s is the socket identifier and %2$s is the authentication type */
+ printf ( '<p class="user_override" style="display:none"><label><span>%s:</span></label> <table id="user_socket_override" class="user_override"></table></p>', _x ( 'Socket', 'A socket is the network term for host and port together', Postman::TEXT_DOMAIN ) );
+ printf ( '<p class="user_override" style="display:none"><label><span>%s:</span></label> <table id="user_auth_override" class="user_override"></table></p>', __ ( 'Authentication', Postman::TEXT_DOMAIN ) );
+ print ('<p><span id="smtp_mitm" style="display:none; background-color:yellow"></span></p>') ;
+ $warning = __ ( 'Warning', Postman::TEXT_DOMAIN );
+ $clearCredentialsWarning = __ ( 'This configuration option will send your authorization credentials in the clear.', Postman::TEXT_DOMAIN );
+ printf ( '<p id="smtp_not_secure" style="display:none"><span style="background-color:yellow">%s: %s</span></p>', $warning, $clearCredentialsWarning );
+ print '</fieldset>';
+
+ // Wizard Step 4
+ printf ( '<h5>%s</h5>', __ ( 'Authentication', Postman::TEXT_DOMAIN ) );
+ print '<fieldset>';
+ printf ( '<legend>%s</legend>', __ ( 'How will you prove your identity to the mail server?', Postman::TEXT_DOMAIN ) );
+ foreach ( PostmanTransportRegistry::getInstance ()->getTransports () as $transport ) {
+ $transport->printWizardAuthenticationStep ();
+ }
+ print '</fieldset>';
+
+ // Wizard Step 5
+ printf ( '<h5>%s</h5>', _x ( 'Finish', 'The final step of the Wizard', Postman::TEXT_DOMAIN ) );
+ print '<fieldset>';
+ printf ( '<legend>%s</legend>', _x ( 'You\'re Done!', 'Wizard Step Title', Postman::TEXT_DOMAIN ) );
+ print '<section>';
+ printf ( '<p>%s</p>', __ ( 'Click Finish to save these settings, then:', Postman::TEXT_DOMAIN ) );
+ print '<ul style="margin-left: 20px">';
+ printf ( '<li class="wizard-auth-oauth2">%s</li>', __ ( 'Grant permission with the Email Provider for Postman to send email and', Postman::TEXT_DOMAIN ) );
+ printf ( '<li>%s</li>', __ ( 'Send yourself a Test Email to make sure everything is working!', Postman::TEXT_DOMAIN ) );
+ print '</ul>';
+ print '</section>';
+ print '</fieldset>';
+ print '</form>';
+ print '</div>';
+ }
+}
+
+/**
+ *
+ * @author jasonhendriks
+ *
+ */
+class PostmanGetHostnameByEmailAjaxController extends PostmanAbstractAjaxHandler {
+ const IS_GOOGLE_PARAMETER = 'is_google';
+ function __construct() {
+ parent::__construct ();
+ PostmanUtils::registerAjaxHandler ( 'postman_check_email', $this, 'getAjaxHostnameByEmail' );
+ }
+ /**
+ * This Ajax function retrieves the smtp hostname for a give e-mail address
+ */
+ function getAjaxHostnameByEmail() {
+ $goDaddyHostDetected = $this->getBooleanRequestParameter ( 'go_daddy' );
+ $email = $this->getRequestParameter ( 'email' );
+ $d = new PostmanSmtpDiscovery ( $email );
+ $smtp = $d->getSmtpServer ();
+ $this->logger->debug ( 'given email ' . $email . ', smtp server is ' . $smtp );
+ $this->logger->trace ( $d );
+ if ($goDaddyHostDetected && ! $d->isGoogle) {
+ // override with the GoDaddy SMTP server
+ $smtp = 'relay-hosting.secureserver.net';
+ $this->logger->debug ( 'detected GoDaddy SMTP server, smtp server is ' . $smtp );
+ }
+ $response = array (
+ 'hostname' => $smtp,
+ self::IS_GOOGLE_PARAMETER => $d->isGoogle,
+ 'is_go_daddy' => $d->isGoDaddy,
+ 'is_well_known' => $d->isWellKnownDomain
+ );
+ $this->logger->trace ( $response );
+ wp_send_json_success ( $response );
+ }
+}
+class PostmanManageConfigurationAjaxHandler extends PostmanAbstractAjaxHandler {
+ function __construct() {
+ parent::__construct ();
+ PostmanUtils::registerAjaxHandler ( 'manual_config', $this, 'getManualConfigurationViaAjax' );
+ PostmanUtils::registerAjaxHandler ( 'get_wizard_configuration_options', $this, 'getWizardConfigurationViaAjax' );
+ }
+
+ /**
+ * Handle a Advanced Configuration request with Ajax
+ *
+ * @throws Exception
+ */
+ function getManualConfigurationViaAjax() {
+ $queryTransportType = $this->getTransportTypeFromRequest ();
+ $queryAuthType = $this->getAuthenticationTypeFromRequest ();
+ $queryHostname = $this->getHostnameFromRequest ();
+
+ // the outgoing server hostname is only required for the SMTP Transport
+ // the Gmail API transport doesn't use an SMTP server
+ $transport = PostmanTransportRegistry::getInstance ()->getTransport ( $queryTransportType );
+ if (! $transport) {
+ throw new Exception ( 'Unable to find transport ' . $queryTransportType );
+ }
+
+ // create the response
+ $response = $transport->populateConfiguration ( $queryHostname );
+ $response ['referer'] = 'manual_config';
+
+ // set the display_auth to oauth2 if the transport needs it
+ if ($transport->isOAuthUsed ( $queryAuthType )) {
+ $response ['display_auth'] = 'oauth2';
+ $this->logger->debug ( 'ajaxRedirectUrl answer display_auth:' . $response ['display_auth'] );
+ }
+ $this->logger->trace ( $response );
+ wp_send_json_success ( $response );
+ }
+
+ /**
+ * Once the Port Tests have run, the results are analyzed.
+ * The Transport place bids on the sockets and highest bid becomes the recommended
+ * The UI response is built so the user may choose a different socket with different options.
+ */
+ function getWizardConfigurationViaAjax() {
+ $this->logger->debug ( 'in getWizardConfiguration' );
+ $originalSmtpServer = $this->getRequestParameter ( 'original_smtp_server' );
+ $queryHostData = $this->getHostDataFromRequest ();
+ $sockets = array ();
+ foreach ( $queryHostData as $id => $datum ) {
+ array_push ( $sockets, new PostmanWizardSocket ( $datum ) );
+ }
+ $this->logger->error ( $sockets );
+ $userPortOverride = $this->getUserPortOverride ();
+ $userAuthOverride = $this->getUserAuthOverride ();
+
+ // determine a configuration recommendation
+ $winningRecommendation = $this->getWinningRecommendation ( $sockets, $userPortOverride, $userAuthOverride, $originalSmtpServer );
+ if ($this->logger->isTrace ()) {
+ $this->logger->trace ( 'winning recommendation:' );
+ $this->logger->trace ( $winningRecommendation );
+ }
+
+ // create the reponse
+ $response = array ();
+ $configuration = array ();
+ $response ['referer'] = 'wizard';
+ if (isset ( $userPortOverride ) || isset ( $userAuthOverride )) {
+ $configuration ['user_override'] = true;
+ }
+
+ if (isset ( $winningRecommendation )) {
+
+ // create an appropriate (theoretical) transport
+ $transport = PostmanTransportRegistry::getInstance ()->getTransport ( $winningRecommendation ['transport'] );
+
+ // create user override menu
+ $overrideMenu = $this->createOverrideMenus ( $sockets, $winningRecommendation, $userPortOverride, $userAuthOverride );
+ if ($this->logger->isTrace ()) {
+ $this->logger->trace ( 'override menu:' );
+ $this->logger->trace ( $overrideMenu );
+ }
+
+ $queryHostName = $winningRecommendation ['hostname'];
+ if ($this->logger->isDebug ()) {
+ $this->logger->debug ( 'Getting scribe for ' . $queryHostName );
+ }
+ $generalConfig1 = $transport->populateConfiguration ( $queryHostName );
+ $generalConfig2 = $transport->populateConfigurationFromRecommendation ( $winningRecommendation );
+ $configuration = array_merge ( $configuration, $generalConfig1, $generalConfig2 );
+ $response ['override_menu'] = $overrideMenu;
+ $response ['configuration'] = $configuration;
+ if ($this->logger->isTrace ()) {
+ $this->logger->trace ( 'configuration:' );
+ $this->logger->trace ( $configuration );
+ $this->logger->trace ( 'response:' );
+ $this->logger->trace ( $response );
+ }
+ wp_send_json_success ( $response );
+ } else {
+ /* translators: where %s is the URL to the Connectivity Test page */
+ $configuration ['message'] = sprintf ( __ ( 'Postman can\'t find any way to send mail on your system. Run a <a href="%s">connectivity test</a>.', Postman::TEXT_DOMAIN ), PostmanViewController::getPageUrl ( PostmanViewController::PORT_TEST_SLUG ) );
+ $response ['configuration'] = $configuration;
+ if ($this->logger->isTrace ()) {
+ $this->logger->trace ( 'configuration:' );
+ $this->logger->trace ( $configuration );
+ }
+ wp_send_json_error ( $response );
+ }
+ }
+
+ /**
+ * // for each successful host/port combination
+ * // ask a transport if they support it, and if they do at what priority is it
+ * // configure for the highest priority you find
+ *
+ * @param unknown $queryHostData
+ * @return unknown
+ */
+ private function getWinningRecommendation($sockets, $userSocketOverride, $userAuthOverride, $originalSmtpServer) {
+ foreach ( $sockets as $socket ) {
+ $winningRecommendation = $this->getWin ( $socket, $userSocketOverride, $userAuthOverride, $originalSmtpServer );
+ $this->logger->error ( $socket->label );
+ }
+ return $winningRecommendation;
+ }
+
+ /**
+ *
+ * @param PostmanSocket $socket
+ * @param unknown $userSocketOverride
+ * @param unknown $userAuthOverride
+ * @param unknown $originalSmtpServer
+ * @return Ambigous <NULL, unknown, string>
+ */
+ private function getWin(PostmanWizardSocket $socket, $userSocketOverride, $userAuthOverride, $originalSmtpServer) {
+ static $recommendationPriority = - 1;
+ static $winningRecommendation = null;
+ $available = $socket->success;
+ if ($available) {
+ $this->logger->debug ( sprintf ( 'Asking for judgement on %s:%s', $socket->hostname, $socket->port ) );
+ $recommendation = PostmanTransportRegistry::getInstance ()->getRecommendation ( $socket, $userAuthOverride, $originalSmtpServer );
+ $recommendationId = sprintf ( '%s_%s', $socket->hostname, $socket->port );
+ $recommendation ['id'] = $recommendationId;
+ $this->logger->debug ( sprintf ( 'Got a recommendation: [%d] %s', $recommendation ['priority'], $recommendationId ) );
+ if (isset ( $userSocketOverride )) {
+ if ($recommendationId == $userSocketOverride) {
+ $winningRecommendation = $recommendation;
+ $this->logger->debug ( sprintf ( 'User chosen socket %s is the winner', $recommendationId ) );
+ }
+ } elseif ($recommendation && $recommendation ['priority'] > $recommendationPriority) {
+ $recommendationPriority = $recommendation ['priority'];
+ $winningRecommendation = $recommendation;
+ }
+ $socket->label = $recommendation ['label'];
+ }
+ return $winningRecommendation;
+ }
+
+ /**
+ *
+ * @param unknown $queryHostData
+ * @return multitype:
+ */
+ private function createOverrideMenus($sockets, $winningRecommendation, $userSocketOverride, $userAuthOverride) {
+ $overrideMenu = array ();
+ foreach ( $sockets as $socket ) {
+ $overrideItem = $this->createOverrideMenu ( $socket, $winningRecommendation, $userSocketOverride, $userAuthOverride );
+ if ($overrideItem != null) {
+ $overrideMenu [$socket->id] = $overrideItem;
+ }
+ }
+
+ // sort
+ krsort ( $overrideMenu );
+ $sortedMenu = array ();
+ foreach ( $overrideMenu as $menu ) {
+ array_push ( $sortedMenu, $menu );
+ }
+
+ return $sortedMenu;
+ }
+
+ /**
+ *
+ * @param PostmanWizardSocket $socket
+ * @param unknown $winningRecommendation
+ * @param unknown $userSocketOverride
+ * @param unknown $userAuthOverride
+ */
+ private function createOverrideMenu(PostmanWizardSocket $socket, $winningRecommendation, $userSocketOverride, $userAuthOverride) {
+ if ($socket->success) {
+ $transport = PostmanTransportRegistry::getInstance ()->getTransport ( $socket->transport );
+ $this->logger->debug ( sprintf ( 'Transport %s is building the override menu for socket', $transport->getSlug () ) );
+ $overrideItem = $transport->createOverrideMenu ( $socket, $winningRecommendation, $userSocketOverride, $userAuthOverride );
+ return $overrideItem;
+ }
+ return null;
+ }
+
+ /**
+ */
+ private function getTransportTypeFromRequest() {
+ return $this->getRequestParameter ( 'transport' );
+ }
+
+ /**
+ */
+ private function getHostnameFromRequest() {
+ return $this->getRequestParameter ( 'hostname' );
+ }
+
+ /**
+ */
+ private function getAuthenticationTypeFromRequest() {
+ return $this->getRequestParameter ( 'auth_type' );
+ }
+
+ /**
+ */
+ private function getHostDataFromRequest() {
+ return $this->getRequestParameter ( 'host_data' );
+ }
+
+ /**
+ */
+ private function getUserPortOverride() {
+ return $this->getRequestParameter ( 'user_port_override' );
+ }
+
+ /**
+ */
+ private function getUserAuthOverride() {
+ return $this->getRequestParameter ( 'user_auth_override' );
+ }
+}
+class PostmanImportConfigurationAjaxController extends PostmanAbstractAjaxHandler {
+ private $options;
+ /**
+ * Constructor
+ *
+ * @param PostmanOptions $options
+ */
+ function __construct(PostmanOptions $options) {
+ parent::__construct ();
+ $this->options = $options;
+ PostmanUtils::registerAjaxHandler ( 'import_configuration', $this, 'getConfigurationFromExternalPluginViaAjax' );
+ }
+
+ /**
+ * This function extracts configuration details form a competing SMTP plugin
+ * and pushes them into the Postman configuration screen.
+ */
+ function getConfigurationFromExternalPluginViaAjax() {
+ $importableConfiguration = new PostmanImportableConfiguration ();
+ $plugin = $this->getRequestParameter ( 'plugin' );
+ $this->logger->debug ( 'Looking for config=' . $plugin );
+ foreach ( $importableConfiguration->getAvailableOptions () as $this->options ) {
+ if ($this->options->getPluginSlug () == $plugin) {
+ $this->logger->debug ( 'Sending configuration response' );
+ $response = array (
+ PostmanOptions::MESSAGE_SENDER_EMAIL => $this->options->getMessageSenderEmail (),
+ PostmanOptions::MESSAGE_SENDER_NAME => $this->options->getMessageSenderName (),
+ PostmanOptions::HOSTNAME => $this->options->getHostname (),
+ PostmanOptions::PORT => $this->options->getPort (),
+ PostmanOptions::AUTHENTICATION_TYPE => $this->options->getAuthenticationType (),
+ PostmanOptions::SECURITY_TYPE => $this->options->getEncryptionType (),
+ PostmanOptions::BASIC_AUTH_USERNAME => $this->options->getUsername (),
+ PostmanOptions::BASIC_AUTH_PASSWORD => $this->options->getPassword (),
+ 'success' => true
+ );
+ break;
+ }
+ }
+ if (! isset ( $response )) {
+ $response = array (
+ 'success' => false
+ );
+ }
+ wp_send_json ( $response );
+ }
+}
diff --git a/Postman/Postman-Configuration/PostmanImportableConfiguration.php b/Postman/Postman-Configuration/PostmanImportableConfiguration.php
new file mode 100644
index 0000000..ba807d3
--- /dev/null
+++ b/Postman/Postman-Configuration/PostmanImportableConfiguration.php
@@ -0,0 +1,576 @@
+<?php
+if (! interface_exists ( 'PostmanPluginOptions' )) {
+ interface PostmanPluginOptions {
+ public function getPluginSlug();
+ public function getPluginName();
+ public function isImportable();
+ public function getHostname();
+ public function getPort();
+ public function getMessageSenderEmail();
+ public function getMessageSenderName();
+ public function getAuthenticationType();
+ public function getEncryptionType();
+ public function getUsername();
+ public function getPassword();
+ }
+}
+if (! class_exists ( 'PostmanImportableConfiguration' )) {
+
+ /**
+ * This class instantiates the Connectors for new users to Postman.
+ * It determines which Connectors can supply configuration data
+ *
+ * @author jasonhendriks
+ *
+ */
+ class PostmanImportableConfiguration {
+ private $lazyInit;
+ private $availableOptions;
+ private $importAvailable;
+ private $logger;
+ function __construct() {
+ $this->logger = new PostmanLogger ( get_class ( $this ) );
+ }
+ function init() {
+ if (! $this->lazyInit) {
+ $this->queueIfAvailable ( new PostmanEasyWpSmtpOptions () );
+ $this->queueIfAvailable ( new PostmanWpSmtpOptions () );
+ $this->queueIfAvailable ( new PostmanWpMailBankOptions () );
+ $this->queueIfAvailable ( new PostmanWpMailSmtpOptions () );
+ $this->queueIfAvailable ( new PostmanCimySwiftSmtpOptions () );
+ $this->queueIfAvailable ( new PostmanConfigureSmtpOptions () );
+ }
+ $this->lazyInit = true;
+ }
+ private function queueIfAvailable(PostmanPluginOptions $options) {
+ $slug = $options->getPluginSlug ();
+ if ($options->isImportable ()) {
+ $this->availableOptions [$slug] = $options;
+ $this->importAvailable = true;
+ $this->logger->debug ( $slug . ' is importable' );
+ } else {
+ $this->logger->debug ( $slug . ' is not importable' );
+ }
+ }
+ public function getAvailableOptions() {
+ $this->init ();
+ return $this->availableOptions;
+ }
+ public function isImportAvailable() {
+ $this->init ();
+ return $this->importAvailable;
+ }
+ }
+}
+
+if (! class_exists ( 'PostmanAbstractPluginOptions' )) {
+
+ /**
+ *
+ * @author jasonhendriks
+ */
+ abstract class PostmanAbstractPluginOptions implements PostmanPluginOptions {
+ protected $options;
+ protected $logger;
+ public function __construct() {
+ $this->logger = new PostmanLogger ( get_class ( $this ) );
+ }
+ public function isValid() {
+ $valid = true;
+ $host = $this->getHostname ();
+ $port = $this->getPort ();
+ $fromEmail = $this->getMessageSenderEmail ();
+ $fromName = $this->getMessageSenderName ();
+ $auth = $this->getAuthenticationType ();
+ $enc = $this->getEncryptionType ();
+ $username = $this->getUsername ();
+ $password = $this->getPassword ();
+ $valid &= ! empty ( $host );
+ $this->logger->trace ( 'host ok ' . $valid );
+ $valid &= ! empty ( $port ) && absint ( $port ) > 0 && absint ( $port ) <= 65535;
+ $this->logger->trace ( 'port ok ' . $valid );
+ $valid &= ! empty ( $fromEmail );
+ $this->logger->trace ( 'from email ok ' . $valid );
+ $valid &= ! empty ( $fromName );
+ $this->logger->trace ( 'from name ok ' . $valid );
+ $valid &= ! empty ( $auth );
+ $this->logger->trace ( 'auth ok ' . $valid );
+ $valid &= ! empty ( $enc );
+ $this->logger->trace ( 'enc ok ' . $valid );
+ if ($auth != PostmanOptions::AUTHENTICATION_TYPE_NONE) {
+ $valid &= ! empty ( $username );
+ $valid &= ! empty ( $password );
+ }
+ $this->logger->trace ( 'user/pass ok ' . $valid );
+ return $valid;
+ }
+ public function isImportable() {
+ return $this->isValid ();
+ }
+ }
+}
+
+if (! class_exists ( 'PostmanConfigureSmtpOptions' )) {
+ // ConfigureSmtp (aka "SMTP") - 80,000
+ class PostmanConfigureSmtpOptions extends PostmanAbstractPluginOptions {
+ const SLUG = 'configure_smtp';
+ const PLUGIN_NAME = 'Configure SMTP';
+ const MESSAGE_SENDER_EMAIL = 'from_email';
+ const MESSAGE_SENDER_NAME = 'from_name';
+ const HOSTNAME = 'host';
+ const PORT = 'port';
+ const AUTHENTICATION_TYPE = 'smtp_auth';
+ const ENCRYPTION_TYPE = 'smtp_secure';
+ const USERNAME = 'smtp_user';
+ const PASSWORD = 'smtp_pass';
+ public function __construct() {
+ parent::__construct ();
+ $this->options = get_option ( 'c2c_configure_smtp' );
+ }
+ public function getPluginSlug() {
+ return self::SLUG;
+ }
+ public function getPluginName() {
+ return self::PLUGIN_NAME;
+ }
+ public function getMessageSenderEmail() {
+ if (isset ( $this->options [self::MESSAGE_SENDER_EMAIL] ))
+ return $this->options [self::MESSAGE_SENDER_EMAIL];
+ }
+ public function getMessageSenderName() {
+ if (isset ( $this->options [self::MESSAGE_SENDER_NAME] ))
+ return $this->options [self::MESSAGE_SENDER_NAME];
+ }
+ public function getHostname() {
+ if (isset ( $this->options [self::HOSTNAME] ))
+ return $this->options [self::HOSTNAME];
+ }
+ public function getPort() {
+ if (isset ( $this->options [self::PORT] ))
+ return $this->options [self::PORT];
+ }
+ public function getUsername() {
+ if (isset ( $this->options [self::USERNAME] ))
+ return $this->options [self::USERNAME];
+ }
+ public function getPassword() {
+ if (isset ( $this->options [self::PASSWORD] ))
+ return $this->options [self::PASSWORD];
+ }
+ public function getAuthenticationType() {
+ if (isset ( $this->options [self::AUTHENTICATION_TYPE] )) {
+ if ($this->options [self::AUTHENTICATION_TYPE] == 1) {
+ return PostmanOptions::AUTHENTICATION_TYPE_PLAIN;
+ } else {
+ return PostmanOptions::AUTHENTICATION_TYPE_NONE;
+ }
+ }
+ }
+ public function getEncryptionType() {
+ if (isset ( $this->options [self::ENCRYPTION_TYPE] )) {
+ switch ($this->options [self::ENCRYPTION_TYPE]) {
+ case 'ssl' :
+ return PostmanOptions::SECURITY_TYPE_SMTPS;
+ case 'tls' :
+ return PostmanOptions::SECURITY_TYPE_STARTTLS;
+ case '' :
+ return PostmanOptions::SECURITY_TYPE_NONE;
+ }
+ }
+ }
+ }
+}
+
+if (! class_exists ( 'PostmanCimySwiftSmtpOptions' )) {
+ // Cimy Swift - 9,000
+ class PostmanCimySwiftSmtpOptions extends PostmanAbstractPluginOptions {
+ const SLUG = 'cimy_swift_smtp';
+ const PLUGIN_NAME = 'Cimy Swift SMTP';
+ const MESSAGE_SENDER_EMAIL = 'sender_mail';
+ const MESSAGE_SENDER_NAME = 'sender_name';
+ const HOSTNAME = 'server';
+ const PORT = 'port';
+ const ENCRYPTION_TYPE = 'ssl';
+ const USERNAME = 'username';
+ const PASSWORD = 'password';
+ public function __construct() {
+ parent::__construct ();
+ $this->options = get_option ( 'cimy_swift_smtp_options' );
+ }
+ public function getPluginSlug() {
+ return self::SLUG;
+ }
+ public function getPluginName() {
+ return self::PLUGIN_NAME;
+ }
+ public function getMessageSenderEmail() {
+ if (isset ( $this->options [self::MESSAGE_SENDER_EMAIL] ))
+ return $this->options [self::MESSAGE_SENDER_EMAIL];
+ }
+ public function getMessageSenderName() {
+ if (isset ( $this->options [self::MESSAGE_SENDER_NAME] ))
+ return $this->options [self::MESSAGE_SENDER_NAME];
+ }
+ public function getHostname() {
+ if (isset ( $this->options [self::HOSTNAME] ))
+ return $this->options [self::HOSTNAME];
+ }
+ public function getPort() {
+ if (isset ( $this->options [self::PORT] ))
+ return $this->options [self::PORT];
+ }
+ public function getUsername() {
+ if (isset ( $this->options [self::USERNAME] ))
+ return $this->options [self::USERNAME];
+ }
+ public function getPassword() {
+ if (isset ( $this->options [self::PASSWORD] ))
+ return $this->options [self::PASSWORD];
+ }
+ public function getAuthenticationType() {
+ if (! empty ( $this->options [self::USERNAME] ) && ! empty ( $this->options [self::PASSWORD] )) {
+ return PostmanOptions::AUTHENTICATION_TYPE_PLAIN;
+ } else {
+ return PostmanOptions::AUTHENTICATION_TYPE_NONE;
+ }
+ }
+ public function getEncryptionType() {
+ if (isset ( $this->options [self::ENCRYPTION_TYPE] )) {
+ switch ($this->options [self::ENCRYPTION_TYPE]) {
+ case 'ssl' :
+ return PostmanOptions::SECURITY_TYPE_SMTPS;
+ case 'tls' :
+ return PostmanOptions::SECURITY_TYPE_STARTTLS;
+ case '' :
+ return PostmanOptions::SECURITY_TYPE_NONE;
+ }
+ }
+ }
+ }
+}
+
+// Easy WP SMTP - 40,000
+if (! class_exists ( 'PostmanEasyWpSmtpOptions' )) {
+
+ /**
+ * Imports Easy WP SMTP options into Postman
+ *
+ * @author jasonhendriks
+ */
+ class PostmanEasyWpSmtpOptions extends PostmanAbstractPluginOptions implements PostmanPluginOptions {
+ const SLUG = 'easy_wp_smtp';
+ const PLUGIN_NAME = 'Easy WP SMTP';
+ const SMTP_SETTINGS = 'smtp_settings';
+ const MESSAGE_SENDER_EMAIL = 'from_email_field';
+ const MESSAGE_SENDER_NAME = 'from_name_field';
+ const HOSTNAME = 'host';
+ const PORT = 'port';
+ const ENCRYPTION_TYPE = 'type_encryption';
+ const AUTHENTICATION_TYPE = 'autentication';
+ const USERNAME = 'username';
+ const PASSWORD = 'password';
+ public function __construct() {
+ parent::__construct ();
+ $this->options = get_option ( 'swpsmtp_options' );
+ }
+ public function getPluginSlug() {
+ return self::SLUG;
+ }
+ public function getPluginName() {
+ return self::PLUGIN_NAME;
+ }
+ public function getMessageSenderEmail() {
+ if (isset ( $this->options [self::MESSAGE_SENDER_EMAIL] ))
+ return $this->options [self::MESSAGE_SENDER_EMAIL];
+ }
+ public function getMessageSenderName() {
+ if (isset ( $this->options [self::MESSAGE_SENDER_NAME] ))
+ return $this->options [self::MESSAGE_SENDER_NAME];
+ }
+ public function getHostname() {
+ if (isset ( $this->options [self::SMTP_SETTINGS] [self::HOSTNAME] ))
+ return $this->options [self::SMTP_SETTINGS] [self::HOSTNAME];
+ }
+ public function getPort() {
+ if (isset ( $this->options [self::SMTP_SETTINGS] [self::PORT] ))
+ return $this->options [self::SMTP_SETTINGS] [self::PORT];
+ }
+ public function getUsername() {
+ if (isset ( $this->options [self::SMTP_SETTINGS] [self::USERNAME] ))
+ return $this->options [self::SMTP_SETTINGS] [self::USERNAME];
+ }
+ public function getPassword() {
+ if (isset ( $this->options [self::SMTP_SETTINGS] [self::PASSWORD] )) {
+ // wpecommerce screwed the pooch
+ $password = $this->options [self::SMTP_SETTINGS] [self::PASSWORD];
+ if (strlen ( $password ) % 4 != 0 || preg_match ( '/[^A-Za-z0-9]/', $password )) {
+ $decodedPw = base64_decode ( $password, true );
+ $reencodedPw = base64_encode ( $decodedPw );
+ if ($reencodedPw === $password) {
+ // encoded
+ return $decodedPw;
+ } else {
+ // not encoded
+ return $password;
+ }
+ }
+ }
+ }
+ public function getAuthenticationType() {
+ if (isset ( $this->options [self::SMTP_SETTINGS] [self::AUTHENTICATION_TYPE] )) {
+ switch ($this->options [self::SMTP_SETTINGS] [self::AUTHENTICATION_TYPE]) {
+ case 'yes' :
+ return PostmanOptions::AUTHENTICATION_TYPE_PLAIN;
+ case 'no' :
+ return PostmanOptions::AUTHENTICATION_TYPE_NONE;
+ }
+ }
+ }
+ public function getEncryptionType() {
+ if (isset ( $this->options [self::SMTP_SETTINGS] [self::ENCRYPTION_TYPE] )) {
+ switch ($this->options [self::SMTP_SETTINGS] [self::ENCRYPTION_TYPE]) {
+ case 'ssl' :
+ return PostmanOptions::SECURITY_TYPE_SMTPS;
+ case 'tls' :
+ return PostmanOptions::SECURITY_TYPE_STARTTLS;
+ case 'none' :
+ return PostmanOptions::SECURITY_TYPE_NONE;
+ }
+ }
+ }
+ }
+}
+
+if (! class_exists ( 'PostmanWpMailBankOptions' )) {
+
+ /**
+ * Import configuration from WP Mail Bank
+ *
+ * @author jasonhendriks
+ *
+ */
+ class PostmanWpMailBankOptions extends PostmanAbstractPluginOptions implements PostmanPluginOptions {
+ const SLUG = 'wp_mail_bank';
+ const PLUGIN_NAME = 'WP Mail Bank';
+ public function __construct() {
+ parent::__construct ();
+ // data is stored in table wp_mail_bank
+ // fields are id, from_name, from_email, mailer_type, return_path, return_email, smtp_host, smtp_port, word_wrap, encryption, smtp_keep_alive, authentication, smtp_username, smtp_password
+ global $wpdb;
+ $wpdb->show_errors ();
+ $wpdb->suppress_errors ();
+ $this->options = @$wpdb->get_row ( "SELECT from_name, from_email, mailer_type, smtp_host, smtp_port, encryption, authentication, smtp_username, smtp_password FROM " . $wpdb->prefix . "mail_bank" );
+ }
+ public function getPluginSlug() {
+ return self::SLUG;
+ }
+ public function getPluginName() {
+ return self::PLUGIN_NAME;
+ }
+ public function getMessageSenderEmail() {
+ if (isset ( $this->options->from_email ))
+ return $this->options->from_email;
+ }
+ public function getMessageSenderName() {
+ if (isset ( $this->options->from_name )) {
+ return stripslashes ( htmlspecialchars_decode ( $this->options->from_name, ENT_QUOTES ) );
+ }
+ }
+ public function getHostname() {
+ if (isset ( $this->options->smtp_host ))
+ return $this->options->smtp_host;
+ }
+ public function getPort() {
+ if (isset ( $this->options->smtp_port ))
+ return $this->options->smtp_port;
+ }
+ public function getUsername() {
+ if (isset ( $this->options->authentication ) && isset ( $this->options->smtp_username ))
+ if ($this->options->authentication == 1)
+ return $this->options->smtp_username;
+ }
+ public function getPassword() {
+ if (isset ( $this->options->authentication ) && isset ( $this->options->smtp_password )) {
+ if ($this->options->authentication == 1)
+ return $this->options->smtp_password;
+ }
+ }
+ public function getAuthenticationType() {
+ if (isset ( $this->options->authentication )) {
+ if ($this->options->authentication == 1) {
+ return PostmanOptions::AUTHENTICATION_TYPE_PLAIN;
+ } else if ($this->options->authentication == 0) {
+ return PostmanOptions::AUTHENTICATION_TYPE_NONE;
+ }
+ }
+ }
+ public function getEncryptionType() {
+ if (isset ( $this->options->mailer_type )) {
+ if ($this->options->mailer_type == 0) {
+ switch ($this->options->encryption) {
+ case 0 :
+ return PostmanOptions::SECURITY_TYPE_NONE;
+ case 1 :
+ return PostmanOptions::SECURITY_TYPE_SMTPS;
+ case 2 :
+ return PostmanOptions::SECURITY_TYPE_STARTTLS;
+ }
+ }
+ }
+ }
+ }
+}
+
+// "WP Mail SMTP" (aka "Email") - 300,000
+// each field is a new row in options : mail_from, mail_from_name, smtp_host, smtp_port, smtp_ssl, smtp_auth, smtp_user, smtp_pass
+// "Easy SMTP Mail" aka. "Webriti SMTP Mail" appears to share the data format of "WP Mail SMTP" so no need to create an Options class for it.
+//
+if (! class_exists ( 'PostmanWpMailSmtpOptions' )) {
+ class PostmanWpMailSmtpOptions extends PostmanAbstractPluginOptions implements PostmanPluginOptions {
+ const SLUG = 'wp_mail_smtp';
+ const PLUGIN_NAME = 'WP Mail SMTP';
+ const MESSAGE_SENDER_EMAIL = 'mail_from';
+ const MESSAGE_SENDER_NAME = 'mail_from_name';
+ const HOSTNAME = 'smtp_host';
+ const PORT = 'smtp_port';
+ const ENCRYPTION_TYPE = 'smtp_ssl';
+ const AUTHENTICATION_TYPE = 'smtp_auth';
+ const USERNAME = 'smtp_user';
+ const PASSWORD = 'smtp_pass';
+ public function __construct() {
+ parent::__construct ();
+ $this->options [self::MESSAGE_SENDER_EMAIL] = get_option ( self::MESSAGE_SENDER_EMAIL );
+ $this->options [self::MESSAGE_SENDER_NAME] = get_option ( self::MESSAGE_SENDER_NAME );
+ $this->options [self::HOSTNAME] = get_option ( self::HOSTNAME );
+ $this->options [self::PORT] = get_option ( self::PORT );
+ $this->options [self::ENCRYPTION_TYPE] = get_option ( self::ENCRYPTION_TYPE );
+ $this->options [self::AUTHENTICATION_TYPE] = get_option ( self::AUTHENTICATION_TYPE );
+ $this->options [self::USERNAME] = get_option ( self::USERNAME );
+ $this->options [self::PASSWORD] = get_option ( self::PASSWORD );
+ }
+ public function getPluginSlug() {
+ return self::SLUG;
+ }
+ public function getPluginName() {
+ return self::PLUGIN_NAME;
+ }
+ public function getMessageSenderEmail() {
+ if (isset ( $this->options [self::MESSAGE_SENDER_EMAIL] ))
+ return $this->options [self::MESSAGE_SENDER_EMAIL];
+ }
+ public function getMessageSenderName() {
+ if (isset ( $this->options [self::MESSAGE_SENDER_NAME] ))
+ return $this->options [self::MESSAGE_SENDER_NAME];
+ }
+ public function getHostname() {
+ if (isset ( $this->options [self::HOSTNAME] ))
+ return $this->options [self::HOSTNAME];
+ }
+ public function getPort() {
+ if (isset ( $this->options [self::PORT] ))
+ return $this->options [self::PORT];
+ }
+ public function getUsername() {
+ if (isset ( $this->options [self::USERNAME] ))
+ return $this->options [self::USERNAME];
+ }
+ public function getPassword() {
+ if (isset ( $this->options [self::PASSWORD] ))
+ return $this->options [self::PASSWORD];
+ }
+ public function getAuthenticationType() {
+ if (isset ( $this->options [self::AUTHENTICATION_TYPE] )) {
+ switch ($this->options [self::AUTHENTICATION_TYPE]) {
+ case 'true' :
+ return PostmanOptions::AUTHENTICATION_TYPE_PLAIN;
+ case 'false' :
+ return PostmanOptions::AUTHENTICATION_TYPE_NONE;
+ }
+ }
+ }
+ public function getEncryptionType() {
+ if (isset ( $this->options [self::ENCRYPTION_TYPE] )) {
+ switch ($this->options [self::ENCRYPTION_TYPE]) {
+ case 'ssl' :
+ return PostmanOptions::SECURITY_TYPE_SMTPS;
+ case 'tls' :
+ return PostmanOptions::SECURITY_TYPE_STARTTLS;
+ case 'none' :
+ return PostmanOptions::SECURITY_TYPE_NONE;
+ }
+ }
+ }
+ }
+}
+
+// WP SMTP - 40,000
+if (! class_exists ( 'PostmanWpSmtpOptions' )) {
+ class PostmanWpSmtpOptions extends PostmanAbstractPluginOptions implements PostmanPluginOptions {
+ const SLUG = 'wp_smtp'; // god these names are terrible
+ const PLUGIN_NAME = 'WP SMTP';
+ const MESSAGE_SENDER_EMAIL = 'from';
+ const MESSAGE_SENDER_NAME = 'fromname';
+ const HOSTNAME = 'host';
+ const PORT = 'port';
+ const ENCRYPTION_TYPE = 'smtpsecure';
+ const AUTHENTICATION_TYPE = 'smtpauth';
+ const USERNAME = 'username';
+ const PASSWORD = 'password';
+ public function __construct() {
+ parent::__construct ();
+ $this->options = get_option ( 'wp_smtp_options' );
+ }
+ public function getPluginSlug() {
+ return self::SLUG;
+ }
+ public function getPluginName() {
+ return self::PLUGIN_NAME;
+ }
+ public function getMessageSenderEmail() {
+ if (isset ( $this->options [self::MESSAGE_SENDER_EMAIL] ))
+ return $this->options [self::MESSAGE_SENDER_EMAIL];
+ }
+ public function getMessageSenderName() {
+ if (isset ( $this->options [self::MESSAGE_SENDER_NAME] ))
+ return $this->options [self::MESSAGE_SENDER_NAME];
+ }
+ public function getHostname() {
+ if (isset ( $this->options [self::HOSTNAME] ))
+ return $this->options [self::HOSTNAME];
+ }
+ public function getPort() {
+ if (isset ( $this->options [self::PORT] ))
+ return $this->options [self::PORT];
+ }
+ public function getUsername() {
+ if (isset ( $this->options [self::USERNAME] ))
+ return $this->options [self::USERNAME];
+ }
+ public function getPassword() {
+ if (isset ( $this->options [self::PASSWORD] ))
+ return $this->options [self::PASSWORD];
+ }
+ public function getAuthenticationType() {
+ if (isset ( $this->options [self::AUTHENTICATION_TYPE] )) {
+ switch ($this->options [self::AUTHENTICATION_TYPE]) {
+ case 'yes' :
+ return PostmanOptions::AUTHENTICATION_TYPE_PLAIN;
+ case 'no' :
+ return PostmanOptions::AUTHENTICATION_TYPE_NONE;
+ }
+ }
+ }
+ public function getEncryptionType() {
+ if (isset ( $this->options [self::ENCRYPTION_TYPE] )) {
+ switch ($this->options [self::ENCRYPTION_TYPE]) {
+ case 'ssl' :
+ return PostmanOptions::SECURITY_TYPE_SMTPS;
+ case 'tls' :
+ return PostmanOptions::SECURITY_TYPE_STARTTLS;
+ case '' :
+ return PostmanOptions::SECURITY_TYPE_NONE;
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Postman/Postman-Configuration/PostmanRegisterConfigurationSettings.php b/Postman/Postman-Configuration/PostmanRegisterConfigurationSettings.php
new file mode 100644
index 0000000..c1a42a2
--- /dev/null
+++ b/Postman/Postman-Configuration/PostmanRegisterConfigurationSettings.php
@@ -0,0 +1,407 @@
+<?php
+class PostmanSettingsRegistry {
+
+ private $options;
+
+ public function __construct() {
+ $this->options = PostmanOptions::getInstance();
+ }
+
+ /**
+ * Fires on the admin_init method
+ */
+ public function on_admin_init() {
+ //
+ $this->registerSettings ();
+ }
+
+ /**
+ * Register and add settings
+ */
+ private function registerSettings() {
+
+ // only administrators should be able to trigger this
+ if (PostmanUtils::isAdmin ()) {
+ //
+ $sanitizer = new PostmanInputSanitizer ();
+ register_setting ( PostmanAdminController::SETTINGS_GROUP_NAME, PostmanOptions::POSTMAN_OPTIONS, array (
+ $sanitizer,
+ 'sanitize'
+ ) );
+
+ // Sanitize
+ add_settings_section ( 'transport_section', __ ( 'Transport', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'printTransportSectionInfo'
+ ), 'transport_options' );
+
+ add_settings_field ( PostmanOptions::TRANSPORT_TYPE, _x ( 'Type', '(i.e.) What kind is it?', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'transport_type_callback'
+ ), 'transport_options', 'transport_section' );
+
+ // the Message From section
+ add_settings_section ( PostmanAdminController::MESSAGE_FROM_SECTION, _x ( 'From Address', 'The Message Sender Email Address', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'printMessageFromSectionInfo'
+ ), PostmanAdminController::MESSAGE_FROM_OPTIONS );
+
+ add_settings_field ( PostmanOptions::MESSAGE_SENDER_EMAIL, __ ( 'Email Address', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'from_email_callback'
+ ), PostmanAdminController::MESSAGE_FROM_OPTIONS, PostmanAdminController::MESSAGE_FROM_SECTION );
+
+ add_settings_field ( PostmanOptions::PREVENT_MESSAGE_SENDER_EMAIL_OVERRIDE, '', array (
+ $this,
+ 'prevent_from_email_override_callback'
+ ), PostmanAdminController::MESSAGE_FROM_OPTIONS, PostmanAdminController::MESSAGE_FROM_SECTION );
+
+ add_settings_field ( PostmanOptions::MESSAGE_SENDER_NAME, __ ( 'Name', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'sender_name_callback'
+ ), PostmanAdminController::MESSAGE_FROM_OPTIONS, PostmanAdminController::MESSAGE_FROM_SECTION );
+
+ add_settings_field ( PostmanOptions::PREVENT_MESSAGE_SENDER_NAME_OVERRIDE, '', array (
+ $this,
+ 'prevent_from_name_override_callback'
+ ), PostmanAdminController::MESSAGE_FROM_OPTIONS, PostmanAdminController::MESSAGE_FROM_SECTION );
+
+ // the Additional Addresses section
+ add_settings_section ( PostmanAdminController::MESSAGE_SECTION, __ ( 'Additional Email Addresses', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'printMessageSectionInfo'
+ ), PostmanAdminController::MESSAGE_OPTIONS );
+
+ add_settings_field ( PostmanOptions::REPLY_TO, __ ( 'Reply-To', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'reply_to_callback'
+ ), PostmanAdminController::MESSAGE_OPTIONS, PostmanAdminController::MESSAGE_SECTION );
+
+ add_settings_field ( PostmanOptions::FORCED_TO_RECIPIENTS, __ ( 'To Recipient(s)', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'to_callback'
+ ), PostmanAdminController::MESSAGE_OPTIONS, PostmanAdminController::MESSAGE_SECTION );
+
+ add_settings_field ( PostmanOptions::FORCED_CC_RECIPIENTS, __ ( 'Carbon Copy Recipient(s)', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'cc_callback'
+ ), PostmanAdminController::MESSAGE_OPTIONS, PostmanAdminController::MESSAGE_SECTION );
+
+ add_settings_field ( PostmanOptions::FORCED_BCC_RECIPIENTS, __ ( 'Blind Carbon Copy Recipient(s)', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'bcc_callback'
+ ), PostmanAdminController::MESSAGE_OPTIONS, PostmanAdminController::MESSAGE_SECTION );
+
+ // the Additional Headers section
+ add_settings_section ( PostmanAdminController::MESSAGE_HEADERS_SECTION, __ ( 'Additional Headers', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'printAdditionalHeadersSectionInfo'
+ ), PostmanAdminController::MESSAGE_HEADERS_OPTIONS );
+
+ add_settings_field ( PostmanOptions::ADDITIONAL_HEADERS, __ ( 'Custom Headers', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'headers_callback'
+ ), PostmanAdminController::MESSAGE_HEADERS_OPTIONS, PostmanAdminController::MESSAGE_HEADERS_SECTION );
+
+ // the Email Validation section
+ add_settings_section ( PostmanAdminController::EMAIL_VALIDATION_SECTION, __ ( 'Validation', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'printEmailValidationSectionInfo'
+ ), PostmanAdminController::EMAIL_VALIDATION_OPTIONS );
+
+ add_settings_field ( PostmanOptions::ENVELOPE_SENDER, __ ( 'Email Address', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'disable_email_validation_callback'
+ ), PostmanAdminController::EMAIL_VALIDATION_OPTIONS, PostmanAdminController::EMAIL_VALIDATION_SECTION );
+
+ // the Logging section
+ add_settings_section ( PostmanAdminController::LOGGING_SECTION, __ ( 'Email Log Settings', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'printLoggingSectionInfo'
+ ), PostmanAdminController::LOGGING_OPTIONS );
+
+ add_settings_field ( 'logging_status', __ ( 'Enable Logging', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'loggingStatusInputField'
+ ), PostmanAdminController::LOGGING_OPTIONS, PostmanAdminController::LOGGING_SECTION );
+
+ add_settings_field ( 'logging_max_entries', __ ( 'Maximum Log Entries', 'Configuration Input Field', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'loggingMaxEntriesInputField'
+ ), PostmanAdminController::LOGGING_OPTIONS, PostmanAdminController::LOGGING_SECTION );
+
+ add_settings_field ( PostmanOptions::TRANSCRIPT_SIZE, __ ( 'Maximum Transcript Size', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'transcriptSizeInputField'
+ ), PostmanAdminController::LOGGING_OPTIONS, PostmanAdminController::LOGGING_SECTION );
+
+ // the Network section
+ add_settings_section ( PostmanAdminController::NETWORK_SECTION, __ ( 'Network Settings', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'printNetworkSectionInfo'
+ ), PostmanAdminController::NETWORK_OPTIONS );
+
+ add_settings_field ( 'connection_timeout', _x ( 'TCP Connection Timeout (sec)', 'Configuration Input Field', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'connection_timeout_callback'
+ ), PostmanAdminController::NETWORK_OPTIONS, PostmanAdminController::NETWORK_SECTION );
+
+ add_settings_field ( 'read_timeout', _x ( 'TCP Read Timeout (sec)', 'Configuration Input Field', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'read_timeout_callback'
+ ), PostmanAdminController::NETWORK_OPTIONS, PostmanAdminController::NETWORK_SECTION );
+
+ // the Advanced section
+ add_settings_section ( PostmanAdminController::ADVANCED_SECTION, _x ( 'Miscellaneous Settings', 'Configuration Section Title', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'printAdvancedSectionInfo'
+ ), PostmanAdminController::ADVANCED_OPTIONS );
+
+ add_settings_field ( PostmanOptions::LOG_LEVEL, _x ( 'PHP Log Level', 'Configuration Input Field', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'log_level_callback'
+ ), PostmanAdminController::ADVANCED_OPTIONS, PostmanAdminController::ADVANCED_SECTION );
+
+ add_settings_field ( PostmanOptions::RUN_MODE, _x ( 'Delivery Mode', 'Configuration Input Field', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'runModeCallback'
+ ), PostmanAdminController::ADVANCED_OPTIONS, PostmanAdminController::ADVANCED_SECTION );
+
+ add_settings_field ( PostmanOptions::STEALTH_MODE, _x ( 'Stealth Mode', 'This mode removes the Postman X-Mailer signature from emails', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'stealthModeCallback'
+ ), PostmanAdminController::ADVANCED_OPTIONS, PostmanAdminController::ADVANCED_SECTION );
+
+ add_settings_field ( PostmanOptions::TEMPORARY_DIRECTORY, __ ( 'Temporary Directory', Postman::TEXT_DOMAIN ), array (
+ $this,
+ 'temporaryDirectoryCallback'
+ ), PostmanAdminController::ADVANCED_OPTIONS, PostmanAdminController::ADVANCED_SECTION );
+ }
+ }
+
+ /**
+ * Print the Transport section info
+ */
+ public function printTransportSectionInfo() {
+ print __ ( 'Choose SMTP or a vendor-specific API:', Postman::TEXT_DOMAIN );
+ }
+ public function printLoggingSectionInfo() {
+ print __ ( 'Configure the delivery audit log:', Postman::TEXT_DOMAIN );
+ }
+
+ /**
+ * Print the Section text
+ */
+ public function printMessageFromSectionInfo() {
+ print sprintf ( __ ( 'This address, like the <b>letterhead</b> printed on a letter, identifies the sender to the recipient. Change this when you are sending on behalf of someone else, for example to use Google\'s <a href="%s">Send Mail As</a> feature. Other plugins, especially Contact Forms, may override this field to be your visitor\'s address.', Postman::TEXT_DOMAIN ), 'https://support.google.com/mail/answer/22370?hl=en' );
+ }
+
+ /**
+ * Print the Section text
+ */
+ public function printMessageSectionInfo() {
+ print __ ( 'Separate multiple <b>to</b>/<b>cc</b>/<b>bcc</b> recipients with commas.', Postman::TEXT_DOMAIN );
+ }
+
+ /**
+ * Print the Section text
+ */
+ public function printNetworkSectionInfo() {
+ print __ ( 'Increase the timeouts if your host is intermittenly failing to send mail. Be careful, this also correlates to how long your user must wait if the mail server is unreachable.', Postman::TEXT_DOMAIN );
+ }
+ /**
+ * Print the Section text
+ */
+ public function printAdvancedSectionInfo() {
+ }
+ /**
+ * Print the Section text
+ */
+ public function printAdditionalHeadersSectionInfo() {
+ print __ ( 'Specify custom headers (e.g. <code>X-MC-Tags: wordpress-site-A</code>), one per line. Use custom headers with caution as they can negatively affect your Spam score.', Postman::TEXT_DOMAIN );
+ }
+
+ /**
+ * Print the Email Validation Description
+ */
+ public function printEmailValidationSectionInfo() {
+ print __ ( 'E-mail addresses can be validated before sending e-mail, however this may fail with some newer domains.', Postman::TEXT_DOMAIN );
+ }
+
+ /**
+ * Get the settings option array and print one of its values
+ */
+ public function transport_type_callback() {
+ $transportType = $this->options->getTransportType ();
+ printf ( '<select id="input_%2$s" class="input_%2$s" name="%1$s[%2$s]">', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::TRANSPORT_TYPE );
+ foreach ( PostmanTransportRegistry::getInstance ()->getTransports () as $transport ) {
+ printf ( '<option class="input_tx_type_%1$s" value="%1$s" %3$s>%2$s</option>', $transport->getSlug (), $transport->getName (), $transportType == $transport->getSlug () ? 'selected="selected"' : '' );
+ }
+ print '</select>';
+ }
+
+ /**
+ * Get the settings option array and print one of its values
+ */
+ public function sender_name_callback() {
+ printf ( '<input type="text" id="input_sender_name" name="postman_options[sender_name]" value="%s" size="40" />', null !== $this->options->getMessageSenderName () ? esc_attr ( $this->options->getMessageSenderName () ) : '' );
+ }
+
+ /**
+ */
+ public function prevent_from_name_override_callback() {
+ $enforced = $this->options->isPluginSenderNameEnforced ();
+ printf ( '<input type="checkbox" id="input_prevent_sender_name_override" name="postman_options[prevent_sender_name_override]" %s /> %s', $enforced ? 'checked="checked"' : '', __ ( 'Prevent <b>plugins</b> and <b>themes</b> from changing this', Postman::TEXT_DOMAIN ) );
+ }
+
+ /**
+ * Get the settings option array and print one of its values
+ */
+ public function from_email_callback() {
+ printf ( '<input type="email" id="input_sender_email" name="postman_options[sender_email]" value="%s" size="40" class="required" placeholder="%s"/>', null !== $this->options->getMessageSenderEmail () ? esc_attr ( $this->options->getMessageSenderEmail () ) : '', __ ( 'Required', Postman::TEXT_DOMAIN ) );
+ }
+
+ /**
+ * Print the Section text
+ */
+ public function printMessageSenderSectionInfo() {
+ print sprintf ( __ ( 'This address, like the <b>return address</b> printed on an envelope, identifies the account owner to the SMTP server.', Postman::TEXT_DOMAIN ), 'https://support.google.com/mail/answer/22370?hl=en' );
+ }
+
+ /**
+ * Get the settings option array and print one of its values
+ */
+ public function prevent_from_email_override_callback() {
+ $enforced = $this->options->isPluginSenderEmailEnforced ();
+ printf ( '<input type="checkbox" id="input_prevent_sender_email_override" name="postman_options[prevent_sender_email_override]" %s /> %s', $enforced ? 'checked="checked"' : '', __ ( 'Prevent <b>plugins</b> and <b>themes</b> from changing this', Postman::TEXT_DOMAIN ) );
+ }
+
+ /**
+ * Shows the Mail Logging enable/disabled option
+ */
+ public function loggingStatusInputField() {
+ // isMailLoggingAllowed
+ $disabled = "";
+ if (! $this->options->isMailLoggingAllowed ()) {
+ $disabled = 'disabled="disabled" ';
+ }
+ printf ( '<select ' . $disabled . 'id="input_%2$s" class="input_%2$s" name="%1$s[%2$s]">', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::MAIL_LOG_ENABLED_OPTION );
+ printf ( '<option value="%s" %s>%s</option>', PostmanOptions::MAIL_LOG_ENABLED_OPTION_YES, $this->options->isMailLoggingEnabled () ? 'selected="selected"' : '', __ ( 'Yes', Postman::TEXT_DOMAIN ) );
+ printf ( '<option value="%s" %s>%s</option>', PostmanOptions::MAIL_LOG_ENABLED_OPTION_NO, ! $this->options->isMailLoggingEnabled () ? 'selected="selected"' : '', __ ( 'No', Postman::TEXT_DOMAIN ) );
+ printf ( '</select>' );
+ }
+ public function loggingMaxEntriesInputField() {
+ printf ( '<input type="text" id="input_logging_max_entries" name="postman_options[%s]" value="%s"/>', PostmanOptions::MAIL_LOG_MAX_ENTRIES, $this->options->getMailLoggingMaxEntries () );
+ }
+ public function transcriptSizeInputField() {
+ $inputOptionsSlug = PostmanOptions::POSTMAN_OPTIONS;
+ $inputTranscriptSlug = PostmanOptions::TRANSCRIPT_SIZE;
+ $inputValue = $this->options->getTranscriptSize ();
+ $inputDescription = __ ( 'Change this value if you can\'t see the beginning of the transcript because your messages are too big.', Postman::TEXT_DOMAIN );
+ printf ( '<input type="text" id="input%2$s" name="%1$s[%2$s]" value="%3$s"/><br/><span class="postman_input_description">%4$s</span>', $inputOptionsSlug, $inputTranscriptSlug, $inputValue, $inputDescription );
+ }
+
+ /**
+ * Get the settings option array and print one of its values
+ */
+ public function reply_to_callback() {
+ printf ( '<input type="text" id="input_reply_to" name="%s[%s]" value="%s" size="40" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::REPLY_TO, null !== $this->options->getReplyTo () ? esc_attr ( $this->options->getReplyTo () ) : '' );
+ }
+
+ /**
+ * Get the settings option array and print one of its values
+ */
+ public function to_callback() {
+ printf ( '<input type="text" id="input_to" name="%s[%s]" value="%s" size="60" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::FORCED_TO_RECIPIENTS, null !== $this->options->getForcedToRecipients () ? esc_attr ( $this->options->getForcedToRecipients () ) : '' );
+ }
+
+ /**
+ * Get the settings option array and print one of its values
+ */
+ public function cc_callback() {
+ printf ( '<input type="text" id="input_cc" name="%s[%s]" value="%s" size="60" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::FORCED_CC_RECIPIENTS, null !== $this->options->getForcedCcRecipients () ? esc_attr ( $this->options->getForcedCcRecipients () ) : '' );
+ }
+
+ /**
+ * Get the settings option array and print one of its values
+ */
+ public function bcc_callback() {
+ printf ( '<input type="text" id="input_bcc" name="%s[%s]" value="%s" size="60" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::FORCED_BCC_RECIPIENTS, null !== $this->options->getForcedBccRecipients () ? esc_attr ( $this->options->getForcedBccRecipients () ) : '' );
+ }
+
+ /**
+ * Get the settings option array and print one of its values
+ */
+ public function headers_callback() {
+ printf ( '<textarea id="input_headers" name="%s[%s]" cols="60" rows="5" >%s</textarea>', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::ADDITIONAL_HEADERS, null !== $this->options->getAdditionalHeaders () ? esc_attr ( $this->options->getAdditionalHeaders () ) : '' );
+ }
+
+ /**
+ */
+ public function disable_email_validation_callback() {
+ $disabled = $this->options->isEmailValidationDisabled ();
+ printf ( '<input type="checkbox" id="%2$s" name="%1$s[%2$s]" %3$s /> %4$s', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::DISABLE_EMAIL_VALIDAITON, $disabled ? 'checked="checked"' : '', __ ( 'Disable e-mail validation', Postman::TEXT_DOMAIN ) );
+ }
+
+ /**
+ * Get the settings option array and print one of its values
+ */
+ public function log_level_callback() {
+ $inputDescription = sprintf ( __ ( 'Log Level specifies the level of detail written to the <a target="_new" href="%s">WordPress Debug log</a> - view the log with <a target-"_new" href="%s">Debug</a>.', Postman::TEXT_DOMAIN ), 'https://codex.wordpress.org/Debugging_in_WordPress', 'https://wordpress.org/plugins/debug/' );
+ printf ( '<select id="input_%2$s" class="input_%2$s" name="%1$s[%2$s]">', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::LOG_LEVEL );
+ $currentKey = $this->options->getLogLevel ();
+ $this->printSelectOption ( __ ( 'Off', Postman::TEXT_DOMAIN ), PostmanLogger::OFF_INT, $currentKey );
+ $this->printSelectOption ( __ ( 'Trace', Postman::TEXT_DOMAIN ), PostmanLogger::TRACE_INT, $currentKey );
+ $this->printSelectOption ( __ ( 'Debug', Postman::TEXT_DOMAIN ), PostmanLogger::DEBUG_INT, $currentKey );
+ $this->printSelectOption ( __ ( 'Info', Postman::TEXT_DOMAIN ), PostmanLogger::INFO_INT, $currentKey );
+ $this->printSelectOption ( __ ( 'Warning', Postman::TEXT_DOMAIN ), PostmanLogger::WARN_INT, $currentKey );
+ $this->printSelectOption ( __ ( 'Error', Postman::TEXT_DOMAIN ), PostmanLogger::ERROR_INT, $currentKey );
+ printf ( '</select><br/><span class="postman_input_description">%s</span>', $inputDescription );
+ }
+ private function printSelectOption($label, $optionKey, $currentKey) {
+ $optionPattern = '<option value="%1$s" %2$s>%3$s</option>';
+ printf ( $optionPattern, $optionKey, $optionKey == $currentKey ? 'selected="selected"' : '', $label );
+ }
+ public function runModeCallback() {
+ $inputDescription = __ ( 'Delivery mode offers options useful for developing or testing.', Postman::TEXT_DOMAIN );
+ printf ( '<select id="input_%2$s" class="input_%2$s" name="%1$s[%2$s]">', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::RUN_MODE );
+ $currentKey = $this->options->getRunMode ();
+ $this->printSelectOption ( _x ( 'Log Email and Send', 'When the server is online to the public, this is "Production" mode', Postman::TEXT_DOMAIN ), PostmanOptions::RUN_MODE_PRODUCTION, $currentKey );
+ $this->printSelectOption ( __ ( 'Log Email and Delete', Postman::TEXT_DOMAIN ), PostmanOptions::RUN_MODE_LOG_ONLY, $currentKey );
+ $this->printSelectOption ( __ ( 'Delete All Emails', Postman::TEXT_DOMAIN ), PostmanOptions::RUN_MODE_IGNORE, $currentKey );
+ printf ( '</select><br/><span class="postman_input_description">%s</span>', $inputDescription );
+ }
+ public function stealthModeCallback() {
+ printf ( '<input type="checkbox" id="input_%2$s" class="input_%2$s" name="%1$s[%2$s]" %3$s /> %4$s', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::STEALTH_MODE, $this->options->isStealthModeEnabled () ? 'checked="checked"' : '', __ ( 'Remove the Postman X-Header signature from messages', Postman::TEXT_DOMAIN ) );
+ }
+ public function temporaryDirectoryCallback() {
+ $inputDescription = __ ( 'Lockfiles are written here to prevent users from triggering an OAuth 2.0 token refresh at the same time.' );
+ printf ( '<input type="text" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::TEMPORARY_DIRECTORY, $this->options->getTempDirectory () );
+ if (PostmanState::getInstance ()->isFileLockingEnabled ()) {
+ printf ( ' <span style="color:green">%s</span></br><span class="postman_input_description">%s</span>', __ ( 'Valid', Postman::TEXT_DOMAIN ), $inputDescription );
+ } else {
+ printf ( ' <span style="color:red">%s</span></br><span class="postman_input_description">%s</span>', __ ( 'Invalid', Postman::TEXT_DOMAIN ), $inputDescription );
+ }
+ }
+
+ /**
+ * Get the settings option array and print one of its values
+ */
+ public function connection_timeout_callback() {
+ printf ( '<input type="text" id="input_connection_timeout" name="%s[%s]" value="%s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::CONNECTION_TIMEOUT, $this->options->getConnectionTimeout () );
+ }
+
+ /**
+ * Get the settings option array and print one of its values
+ */
+ public function read_timeout_callback() {
+ printf ( '<input type="text" id="input_read_timeout" name="%s[%s]" value="%s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::READ_TIMEOUT, $this->options->getReadTimeout () );
+ }
+
+ /**
+ * Get the settings option array and print one of its values
+ */
+ public function port_callback($args) {
+ printf ( '<input type="text" id="input_port" name="postman_options[port]" value="%s" %s placeholder="%s"/>', null !== $this->options->getPort () ? esc_attr ( $this->options->getPort () ) : '', isset ( $args ['style'] ) ? $args ['style'] : '', __ ( 'Required', Postman::TEXT_DOMAIN ) );
+ }
+} \ No newline at end of file
diff --git a/Postman/Postman-Configuration/PostmanSmtpDiscovery.php b/Postman/Postman-Configuration/PostmanSmtpDiscovery.php
new file mode 100644
index 0000000..60728c6
--- /dev/null
+++ b/Postman/Postman-Configuration/PostmanSmtpDiscovery.php
@@ -0,0 +1,233 @@
+<?php
+if (! class_exists ( 'PostmanSmtpMappings' )) {
+ class PostmanSmtpMappings {
+ // if an email is in this domain array, it is a known smtp server (easy lookup)
+ private static $emailDomain = array (
+ // from http://www.serversmtp.com/en/outgoing-mail-server-hostname
+ '1and1.com' => 'smtp.1and1.com',
+ 'airmail.net' => 'smtp.airmail.net',
+ 'aol.com' => 'smtp.aol.com',
+ 'Bluewin.ch' => 'Smtpauths.bluewin.ch',
+ 'Comcast.net' => 'Smtp.comcast.net',
+ 'Earthlink.net' => 'Smtpauth.earthlink.net',
+ 'gmail.com' => 'smtp.gmail.com',
+ 'Gmx.com' => 'mail.gmx.com',
+ 'Gmx.net' => 'mail.gmx.com',
+ 'Gmx.us' => 'mail.gmx.com',
+ 'hotmail.com' => 'smtp.live.com',
+ 'icloud.com' => 'smtp.mail.me.com',
+ 'mail.com' => 'smtp.mail.com',
+ 'ntlworld.com' => 'smtp.ntlworld.com',
+ 'rocketmail.com' => 'plus.smtp.mail.yahoo.com',
+ 'rogers.com' => 'smtp.broadband.rogers.com',
+ 'yahoo.ca' => 'smtp.mail.yahoo.ca',
+ 'yahoo.co.id' => 'smtp.mail.yahoo.co.id',
+ 'yahoo.co.in' => 'smtp.mail.yahoo.co.in',
+ 'yahoo.co.kr' => 'smtp.mail.yahoo.com',
+ 'yahoo.com' => 'smtp.mail.yahoo.com',
+ 'yahoo.com.ar' => 'smtp.mail.yahoo.com.ar',
+ 'yahoo.com.au' => 'smtp.mail.yahoo.com.au',
+ 'yahoo.com.br' => 'smtp.mail.yahoo.com.br',
+ 'yahoo.com.cn' => 'smtp.mail.yahoo.com.cn',
+ 'yahoo.com.hk' => 'smtp.mail.yahoo.com.hk',
+ 'yahoo.com.mx' => 'smtp.mail.yahoo.com',
+ 'yahoo.com.my' => 'smtp.mail.yahoo.com.my',
+ 'yahoo.com.ph' => 'smtp.mail.yahoo.com.ph',
+ 'yahoo.com.sg' => 'smtp.mail.yahoo.com.sg',
+ 'yahoo.com.tw' => 'smtp.mail.yahoo.com.tw',
+ 'yahoo.com.vn' => 'smtp.mail.yahoo.com.vn',
+ 'yahoo.co.nz' => 'smtp.mail.yahoo.com.au',
+ 'yahoo.co.th' => 'smtp.mail.yahoo.co.th',
+ 'yahoo.co.uk' => 'smtp.mail.yahoo.co.uk',
+ 'yahoo.de' => 'smtp.mail.yahoo.de',
+ 'yahoo.es' => 'smtp.correo.yahoo.es',
+ 'yahoo.fr' => 'smtp.mail.yahoo.fr',
+ 'yahoo.ie' => 'smtp.mail.yahoo.co.uk',
+ 'yahoo.it' => 'smtp.mail.yahoo.it',
+ 'zoho.com' => 'smtp.zoho.com',
+ // from http://www.att.com/esupport/article.jsp?sid=KB401570&cv=801
+ 'ameritech.net' => 'outbound.att.net',
+ 'att.net' => 'outbound.att.net',
+ 'bellsouth.net' => 'outbound.att.net',
+ 'flash.net' => 'outbound.att.net',
+ 'nvbell.net' => 'outbound.att.net',
+ 'pacbell.net' => 'outbound.att.net',
+ 'prodigy.net' => 'outbound.att.net',
+ 'sbcglobal.net' => 'outbound.att.net',
+ 'snet.net' => 'outbound.att.net',
+ 'swbell.net' => 'outbound.att.net',
+ 'wans.net' => 'outbound.att.net'
+ );
+ // if an email's mx is in this domain array, it is a known smtp server (dns lookup)
+ // useful for custom domains that map to a mail service
+ private static $mxMappings = array (
+ '1and1help.com' => 'smtp.1and1.com',
+ 'google.com' => 'smtp.gmail.com',
+ 'Gmx.net' => 'mail.gmx.com',
+ 'icloud.com' => 'smtp.mail.me.com',
+ 'hotmail.com' => 'smtp.live.com',
+ 'mx-eu.mail.am0.yahoodns.net' => 'smtp.mail.yahoo.com',
+ // 'mail.protection.outlook.com' => 'smtp.office365.com',
+ // 'mail.eo.outlook.com' => 'smtp.office365.com',
+ 'outlook.com' => 'smtp.office365.com',
+ 'biz.mail.am0.yahoodns.net' => 'smtp.bizmail.yahoo.com',
+ 'BIZ.MAIL.YAHOO.com' => 'smtp.bizmail.yahoo.com',
+ 'hushmail.com' => 'smtp.hushmail.com',
+ 'gmx.net' => 'mail.gmx.com',
+ 'mandrillapp.com' => 'smtp.mandrillapp.com',
+ 'smtp.secureserver.net' => 'relay-hosting.secureserver.net',
+ 'presmtp.ex1.secureserver.net' => 'smtp.ex1.secureserver.net',
+ 'presmtp.ex2.secureserver.net' => 'smtp.ex2.secureserver.net',
+ 'presmtp.ex3.secureserver.net' => 'smtp.ex2.secureserver.net',
+ 'presmtp.ex4.secureserver.net' => 'smtp.ex2.secureserver.net',
+ 'htvhosting.com' => 'mail.htvhosting.com'
+ );
+ public static function getSmtpFromEmail($hostname) {
+ reset ( PostmanSmtpMappings::$emailDomain );
+ while ( list ( $domain, $smtp ) = each ( PostmanSmtpMappings::$emailDomain ) ) {
+ if (strcasecmp ( $hostname, $domain ) == 0) {
+ return $smtp;
+ }
+ }
+ return false;
+ }
+ public static function getSmtpFromMx($mx) {
+ reset ( PostmanSmtpMappings::$mxMappings );
+ while ( list ( $domain, $smtp ) = each ( PostmanSmtpMappings::$mxMappings ) ) {
+ if (PostmanUtils::endswith ( $mx, $domain )) {
+ return $smtp;
+ }
+ }
+ return false;
+ }
+ }
+}
+if (! class_exists ( 'PostmanSmtpDiscovery' )) {
+ class PostmanSmtpDiscovery {
+
+ // private instance variables
+ public $isGoogle;
+ public $isGoDaddy;
+ public $isWellKnownDomain;
+ private $smtpServer;
+ private $primaryMx;
+ private $email;
+ private $domain;
+
+ /**
+ * Constructor
+ *
+ * @param unknown $email
+ */
+ public function __construct($email) {
+ $this->email = $email;
+ $this->determineSmtpServer ( $email );
+ $this->isGoogle = $this->smtpServer == 'smtp.gmail.com';
+ $this->isGoDaddy = $this->smtpServer == 'relay-hosting.secureserver.net';
+ }
+ /**
+ * The SMTP server we suggest to use - this is determined
+ * by looking up the MX hosts for the domain.
+ */
+ public function getSmtpServer() {
+ return $this->smtpServer;
+ }
+ public function getPrimaryMx() {
+ return $this->primaryMx;
+ }
+ /**
+ *
+ * @param unknown $email
+ * @return Ambigous <number, boolean>
+ */
+ private function validateEmail($email) {
+ return PostmanUtils::validateEmail ( $email );
+ }
+ private function determineSmtpServer($email) {
+ $hostname = substr ( strrchr ( $email, "@" ), 1 );
+ $this->domain = $hostname;
+ $smtp = PostmanSmtpMappings::getSmtpFromEmail ( $hostname );
+ if ($smtp) {
+ $this->smtpServer = $smtp;
+ $this->isWellKnownDomain = true;
+ return true;
+ } else {
+ $host = strtolower ( $this->findMxHostViaDns ( $hostname ) );
+ if ($host) {
+ $this->primaryMx = $host;
+ $smtp = PostmanSmtpMappings::getSmtpFromMx ( $host );
+ if ($smtp) {
+ $this->smtpServer = $smtp;
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Uses getmxrr to retrieve the MX records of a hostname
+ *
+ * @param unknown $hostname
+ * @return mixed|boolean
+ */
+ private function findMxHostViaDns($hostname) {
+ if (function_exists ( 'getmxrr' )) {
+ $b_mx_avail = getmxrr ( $hostname, $mx_records, $mx_weight );
+ } else {
+ $b_mx_avail = $this->getmxrr ( $hostname, $mx_records, $mx_weight );
+ }
+ if ($b_mx_avail && sizeof ( $mx_records ) > 0) {
+ // copy mx records and weight into array $mxs
+ $mxs = array ();
+
+ for($i = 0; $i < count ( $mx_records ); $i ++) {
+ $mxs [$mx_weight [$i]] = $mx_records [$i];
+ }
+
+ // sort array mxs to get servers with highest prio
+ ksort ( $mxs, SORT_NUMERIC );
+ reset ( $mxs );
+ $mxs_vals = array_values ( $mxs );
+ return array_shift ( $mxs_vals );
+ } else {
+ return false;
+ }
+ }
+ /**
+ * This is a custom implementation of mxrr for Windows PHP installations
+ * which don't have this method natively.
+ *
+ * @param unknown $hostname
+ * @param unknown $mxhosts
+ * @param unknown $mxweight
+ * @return boolean
+ */
+ function getmxrr($hostname, &$mxhosts, &$mxweight) {
+ if (! is_array ( $mxhosts )) {
+ $mxhosts = array ();
+ }
+ $hostname = escapeshellarg ( $hostname );
+ if (! empty ( $hostname )) {
+ $output = "";
+ @exec ( "nslookup.exe -type=MX $hostname.", $output );
+ $imx = - 1;
+
+ foreach ( $output as $line ) {
+ $imx ++;
+ $parts = "";
+ if (preg_match ( "/^$hostname\tMX preference = ([0-9]+), mail exchanger = (.*)$/", $line, $parts )) {
+ $mxweight [$imx] = $parts [1];
+ $mxhosts [$imx] = $parts [2];
+ }
+ }
+ return ($imx != - 1);
+ }
+ return false;
+ }
+ }
+}
+
diff --git a/Postman/Postman-Configuration/postman_manual_config.js b/Postman/Postman-Configuration/postman_manual_config.js
new file mode 100644
index 0000000..14d4d9f
--- /dev/null
+++ b/Postman/Postman-Configuration/postman_manual_config.js
@@ -0,0 +1,78 @@
+var transports = [];
+
+jQuery(document).ready(
+ function() {
+
+ // display password on entry
+ enablePasswordDisplayOnEntry('input_basic_auth_password',
+ 'togglePasswordField');
+
+ // tabs
+ jQuery("#config_tabs").tabs();
+
+ // on first viewing, determine whether to show password or
+ // oauth section
+ reloadOauthSection();
+
+ // add an event on the transport input field
+ // when the user changes the transport, determine whether
+ // to show or hide the SMTP Settings
+ jQuery('select#input_transport_type').change(function() {
+ hide('#wizard_oauth2_help');
+ reloadOauthSection();
+ switchBetweenPasswordAndOAuth();
+ });
+
+ // add an event on the authentication input field
+ // on user changing the auth type, determine whether to show
+ // password or oauth section
+ jQuery('select#input_auth_type').change(function() {
+ switchBetweenPasswordAndOAuth();
+ doneTyping();
+ });
+
+ // setup before functions
+ var typingTimer; // timer identifier
+ var doneTypingInterval = 250; // time in ms, 5 second for
+ // example
+
+ // add an event on the hostname input field
+ // on keyup, start the countdown
+ jQuery(postman_hostname_element_name).keyup(function() {
+ clearTimeout(typingTimer);
+ if (jQuery(postman_hostname_element_name).val) {
+ typingTimer = setTimeout(doneTyping, doneTypingInterval);
+ }
+ });
+
+ // user is "finished typing," do something
+ function doneTyping() {
+ if (jQuery(postman_input_auth_type).val() == 'oauth2') {
+ reloadOauthSection();
+ }
+ }
+ });
+function reloadOauthSection() {
+ var hostname = jQuery(postman_hostname_element_name).val();
+ var transport = jQuery('#input_transport_type').val();
+ var authtype = jQuery('select#input_auth_type').val();
+ var data = {
+ 'action' : 'manual_config',
+ 'auth_type' : authtype,
+ 'hostname' : hostname,
+ 'transport' : transport,
+ };
+ jQuery.post(ajaxurl, data, function(response) {
+ if (response.success) {
+ handleConfigurationResponse(response);
+ }
+ }).fail(function(response) {
+ ajaxFailed(response);
+ });
+}
+function switchBetweenPasswordAndOAuth() {
+ var transportName = jQuery('select#input_transport_type').val();
+ transports.forEach(function(item) {
+ item.handleTransportChange(transportName);
+ })
+}
diff --git a/Postman/Postman-Configuration/postman_wizard.js b/Postman/Postman-Configuration/postman_wizard.js
new file mode 100644
index 0000000..097fd65
--- /dev/null
+++ b/Postman/Postman-Configuration/postman_wizard.js
@@ -0,0 +1,569 @@
+var transports = [];
+
+connectivtyTestResults = {};
+portTestInProgress = false;
+
+/**
+ * Functions to run on document load
+ */
+jQuery(document).ready(function() {
+ jQuery(postman_input_sender_email).focus();
+ initializeJQuerySteps();
+ // add an event on the plugin selection
+ jQuery('input[name="input_plugin"]').click(function() {
+ getConfiguration();
+ });
+
+ // add an event on the transport input field
+ // when the user changes the transport, determine whether
+ // to show or hide the SMTP Settings
+ jQuery('select#input_transport_type').change(function() {
+ hide('#wizard_oauth2_help');
+ reloadOauthSection();
+ switchBetweenPasswordAndOAuth();
+ });
+
+});
+
+function checkGoDaddyAndCheckEmail(email) {
+ hide('#godaddy_block');
+ hide('#godaddy_spf_required');
+ // are we hosted on GoDaddy? check.
+ var data = {
+ 'action' : 'postman_wizard_port_test',
+ 'hostname' : 'relay-hosting.secureserver.net',
+ 'port' : 25,
+ 'timeout' : 3
+ };
+ goDaddy = 'unknown';
+ checkedEmail = false;
+ jQuery.post(ajaxurl, data, function(response) {
+ if (postmanValidateAjaxResponseWithPopup(response)) {
+ checkEmail(response.success, email);
+ }
+ }).fail(function(response) {
+ ajaxFailed(response);
+ });
+}
+
+function checkEmail(goDaddyHostDetected, email) {
+ var data = {
+ 'action' : 'postman_check_email',
+ 'go_daddy' : goDaddyHostDetected,
+ 'email' : email
+ };
+ jQuery.post(
+ ajaxurl,
+ data,
+ function(response) {
+ if (postmanValidateAjaxResponseWithPopup(response)) {
+ checkedEmail = true;
+ smtpDiscovery = response.data;
+ if (response.data.hostname != null
+ && response.data.hostname) {
+ jQuery(postman_hostname_element_name).val(
+ response.data.hostname);
+ }
+ enableSmtpHostnameInput(goDaddyHostDetected);
+ }
+ }).fail(function(response) {
+ ajaxFailed(response);
+ });
+}
+
+function enableSmtpHostnameInput(goDaddyHostDetected) {
+ if (goDaddyHostDetected && !smtpDiscovery.is_google) {
+ // this is a godaddy server and we are using a godaddy smtp server
+ // (gmail excepted)
+ if (smtpDiscovery.is_go_daddy) {
+ // we detected GoDaddy, and the user has entered a GoDaddy hosted
+ // email
+ } else if (smtpDiscovery.is_well_known) {
+ // this is a godaddy server but the SMTP must be the email
+ // service
+ show('#godaddy_block');
+ } else {
+ // this is a godaddy server and we're using a (possibly) custom
+ // domain
+ show('#godaddy_spf_required');
+ }
+ }
+ enable('#input_hostname');
+ jQuery('li').removeClass('disabled');
+ hideLoaderIcon();
+}
+
+/**
+ * Initialize the Steps wizard
+ */
+function initializeJQuerySteps() {
+ jQuery("#postman_wizard").steps(
+ {
+ bodyTag : "fieldset",
+ headerTag : "h5",
+ transitionEffect : "slideLeft",
+ stepsOrientation : "vertical",
+ autoFocus : true,
+ startIndex : parseInt(postman_setup_wizard.start_page),
+ labels : {
+ current : steps_current_step,
+ pagination : steps_pagination,
+ finish : steps_finish,
+ next : steps_next,
+ previous : steps_previous,
+ loading : steps_loading
+ },
+ onStepChanging : function(event, currentIndex, newIndex) {
+ return handleStepChange(event, currentIndex, newIndex,
+ jQuery(this));
+
+ },
+ onInit : function() {
+ jQuery(postman_input_sender_email).focus();
+ },
+ onStepChanged : function(event, currentIndex, priorIndex) {
+ return postHandleStepChange(event, currentIndex,
+ priorIndex, jQuery(this));
+ },
+ onFinishing : function(event, currentIndex) {
+ var form = jQuery(this);
+
+ // Disable validation on fields that
+ // are disabled.
+ // At this point it's recommended to
+ // do an overall check (mean
+ // ignoring
+ // only disabled fields)
+ // form.validate().settings.ignore =
+ // ":disabled";
+
+ // Start validation; Prevent form
+ // submission if false
+ return form.valid();
+ },
+ onFinished : function(event, currentIndex) {
+ var form = jQuery(this);
+
+ // Submit form input
+ form.submit();
+ }
+ }).validate({
+ errorPlacement : function(error, element) {
+ element.before(error);
+ }
+ });
+}
+
+function handleStepChange(event, currentIndex, newIndex, form) {
+ // Always allow going backward even if
+ // the current step contains invalid fields!
+ if (currentIndex > newIndex) {
+ if (currentIndex === 2 && !(checkedEmail)) {
+ return false;
+ }
+ if (currentIndex === 3 && portTestInProgress) {
+ return false;
+ }
+ return true;
+ }
+
+ // Clean up if user went backward
+ // before
+ if (currentIndex < newIndex) {
+ // To remove error styles
+ jQuery(".body:eq(" + newIndex + ") label.error", form).remove();
+ jQuery(".body:eq(" + newIndex + ") .error", form).removeClass("error");
+ }
+
+ // Disable validation on fields that
+ // are disabled or hidden.
+ form.validate().settings.ignore = ":disabled,:hidden";
+
+ // Start validation; Prevent going
+ // forward if false
+ valid = form.valid();
+ if (!valid) {
+ return false;
+ }
+
+ if (currentIndex === 1) {
+ // page 1 : look-up the email
+ // address for the smtp server
+ checkGoDaddyAndCheckEmail(jQuery(postman_input_sender_email).val());
+
+ } else if (currentIndex === 2) {
+
+ if (!(checkedEmail)) {
+ return false;
+ }
+ // page 2 : check the port
+ portsChecked = 0;
+ portsToCheck = 0;
+ totalAvail = 0;
+
+ getHostsToCheck(jQuery(postman_hostname_element_name).val());
+
+ } else if (currentIndex === 3) {
+
+ // user has clicked next but we haven't finished the check
+ if (portTestInProgress) {
+ return false;
+ }
+ // or all ports are unavailable
+ if (portCheckBlocksUi) {
+ return false;
+ }
+ valid = form.valid();
+ if (!valid) {
+ return false;
+ }
+ var chosenPort = jQuery(postman_port_element_name).val();
+ var hostname = jQuery(postman_hostname_element_name).val();
+ var authType = jQuery(postman_input_auth_type).val()
+
+ }
+
+ return true;
+}
+
+function postHandleStepChange(event, currentIndex, priorIndex, myself) {
+ var chosenPort = jQuery('#input_auth_type').val();
+ // Suppress (skip) "Warning" step if
+ // the user is old enough and wants
+ // to the previous step.
+ if (currentIndex === 2) {
+ jQuery(postman_hostname_element_name).focus();
+ // this is the second place i disable the next button but Steps
+ // re-enables it after the screen slides
+ if (priorIndex === 1) {
+ disable('#input_hostname');
+ jQuery('li').addClass('disabled');
+ showLoaderIcon();
+ }
+ }
+ if (currentIndex === 3) {
+ if (priorIndex === 2) {
+ // this is the second place i disable the next button but Steps
+ // re-enables it after the screen slides
+ jQuery('li').addClass('disabled');
+ showLoaderIcon();
+ }
+ }
+ if (currentIndex === 4) {
+ if (redirectUrlWarning) {
+ alert(postman_wizard_bad_redirect_url);
+ }
+ if (chosenPort == 'none') {
+ if (priorIndex === 5) {
+
+ myself.steps("previous");
+ return;
+ }
+ myself.steps("next");
+ }
+ }
+
+}
+
+/**
+ * Asks the server for a List of sockets to perform port checks upon.
+ *
+ * @param hostname
+ */
+function getHostsToCheck(hostname) {
+ jQuery('table#wizard_port_test').html('');
+ jQuery('#wizard_recommendation').html('');
+ hide('.user_override');
+ hide('#smtp_not_secure');
+ hide('#smtp_mitm');
+ connectivtyTestResults = {};
+ portCheckBlocksUi = true;
+ portTestInProgress = true;
+ var data = {
+ 'action' : 'postman_get_hosts_to_test',
+ 'hostname' : hostname,
+ 'original_smtp_server' : smtpDiscovery.hostname
+ };
+ jQuery.post(ajaxurl, data, function(response) {
+ if (postmanValidateAjaxResponseWithPopup(response)) {
+ handleHostsToCheckResponse(response.data);
+ }
+ }).fail(function(response) {
+ ajaxFailed(response);
+ });
+}
+
+/**
+ * Handles the response from the server of the list of sockets to check.
+ *
+ * @param hostname
+ * @param response
+ */
+function handleHostsToCheckResponse(response) {
+ for ( var x in response.hosts) {
+ var hostname = response.hosts[x].host;
+ var port = response.hosts[x].port;
+ var transport = response.hosts[x].transport_id;
+ portsToCheck++;
+ show('#connectivity_test_status');
+ updateStatus(postman_port_test.in_progress + " " + portsToCheck);
+ var data = {
+ 'action' : 'postman_wizard_port_test',
+ 'hostname' : hostname,
+ 'port' : port,
+ 'transport' : transport
+ };
+ postThePortTest(hostname, port, data);
+ }
+}
+
+/**
+ * Asks the server to run a connectivity test on the given port
+ *
+ * @param hostname
+ * @param port
+ * @param data
+ */
+function postThePortTest(hostname, port, data) {
+ jQuery.post(ajaxurl, data, function(response) {
+ if (postmanValidateAjaxResponseWithPopup(response)) {
+ handlePortTestResponse(hostname, port, data, response);
+ }
+ }).fail(function(response) {
+ ajaxFailed(response);
+ portsChecked++;
+ afterPortsChecked();
+ });
+}
+
+/**
+ * Handles the result of the port test
+ *
+ * @param hostname
+ * @param port
+ * @param data
+ * @param response
+ */
+function handlePortTestResponse(hostname, port, data, response) {
+ if (!response.data.try_smtps) {
+ portsChecked++;
+ updateStatus(postman_port_test.in_progress + " "
+ + (portsToCheck - portsChecked));
+ connectivtyTestResults[hostname + '_' + port] = response.data;
+ if (response.success) {
+ // a totalAvail > 0 is our signal to go to the next step
+ totalAvail++;
+ }
+ afterPortsChecked();
+ } else {
+ // SMTP failed, try again on the SMTPS port
+ data['action'] = 'postman_wizard_port_test_smtps';
+ postThePortTest(hostname, port, data);
+ }
+}
+
+/**
+ *
+ * @param message
+ */
+function updateStatus(message) {
+ jQuery('#port_test_status').html(
+ '<span style="color:blue">' + message + '</span>');
+}
+
+/**
+ * This functions runs after ALL the ports have been checked. It's chief
+ * function is to push the results of the port test back to the server to get a
+ * suggested configuration.
+ */
+function afterPortsChecked() {
+ if (portsChecked >= portsToCheck) {
+ hideLoaderIcon();
+ if (totalAvail != 0) {
+ jQuery('li').removeClass('disabled');
+ portCheckBlocksUi = false;
+ }
+ var data = {
+ 'action' : 'get_wizard_configuration_options',
+ 'original_smtp_server' : smtpDiscovery.hostname,
+ 'host_data' : connectivtyTestResults
+ };
+ postTheConfigurationRequest(data);
+ hide('#connectivity_test_status');
+ }
+}
+
+function userOverrideMenu() {
+ disable('input.user_socket_override');
+ disable('input.user_auth_override');
+ var data = {
+ 'action' : 'get_wizard_configuration_options',
+ 'original_smtp_server' : smtpDiscovery.hostname,
+ 'user_port_override' : jQuery(
+ "input:radio[name='user_socket_override']:checked").val(),
+ 'user_auth_override' : jQuery(
+ "input:radio[name='user_auth_override']:checked").val(),
+ 'host_data' : connectivtyTestResults
+ };
+ postTheConfigurationRequest(data);
+}
+
+function postTheConfigurationRequest(data) {
+ jQuery.post(
+ ajaxurl,
+ data,
+ function(response) {
+ if (postmanValidateAjaxResponseWithPopup(response)) {
+ portTestInProgress = false;
+ var $message = '';
+ if (response.success) {
+ $message = '<span style="color:green">'
+ + response.data.configuration.message
+ + '</span>';
+ handleConfigurationResponse(response.data);
+ enable('input.user_socket_override');
+ enable('input.user_auth_override');
+ // enable both next/back buttons
+ jQuery('li').removeClass('disabled');
+ } else {
+ $message = '<span style="color:red">'
+ + response.data.configuration.message
+ + '</span>';
+ // enable the back button only
+ jQuery('li').removeClass('disabled');
+ jQuery('li + li').addClass('disabled');
+ }
+ if (!response.data.configuration.user_override) {
+ jQuery('#wizard_recommendation').append($message);
+ }
+ }
+ }).fail(function(response) {
+ ajaxFailed(response);
+ });
+}
+function handleConfigurationResponse(response) {
+ jQuery('#input_transport_type').val(response.configuration.transport_type);
+ transports.forEach(function(item) {
+ item.handleConfigurationResponse(response);
+ })
+
+ // this stuff builds the options and is common to all transports
+ // populate user Port Override menu
+ show('.user_override');
+ var el1 = jQuery('#user_socket_override');
+ el1.html('');
+ for (i = 0; i < response.override_menu.length; i++) {
+ buildRadioButtonGroup(el1, 'user_socket_override',
+ response.override_menu[i].selected,
+ response.override_menu[i].value,
+ response.override_menu[i].description,
+ response.override_menu[i].secure);
+ // populate user Auth Override menu
+ if (response.override_menu[i].selected) {
+ if (response.override_menu[i].mitm) {
+ show('#smtp_mitm');
+ jQuery('#smtp_mitm')
+ .html(
+ sprintf(
+ postman_port_test.mitm,
+ response.override_menu[i].reported_hostname_domain_only,
+ response.override_menu[i].hostname_domain_only));
+ } else {
+ hide('#smtp_mitm');
+ }
+ var el2 = jQuery('#user_auth_override');
+ el2.html('');
+ hide('#smtp_not_secure');
+ for (j = 0; j < response.override_menu[i].auth_items.length; j++) {
+ buildRadioButtonGroup(el2, 'user_auth_override',
+ response.override_menu[i].auth_items[j].selected,
+ response.override_menu[i].auth_items[j].value,
+ response.override_menu[i].auth_items[j].name, false);
+ if (response.override_menu[i].auth_items[j].selected
+ && !response.override_menu[i].secure
+ && response.override_menu[i].auth_items[j].value != 'none') {
+ show('#smtp_not_secure');
+ }
+ }
+ // add an event on the user port override field
+ jQuery('input.user_auth_override').change(function() {
+ userOverrideMenu();
+ });
+ }
+
+ }
+ // add an event on the user port override field
+ jQuery('input.user_socket_override').change(function() {
+ userOverrideMenu();
+ });
+}
+
+function buildRadioButtonGroup(tableElement, radioGroupName, isSelected, value,
+ label, isSecure) {
+ var radioInputValue = ' value="' + value + '"';
+ var radioInputChecked = '';
+ if (isSelected) {
+ radioInputChecked = ' checked = "checked"';
+ }
+ var secureIcon = '';
+ if (isSecure) {
+ secureIcon = '&#x1f512; ';
+ }
+ tableElement.append('<tr><td><input class="' + radioGroupName
+ + '" type="radio" name="' + radioGroupName + '"'
+ + radioInputChecked + radioInputValue + '/></td><td>' + secureIcon
+ + label + '</td></tr>');
+}
+
+/**
+ * Handles population of the configuration based on the options set in a
+ * 3rd-party SMTP plugin
+ */
+function getConfiguration() {
+ var plugin = jQuery('input[name="input_plugin"]' + ':checked').val();
+ if (plugin != '') {
+ var data = {
+ 'action' : 'import_configuration',
+ 'plugin' : plugin
+ };
+ jQuery
+ .post(
+ ajaxurl,
+ data,
+ function(response) {
+ if (response.success) {
+ jQuery('select#input_transport_type').val(
+ 'smtp');
+ jQuery(postman_input_sender_email).val(
+ response.sender_email);
+ jQuery(postman_input_sender_name).val(
+ response.sender_name);
+ jQuery(postman_hostname_element_name).val(
+ response.hostname);
+ jQuery(postman_port_element_name).val(
+ response.port);
+ jQuery(postman_input_auth_type).val(
+ response.auth_type);
+ jQuery('#input_enc_type')
+ .val(response.enc_type);
+ jQuery(postman_input_basic_username).val(
+ response.basic_auth_username);
+ jQuery(postman_input_basic_password).val(
+ response.basic_auth_password);
+ switchBetweenPasswordAndOAuth();
+ }
+ }).fail(function(response) {
+ ajaxFailed(response);
+ });
+ } else {
+ jQuery(postman_input_sender_email).val('');
+ jQuery(postman_input_sender_name).val('');
+ jQuery(postman_input_basic_username).val('');
+ jQuery(postman_input_basic_password).val('');
+ jQuery(postman_hostname_element_name).val('');
+ jQuery(postman_port_element_name).val('');
+ jQuery(postman_input_auth_type).val('none');
+ jQuery(postman_enc_for_password_el).val('none');
+ switchBetweenPasswordAndOAuth();
+ }
+}