/**
  * Important: bind() may be called multiple times
  *
  * Replace wp_mail() after making sure:
  * 1) the plugin has not already bound to wp_mail and
  * 2) wp_mail is available for use
  * 3) the plugin is properly configured.
  * 4) the plugin's prerequisites are met.
  */
 function bind()
 {
     if (!$this->bound) {
         $binderOptions = PostmanOptions::getInstance();
         $binderAuthorizationToken = PostmanOAuthToken::getInstance();
         $ready = true;
         if (function_exists('wp_mail')) {
             // If the function exists, it's probably because another plugin has
             // replaced the pluggable function first, and we set an error flag.
             // this is an error message because it is a Bind error
             $this->logger->error('wp_mail is already bound, Postman can not use it');
             $this->bindError = true;
         }
         if (!PostmanTransportRegistry::getInstance()->isPostmanReadyToSendEmail($binderOptions, $binderAuthorizationToken)) {
             // this is a debug message because bound may be called again with a NEW transport that IS configured
             // this is a debug message because it is not up to the Binder to report transport errors
             $this->logger->debug('Transport is not configured and ready');
             $ready = false;
         }
         if (!PostmanPreRequisitesCheck::isReady()) {
             // this is a debug message because it is not up to the Binder to report transport errors
             $this->logger->debug('Prerequisite check failed');
             $ready = false;
         }
         if ($ready && !$this->bindError) {
             $this->logger->debug('Binding to wp_mail()');
             $this->replacePluggableFunctionWpMail();
         }
     }
 }
 public function createAuthenticationManager(PostmanTransport $transport, PostmanOptions $options, PostmanOAuthToken $authorizationToken, PostmanConfigTextHelper $scribe = null)
 {
     $authenticationType = $options->getAuthenticationType();
     $hostname = $options->getHostname();
     $clientId = $options->getClientId();
     $clientSecret = $options->getClientSecret();
     $senderEmail = $options->getMessageSenderEmail();
     if (!isset($scribe)) {
         $transport = PostmanTransportRegistry::getInstance()->getCurrentTransport();
         $scribe = PostmanConfigTextHelperFactory::createScribe($hostname, $transport);
     }
     $redirectUrl = $scribe->getCallbackUrl();
     if ($transport->isOAuthUsed($options->getAuthenticationType()) && $transport->isServiceProviderGoogle($hostname)) {
         $authenticationManager = new PostmanGoogleAuthenticationManager($clientId, $clientSecret, $authorizationToken, $redirectUrl, $senderEmail);
     } else {
         if ($transport->isOAuthUsed($options->getAuthenticationType()) && $transport->isServiceProviderMicrosoft($hostname)) {
             $authenticationManager = new PostmanMicrosoftAuthenticationManager($clientId, $clientSecret, $authorizationToken, $redirectUrl);
         } else {
             if ($transport->isOAuthUsed($options->getAuthenticationType()) && $transport->isServiceProviderYahoo($hostname)) {
                 $authenticationManager = new PostmanYahooAuthenticationManager($clientId, $clientSecret, $authorizationToken, $redirectUrl);
             } else {
                 $authenticationManager = new PostmanNonOAuthAuthenticationManager();
             }
         }
     }
     $this->logger->debug('Created ' . get_class($authenticationManager));
     return $authenticationManager;
 }
 /**
  * Print the human-readable plugin state
  */
 public function print_postman_status()
 {
     if (!PostmanPreRequisitesCheck::isReady()) {
         printf('<p><span style="color:red">%s</span></p>', __('Error: Postman is missing a required PHP library.', 'postman-smtp'));
     } else {
         if ($this->wpMailBinder->isUnboundDueToException()) {
             printf('<p><span style="color:red">%s</span></p>', __('Postman: wp_mail has been declared by another plugin or theme, so you won\'t be able to use Postman until the conflict is resolved.', 'postman-smtp'));
         } else {
             if ($this->options->getRunMode() != PostmanOptions::RUN_MODE_PRODUCTION) {
                 printf('<p><span style="background-color:yellow">%s</span></p>', __('Postman is in <em>non-Production</em> mode and is dumping all emails.', 'postman-smtp'));
             } else {
                 if (PostmanTransportRegistry::getInstance()->isPostmanReadyToSendEmail($this->options, $this->authorizationToken)) {
                     printf('<p class="wp-menu-image dashicons-before dashicons-email"> %s </p>', sprintf(_n('<span style="color:green">Postman is configured</span> and has delivered <span style="color:green">%d</span> email.', '<span style="color:green">Postman is configured</span> and has delivered <span style="color:green">%d</span> emails.', PostmanStats::getInstance()->getSuccessfulDeliveries(), 'postman-smtp'), PostmanStats::getInstance()->getSuccessfulDeliveries()));
                     $currentTransport = PostmanTransportRegistry::getInstance()->getCurrentTransport();
                     $deliveryDetails = $currentTransport->getDeliveryDetails($this->options);
                     printf('<p>%s</p>', $deliveryDetails);
                 } else {
                     printf('<p><span>%s %s</span></p>', __('Postman is <em>not</em> handling email delivery.', 'postman-smtp'), sprintf(__('<a href="%s">Configure</a> the plugin.', 'postman-smtp'), PostmanUtils::getSettingsPageUrl()));
                 }
             }
         }
     }
 }
 /**
  */
 private function displayTopNavigation()
 {
     screen_icon();
     printf('<h2>%s</h2>', _x('Postman Setup', 'Page Title', 'postman-smtp'));
     print '<div id="postman-main-menu" class="welcome-panel">';
     print '<div class="welcome-panel-content">';
     print '<div class="welcome-panel-column-container">';
     print '<div class="welcome-panel-column">';
     printf('<h4>%s</h4>', _x('Settings', 'The configuration page of the plugin', 'postman-smtp'));
     printf('<a class="button button-primary button-hero" href="%s">%s</a>', $this->getPageUrl(self::CONFIGURATION_WIZARD_SLUG), __('Start the Wizard', 'postman-smtp'));
     printf('<p class="">or, <a href="%s" class="configure_manually">%s</a>. </p>', $this->getPageUrl(self::CONFIGURATION_SLUG), _x('configure manually', 'Adjust the Postman settings by hand', 'postman-smtp'));
     print '</div>';
     print '<div class="welcome-panel-column">';
     printf('<h4>%s</h4>', _x('Actions', 'Main Menu', 'postman-smtp'));
     print '<ul>';
     if (PostmanTransportRegistry::getInstance()->isRequestOAuthPermissionAllowed($this->options, $this->authorizationToken)) {
         printf('<li><a href="%s" class="welcome-icon send-test-email">%s</a></li>', PostmanUtils::getGrantOAuthPermissionUrl(), $this->oauthScribe->getRequestPermissionLinkText());
     } else {
         printf('<li><div class="welcome-icon send_test_email">%s</div></li>', $this->oauthScribe->getRequestPermissionLinkText());
     }
     if (PostmanTransportRegistry::getInstance()->isPostmanReadyToSendEmail($this->options, $this->authorizationToken)) {
         printf('<li><a href="%s" class="welcome-icon send_test_email">%s</a></li>', $this->getPageUrl(self::EMAIL_TEST_SLUG), __('Send a Test Email', 'postman-smtp'));
     } else {
         printf('<li><div class="welcome-icon send_test_email">%s</div></li>', __('Send a Test Email', 'postman-smtp'));
     }
     $purgeLinkPattern = '<li><a href="%1$s" class="welcome-icon oauth-authorize">%2$s</a></li>';
     if ($this->options->isNew()) {
         $purgeLinkPattern = '<li>%2$s</li>';
     }
     printf($purgeLinkPattern, $this->getPageUrl(PostmanAdminController::PURGE_DATA_SLUG), __('Delete plugin settings', 'postman-smtp'));
     print '</ul>';
     print '</div>';
     print '<div class="welcome-panel-column welcome-panel-last">';
     printf('<h4>%s</h4>', _x('Troubleshooting', 'Main Menu', 'postman-smtp'));
     print '<ul>';
     printf('<li><a href="%s" class="welcome-icon run-port-test">%s</a></li>', $this->getPageUrl(self::PORT_TEST_SLUG), __('Connectivity Test', 'postman-smtp'));
     printf('<li><a href="%s" class="welcome-icon run-port-test">%s</a></li>', $this->getPageUrl(self::DIAGNOSTICS_SLUG), __('Diagnostic Test', 'postman-smtp'));
     printf('<li><a href="https://wordpress.org/support/plugin/postman-smtp" class="welcome-icon postman_support">%s</a></li>', __('Online Support', 'postman-smtp'));
     print '</ul></div></div></div></div>';
 }
