Changed source root directory

This commit is contained in:
2026-03-05 16:30:11 +01:00
parent dc85447ee1
commit 538f85d7a2
5868 changed files with 749734 additions and 99 deletions

View File

@@ -0,0 +1,692 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
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();
/**
* Get plugin's logo
*
* @since 2.1
* @version 1.0
*/
public function getPluginLogo();
}
}
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;
}
}
}
/**
* Get plugin's logo
*
* @since 2.1
* @version 1.0
*/
public function getPluginLogo() {
return POST_SMTP_ASSETS . "images/logos/configure-smtp.png";
}
}
}
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;
}
}
}
/**
* Get plugin's logo
*
* @since 2.1
* @version 1.0
*/
public function getPluginLogo() {
return POST_SMTP_ASSETS . "images/logos/php.png";
}
}
}
// 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 ) ) {
$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;
}
}
}
/**
* Get plugin's logo
*
* @since 2.1
* @version 1.0
*/
public function getPluginLogo() {
return POST_SMTP_ASSETS . "images/logos/easy-wp-smtp.png";
}
}
}
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';
const MESSAGE_SENDER_EMAIL = 'sender_email';
const MESSAGE_SENDER_NAME = 'sender_name';
const HOSTNAME = 'hostname';
const PORT = 'port';
const ENCRYPTION_TYPE = 'enc_type';
const AUTHENTICATION_TYPE = 'auth_type';
const USERNAME = 'username';
const PASSWORD = 'password';
const MAILER_TYPE = 'mailer_type';
public function __construct() {
parent::__construct ();
// data is stored in table wp_mail_meta
// 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
if( array_key_exists ( 'wp-mail-bank/wp-mail-bank.php', get_plugins () ) ) {
global $wpdb;
$wpdb->show_errors ();
$wpdb->suppress_errors ();
$mb_email_configuration_data = $wpdb->get_row(
$wpdb->prepare(
'SELECT meta_value FROM ' . $wpdb->prefix . 'mail_bank_meta WHERE meta_key = %s', 'email_configuration'
), ARRAY_A
);
if( isset( $mb_email_configuration_data['meta_value'] ) ) {
$mb_email_configuration_data = unserialize( $mb_email_configuration_data['meta_value'] );
$this->options [self::MESSAGE_SENDER_EMAIL] = $mb_email_configuration_data[ self::MESSAGE_SENDER_EMAIL ];
$this->options [self::MESSAGE_SENDER_NAME] = $mb_email_configuration_data[ self::MESSAGE_SENDER_NAME ];
$this->options [self::HOSTNAME] = $mb_email_configuration_data[ self::HOSTNAME ];
$this->options [self::PORT] = $mb_email_configuration_data[ self::PORT ];
$this->options [self::ENCRYPTION_TYPE] = $mb_email_configuration_data[ self::ENCRYPTION_TYPE ];
$this->options [self::AUTHENTICATION_TYPE] = $mb_email_configuration_data[ self::AUTHENTICATION_TYPE ];
$this->options [self::USERNAME] = $mb_email_configuration_data[ self::USERNAME ];
$this->options [self::PASSWORD] = base64_decode( $mb_email_configuration_data[ self::PASSWORD ] );
$this->options [self::MAILER_TYPE] = $mb_email_configuration_data[ self::MAILER_TYPE ];
}
}
}
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 stripslashes ( htmlspecialchars_decode ( $this->options [self::MESSAGE_SENDER_NAME], ENT_QUOTES ) );
}
}
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::AUTHENTICATION_TYPE] ) && isset ( $this->options [self::USERNAME] ))
if ($this->options[self::AUTHENTICATION_TYPE] != 'none' )
return $this->options [self::USERNAME];
}
public function getPassword() {
if (isset ( $this->options [self::AUTHENTICATION_TYPE] ) && isset ( $this->options [self::PASSWORD] )) {
if ($this->options [self::AUTHENTICATION_TYPE] != 'none' )
return $this->options [self::PASSWORD];
}
}
public function getAuthenticationType() {
if (isset ( $this->options [self::AUTHENTICATION_TYPE] )) {
switch( $this->options [self::AUTHENTICATION_TYPE] ) {
case 'none':
return PostmanOptions::AUTHENTICATION_TYPE_NONE;
case 'plain':
return PostmanOptions::AUTHENTICATION_TYPE_PLAIN;
case 'login':
return PostmanOptions::AUTHENTICATION_TYPE_LOGIN;
case 'crammd5':
return PostmanOptions::AUTHENTICATION_TYPE_CRAMMD5;
case 'oauth2':
return PostmanOptions::AUTHENTICATION_TYPE_OAUTH2;
}
}
}
public function getEncryptionType() {
if (isset ( $this->options [self::MAILER_TYPE] )) {
if ($this->options[self::MAILER_TYPE] == 'smtp') {
switch ($this->options [self::ENCRYPTION_TYPE]) {
case 'none' :
return PostmanOptions::SECURITY_TYPE_NONE;
case 'ssl' :
return PostmanOptions::SECURITY_TYPE_SMTPS;
case 'tls' :
return PostmanOptions::SECURITY_TYPE_STARTTLS;
}
}
}
}
/**
* Get plugin's logo
*
* @since 2.1
* @version 1.0
*/
public function getPluginLogo() {
return POST_SMTP_ASSETS . "images/logos/wp-mail-bank.png";
}
}
}
// "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;
}
}
}
/**
* Get plugin's logo
*
* @since 2.1
* @version 1.0
*/
public function getPluginLogo() {
return POST_SMTP_ASSETS . "images/logos/wp-mail-smtp.png";
}
}
}
// 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;
}
}
}
/**
* Get plugin's logo
*
* @since 2.1
* @version 1.0
*/
public function getPluginLogo() {
return POST_SMTP_ASSETS . "images/logos/wp-smtp.png";
}
}
}

