示例#1
0
 /**
  * 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 = PostmanState::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::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);
         }
     }
 }
示例#3
0
 /**
  * The constructor
  *
  * @param unknown $rootPluginFilenameAndPath
  *        	- the __FILE__ of the caller
  */
 public function __construct($rootPluginFilenameAndPath, $version)
 {
     assert(!empty($rootPluginFilenameAndPath));
     assert(!empty($version));
     $this->rootPluginFilenameAndPath = $rootPluginFilenameAndPath;
     // load the dependencies
     require_once 'PostmanOptions.php';
     require_once 'PostmanState.php';
     require_once 'PostmanLogger.php';
     require_once 'PostmanUtils.php';
     require_once 'Postman-Mail/PostmanTransportRegistry.php';
     require_once 'Postman-Mail/PostmanSmtpModuleTransport.php';
     require_once 'Postman-Mail/PostmanGmailApiModuleTransport.php';
     require_once 'PostmanOAuthToken.php';
     require_once 'PostmanWpMailBinder.php';
     require_once 'PostmanConfigTextHelper.php';
     require_once 'Postman-Email-Log/PostmanEmailLogPostType.php';
     require_once 'Postman-Mail/PostmanMyMailConnector.php';
     // get plugin metadata - alternative to get_plugin_data
     $this->pluginData = array('name' => __('Postman SMTP', 'postman-smtp'), 'version' => $version);
     // register the plugin metadata filter (part of the Postman API)
     add_filter('postman_get_plugin_metadata', array($this, 'getPluginMetaData'));
     // create an instance of the logger
     $this->logger = new PostmanLogger(get_class($this));
     $this->logger->debug(sprintf('%1$s v%2$s starting', $this->pluginData['name'], $this->pluginData['version']));
     if (isset($_REQUEST['page'])) {
         $this->logger->trace('Current page: ' . $_REQUEST['page']);
     }
     // load the text domain
     $this->loadTextDomain($rootPluginFilenameAndPath);
     // register the email transports
     $this->registerTransports();
     // store an instance of the WpMailBinder
     $this->wpMailBinder = PostmanWpMailBinder::getInstance();
     // bind to wp_mail - this has to happen before the "init" action
     // this design allows other plugins to register a Postman transport and call bind()
     // bind may be called more than once
     $this->wpMailBinder->bind();
     // registers the custom post type for all callers
     PostmanEmailLogPostType::automaticallyCreatePostType();
     // register activation handler on the activation event
     // must be called in constructor
     if (PostmanState::getInstance()->getVersion() != $this->pluginData['version']) {
         require_once 'PostmanDatastoreUpgrader.php';
         $this->logger->info(sprintf("Upgrading datastore from version %s to %s", PostmanState::getInstance()->getVersion(), $this->pluginData['version']));
         $activate = new PostmanActivationHandler();
         $activate->activate_postman();
     }
     // register the shortcode handler on the add_shortcode event
     add_shortcode('postman-version', array($this, 'version_shortcode'));
     // load the administration screens
     if (is_admin()) {
         // the is_admin check only tells us that we are not on the public pages
         $this->setup_admin();
     }
     // register the check for configuration errors on the wp_loaded hook,
     // because we want it to run after the OAuth Grant Code check on the init hook
     add_action('wp_loaded', array($this, 'check_for_configuration_errors'));
     // MyMail integration
     new PostmanMyMailConnector($rootPluginFilenameAndPath);
 }
 public function temporaryDirectoryCallback()
 {
     printf('<input type="text" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::TEMPORARY_DIRECTORY, $this->options->getTempDirectory());
     if (PostmanState::getInstance()->isFileLockingEnabled()) {
         printf(' <span style="color:green">Valid</span>');
     } else {
         printf(' <span style="color:red">Invalid</span>');
     }
 }
 /**
  * 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)));
         }
     }
 }
 /**
  * Sanitize each setting field as needed
  *
  * @param array $input
  *        	Contains all settings fields as array keys
  */
 public function sanitize($input)
 {
     $this->logger->debug("Sanitizing data before storage");
     $new_input = array();
     $success = true;
     $this->sanitizeString('Encryption Type', PostmanOptions::SECURITY_TYPE, $input, $new_input);
     $this->sanitizeString('Hostname', PostmanOptions::HOSTNAME, $input, $new_input);
     if (!empty($input[PostmanOptions::PORT])) {
         $port = absint($input[PostmanOptions::PORT]);
         if ($port > 0) {
             $this->sanitizeInt('Port', PostmanOptions::PORT, $input, $new_input);
         } else {
             $new_input[PostmanOptions::PORT] = $this->options->getPort();
             add_settings_error(PostmanOptions::PORT, PostmanOptions::PORT, 'Invalid TCP Port', 'error');
             $success = false;
         }
     }
     // check the auth type AFTER the hostname because we reset the hostname if auth is bad
     $this->sanitizeString('From Email', PostmanOptions::MESSAGE_SENDER_EMAIL, $input, $new_input);
     // the wizard doesn't set an envelope sender, so we'll default it to From Email
     $new_input[PostmanOptions::ENVELOPE_SENDER] = $new_input[PostmanOptions::MESSAGE_SENDER_EMAIL];
     $this->sanitizeString('Sender Email', PostmanOptions::ENVELOPE_SENDER, $input, $new_input);
     $this->sanitizeString('Transport Type', PostmanOptions::TRANSPORT_TYPE, $input, $new_input);
     $this->sanitizeString('Authorization Type', PostmanOptions::AUTHENTICATION_TYPE, $input, $new_input);
     $this->sanitizeString('From Name', PostmanOptions::MESSAGE_SENDER_NAME, $input, $new_input);
     $this->sanitizeString('Client ID', PostmanOptions::CLIENT_ID, $input, $new_input);
     $this->sanitizeString('Client Secret', PostmanOptions::CLIENT_SECRET, $input, $new_input);
     $this->sanitizeString('Username', PostmanOptions::BASIC_AUTH_USERNAME, $input, $new_input);
     $this->sanitizePassword('Password', PostmanOptions::BASIC_AUTH_PASSWORD, $input, $new_input, $this->options->getPassword());
     $this->sanitizePassword('Mandrill API Key', PostmanOptions::MANDRILL_API_KEY, $input, $new_input, $this->options->getMandrillApiKey());
     $this->sanitizePassword('SendGrid API Key', PostmanOptions::SENDGRID_API_KEY, $input, $new_input, $this->options->getSendGridApiKey());
     $this->sanitizeString('Reply-To', PostmanOptions::REPLY_TO, $input, $new_input);
     $this->sanitizeString('From Name Override', PostmanOptions::PREVENT_MESSAGE_SENDER_NAME_OVERRIDE, $input, $new_input);
     $this->sanitizeString('From Email Override', PostmanOptions::PREVENT_MESSAGE_SENDER_EMAIL_OVERRIDE, $input, $new_input);
     $this->sanitizeString('Disable Email Validation', PostmanOptions::DISABLE_EMAIL_VALIDAITON, $input, $new_input);
     $this->sanitizeString('Forced To Recipients', PostmanOptions::FORCED_TO_RECIPIENTS, $input, $new_input);
     $this->sanitizeString('Forced CC Recipients', PostmanOptions::FORCED_CC_RECIPIENTS, $input, $new_input);
     $this->sanitizeString('Forced BCC Recipients', PostmanOptions::FORCED_BCC_RECIPIENTS, $input, $new_input);
     $this->sanitizeString('Additional Headers', PostmanOptions::ADDITIONAL_HEADERS, $input, $new_input);
     $this->sanitizeInt('Read Timeout', PostmanOptions::READ_TIMEOUT, $input, $new_input);
     $this->sanitizeInt('Conenction Timeout', PostmanOptions::CONNECTION_TIMEOUT, $input, $new_input);
     $this->sanitizeInt('Log Level', PostmanOptions::LOG_LEVEL, $input, $new_input);
     $this->sanitizeString('Email Log Enabled', PostmanOptions::MAIL_LOG_ENABLED_OPTION, $input, $new_input);
     $this->sanitizeLogMax('Email Log Max Entries', PostmanOptions::MAIL_LOG_MAX_ENTRIES, $input, $new_input);
     $this->sanitizeString('Run Mode', PostmanOptions::RUN_MODE, $input, $new_input);
     $this->sanitizeString('Stealth Mode', PostmanOptions::STEALTH_MODE, $input, $new_input);
     $this->sanitizeInt('Transcript Size', PostmanOptions::TRANSCRIPT_SIZE, $input, $new_input);
     $this->sanitizeString('Temporary Directory', PostmanOptions::TEMPORARY_DIRECTORY, $input, $new_input);
     if ($new_input[PostmanOptions::CLIENT_ID] != $this->options->getClientId() || $new_input[PostmanOptions::CLIENT_SECRET] != $this->options->getClientSecret() || $new_input[PostmanOptions::HOSTNAME] != $this->options->getHostname()) {
         $this->logger->debug("Recognized new Client ID");
         // the user entered a new client id and we should destroy the stored auth token
         delete_option(PostmanOAuthToken::OPTIONS_NAME);
     }
     // can we create a tmp file? - this code is duplicated in ActivationHandler
     PostmanUtils::deleteLockFile($new_input[PostmanOptions::TEMPORARY_DIRECTORY]);
     $lockSuccess = PostmanUtils::createLockFile($new_input[PostmanOptions::TEMPORARY_DIRECTORY]);
     // &= does not work as expected in my PHP
     $lockSuccess = $lockSuccess && PostmanUtils::deleteLockFile($new_input[PostmanOptions::TEMPORARY_DIRECTORY]);
     $this->logger->debug('FileLocking=' . $lockSuccess);
     PostmanState::getInstance()->setFileLockingEnabled($lockSuccess);
     if ($success) {
         PostmanSession::getInstance()->setAction(self::VALIDATION_SUCCESS);
     } else {
         PostmanSession::getInstance()->setAction(self::VALIDATION_FAILED);
     }
     return $new_input;
 }
示例#7
0
 /**
  * The constructor
  *
  * @param unknown $rootPluginFilenameAndPath
  *        	- the __FILE__ of the caller
  */
 public function __construct($rootPluginFilenameAndPath, $version)
 {
     assert(!empty($rootPluginFilenameAndPath));
     assert(!empty($version));
     $this->rootPluginFilenameAndPath = $rootPluginFilenameAndPath;
     // load the dependencies
     require_once 'PostmanOptions.php';
     require_once 'PostmanState.php';
     require_once 'PostmanLogger.php';
     require_once 'PostmanUtils.php';
     require_once 'Postman-Mail/PostmanTransportRegistry.php';
     require_once 'Postman-Mail/PostmanDefaultModuleTransport.php';
     require_once 'Postman-Mail/PostmanSmtpModuleTransport.php';
     require_once 'Postman-Mail/PostmanGmailApiModuleTransport.php';
     require_once 'Postman-Mail/PostmanMandrillTransport.php';
     require_once 'Postman-Mail/PostmanSendGridTransport.php';
     require_once 'PostmanOAuthToken.php';
     require_once 'PostmanWpMailBinder.php';
     require_once 'PostmanConfigTextHelper.php';
     require_once 'Postman-Email-Log/PostmanEmailLogPostType.php';
     require_once 'Postman-Mail/PostmanMyMailConnector.php';
     // get plugin metadata - alternative to get_plugin_data
     $this->pluginData = array('name' => __('Postman SMTP', Postman::TEXT_DOMAIN), 'version' => $version);
     // register the plugin metadata filter (part of the Postman API)
     add_filter('postman_get_plugin_metadata', array($this, 'getPluginMetaData'));
     // create an instance of the logger
     $this->logger = new PostmanLogger(get_class($this));
     if ($this->logger->isDebug()) {
         $this->logger->debug(sprintf('%1$s v%2$s starting', $this->pluginData['name'], $this->pluginData['version']));
     }
     if (isset($_REQUEST['page']) && $this->logger->isTrace()) {
         $this->logger->trace('Current page: ' . $_REQUEST['page']);
     }
     // register the email transports
     $this->registerTransports($rootPluginFilenameAndPath);
     // store an instance of the WpMailBinder
     $this->wpMailBinder = PostmanWpMailBinder::getInstance();
     // bind to wp_mail - this has to happen before the "init" action
     // this design allows other plugins to register a Postman transport and call bind()
     // bind may be called more than once
     $this->wpMailBinder->bind();
     // registers the custom post type for all callers
     PostmanEmailLogPostType::automaticallyCreatePostType();
     // run the DatastoreUpgrader any time there is a version mismatch
     if (PostmanState::getInstance()->getVersion() != $this->pluginData['version']) {
         // manually trigger the activation hook
         if ($this->logger->isInfo()) {
             $this->logger->info(sprintf("Upgrading datastore from version %s to %s", PostmanState::getInstance()->getVersion(), $this->pluginData['version']));
         }
         require_once 'PostmanInstaller.php';
         $upgrader = new PostmanInstaller();
         $upgrader->activatePostman();
     }
     // MyMail integration
     new PostmanMyMailConnector($rootPluginFilenameAndPath);
     // register the shortcode handler on the add_shortcode event
     add_shortcode('postman-version', array($this, 'version_shortcode'));
     // hook on the plugins_loaded event
     add_action('plugins_loaded', array($this, 'on_plugins_loaded'));
     // hook on the wp_loaded event
     add_action('wp_loaded', array($this, 'on_wp_loaded'));
     // hook on the acivation event
     register_activation_hook($rootPluginFilenameAndPath, array($this, 'on_activation'));
     // hook on the deactivation event
     register_deactivation_hook($rootPluginFilenameAndPath, array($this, 'on_deactivation'));
 }
 /**
  * (non-PHPdoc)
  *
  * @see PostmanSmtpEngine::send()
  */
 public function send(PostmanMessage $message)
 {
     $options = PostmanOptions::getInstance();
     // add the Postman signature - append it to whatever the user may have set
     if (!$options->isStealthModeEnabled()) {
         $pluginData = apply_filters('postman_get_plugin_metadata', null);
         $this->addHeader('X-Mailer', sprintf('Postman SMTP %s for WordPress (%s)', $pluginData['version'], 'https://wordpress.org/plugins/postman-smtp/'));
     }
     // add the headers - see http://framework.zend.com/manual/1.12/en/zend.mail.additional-headers.html
     foreach ((array) $message->getHeaders() as $header) {
         $this->logger->debug(sprintf('Adding user header %s=%s', $header['name'], $header['content']));
         $this->addHeader($header['name'], $header['content'], true);
     }
     // if the caller set a Content-Type header, use it
     $contentType = $message->getContentType();
     if (!empty($contentType)) {
         $this->logger->debug('Adding content-type ' . $contentType);
         $this->addHeader('Content-Type', $contentType);
     }
     // add the From Header
     $sender = $message->getFromAddress();
     $senderEmail = $sender->getEmail();
     $senderName = $sender->getName();
     assert(!empty($senderEmail));
     $this->mandrillMessage['from_email'] = $senderEmail;
     if (!empty($senderName)) {
         $this->mandrillMessage['from_name'] = $senderName;
     }
     // now log it
     $sender->log($this->logger, 'From');
     // add the Sender Header, overriding what the user may have set
     $this->addHeader('Sender', $options->getEnvelopeSender());
     // add the to recipients
     foreach ((array) $message->getToRecipients() as $recipient) {
         $recipient->log($this->logger, 'To');
         $recipient = array('email' => $recipient->getEmail(), 'name' => $recipient->getName(), 'type' => 'to');
         array_push($this->mandrillMessage['to'], $recipient);
     }
     // add the cc recipients
     foreach ((array) $message->getCcRecipients() as $recipient) {
         $recipient->log($this->logger, 'Cc');
         $recipient = array('email' => $recipient->getEmail(), 'name' => $recipient->getName(), 'type' => 'cc');
         array_push($this->mandrillMessage['to'], $recipient);
     }
     // add the bcc recipients
     foreach ((array) $message->getBccRecipients() as $recipient) {
         $recipient->log($this->logger, 'Bcc');
         $recipient = array('email' => $recipient->getEmail(), 'name' => $recipient->getName(), 'type' => 'bcc');
         array_push($this->mandrillMessage['to'], $recipient);
     }
     // add the reply-to
     $replyTo = $message->getReplyTo();
     // $replyTo is null or a PostmanEmailAddress object
     if (isset($replyTo)) {
         $this->addHeader('reply-to', $replyTo->format());
     }
     // add the date
     $date = $message->getDate();
     if (!empty($date)) {
         $this->addHeader('date', $message->getDate());
     }
     // add the messageId
     $messageId = $message->getMessageId();
     if (!empty($messageId)) {
         $this->addHeader('message-id', $messageId);
     }
     // add the subject
     if (null !== $message->getSubject()) {
         $this->mandrillMessage['subject'] = $message->getSubject();
     }
     $textPart = $message->getBodyTextPart();
     if (!empty($textPart)) {
         $this->logger->debug('Adding body as text');
         $this->mandrillMessage['text'] = $textPart;
     }
     $htmlPart = $message->getBodyHtmlPart();
     if (!empty($htmlPart)) {
         $this->logger->debug('Adding body as html');
         $this->mandrillMessage['html'] = $htmlPart;
     }
     // add attachments
     $this->logger->debug("Adding attachments");
     $this->addAttachmentsToMail($message);
     $result = array();
     try {
         if ($this->logger->isDebug()) {
             $this->logger->debug("Creating Mandrill service with apiKey=" . $this->apiKey);
         }
         $mandrill = new Postman_Mandrill($this->apiKey);
         // send the message
         if ($this->logger->isDebug()) {
             $this->logger->debug("Sending mail");
         }
         $result = $mandrill->messages->send($this->mandrillMessage);
         if ($this->logger->isInfo()) {
             $this->logger->info(sprintf('Message %d accepted for delivery', PostmanState::getInstance()->getSuccessfulDeliveries() + 1));
         }
         $this->transcript = print_r($result, true);
         $this->transcript .= PostmanModuleTransport::RAW_MESSAGE_FOLLOWS;
         $this->transcript .= print_r($this->mandrillMessage, true);
     } catch (Exception $e) {
         $this->transcript = $e->getMessage();
         $this->transcript .= PostmanModuleTransport::RAW_MESSAGE_FOLLOWS;
         $this->transcript .= print_r($this->mandrillMessage, true);
         throw $e;
     }
 }
 /**
  * (non-PHPdoc)
  *
  * @see PostmanSmtpEngine::send()
  */
 public function send(PostmanMessage $message)
 {
     $this->logger->debug("Prepping Zend");
     $envelopeFrom = new PostmanEmailAddress($this->transport->getEnvelopeFromEmailAddress());
     if ($this->transport->isEnvelopeFromValidationSupported()) {
         // validate the envelope from since we didn't do it in the Message
         $envelopeFrom->validate('Envelope From');
     }
     // create the Message
     $charset = $message->getCharset();
     $this->logger->debug('Building Postman_Zend_Mail with charset=' . $charset);
     $mail = new Postman_Zend_Mail($charset);
     // add the Postman signature - append it to whatever the user may have set
     if (!PostmanOptions::getInstance()->isStealthModeEnabled()) {
         $pluginData = apply_filters('postman_get_plugin_metadata', null);
         $mail->addHeader('X-Mailer', sprintf('Postman SMTP %s for WordPress (%s)', $pluginData['version'], 'https://wordpress.org/plugins/postman-smtp/'));
     }
     // add the headers - see http://framework.zend.com/manual/1.12/en/zend.mail.additional-headers.html
     foreach ((array) $message->getHeaders() as $header) {
         $this->logger->debug(sprintf('Adding user header %s=%s', $header['name'], $header['content']));
         $mail->addHeader($header['name'], $header['content'], true);
     }
     // if the caller set a Content-Type header, use it
     $contentType = $message->getContentType();
     if (!empty($contentType)) {
         $mail->addHeader('Content-Type', $contentType, false);
         $this->logger->debug('Adding content-type ' . $contentType);
     }
     // add the From Header
     $fromHeader = $this->addFrom($message, $mail);
     $fromHeader->log($this->logger, 'From');
     // add the Sender Header, overriding what the user may have set
     $mail->addHeader('Sender', $this->transport->getFromEmailAddress(), false);
     // from RFC 5321: http://tools.ietf.org/html/rfc5321#section-4.4
     // A message-originating SMTP system SHOULD NOT send a message that
     // already contains a Return-path header field.
     // I changed Zend/Mail/Mail.php to fix this
     $mail->setReturnPath($this->transport->getEnvelopeFromEmailAddress());
     // add the to recipients
     foreach ((array) $message->getToRecipients() as $recipient) {
         $recipient->log($this->logger, 'To');
         $mail->addTo($recipient->getEmail(), $recipient->getName());
     }
     // add the cc recipients
     foreach ((array) $message->getCcRecipients() as $recipient) {
         $recipient->log($this->logger, 'Cc');
         $mail->addCc($recipient->getEmail(), $recipient->getName());
     }
     // add the to recipients
     foreach ((array) $message->getBccRecipients() as $recipient) {
         $recipient->log($this->logger, 'Bcc');
         $mail->addBcc($recipient->getEmail(), $recipient->getName());
     }
     // add the reply-to
     $replyTo = $message->getReplyTo();
     // $replyTo is null or a PostmanEmailAddress object
     if (isset($replyTo)) {
         $mail->setReplyTo($replyTo->getEmail(), $replyTo->getName());
     }
     // add the date
     $date = $message->getDate();
     if (!empty($date)) {
         $mail->setDate($date);
     }
     // add the messageId
     $messageId = $message->getMessageId();
     if (!empty($messageId)) {
         $mail->setMessageId($messageId);
     }
     // add the subject
     if (null !== $message->getSubject()) {
         $mail->setSubject($message->getSubject());
     }
     $textPart = $message->getBodyTextPart();
     if (!empty($textPart)) {
         $this->logger->debug('Adding body as text');
         $mail->setBodyText($textPart);
     }
     $htmlPart = $message->getBodyHtmlPart();
     if (!empty($htmlPart)) {
         $this->logger->debug('Adding body as html');
         $mail->setBodyHtml($htmlPart);
     }
     // add attachments
     $this->logger->debug("Adding attachments");
     $message->addAttachmentsToMail($mail);
     // create the SMTP transport
     $this->logger->debug("Create the Zend_Mail transport");
     $zendTransport = $this->transport->createZendMailTransport($this->transport->getHostname(), array());
     try {
         // send the message
         $this->logger->debug("Sending mail");
         $mail->send($zendTransport);
         if ($this->logger->isInfo()) {
             $this->logger->info(sprintf('Message %d accepted for delivery', PostmanState::getInstance()->getSuccessfulDeliveries() + 1));
         }
         // finally not supported??
         if ($zendTransport->getConnection() && !PostmanUtils::isEmpty($zendTransport->getConnection()->getLog())) {
             $this->transcript = $zendTransport->getConnection()->getLog();
         } else {
             if (method_exists($zendTransport, 'getTranscript') && !PostmanUtils::isEmpty($zendTransport->getTranscript())) {
                 // then use the API response
                 $this->transcript = $zendTransport->getTranscript();
             } else {
                 if (method_exists($zendTransport, 'getMessage') && !PostmanUtils::isEmpty($zendTransport->getMessage())) {
                     // then use the Raw Message as the Transcript
                     $this->transcript = $zendTransport->getMessage();
                 }
             }
         }
     } catch (Exception $e) {
         // finally not supported??
         if ($zendTransport->getConnection() && !PostmanUtils::isEmpty($zendTransport->getConnection()->getLog())) {
             $this->transcript = $zendTransport->getConnection()->getLog();
         } else {
             if (method_exists($zendTransport, 'getTranscript') && !PostmanUtils::isEmpty($zendTransport->getTranscript())) {
                 // then use the API response
                 $this->transcript = $zendTransport->getTranscript();
             } else {
                 if (method_exists($zendTransport, 'getMessage') && !PostmanUtils::isEmpty($zendTransport->getMessage())) {
                     // then use the Raw Message as the Transcript
                     $this->transcript = $zendTransport->getMessage();
                 }
             }
         }
         // get the current exception message
         $message = $e->getMessage();
         if ($e->getCode() == 334) {
             // replace the unusable Google message with a better one in the case of code 334
             $message = sprintf(__('Communication Error [334] - make sure the Envelope From email is the same account used to create the Client ID.', Postman::TEXT_DOMAIN));
         }
         // create a new exception
         $newException = new Exception($message, $e->getCode());
         // throw the new exception after handling
         throw $newException;
     }
 }
示例#10
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;
     }
 }
 public function temporaryDirectoryCallback()
 {
     $inputDescription = __('Lockfiles are written here to prevent users from triggering an OAuth 2.0 token refresh at the same time.');
     printf('<input type="text" id="input_%2$s" name="%1$s[%2$s]" value="%3$s" />', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::TEMPORARY_DIRECTORY, $this->options->getTempDirectory());
     if (PostmanState::getInstance()->isFileLockingEnabled()) {
         printf(' <span style="color:green">%s</span></br><span class="postman_input_description">%s</span>', __('Valid', Postman::TEXT_DOMAIN), $inputDescription);
     } else {
         printf(' <span style="color:red">%s</span></br><span class="postman_input_description">%s</span>', __('Invalid', Postman::TEXT_DOMAIN), $inputDescription);
     }
 }
 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);
 }
 /**
  * Options page callback
  */
 public function outputDefaultContent()
 {
     // Set class property
     print '<div class="wrap">';
     $this->displayTopNavigation();
     if (!PostmanPreRequisitesCheck::isReady()) {
         printf('<p><span style="color:red; padding:2px 0; font-size:1.1em">%s</span></p>', __('Postman is unable to run. Email delivery is being handled by WordPress (or another plugin).', Postman::TEXT_DOMAIN));
     } else {
         $statusMessage = PostmanTransportRegistry::getInstance()->getReadyMessage();
         if (PostmanTransportRegistry::getInstance()->getActiveTransport()->isConfiguredAndReady()) {
             if ($this->options->getRunMode() != PostmanOptions::RUN_MODE_PRODUCTION) {
                 printf('<p><span style="background-color:yellow">%s</span></p>', $statusMessage);
             } else {
                 printf('<p><span style="color:green;padding:2px 0; font-size:1.1em">%s</span></p>', $statusMessage);
             }
         } else {
             printf('<p><span style="color:red; padding:2px 0; font-size:1.1em">%s</span></p>', $statusMessage);
         }
         $this->printDeliveryDetails();
         /* translators: where %d is the number of emails delivered */
         print '<p style="margin:10px 10px"><span>';
         printf(_n('Postman has delivered <span style="color:green">%d</span> email.', 'Postman has delivered <span style="color:green">%d</span> emails.', PostmanState::getInstance()->getSuccessfulDeliveries(), Postman::TEXT_DOMAIN), PostmanState::getInstance()->getSuccessfulDeliveries());
         if ($this->options->isMailLoggingEnabled()) {
             print ' ';
             printf(__('The last %d email attempts are recorded <a href="%s">in the log</a>.', Postman::TEXT_DOMAIN), PostmanOptions::getInstance()->getMailLoggingMaxEntries(), PostmanUtils::getEmailLogPageUrl());
         }
         print '</span></p>';
     }
     if ($this->options->isNew()) {
         printf('<h3 style="padding-top:10px">%s</h3>', __('Thank-you for choosing Postman!', Postman::TEXT_DOMAIN));
         /* 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::TEXT_DOMAIN), $this->getPageUrl(PostmanConfigurationController::CONFIGURATION_WIZARD_SLUG)));
         printf('<p><span>%s</span></p>', sprintf(__('Alternately, <a href="%s">manually configure</a> your own settings and/or modify advanced options.', Postman::TEXT_DOMAIN), $this->getPageUrl(PostmanConfigurationController::CONFIGURATION_SLUG)));
     } else {
         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::TEXT_DOMAIN), 'https://wordpress.org/support/view/plugin-reviews/postman-smtp?filter=5'));
         }
         printf('<p><span>%s :-)</span></p>', sprintf(__('Postman needs translators! Please take a moment to <a href="%s">translate a few sentences on-line</a>', Postman::TEXT_DOMAIN), 'https://translate.wordpress.org/projects/wp-plugins/postman-smtp/stable'));
     }
     printf('<p><span>%s</span></p>', __('<b style="background-color:yellow">New for v1.7!</style></b> Send mail with the Mandrill or SendGrid APIs.', Postman::TEXT_DOMAIN));
 }
示例#14
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;
     }
 }
示例#15
0
 /**
  * Processes will block on this method until unlock() is called
  * Inspired by http://cubicspot.blogspot.ca/2010/10/forget-flock-and-system-v-semaphores.html
  *
  * @throws Exception
  */
 static function lock()
 {
     if (PostmanState::getInstance()->isFileLockingEnabled()) {
         $attempts = 0;
         while (true) {
             // create the semaphore
             $lock = PostmanUtils::createLockFile();
             if ($lock) {
                 // if we got the lock, return
                 return;
             } else {
                 $attempts++;
                 if ($attempts >= 10) {
                     throw new Exception(sprintf('Could not create lockfile %s', '/tmp' . '/.postman.lock'));
                 }
                 sleep(1);
             }
         }
     }
 }
示例#16
0
 /**
  * Handle activation of plugin
  */
 private function handleOptionUpdates()
 {
     $this->logger->debug("Activating plugin");
     // prior to version 0.2.5, $authOptions did not exist
     $authOptions = get_option('postman_auth_token');
     $options = get_option('postman_options');
     $postmanState = get_option('postman_state');
     if (empty($authOptions) && !empty($options) && !empty($options['access_token'])) {
         $this->logger->debug("Upgrading database: copying Authorization token from postman_options to postman_auth_token");
         // copy the variables from $options to $authToken
         $authOptions['access_token'] = $options['access_token'];
         $authOptions['refresh_token'] = $options['refresh_token'];
         // there was a bug where we weren't setting the expiry time
         if (!empty($options['auth_token_expires'])) {
             $authOptions['auth_token_expires'] = $options['auth_token_expires'];
         }
         update_option('postman_auth_token', $authOptions);
     }
     if (!isset($options['authorization_type']) && !isset($options['auth_type'])) {
         // prior to 1.0.0, access tokens were saved in authOptions without an auth type
         // prior to 0.2.5, access tokens were save in options without an auth type
         // either way, only oauth2 was supported
         if (isset($authOptions['access_token']) || isset($options['access_token'])) {
             $this->logger->debug("Upgrading database: setting authorization_type to 'oauth2'");
             $options['authorization_type'] = 'oauth2';
             update_option('postman_options', $options);
         }
     }
     if (!isset($options['enc_type'])) {
         // prior to 1.3, encryption type was combined with authentication type
         if (isset($options['authorization_type'])) {
             $this->logger->debug("Upgrading database: creating auth_type and enc_type from authorization_type");
             $authType = $options['authorization_type'];
             switch ($authType) {
                 case 'none':
                     $options['auth_type'] = 'none';
                     $options['enc_type'] = 'none';
                     break;
                 case 'basic-ssl':
                     $options['auth_type'] = 'login';
                     $options['enc_type'] = 'ssl';
                     break;
                 case 'basic-tls':
                     $options['auth_type'] = 'login';
                     $options['enc_type'] = 'tls';
                     break;
                 case 'oauth2':
                     $options['auth_type'] = 'oauth2';
                     $options['enc_type'] = 'ssl';
                     break;
                 default:
             }
             update_option('postman_options', $options);
         }
     }
     // prior to 1.3.3, the version identifier was not stored and the passwords were plaintext
     if (isset($options['enc_type']) && !(isset($options['version']) || isset($postmanState['version']))) {
         $this->logger->debug("Upgrading database: added plugin version and encoding password");
         $options['version'] = '1.3.3';
         if (isset($options['basic_auth_password'])) {
             $options['basic_auth_password'] = base64_encode($options['basic_auth_password']);
         }
         update_option('postman_options', $options);
     }
     // prior to 1.4.2, the transport was not identified and the auth token had no vendor
     if (isset($options['auth_type']) && !isset($options['transport_type'])) {
         $this->logger->debug("Upgrading database: added transport_type and vendor_name");
         $options['transport_type'] = 'smtp';
         update_option('postman_options', $options);
         if (isset($authOptions['access_token']) && isset($options['oauth_client_id'])) {
             // if there is a stored token..
             if (PostmanUtils::endsWith($options['oauth_client_id'], 'googleusercontent.com')) {
                 $authOptions['vendor_name'] = 'google';
             } else {
                 if (strlen($options['oauth_client_id'] < strlen($options['oauth_client_secret']))) {
                     $authOptions['vendor_name'] = 'microsoft';
                 } else {
                     $authOptions['vendor_name'] = 'yahoo';
                 }
             }
             update_option('postman_auth_token', $authOptions);
         }
     }
     // for version 1.6.18, the envelope from was introduced
     if (!empty($options['sender_email']) && empty($options['envelope_sender'])) {
         $this->logger->debug("Upgrading database: adding envelope_sender");
         $options['envelope_sender'] = $options['sender_email'];
         update_option('postman_options', $options);
     }
     if (isset($postmanState['version']) && version_compare($postmanState['version'], '1.7.0', '<')) {
         if ($options['mail_log_max_entries'] == 10) {
             $options['mail_log_max_entries'] = 250;
         }
         $postmanStats = get_option('postman_stats');
         $stateCleared = false;
         if (!isset($postmanState['delivery_success_total']) && isset($postmanStats['delivery_success_total'])) {
             $postmanState['delivery_success_total'] = $postmanStats['delivery_success_total'];
             $stateCleared = true;
         }
         if (!isset($postmanState['delivery_fail_total']) && isset($postmanStats['delivery_fail_total'])) {
             $postmanState['delivery_fail_total'] = $postmanStats['delivery_fail_total'];
             $stateCleared = true;
         }
         if ($stateCleared) {
             delete_option('postman_stats');
         }
     }
     // can we create a tmp file? - this code is duplicated in InputSanitizer
     PostmanUtils::deleteLockFile();
     $lockSuccess = PostmanUtils::createLockFile();
     // &= does not work as expected in my PHP
     $lockSuccess = $lockSuccess && PostmanUtils::deleteLockFile();
     $postmanState['locking_enabled'] = $lockSuccess;
     // always update the version number
     if (!isset($postmanState['install_date'])) {
         $this->logger->debug("Upgrading database: adding install_date");
         $postmanState['install_date'] = time();
     }
     $pluginData = apply_filters('postman_get_plugin_metadata', null);
     $postmanState['version'] = $pluginData['version'];
     update_option('postman_state', $postmanState);
     //
     delete_option('postman_session');
     // reload options
     PostmanState::getInstance()->reload();
     PostmanOptions::getInstance()->reload();
 }
 /**
  */
 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);
 }
 /**
  * Send an email via the Gmail API
  *
  * Uses URI https://www.googleapis.com
  *
  *
  * @return void
  * @todo Rename this to sendMail, it's a public method...
  */
 public function _sendMail()
 {
     // Prepare the message in message/rfc822
     $message = $this->header . Postman_Zend_Mime::LINEEND . $this->body;
     $this->message = $message;
     // The message needs to be encoded in Base64URL
     $encodedMessage = rtrim(strtr(base64_encode($message), '+/', '-_'), '=');
     $googleApiMessage = new Postman_Google_Service_Gmail_Message();
     $googleApiMessage->setRaw($encodedMessage);
     $googleService = $this->_config[self::SERVICE_OPTION];
     $result = array();
     try {
         $result = $googleService->users_messages->send('me', $googleApiMessage);
         if ($this->logger->isInfo()) {
             $this->logger->info(sprintf('Message %d accepted for delivery', PostmanState::getInstance()->getSuccessfulDeliveries() + 1));
         }
         $this->transcript = print_r($result, true);
         $this->transcript .= PostmanModuleTransport::RAW_MESSAGE_FOLLOWS;
         $this->transcript .= $message;
     } catch (Exception $e) {
         $this->transcript = $e->getMessage();
         $this->transcript .= PostmanModuleTransport::RAW_MESSAGE_FOLLOWS;
         $this->transcript .= $message;
         throw $e;
     }
 }