Beispiel #5
0
 /**
  * Register the email transports.
  *
  * The Gmail API used to be a separate plugin which was registered when that plugin
  * was loaded. But now both the SMTP, Gmail API and other transports are registered here.
  *
  * @param unknown $pluginData        	
  */
 private function registerTransports($rootPluginFilenameAndPath)
 {
     PostmanTransportRegistry::getInstance()->registerTransport(new PostmanDefaultModuleTransport($rootPluginFilenameAndPath));
     PostmanTransportRegistry::getInstance()->registerTransport(new PostmanSmtpModuleTransport($rootPluginFilenameAndPath));
     PostmanTransportRegistry::getInstance()->registerTransport(new PostmanGmailApiModuleTransport($rootPluginFilenameAndPath));
     PostmanTransportRegistry::getInstance()->registerTransport(new PostmanMandrillTransport($rootPluginFilenameAndPath));
     PostmanTransportRegistry::getInstance()->registerTransport(new PostmanSendGridTransport($rootPluginFilenameAndPath));
 }
 /**
  * This Ajax function determines which hosts/ports to test in both the Wizard Connectivity Test and direct Connectivity Test
  *
  * Given a single outgoing smtp server hostname, return an array of host/port
  * combinations to run the connectivity test on
  */
 function getPortsToTestViaAjax()
 {
     $queryHostname = PostmanUtils::getRequestParameter('hostname');
     // originalSmtpServer is what SmtpDiscovery thinks the SMTP server should be, given an email address
     $originalSmtpServer = PostmanUtils::getRequestParameter('original_smtp_server');
     if ($this->logger->isDebug()) {
         $this->logger->debug('Probing available transports for sockets against hostname ' . $queryHostname);
     }
     $sockets = PostmanTransportRegistry::getInstance()->getSocketsForSetupWizardToProbe($queryHostname, $originalSmtpServer);
     $response = array('hosts' => $sockets);
     wp_send_json_success($response);
 }
 /**
  * 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()
 {
     // only administrators should be able to trigger this
     if (PostmanUtils::isAdmin()) {
         //
         $transport = PostmanTransportRegistry::getInstance()->getCurrentTransport();
         $this->oauthScribe = $transport->getScribe();
         // register content handlers
         $viewController = new PostmanViewController($this->rootPluginFilenameAndPath, $this->options, $this->authorizationToken, $this->oauthScribe, $this);
         // register action handlers
         $this->registerAdminPostAction(self::PURGE_DATA_SLUG, 'handlePurgeDataAction');
         $this->registerAdminPostAction(self::IMPORT_SETTINGS_SLUG, 'importSettingsAction');
         $this->registerAdminPostAction(PostmanUtils::REQUEST_OAUTH2_GRANT_SLUG, 'handleOAuthPermissionRequestAction');
         if (PostmanUtils::isCurrentPagePostmanAdmin()) {
             $this->checkPreRequisites();
         }
     }
 }
Beispiel #8
0
 /**
  * A convenient place for any code to inject a constructed PostmanMessage
  * (for example, from MyMail)
  *
  * The body parts may be set already at this time.
  *
  * @param PostmanMessage $message        	
  * @return boolean
  */
 public function sendMessage(PostmanMessage $message, PostmanEmailLog $log)
 {
     // get the Options and AuthToken
     $options = PostmanOptions::getInstance();
     $authorizationToken = PostmanOAuthToken::getInstance();
     // get the transport and create the transportConfig and engine
     $transport = PostmanTransportRegistry::getInstance()->getActiveTransport();
     // create the Mail Engine
     $engine = $transport->createMailEngine();
     // add plugin-specific attributes to PostmanMessage
     $message->addHeaders($options->getAdditionalHeaders());
     $message->addTo($options->getForcedToRecipients());
     $message->addCc($options->getForcedCcRecipients());
     $message->addBcc($options->getForcedBccRecipients());
     // apply the WordPress filters
     // may impact the from address, from email, charset and content-type
     $message->applyFilters();
     // create the body parts (if they are both missing)
     if ($message->isBodyPartsEmpty()) {
         $message->createBodyParts();
     }
     // is this a test run?
     $testMode = apply_filters('postman_test_email', false);
     if ($this->logger->isDebug()) {
         $this->logger->debug('testMode=' . $testMode);
     }
     // start the clock
     $startTime = microtime(true) * 1000;
     try {
         // prepare the message
         $message->validate($transport);
         // send the message
         if ($options->getRunMode() == PostmanOptions::RUN_MODE_PRODUCTION) {
             if ($transport->isLockingRequired()) {
                 PostmanUtils::lock();
                 // may throw an exception attempting to contact the OAuth2 provider
                 $this->ensureAuthtokenIsUpdated($transport, $options, $authorizationToken);
             }
             $this->logger->debug('Sending mail');
             // may throw an exception attempting to contact the SMTP server
             $engine->send($message);
             // increment the success counter, unless we are just tesitng
             if (!$testMode) {
                 PostmanState::getInstance()->incrementSuccessfulDelivery();
             }
         }
         // clean up
         $this->postSend($engine, $startTime, $options, $transport);
         if ($options->getRunMode() == PostmanOptions::RUN_MODE_PRODUCTION || $options->getRunMode() == PostmanOptions::RUN_MODE_LOG_ONLY) {
             // log the successful delivery
             PostmanEmailLogService::getInstance()->writeSuccessLog($log, $message, $engine->getTranscript(), $transport);
         }
         // return successful
         return true;
     } catch (Exception $e) {
         // save the error for later
         $this->exception = $e;
         // write the error to the PHP log
         $this->logger->error(get_class($e) . ' code=' . $e->getCode() . ' message=' . trim($e->getMessage()));
         // increment the failure counter, unless we are just tesitng
         if (!$testMode && $options->getRunMode() == PostmanOptions::RUN_MODE_PRODUCTION) {
             PostmanState::getInstance()->incrementFailedDelivery();
         }
         // clean up
         $this->postSend($engine, $startTime, $options, $transport);
         if ($options->getRunMode() == PostmanOptions::RUN_MODE_PRODUCTION || $options->getRunMode() == PostmanOptions::RUN_MODE_LOG_ONLY) {
             // log the failed delivery
             PostmanEmailLogService::getInstance()->writeFailureLog($log, $message, $engine->getTranscript(), $transport, $e->getMessage());
         }
         // return failure
         return false;
     }
 }