View File

@@ -0,0 +1,493 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
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', 'post-smtp' ), array(
$this,
'printTransportSectionInfo',
), 'transport_options' );
add_settings_field( PostmanOptions::TRANSPORT_TYPE, _x( 'Type', '(i.e.) What kind is it?', 'post-smtp' ), array(
$this,
'transport_type_callback',
), 'transport_options', 'transport_section' );
add_settings_field( 'smtp_mailers', __( 'Mailer Type', 'post-smtp' ), array(
$this,
'smtp_mailer_callback',
), 'transport_options', 'transport_section' );
// the Message From section
add_settings_section( PostmanAdminController::MESSAGE_FROM_SECTION, _x( 'From Address', 'The Message Sender Email Address', 'post-smtp' ), array(
$this,
'printMessageFromSectionInfo',
), PostmanAdminController::MESSAGE_FROM_OPTIONS );
add_settings_field( PostmanOptions::MESSAGE_SENDER_EMAIL, __( 'Email Address', 'post-smtp' ), array(
$this,
'from_email_callback',
), PostmanAdminController::MESSAGE_FROM_OPTIONS, PostmanAdminController::MESSAGE_FROM_SECTION, array( true ) );
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', 'post-smtp' ), array(
$this,
'sender_name_callback',
), PostmanAdminController::MESSAGE_FROM_OPTIONS, PostmanAdminController::MESSAGE_FROM_SECTION, array( true ) );
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', 'post-smtp' ), array(
$this,
'printMessageSectionInfo',
), PostmanAdminController::MESSAGE_OPTIONS );
add_settings_field( PostmanOptions::REPLY_TO, __( 'Reply-To', 'post-smtp' ), array(
$this,
'reply_to_callback',
), PostmanAdminController::MESSAGE_OPTIONS, PostmanAdminController::MESSAGE_SECTION );
add_settings_field( PostmanOptions::FORCED_TO_RECIPIENTS, __( 'To Recipient(s)', 'post-smtp' ), array(
$this,
'to_callback',
), PostmanAdminController::MESSAGE_OPTIONS, PostmanAdminController::MESSAGE_SECTION );
add_settings_field( PostmanOptions::FORCED_CC_RECIPIENTS, __( 'Carbon Copy Recipient(s)', 'post-smtp' ), array(
$this,
'cc_callback',
), PostmanAdminController::MESSAGE_OPTIONS, PostmanAdminController::MESSAGE_SECTION );
add_settings_field( PostmanOptions::FORCED_BCC_RECIPIENTS, __( 'Blind Carbon Copy Recipient(s)', 'post-smtp' ), array(
$this,
'bcc_callback',
), PostmanAdminController::MESSAGE_OPTIONS, PostmanAdminController::MESSAGE_SECTION );
// the Additional Headers section
add_settings_section( PostmanAdminController::MESSAGE_HEADERS_SECTION, __( 'Additional Headers', 'post-smtp' ), array(
$this,
'printAdditionalHeadersSectionInfo',
), PostmanAdminController::MESSAGE_HEADERS_OPTIONS );
add_settings_field( PostmanOptions::ADDITIONAL_HEADERS, __( 'Custom Headers', 'post-smtp' ), array(
$this,
'headers_callback',
), PostmanAdminController::MESSAGE_HEADERS_OPTIONS, PostmanAdminController::MESSAGE_HEADERS_SECTION );
// Fallback
// the Email Validation section
add_settings_section( PostmanAdminController::EMAIL_VALIDATION_SECTION, __( 'Validation', 'post-smtp' ), array(
$this,
'printEmailValidationSectionInfo',
), PostmanAdminController::EMAIL_VALIDATION_OPTIONS );
add_settings_field( PostmanOptions::ENVELOPE_SENDER, __( 'Email Address', 'post-smtp' ), 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', 'post-smtp' ), array(
$this,
'printLoggingSectionInfo',
), PostmanAdminController::LOGGING_OPTIONS );
add_settings_field( 'logging_status', __( 'Enable Logging', 'post-smtp' ), array(
$this,
'loggingStatusInputField',
), PostmanAdminController::LOGGING_OPTIONS, PostmanAdminController::LOGGING_SECTION );
add_settings_field( 'logging_max_entries', __( 'Maximum Log Entries', 'post-smtp' ), array(
$this,
'loggingMaxEntriesInputField',
), PostmanAdminController::LOGGING_OPTIONS, PostmanAdminController::LOGGING_SECTION );
add_settings_field( PostmanOptions::TRANSCRIPT_SIZE, __( 'Maximum Transcript Size', 'post-smtp' ), array(
$this,
'transcriptSizeInputField',
), PostmanAdminController::LOGGING_OPTIONS, PostmanAdminController::LOGGING_SECTION );
// the Network section
add_settings_section( PostmanAdminController::NETWORK_SECTION, __( 'Network Settings', 'post-smtp' ), array(
$this,
'printNetworkSectionInfo',
), PostmanAdminController::NETWORK_OPTIONS );
add_settings_field( 'connection_timeout', _x( 'TCP Connection Timeout (sec)', 'Configuration Input Field', 'post-smtp' ), array(
$this,
'connection_timeout_callback',
), PostmanAdminController::NETWORK_OPTIONS, PostmanAdminController::NETWORK_SECTION );
add_settings_field( 'read_timeout', _x( 'TCP Read Timeout (sec)', 'Configuration Input Field', 'post-smtp' ), 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', 'post-smtp' ), array(
$this,
'printAdvancedSectionInfo',
), PostmanAdminController::ADVANCED_OPTIONS );
add_settings_field( PostmanOptions::LOG_LEVEL, _x( 'PHP Log Level', 'Configuration Input Field', 'post-smtp' ), array(
$this,
'log_level_callback',
), PostmanAdminController::ADVANCED_OPTIONS, PostmanAdminController::ADVANCED_SECTION );
add_settings_field( PostmanOptions::RUN_MODE, _x( 'Delivery Mode', 'Configuration Input Field', 'post-smtp' ), 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', 'post-smtp' ), array(
$this,
'stealthModeCallback',
), PostmanAdminController::ADVANCED_OPTIONS, PostmanAdminController::ADVANCED_SECTION );
add_settings_field( PostmanOptions::TEMPORARY_DIRECTORY, __( 'Temporary Directory', 'post-smtp' ), array(
$this,
'temporaryDirectoryCallback',
), PostmanAdminController::ADVANCED_OPTIONS, PostmanAdminController::ADVANCED_SECTION );
add_settings_field( PostmanOptions::INCOMPATIBLE_PHP_VERSION, __( 'Broken Email Fix', 'post-smtp' ), array(
$this,
'incompatible_php_version_callback',
), PostmanAdminController::ADVANCED_OPTIONS, PostmanAdminController::ADVANCED_SECTION );
do_action( 'post_smtp_settings_fields' );
}
}
/**
* Print the Transport section info
*/
public function printTransportSectionInfo() {
print __( 'Choose SMTP or a vendor-specific API:', 'post-smtp' );
}
public function printLoggingSectionInfo() {
print __( 'Configure the delivery audit log:', 'post-smtp' );
}
/**
* 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.', 'post-smtp' ), '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.', 'post-smtp' );
}
/**
* 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.', 'post-smtp' );
}
/**
* Print the Section text
*/
public function printAdvancedSectionInfo() {
}
/**
* Print the Section text
*/
public function printNotificationsSectionInfo() {
}
/**
* 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.', 'post-smtp' );
}
/**
* 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.', 'post-smtp' );
}
/**
* 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 smtp_mailer_callback() {
$smtp_mailers = PostmanOptions::SMTP_MAILERS;
$current_smtp_mailer = $this->options->getSmtpMailer();
printf( '<select id="input_%2$s" class="input_%2$s" name="%1$s[%2$s]">', PostmanOptions::POSTMAN_OPTIONS, 'smtp_mailers' );
foreach ( $smtp_mailers as $key => $smtp_mailer ) {
printf( '<option class="input_tx_type_%1$s" value="%1$s" %3$s>%2$s</option>', $key, $smtp_mailer, $current_smtp_mailer == $key ? 'selected="selected"' : '' );
}
print '</select>';
?>
<p class="description" id="mailer-type-description"><?php _e( 'Beta Feature: ONLY change this to <strong>PHPMailer</strong> only if you see <code>wp_mail</code> conflict message, conflicts when another plugin is activated, and <strong><u>sometimes</u></strong> your mail marked as spam.', 'post-smtp' ); ?></p>
<?php
}
/**
* Get the settings option array and print one of its values
*/
public function sender_name_callback( $_echo = true ) {
if( $_echo ) {
printf( '<input type="text" id="input_sender_name" class="ps-input ps-w-75" name="postman_options[sender_name]" value="%s" size="40" />', null !== $this->options->getMessageSenderName() ? esc_attr( $this->options->getMessageSenderName() ) : '' );
}
else {
return sprintf( '<input type="text" id="input_sender_name" class="ps-input ps-w-75" 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', 'post-smtp' ) );
}
/**
* Get the settings option array and print one of its values
*/
public function from_email_callback( $_echo = true ) {
if( $_echo ) {
printf( '<input type="email" id="input_sender_email" class="ps-input ps-w-75" name="postman_options[sender_email]" value="%s" size="40" class="required" placeholder="%s"/>', null !== $this->options->getMessageSenderEmail() ? esc_attr( $this->options->getMessageSenderEmail() ) : '', __( 'Required', 'post-smtp' ) );
}
else {
return sprintf( '<input type="email" id="input_sender_email" class="ps-input ps-w-75" name="postman_options[sender_email]" value="%s" size="40" class="required" placeholder="%s"/>', null !== $this->options->getMessageSenderEmail() ? esc_attr( $this->options->getMessageSenderEmail() ) : '', __( 'Required', 'post-smtp' ) );
}
}
/**
* 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.', 'post-smtp' ), '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', 'post-smtp' ) );
}
/**
* 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', 'post-smtp' ) );
printf( '<option value="%s" %s>%s</option>', PostmanOptions::MAIL_LOG_ENABLED_OPTION_NO, ! $this->options->isMailLoggingEnabled() ? 'selected="selected"' : '', __( 'No', 'post-smtp' ) );
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.', 'post-smtp' );
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', 'post-smtp' ) );
}
/**
* 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="_blank" href="%s">WordPress Debug log</a> - view the log with <a target-"_new" href="%s">Debug</a>.', 'post-smtp' ), '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', 'post-smtp' ), PostmanLogger::OFF_INT, $currentKey );
$this->printSelectOption( __( 'Trace', 'post-smtp' ), PostmanLogger::TRACE_INT, $currentKey );
$this->printSelectOption( __( 'Debug', 'post-smtp' ), PostmanLogger::DEBUG_INT, $currentKey );
$this->printSelectOption( __( 'Info', 'post-smtp' ), PostmanLogger::INFO_INT, $currentKey );
$this->printSelectOption( __( 'Warning', 'post-smtp' ), PostmanLogger::WARN_INT, $currentKey );
$this->printSelectOption( __( 'Error', 'post-smtp' ), 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.', 'post-smtp' );
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', 'post-smtp' ), PostmanOptions::RUN_MODE_PRODUCTION, $currentKey );
$this->printSelectOption( __( 'Log only', 'post-smtp' ), PostmanOptions::RUN_MODE_LOG_ONLY, $currentKey );
$this->printSelectOption( __( 'No Action', 'post-smtp' ), 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', 'post-smtp' ) );
}
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,
esc_attr( $this->options->getTempDirectory() )
);
if ( PostmanState::getInstance()->isFileLockingEnabled() ) {
printf( ' <span style="color:green">%s</span></br><span class="postman_input_description">%s</span>', __( 'Valid', 'post-smtp' ), $inputDescription );
} else {
printf( ' <span style="color:red">%s</span></br><span class="postman_input_description">%s</span>', __( 'Invalid', 'post-smtp' ), $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', 'post-smtp' ) );
}
/**
* Incompatible PHP Version Callback
*
* @since 2.5.0
* @version 1.0.0
*/
public function incompatible_php_version_callback() {
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::INCOMPATIBLE_PHP_VERSION, $this->options->is_php_compatibility_enabled() ? 'checked="checked"' : '', __( 'Only enable this option, if the email\'s header or body seems broken.', 'post-smtp' ) );
}
}

