/** * Shows the review feature of Postman up to thirty days after install * * @return boolean */ public function isTimeToReviewPostman() { if (!empty($this->options[self::INSTALL_DATE])) { $successful = PostmanStats::getInstance()->getSuccessfulDeliveries() > 0; $maxTime = $this->options[self::INSTALL_DATE] + self::TOO_LONG_SEC; return $successful && time() <= $maxTime; } }
/** * 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())); } } } } }
/** * Options page callback */ public function outputDefaultContent() { // Set class property print '<div class="wrap">'; $this->displayTopNavigation(); if (PostmanTransportRegistry::getInstance()->isPostmanReadyToSendEmail($this->options, $this->authorizationToken) && PostmanPreRequisitesCheck::isReady()) { 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 { printf('<p><span style="color:green;padding:2px 5px; font-size:1.2em">%s</span></p>', __('Postman is configured.', 'postman-smtp')); $currentTransport = PostmanTransportRegistry::getInstance()->getCurrentTransport(); $deliveryDetails = $currentTransport->getDeliveryDetails($this->options); printf('<p style="margin:0 10px"><span>%s</span></p>', $deliveryDetails); } /* translators: where %d is the number of emails delivered */ printf('<p style="margin:10px 10px"><span>%s', sprintf(_n('Postman has delivered <span style="color:green">%d</span> email for you.', 'Postman has delivered <span style="color:green">%d</span> emails for you.', PostmanStats::getInstance()->getSuccessfulDeliveries(), 'postman-smtp'), PostmanStats::getInstance()->getSuccessfulDeliveries())); if ($this->options->isMailLoggingEnabled()) { print ' '; printf('<a href="%s">%s</a>.</span></p>', PostmanUtils::getEmailLogPageUrl(), __('View the log', 'postman-smtp')); } if (PostmanState::getInstance()->isTimeToReviewPostman() && !PostmanOptions::getInstance()->isNew()) { print '</br><hr width="70%"></br>'; /* translators: where %s is the URL to the WordPress.org review and ratings page */ printf('%s</span></p>', sprintf(__('Please consider <a href="%s">leaving a review</a> to help spread the word! :D', 'postman-smtp'), 'https://wordpress.org/support/view/plugin-reviews/postman-smtp?filter=5')); } } else { printf('<p><span style="color:red; padding:2px 5px; font-size:1.1em">%s</span></p>', __('Postman is <em>not</em> handling email delivery.', 'postman-smtp')); if ($this->options->isNew()) { printf('<h3>%s</h3>', __('Thank-you for choosing Postman!', 'postman-smtp')); /* translators: where %s is the URL of the Setup Wizard */ printf('<p><span>%s</span></p>', sprintf(__('Let\'s get started! All users are strongly encouraged to <a href="%s">run the Setup Wizard</a>.', 'postman-smtp'), $this->getPageUrl(self::CONFIGURATION_WIZARD_SLUG))); } } }
public function getDiagnostics() { $transportRegistry = PostmanTransportRegistry::getInstance(); $this->addToDiagnostics(sprintf('OS: %s', php_uname())); $this->addToDiagnostics(sprintf('HTTP User Agent: %s', $_SERVER['HTTP_USER_AGENT'])); $this->addToDiagnostics(sprintf('Platform: PHP %s %s / WordPress %s %s %s', PHP_OS, PHP_VERSION, is_multisite() ? 'Multisite' : '', get_bloginfo('version'), get_locale())); $this->addToDiagnostics($this->getPhpDependencies()); $this->addToDiagnostics(sprintf('WordPress Theme: %s', wp_get_theme())); $this->addToDiagnostics($this->getActivePlugins()); $pluginData = apply_filters('postman_get_plugin_metadata', null); $this->addToDiagnostics(sprintf('Postman Version: %s', $pluginData['version'])); $this->addToDiagnostics(sprintf('Postman Sender Domain (Envelope|Message): %s|%s', $hostname = substr(strrchr($this->options->getEnvelopeSender(), "@"), 1), $hostname = substr(strrchr($this->options->getMessageSenderEmail(), "@"), 1))); $this->addToDiagnostics(sprintf('Postman Prevent Message Sender Override (Email|Name): %s|%s', $this->options->isSenderEmailOverridePrevented() ? 'Yes' : 'No', $this->options->isSenderNameOverridePrevented() ? 'Yes' : 'No')); $this->addToDiagnostics(sprintf('Postman Transport URI: %s', $transportRegistry->getPublicTransportUri($transportRegistry->getCurrentTransport()))); $this->addToDiagnostics(sprintf('Postman Transport Status (Configured|Ready|Connected): %s|%s|%s', $transportRegistry->getCurrentTransport()->isConfigured($this->options, $this->authorizationToken) ? 'Yes' : 'No', PostmanTransportRegistry::getInstance()->getCurrentTransport()->isReady($this->options, $this->authorizationToken) ? 'Yes' : 'No', $this->testConnectivity())); $this->addToDiagnostics(sprintf('Postman Deliveries (Success|Fail): %d|%d', PostmanStats::getInstance()->getSuccessfulDeliveries(), PostmanStats::getInstance()->getFailedDeliveries())); $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()); } $this->addToDiagnostics(sprintf('Postman Bind (Success|Fail|Path): %s|%s|%s', $bindResult['bound'] ? 'Yes' : 'No', $bindResult['bind_error'] ? 'Yes' : 'No', $wp_mail_file_name)); $this->addToDiagnostics(sprintf('Postman TCP Timeout (Connection|Read): %d|%d', $this->options->getConnectionTimeout(), $this->options->getReadTimeout())); $this->addToDiagnostics(sprintf('Postman Email Log (Enabled|Limit|Transcript Size): %s|%d|%d', $this->options->isMailLoggingEnabled() ? 'Yes' : 'No', $this->options->getMailLoggingMaxEntries(), $this->options->getTranscriptSize())); $this->addToDiagnostics(sprintf('Postman Run Mode: %s', $this->options->getRunMode())); $this->addToDiagnostics(sprintf('Postman PHP LogLevel: %s', $this->options->getLogLevel())); $this->addToDiagnostics(sprintf('Postman Stealth Mode: %s', $this->options->isStealthModeEnabled() ? 'Yes' : 'No')); $this->addToDiagnostics(sprintf('Postman File Locking (Enabled|Temp Dir): %s|%s', PostmanState::getInstance()->isFileLockingEnabled() ? 'Yes' : 'No', $this->options->getTempDirectory())); $response = array('message' => $this->diagnostics); wp_send_json_success($response); }
/** */ public function getDiagnostics() { $transportRegistry = PostmanTransportRegistry::getInstance(); $this->addToDiagnostics('OS', php_uname()); $this->addToDiagnostics('HTTP User Agent', $_SERVER['HTTP_USER_AGENT']); $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()); $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')); $this->addToDiagnostics('Postman Transport URI', $transportRegistry->getPublicTransportUri($transportRegistry->getCurrentTransport())); $this->addToDiagnostics('Postman Transport Status (Configured|Ready|Connected)', ($transportRegistry->getCurrentTransport()->isConfigured($this->options, $this->authorizationToken) ? 'Yes' : 'No') . ' | ' . (PostmanTransportRegistry::getInstance()->getCurrentTransport()->isReady($this->options, $this->authorizationToken) ? 'Yes' : 'No') . ' | ' . $this->testConnectivity()); $this->addToDiagnostics('Postman Deliveries (Success|Fail)', PostmanStats::getInstance()->getSuccessfulDeliveries() . ' | ' . PostmanStats::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); }
/** * 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; } }