Beispiel #9
0
 /**
  * A convenient place for other code to send a PostmanMessage
  *
  * @param PostmanMessage $message        	
  * @return boolean
  */
 public function sendMessage(PostmanMessage $message, PostmanEmailLog $log)
 {
     // start the clock
     $startTime = microtime(true) * 1000;
     // get the Options and AuthToken
     $options = PostmanOptions::getInstance();
     $authorizationToken = PostmanOAuthToken::getInstance();
     // add plugin-specific attributes to PostmanMessage
     $message->addHeaders($options->getAdditionalHeaders());
     $message->addTo($options->getForcedToRecipients());
     $message->addCc($options->getForcedCcRecipients());
     $message->addBcc($options->getForcedBccRecipients());
     // get the transport and create the transportConfig and engine
     $transport = PostmanTransportRegistry::getInstance()->getCurrentTransport();
     // create the Zend Mail Transport Configuration Factory
     if (PostmanOptions::AUTHENTICATION_TYPE_OAUTH2 == $transport->getAuthenticationType()) {
         $transportConfiguration = new PostmanOAuth2ConfigurationFactory();
     } else {
         $transportConfiguration = new PostmanBasicAuthConfigurationFactory();
     }
     // create the Mail Engine
     $engine = new PostmanMailEngine($transport, $transportConfiguration);
     // is this a test run?
     $testMode = apply_filters('postman_test_email', false);
     $this->logger->debug('testMode=' . $testMode);
     try {
         // validate the message
         $message->applyFilters();
         $message->validate();
         // send the message
         if ($options->getRunMode() == PostmanOptions::RUN_MODE_PRODUCTION) {
             if ($options->isAuthTypeOAuth2()) {
                 PostmanUtils::lock();
                 // may throw an exception attempting to contact the OAuth2 provider
                 $this->ensureAuthtokenIsUpdated($transport, $options, $authorizationToken);
             }
             $this->logger->debug('Sending mail');
             // may throw an exception attempting to contact the SMTP server
             $engine->send($message, $options->getHostname());
             // increment the success counter, unless we are just tesitng
             if (!$testMode) {
                 PostmanStats::getInstance()->incrementSuccessfulDelivery();
             }
         }
         if ($options->getRunMode() == PostmanOptions::RUN_MODE_PRODUCTION || $options->getRunMode() == PostmanOptions::RUN_MODE_LOG_ONLY) {
             // log the successful delivery
             PostmanEmailLogService::getInstance()->writeSuccessLog($log, $message, $engine->getTranscript(), $transport);
         }
         // clean up
         $this->postSend($engine, $startTime, $options);
         // return successful
         return true;
     } catch (Exception $e) {
         // save the error for later
         $this->exception = $e;
         // write the error to the PHP log
         $this->logger->error(get_class($e) . ' code=' . $e->getCode() . ' message=' . trim($e->getMessage()));
         // increment the failure counter, unless we are just tesitng
         if (!$testMode && $options->getRunMode() == PostmanOptions::RUN_MODE_PRODUCTION) {
             PostmanStats::getInstance()->incrementFailedDelivery();
         }
         if ($options->getRunMode() == PostmanOptions::RUN_MODE_PRODUCTION || $options->getRunMode() == PostmanOptions::RUN_MODE_LOG_ONLY) {
             // log the failed delivery
             PostmanEmailLogService::getInstance()->writeFailureLog($log, $message, $engine->getTranscript(), $transport, $e->getMessage());
         }
         // clean up
         $this->postSend($engine, $startTime, $options);
         // return failure
         return false;
     }
 }
 /**
  * Register the email transports.
  *
  * The Gmail API used to be a separate plugin which was registered when that plugin
  * was loaded. But now both the SMTP and Gmail API transports are registered here.
  *
  * @param unknown $pluginData        	
  */
 private function registerTransports()
 {
     PostmanTransportRegistry::getInstance()->registerTransport(new PostmanSmtpModuleTransport());
     PostmanTransportRegistry::getInstance()->registerTransport(new PostmanGmailApiModuleTransport());
 }
 /**
  * // 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($queryHostData, $userSocketOverride, $userAuthOverride, $originalSmtpServer)
 {
     $recommendationPriority = -1;
     $winningRecommendation = null;
     foreach ($queryHostData as $id => $value) {
         $available = filter_var($value['success'], FILTER_VALIDATE_BOOLEAN);
         if ($available) {
             $this->logger->debug(sprintf('Asking for judgement on %s:%s', $value['hostname'], $value['port']));
             $recommendation = PostmanTransportRegistry::getInstance()->getRecommendation($value, $userAuthOverride, $originalSmtpServer);
             $recommendationId = sprintf('%s_%s', $value['hostname'], $value['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;
             }
         }
     }
     return $winningRecommendation;
 }
 /**
  */
 private function displayTopNavigation()
 {
     screen_icon();
     printf('<h2>%s</h2>', sprintf(__('%s Setup', Postman::TEXT_DOMAIN), __('Postman SMTP', Postman::TEXT_DOMAIN)));
     print '<div id="postman-main-menu" class="welcome-panel">';
     print '<div class="welcome-panel-content">';
     print '<div class="welcome-panel-column-container">';
     print '<div class="welcome-panel-column">';
     printf('<h4>%s</h4>', __('Configuration', Postman::TEXT_DOMAIN));
     printf('<a class="button button-primary button-hero" href="%s">%s</a>', $this->getPageUrl(PostmanConfigurationController::CONFIGURATION_WIZARD_SLUG), __('Start the Wizard', Postman::TEXT_DOMAIN));
     printf('<p class="">or <a href="%s" class="configure_manually">%s</a></p>', $this->getPageUrl(PostmanConfigurationController::CONFIGURATION_SLUG), __('Show All Settings', Postman::TEXT_DOMAIN));
     print '</div>';
     print '<div class="welcome-panel-column">';
     printf('<h4>%s</h4>', _x('Actions', 'Main Menu', Postman::TEXT_DOMAIN));
     print '<ul>';
     // Grant permission with Google
     PostmanTransportRegistry::getInstance()->getSelectedTransport()->printActionMenuItem();
     if (PostmanWpMailBinder::getInstance()->isBound()) {
         printf('<li><a href="%s" class="welcome-icon send_test_email">%s</a></li>', $this->getPageUrl(PostmanSendTestEmailController::EMAIL_TEST_SLUG), __('Send a Test Email', Postman::TEXT_DOMAIN));
     } else {
         printf('<li><div class="welcome-icon send_test_email">%s</div></li>', __('Send a Test Email', Postman::TEXT_DOMAIN));
     }
     // import-export-reset menu item
     if (!$this->options->isNew() || true) {
         $purgeLinkPattern = '<li><a href="%1$s" class="welcome-icon oauth-authorize">%2$s</a></li>';
     } else {
         $purgeLinkPattern = '<li>%2$s</li>';
     }
     $importTitle = __('Import', Postman::TEXT_DOMAIN);
     $exportTile = __('Export', Postman::TEXT_DOMAIN);
     $resetTitle = __('Reset Plugin', Postman::TEXT_DOMAIN);
     $importExportReset = sprintf('%s/%s/%s', $importTitle, $exportTile, $resetTitle);
     printf($purgeLinkPattern, $this->getPageUrl(PostmanAdminController::MANAGE_OPTIONS_PAGE_SLUG), sprintf('%s', $importExportReset));
     print '</ul>';
     print '</div>';
     print '<div class="welcome-panel-column welcome-panel-last">';
     printf('<h4>%s</h4>', _x('Troubleshooting', 'Main Menu', Postman::TEXT_DOMAIN));
     print '<ul>';
     printf('<li><a href="%s" class="welcome-icon run-port-test">%s</a></li>', $this->getPageUrl(PostmanConnectivityTestController::PORT_TEST_SLUG), __('Connectivity Test', Postman::TEXT_DOMAIN));
     printf('<li><a href="%s" class="welcome-icon run-port-test">%s</a></li>', $this->getPageUrl(PostmanDiagnosticTestController::DIAGNOSTICS_SLUG), __('Diagnostic Test', Postman::TEXT_DOMAIN));
     printf('<li><a href="https://wordpress.org/support/plugin/postman-smtp" class="welcome-icon postman_support">%s</a></li>', __('Online Support', Postman::TEXT_DOMAIN));
     print '</ul></div></div></div></div>';
 }