View File

@@ -0,0 +1,237 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
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 );
foreach ( PostmanSmtpMappings::$emailDomain as $domain => $smtp ) {
if (strcasecmp ( $hostname, $domain ) == 0) {
return $smtp;
}
}
return false;
}
public static function getSmtpFromMx($mx) {
reset ( PostmanSmtpMappings::$mxMappings );
foreach ( PostmanSmtpMappings::$mxMappings as $domain => $smtp ) {
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 mixed $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 mixed $email
* @return string|bool
*/
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 mixed $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 mixed $hostname
* @param mixed $mxhosts
* @param mixed $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;
}
}
}

View File

@@ -0,0 +1,89 @@
var transports = [];
jQuery(document).ready(
function($) {
// display password on entry
enablePasswordDisplayOnEntry('input_basic_auth_password',
'togglePasswordField');
// tabs
jQuery("#config_tabs").tabs( {
activate: function( event ,ui ) {
jQuery( ui.oldTab ).addClass( 'visited-config-ui-tab' );
}
} );
// 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(post_smtp_localize.postman_hostname_element_name).keyup(function() {
clearTimeout(typingTimer);
if (jQuery(post_smtp_localize.postman_hostname_element_name).val) {
typingTimer = setTimeout(doneTyping, doneTypingInterval);
}
});
// user is "finished typing," do something
function doneTyping() {
if (jQuery(post_smtp_localize.postman_input_auth_type).val() == 'oauth2') {
reloadOauthSection();
}
}
});
function reloadOauthSection() {
var hostname = jQuery(post_smtp_localize.postman_hostname_element_name).val();
var transport = jQuery('#input_transport_type').val();
var authtype = jQuery('select#input_auth_type').val();
var security = jQuery('#security').val();
var data = {
'action' : 'manual_config',
'auth_type' : authtype,
'hostname' : hostname,
'transport' : transport,
'security' : security
};
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);
});
}

