public function isYahoo()
 {
     return PostmanUtils::endsWith($this->hostname, 'yahoo.com');
 }
Beispiel #2
0
 /**
  * Does this hostname belong to Google?
  *
  * @param unknown $hostname        	
  * @return boolean
  */
 static function isGoogle($hostname)
 {
     return PostmanUtils::endsWith($hostname, 'gmail.com') || PostmanUtils::endsWith($hostname, 'googleapis.com');
 }
 /**
  * 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();
 }
 /**
  * Create the vendor string (for Yahoo servers only)
  *
  * @param unknown $hostname        	
  * @return string
  */
 private function createVendorString($hostname)
 {
     // the vendor is required for Yahoo's OAuth2 implementation
     $vendor = '';
     if (PostmanUtils::endsWith($hostname, 'yahoo.com')) {
         // Yahoo Mail requires a Vendor - see http://imapclient.freshfoo.com/changeset/535%3A80ae438f4e4a/
         $pluginData = apply_filters('postman_get_plugin_metadata', null);
         $vendor = sprintf("vendor=Postman SMTP %s", $pluginData['version']);
     }
     return $vendor;
 }
 public function isServiceProviderMicrosoft($hostname)
 {
     return PostmanUtils::endsWith($hostname, 'live.com');
 }
 public function isServiceProviderYahoo($hostname)
 {
     return PostmanUtils::endsWith($hostname, 'yahoo.com');
 }