Beispiel #13
0
 /**
  *
  * @return string
  */
 public function export()
 {
     if (PostmanPreRequisitesCheck::checkZlibEncode()) {
         $data = $this->options;
         $data['version'] = PostmanState::getInstance()->getVersion();
         foreach (PostmanTransportRegistry::getInstance()->getTransports() as $transport) {
             $data = $transport->prepareOptionsForExport($data);
         }
         $data = base64_encode(gzcompress(json_encode($data), 9));
         return $data;
     }
 }
 /**
  * Creates a Log object for use by writeToEmailLog()
  *
  * @param PostmanMessage $message        	
  * @param unknown $transcript        	
  * @param unknown $statusMessage        	
  * @param unknown $success        	
  * @param PostmanModuleTransport $transport        	
  * @return PostmanEmailLog
  */
 private function createLog(PostmanEmailLog $log, PostmanMessage $message = null, $transcript, $statusMessage, $success, PostmanModuleTransport $transport)
 {
     if ($message) {
         $log->sender = $message->getFromAddress()->format();
         $log->toRecipients = $this->flattenEmails($message->getToRecipients());
         $log->ccRecipients = $this->flattenEmails($message->getCcRecipients());
         $log->bccRecipients = $this->flattenEmails($message->getBccRecipients());
         $log->subject = $message->getSubject();
         $log->body = $message->getBody();
         if (null !== $message->getReplyTo()) {
             $log->replyTo = $message->getReplyTo()->format();
         }
     }
     $log->success = $success;
     $log->statusMessage = $statusMessage;
     $log->transportUri = PostmanTransportRegistry::getInstance()->getPublicTransportUri($transport);
     $log->sessionTranscript = $log->transportUri . "\n\n" . $transcript;
     return $log;
 }
 /**
  * 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>';
 }
 /**
  * This Ajax function determines which hosts/ports to test in the Wizard Port Test
  *
  * Given a single outgoing smtp server hostname, return an array of host/port
  * combinations to run the connectivity test on
  */
 function getPortsToTestViaAjax()
 {
     $queryHostname = $this->getRequestParameter('hostname');
     $isGmail = $this->getBooleanRequestParameter(PostmanGetHostnameByEmailAjaxController::IS_GOOGLE_PARAMETER);
     $hosts = PostmanTransportRegistry::getInstance()->getSocketsForSetupWizardToProbe($queryHostname, $isGmail);
     $this->logger->trace('hostsToTest:');
     $this->logger->trace($hosts);
     $response = array('hosts' => $hosts, 'success' => true);
     wp_send_json($response);
 }
 /**
  * Print the human-readable plugin state
  */
 public function print_postman_status()
 {
     if (!PostmanPreRequisitesCheck::isReady()) {
         printf('<p><span style="color:red">%s</span></p>', __('Error: Postman is missing a required PHP library.', Postman::TEXT_DOMAIN));
     } else {
         if ($this->wpMailBinder->isUnboundDueToException()) {
             printf('<p><span style="color:red">%s</span></p>', __('Postman: wp_mail has been declared by another plugin or theme, so you won\'t be able to use Postman until the conflict is resolved.', Postman::TEXT_DOMAIN));
         } else {
             if ($this->options->getRunMode() != PostmanOptions::RUN_MODE_PRODUCTION) {
                 printf('<p><span style="background-color:yellow">%s</span></p>', __('Postman is in <em>non-Production</em> mode and is dumping all emails.', Postman::TEXT_DOMAIN));
             } else {
                 if (PostmanTransportRegistry::getInstance()->getSelectedTransport()->isConfiguredAndReady()) {
                     printf('<p class="wp-menu-image dashicons-before dashicons-email"> %s </p>', sprintf(_n('<span style="color:green">Postman is configured</span> and has delivered <span style="color:green">%d</span> email.', '<span style="color:green">Postman is configured</span> and has delivered <span style="color:green">%d</span> emails.', PostmanState::getInstance()->getSuccessfulDeliveries(), Postman::TEXT_DOMAIN), PostmanState::getInstance()->getSuccessfulDeliveries()));
                 } else {
                     printf('<p><span style="color:red">%s</span></p>', __('Postman is <em>not</em> configured and is mimicking out-of-the-box WordPress email delivery.', Postman::TEXT_DOMAIN));
                 }
             }
             $currentTransport = PostmanTransportRegistry::getInstance()->getActiveTransport();
             $deliveryDetails = $currentTransport->getDeliveryDetails($this->options);
             printf('<p>%s</p>', $deliveryDetails);
         }
     }
 }
 /**
  *
  * @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;
 }
 /**
  */
 public function getDiagnostics()
 {
     $transportRegistry = PostmanTransportRegistry::getInstance();
     $this->addToDiagnostics('OS', php_uname());
     $this->addToDiagnostics('PHP', PHP_OS . ' ' . PHP_VERSION . ' ' . setlocale(LC_CTYPE, 0));
     $this->addToDiagnostics('PHP Dependencies', $this->getPhpDependencies());
     $this->addToDiagnostics('WordPress', (is_multisite() ? 'Multisite ' : '') . get_bloginfo('version') . ' ' . get_locale() . ' ' . get_bloginfo('charset', 'display'));
     $this->addToDiagnostics('WordPress Theme', wp_get_theme());
     $this->addToDiagnostics('WordPress Plugins', $this->getActivePlugins());
     $bindResult = apply_filters('postman_wp_mail_bind_status', null);
     $wp_mail_file_name = 'n/a';
     if (class_exists('ReflectionFunction')) {
         $wp_mail = new ReflectionFunction('wp_mail');
         $wp_mail_file_name = realpath($wp_mail->getFileName());
     }
     if (!$bindResult['bound']) {
         $this->addToDiagnostics('WordPress wp_mail Owner', $wp_mail_file_name);
     }
     $this->addToDiagnostics('WordPress wp_mail Filter(s)', $this->getFilters('wp_mail'));
     $this->addToDiagnostics('WordPress wp_mail_from Filter(s)', $this->getFilters('wp_mail_from'));
     $this->addToDiagnostics('WordPress wp_mail_from_name Filter(s)', $this->getFilters('wp_mail_from_name'));
     $this->addToDiagnostics('WordPress wp_mail_content_type Filter(s)', $this->getFilters('wp_mail_content_type'));
     $this->addToDiagnostics('WordPress wp_mail_charset Filter(s)', $this->getFilters('wp_mail_charset'));
     $this->addToDiagnostics('WordPress phpmailer_init Action(s)', $this->getFilters('phpmailer_init'));
     $pluginData = apply_filters('postman_get_plugin_metadata', null);
     $this->addToDiagnostics('Postman', $pluginData['version']);
     $s1 = $this->options->getEnvelopeSender();
     $s2 = $this->options->getMessageSenderEmail();
     if (!empty($s1) || !empty($s2)) {
         $this->addToDiagnostics('Postman Sender Domain (Envelope|Message)', ($hostname = substr(strrchr($this->options->getEnvelopeSender(), "@"), 1)) . ' | ' . ($hostname = substr(strrchr($this->options->getMessageSenderEmail(), "@"), 1)));
     }
     $this->addToDiagnostics('Postman Prevent Message Sender Override (Email|Name)', ($this->options->isSenderEmailOverridePrevented() ? 'Yes' : 'No') . ' | ' . ($this->options->isSenderNameOverridePrevented() ? 'Yes' : 'No'));
     // status of the active transport
     $transport = $transportRegistry->getActiveTransport();
     $this->addToDiagnostics('Postman Active Transport', sprintf('%s (%s)', $transport->getName(), $transportRegistry->getPublicTransportUri($transport)));
     $this->addToDiagnostics('Postman Active Transport Status (Ready|Connected)', ($transport->isConfiguredAndReady() ? 'Yes' : 'No') . ' | ' . $this->testConnectivity($transport));
     if ($transportRegistry->getActiveTransport() != $transportRegistry->getSelectedTransport() && $transportRegistry->getSelectedTransport() != null) {
         // status of the selected transport
         $transport = $transportRegistry->getSelectedTransport();
         $this->addToDiagnostics('Postman Selected Transport', sprintf('%s (%s)', $transport->getName(), $transportRegistry->getPublicTransportUri($transport)));
         $this->addToDiagnostics('Postman Selected Transport Status (Ready|Connected)', ($transport->isConfiguredAndReady() ? 'Yes' : 'No') . ' | ' . $this->testConnectivity($transport));
     }
     $this->addToDiagnostics('Postman Deliveries (Success|Fail)', PostmanState::getInstance()->getSuccessfulDeliveries() . ' | ' . PostmanState::getInstance()->getFailedDeliveries());
     if ($this->options->getConnectionTimeout() != PostmanOptions::DEFAULT_TCP_CONNECTION_TIMEOUT || $this->options->getReadTimeout() != PostmanOptions::DEFAULT_TCP_READ_TIMEOUT) {
         $this->addToDiagnostics('Postman TCP Timeout (Connection|Read)', $this->options->getConnectionTimeout() . ' | ' . $this->options->getReadTimeout());
     }
     if ($this->options->isMailLoggingEnabled() != PostmanOptions::DEFAULT_MAIL_LOG_ENABLED || $this->options->getMailLoggingMaxEntries() != PostmanOptions::DEFAULT_MAIL_LOG_ENTRIES || $this->options->getTranscriptSize() != PostmanOptions::DEFAULT_TRANSCRIPT_SIZE) {
         $this->addToDiagnostics('Postman Email Log (Enabled|Limit|Transcript Size)', ($this->options->isMailLoggingEnabled() ? 'Yes' : 'No') . ' | ' . $this->options->getMailLoggingMaxEntries() . ' | ' . $this->options->getTranscriptSize());
     }
     $this->addToDiagnostics('Postman Run Mode', $this->options->getRunMode() == PostmanOptions::RUN_MODE_PRODUCTION ? null : $this->options->getRunMode());
     $this->addToDiagnostics('Postman PHP LogLevel', $this->options->getLogLevel() == PostmanLogger::ERROR_INT ? null : $this->options->getLogLevel());
     $this->addToDiagnostics('Postman Stealth Mode', $this->options->isStealthModeEnabled() ? 'Yes' : null);
     $this->addToDiagnostics('Postman File Locking (Enabled|Temp Dir)', PostmanState::getInstance()->isFileLockingEnabled() ? null : 'No' . ' | ' . $this->options->getTempDirectory());
     $response = array('message' => $this->diagnostics);
     wp_send_json_success($response);
 }
 public function createAuthenticationManager()
 {
     $transport = PostmanTransportRegistry::getInstance()->getSelectedTransport();
     return $this->createManager($transport);
 }