View File

@@ -0,0 +1,714 @@
var transports = [];
connectivtyTestResults = {};
portTestInProgress = false;
/**
* Functions to run on document load
*/
jQuery(document).ready(function() {
jQuery(post_smtp_localize.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,
'security' : jQuery('#security').val(),
};
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,
'security' : jQuery('#security').val()
};
jQuery.post(
ajaxurl,
data,
function(response) {
if (postmanValidateAjaxResponseWithPopup(response)) {
checkedEmail = true;
smtpDiscovery = response.data;
if (response.data.hostname != null
&& response.data.hostname) {
jQuery(post_smtp_localize.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 : post_smtp_localize.steps_current_step,
pagination : post_smtp_localize.steps_pagination,
finish : post_smtp_localize.steps_finish,
next : post_smtp_localize.steps_next,
previous : post_smtp_localize.steps_previous,
loading : post_smtp_localize.steps_loading
},
onStepChanging : function(event, currentIndex, newIndex) {
var response = handleStepChange( event, currentIndex, newIndex, jQuery( this ) );
if( response ) {
if( !jQuery( `#postman_wizard-t-${currentIndex} span` ).hasClass( 'dashicons' ) )
jQuery( `#postman_wizard-t-${currentIndex}` ).append( '<span class="ps-right dashicons dashicons-yes-alt"></span>' );
}
return response;
},
onInit : function() {
if( !jQuery( `#postman_wizard-t-0 span` ).hasClass( 'dashicons' ) )
jQuery( '#postman_wizard-t-0' ).append( '<span class="ps-right dashicons dashicons-yes-alt"></span>' );
jQuery(post_smtp_localize.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(post_smtp_localize.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(post_smtp_localize.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(post_smtp_localize.postman_port_element_name).val();
var hostname = jQuery(post_smtp_localize.postman_hostname_element_name).val();
var authType = jQuery(post_smtp_localize.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(post_smtp_localize.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(post_smtp_localize.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,
'security' : jQuery('#security').val(),
};
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;
var logoURL = response.hosts[x].logo_url;
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,
'logo_url': logoURL,
'security' : jQuery('#security').val(),
};
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';
data['security'] = jQuery('#security').val();
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,
'security': jQuery('#security').val()
};
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,
'security' : jQuery('#security').val()
};
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) {
var html = '';
var authHtml = '';
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('');
var columns = 1;
for (i = 0; i < response.override_menu.length; i++) {
response.override_menu[i].data = response.override_menu[i].data !== null ? response.override_menu[i].data : false;
if( columns == 1 ) {
html += "<div class='ps-socket-wizad-row'>";
}
html += buildRadioButtonGroup(
'user_socket_override',
response.override_menu[i].selected,
response.override_menu[i].value,
response.override_menu[i].description,
response.override_menu[i].secure,
response.override_menu[i].data
);
if( columns == 3 ) {
html += '</div>';
columns = 0;
}
columns++;
// 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++) {
authHtml += buildRadioButtonGroup(
'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');
}
}
}
}
el1.append( html );
el2.append( authHtml );
jQuery( postmanPro ).each( function( index, value ){
var allRows = jQuery( '.ps-socket-wizad-row' );
var totalRows = allRows.length - 1;
var lastRow = jQuery( allRows[totalRows] );
var lastRowLength = lastRow.find( 'label' );
//Write in existing row
if( lastRowLength.length < 3 ) {
jQuery( lastRow ).append(
`<a href="${value.url}" style="box-shadow: none;" target="_blank">
<label style="text-align:center">
<div class="ps-single-socket-outer ps-sib">
<img src="${value.pro}" class="ps-sib-recommended">
<img src="${value.logo}" class="ps-wizard-socket-logo" width="165px">
</div>
<img draggable="false" role="img" class="emoji" alt="🔒" src="https://s.w.org/images/core/emoji/14.0.0/svg/1f512.svg">${value.extenstion}
</label>
</a>`
);
}
//New row
else {
jQuery( lastRow ).after(
`<div class='ps-socket-wizad-row'>
<a href="${value.url}" style="box-shadow: none;" target="_blank">
<label style="text-align:center">
<div class="ps-single-socket-outer ps-sib">
<img src="${value.pro}" class="ps-sib-recommended">
<img src="${value.logo}" class="ps-wizard-socket-logo" width="165px">
</div>
<img draggable="false" role="img" class="emoji" alt="🔒" src="https://s.w.org/images/core/emoji/14.0.0/svg/1f512.svg">${value.extenstion}
</label>
</a>
</div>`
);
}
} );
// Add an event on Socket Selection/ Switching
jQuery( 'input.user_socket_override' ).change( function() {
userOverrideMenu();
} );
// Add an event on Socket's Auth Type Selection/ Switching
jQuery( 'input.user_auth_override' ).change( function() {
userOverrideMenu();
} );
}
/**
*
* @param {*} radioGroupName
* @param {*} isSelected
* @param {*} value
* @param {*} label
* @param {*} isSecure
* @param {*} data
* @returns
*
* @since 2.1 Returns html instead of appending
*/
function buildRadioButtonGroup( radioGroupName, isSelected, value, label, isSecure, data = '' ) {
var radioInputValue = ' value="' + value + '"';
var radioInputChecked = '';
var secureIcon = '';
var logoTag = '';
var html = '';
var recommendedBlock = '';
var relativeClass = '';
if (isSelected) {
radioInputChecked = ' checked = "checked"';
}
if (isSecure) {
secureIcon = '&#x1f512;';
}
if( data.logo_url && data.logo_url !== undefined ) {
if( label == 'Sendinblue' ) {
relativeClass = 'ps-sib';
recommendedBlock = `
<img src="${postman.assets}images/icons/recommended.png" class="ps-sib-recommended" />
`;
}
logoTag = `
<div class='ps-single-socket-outer ${relativeClass}'>
${recommendedBlock}
<img src='${data.logo_url}' class='ps-wizard-socket-logo' width='165px' />
</div>
`;
}
html = `
<label>
${logoTag}
<input class="${radioGroupName}" type="radio" name="${radioGroupName}"${radioInputChecked} ${radioInputValue} />
${secureIcon + label}
</label>
`;
return html;
}
/**
* 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,
'security' : jQuery('#security').val(),
};
jQuery
.post(
ajaxurl,
data,
function(response) {
if (response.success) {
jQuery('select#input_transport_type').val(
'smtp');
jQuery(post_smtp_localize.postman_input_sender_email).val(
response.sender_email);
jQuery(post_smtp_localize.postman_input_sender_name).val(
response.sender_name);
jQuery(post_smtp_localize.postman_hostname_element_name).val(
response.hostname);
jQuery(post_smtp_localize.postman_port_element_name).val(
response.port);
jQuery(post_smtp_localize.postman_input_auth_type).val(
response.auth_type);
jQuery('#input_enc_type')
.val(response.enc_type);
jQuery(post_smtp_localize.postman_input_basic_username).val(
response.basic_auth_username);
jQuery(post_smtp_localize.postman_input_basic_password).val(
response.basic_auth_password);
switchBetweenPasswordAndOAuth();
}
}).fail(function(response) {
ajaxFailed(response);
});
} else {
jQuery(post_smtp_localize.postman_input_sender_email).val('');
jQuery(post_smtp_localize.postman_input_sender_name).val('');
jQuery(post_smtp_localize.postman_input_basic_username).val('');
jQuery(post_smtp_localize.postman_input_basic_password).val('');
jQuery(post_smtp_localize.postman_hostname_element_name).val('');
jQuery(post_smtp_localize.postman_port_element_name).val('');
jQuery(post_smtp_localize.postman_input_auth_type).val('none');
jQuery(post_smtp_localize.postman_enc_for_password_el).val('none');
switchBetweenPasswordAndOAuth();
}
}