diff options
author | yehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664> | 2017-10-17 21:04:37 +0000 |
---|---|---|
committer | yehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664> | 2017-10-17 21:04:37 +0000 |
commit | a55cff0dfacfb27a80e763b009b47daea9b61f12 (patch) | |
tree | c2c4286b1d7c2f96748e47b288a9f40762a2a724 /Postman/PostmanOptions.php | |
parent | 0e5055bf5b513df03b0f9ac8bd2810ffe72ed744 (diff) | |
download | Post-SMTP-a55cff0dfacfb27a80e763b009b47daea9b61f12.zip |
= 1.7.7 - 2017-10-17
* Fixed: Error sending files with sendgrid
* Fixed: Wrong attachments format in Mandrill
* Fixed: Wrong Sender Header in Mandrill
Diffstat (limited to 'Postman/PostmanOptions.php')
-rw-r--r-- | Postman/PostmanOptions.php | 301 |
1 files changed, 144 insertions, 157 deletions
diff --git a/Postman/PostmanOptions.php b/Postman/PostmanOptions.php index 863ce0d..ca16789 100644 --- a/Postman/PostmanOptions.php +++ b/Postman/PostmanOptions.php @@ -1,5 +1,5 @@ <?php -if (! interface_exists ( "PostmanOptionsInterface" )) { +if ( ! interface_exists( 'PostmanOptionsInterface' ) ) { interface PostmanOptionsInterface { /** * I'm stuck with these methods because of Gmail API Extension @@ -28,24 +28,22 @@ if (! interface_exists ( "PostmanOptionsInterface" )) { public function isAuthTypePlain(); public function isAuthTypeCrammd5(); public function isAuthTypeNone(); - + /** * * @deprecated - * */ public function getSenderEmail(); /** * * @deprecated - * */ public function getSenderName(); } } -if (! class_exists ( "PostmanOptions" )) { - +if ( ! class_exists( 'PostmanOptions' ) ) { + /** * http://stackoverflow.com/questions/23880928/use-oauth-refresh-token-to-obtain-new-access-token-google-api * http://pastebin.com/jA9sBNTk @@ -53,10 +51,10 @@ if (! class_exists ( "PostmanOptions" )) { * Make sure these emails are permitted (see http://en.wikipedia.org/wiki/E-mail_address#Internationalization): */ class PostmanOptions implements PostmanOptionsInterface { - + // the option database name const POSTMAN_OPTIONS = 'postman_options'; - + // the options fields const VERSION = 'version'; const ENVELOPE_SENDER = 'envelope_sender'; @@ -104,7 +102,7 @@ if (! class_exists ( "PostmanOptions" )) { const TRANSCRIPT_SIZE = 'transcript_size'; const TEMPORARY_DIRECTORY = 'tmp_dir'; const DISABLE_EMAIL_VALIDAITON = 'disable_email_validation'; - + // defaults const DEFAULT_TRANSCRIPT_SIZE = 128; const DEFAULT_STEALTH_MODE = false; @@ -118,186 +116,175 @@ if (! class_exists ( "PostmanOptions" )) { const DEFAULT_PLUGIN_MESSAGE_SENDER_NAME_ENFORCED = false; const DEFAULT_PLUGIN_MESSAGE_SENDER_EMAIL_ENFORCED = false; const DEFAULT_TEMP_DIRECTORY = '/tmp'; - + // options data private $options; - + // singleton instance public static function getInstance() { static $inst = null; - if ($inst === null) { - $inst = new PostmanOptions (); + if ( $inst === null ) { + $inst = new PostmanOptions(); } return $inst; } - + /** * private constructor */ private function __construct() { - $this->load (); + $this->load(); } - // public function save() { - update_option ( PostmanOptions::POSTMAN_OPTIONS, $this->options ); + update_option( PostmanOptions::POSTMAN_OPTIONS, $this->options ); } public function reload() { - $this->load (); + $this->load(); } private function load() { - $this->options = get_option ( PostmanOptions::POSTMAN_OPTIONS ); + $this->options = get_option( PostmanOptions::POSTMAN_OPTIONS ); } public function isNew() { - return ! isset ( $this->options [PostmanOptions::TRANSPORT_TYPE] ); + return ! isset( $this->options [ PostmanOptions::TRANSPORT_TYPE ] ); } public function isMailLoggingEnabled() { - $allowed = $this->isMailLoggingAllowed (); - $enabled = $this->getMailLoggingEnabled () == self::MAIL_LOG_ENABLED_OPTION_YES; + $allowed = $this->isMailLoggingAllowed(); + $enabled = $this->getMailLoggingEnabled() == self::MAIL_LOG_ENABLED_OPTION_YES; return $allowed && $enabled; } public function getTempDirectory() { - if (isset ( $this->options [self::TEMPORARY_DIRECTORY] )) - return $this->options [self::TEMPORARY_DIRECTORY]; - else - return self::DEFAULT_TEMP_DIRECTORY; + if ( isset( $this->options [ self::TEMPORARY_DIRECTORY ] ) ) { + return $this->options [ self::TEMPORARY_DIRECTORY ]; + } else { return self::DEFAULT_TEMP_DIRECTORY; } } public function isMailLoggingAllowed() { return true; } public function isStealthModeEnabled() { - if (isset ( $this->options [PostmanOptions::STEALTH_MODE] )) - return $this->options [PostmanOptions::STEALTH_MODE]; - else - return self::DEFAULT_STEALTH_MODE; + if ( isset( $this->options [ PostmanOptions::STEALTH_MODE ] ) ) { + return $this->options [ PostmanOptions::STEALTH_MODE ]; + } else { return self::DEFAULT_STEALTH_MODE; } } public function getMailLoggingEnabled() { - if (isset ( $this->options [PostmanOptions::MAIL_LOG_ENABLED_OPTION] )) - return $this->options [PostmanOptions::MAIL_LOG_ENABLED_OPTION]; - else - return self::DEFAULT_MAIL_LOG_ENABLED; + if ( isset( $this->options [ PostmanOptions::MAIL_LOG_ENABLED_OPTION ] ) ) { + return $this->options [ PostmanOptions::MAIL_LOG_ENABLED_OPTION ]; + } else { return self::DEFAULT_MAIL_LOG_ENABLED; } } public function getRunMode() { - if (isset ( $this->options [self::RUN_MODE] )) - return $this->options [self::RUN_MODE]; - else - return self::DEFAULT_RUN_MODE; + if ( isset( $this->options [ self::RUN_MODE ] ) ) { + return $this->options [ self::RUN_MODE ]; + } else { return self::DEFAULT_RUN_MODE; } } public function getMailLoggingMaxEntries() { - if (isset ( $this->options [PostmanOptions::MAIL_LOG_MAX_ENTRIES] )) - return $this->options [PostmanOptions::MAIL_LOG_MAX_ENTRIES]; - else - return self::DEFAULT_MAIL_LOG_ENTRIES; + if ( isset( $this->options [ PostmanOptions::MAIL_LOG_MAX_ENTRIES ] ) ) { + return $this->options [ PostmanOptions::MAIL_LOG_MAX_ENTRIES ]; + } else { return self::DEFAULT_MAIL_LOG_ENTRIES; } } public function getTranscriptSize() { - if (isset ( $this->options [PostmanOptions::TRANSCRIPT_SIZE] )) - return $this->options [PostmanOptions::TRANSCRIPT_SIZE]; - else - return self::DEFAULT_TRANSCRIPT_SIZE; + if ( isset( $this->options [ PostmanOptions::TRANSCRIPT_SIZE ] ) ) { + return $this->options [ PostmanOptions::TRANSCRIPT_SIZE ]; + } else { return self::DEFAULT_TRANSCRIPT_SIZE; } } public function getLogLevel() { - if (isset ( $this->options [PostmanOptions::LOG_LEVEL] )) - return $this->options [PostmanOptions::LOG_LEVEL]; - else - return self::DEFAULT_LOG_LEVEL; + if ( isset( $this->options [ PostmanOptions::LOG_LEVEL ] ) ) { + return $this->options [ PostmanOptions::LOG_LEVEL ]; + } else { return self::DEFAULT_LOG_LEVEL; } } public function getForcedToRecipients() { - if (isset ( $this->options [self::FORCED_TO_RECIPIENTS] )) - return $this->options [self::FORCED_TO_RECIPIENTS]; + if ( isset( $this->options [ self::FORCED_TO_RECIPIENTS ] ) ) { + return $this->options [ self::FORCED_TO_RECIPIENTS ]; } } public function getForcedCcRecipients() { - if (isset ( $this->options [self::FORCED_CC_RECIPIENTS] )) - return $this->options [self::FORCED_CC_RECIPIENTS]; + if ( isset( $this->options [ self::FORCED_CC_RECIPIENTS ] ) ) { + return $this->options [ self::FORCED_CC_RECIPIENTS ]; } } public function getForcedBccRecipients() { - if (isset ( $this->options [self::FORCED_BCC_RECIPIENTS] )) - return $this->options [self::FORCED_BCC_RECIPIENTS]; + if ( isset( $this->options [ self::FORCED_BCC_RECIPIENTS ] ) ) { + return $this->options [ self::FORCED_BCC_RECIPIENTS ]; } } public function getAdditionalHeaders() { - if (isset ( $this->options [self::ADDITIONAL_HEADERS] )) - return $this->options [self::ADDITIONAL_HEADERS]; + if ( isset( $this->options [ self::ADDITIONAL_HEADERS ] ) ) { + return $this->options [ self::ADDITIONAL_HEADERS ]; } } - // public function getHostname() { - if (isset ( $this->options [PostmanOptions::HOSTNAME] )) - return $this->options [PostmanOptions::HOSTNAME]; + if ( isset( $this->options [ PostmanOptions::HOSTNAME ] ) ) { + return $this->options [ PostmanOptions::HOSTNAME ]; } } public function getPort() { - if (isset ( $this->options [PostmanOptions::PORT] )) - return $this->options [PostmanOptions::PORT]; + if ( isset( $this->options [ PostmanOptions::PORT ] ) ) { + return $this->options [ PostmanOptions::PORT ]; } } public function getEnvelopeSender() { - if (isset ( $this->options [PostmanOptions::ENVELOPE_SENDER] )) - return $this->options [PostmanOptions::ENVELOPE_SENDER]; + if ( isset( $this->options [ PostmanOptions::ENVELOPE_SENDER ] ) ) { + return $this->options [ PostmanOptions::ENVELOPE_SENDER ]; } } public function getMessageSenderEmail() { - if (isset ( $this->options [PostmanOptions::MESSAGE_SENDER_EMAIL] )) - return $this->options [PostmanOptions::MESSAGE_SENDER_EMAIL]; + if ( isset( $this->options [ PostmanOptions::MESSAGE_SENDER_EMAIL ] ) ) { + return $this->options [ PostmanOptions::MESSAGE_SENDER_EMAIL ]; } } public function getMessageSenderName() { - if (isset ( $this->options [PostmanOptions::MESSAGE_SENDER_NAME] )) - return $this->options [PostmanOptions::MESSAGE_SENDER_NAME]; + if ( isset( $this->options [ PostmanOptions::MESSAGE_SENDER_NAME ] ) ) { + return $this->options [ PostmanOptions::MESSAGE_SENDER_NAME ]; } } public function getClientId() { - if (isset ( $this->options [PostmanOptions::CLIENT_ID] )) - return $this->options [PostmanOptions::CLIENT_ID]; + if ( isset( $this->options [ PostmanOptions::CLIENT_ID ] ) ) { + return $this->options [ PostmanOptions::CLIENT_ID ]; } } public function getClientSecret() { - if (isset ( $this->options [PostmanOptions::CLIENT_SECRET] )) - return $this->options [PostmanOptions::CLIENT_SECRET]; + if ( isset( $this->options [ PostmanOptions::CLIENT_SECRET ] ) ) { + return $this->options [ PostmanOptions::CLIENT_SECRET ]; } } public function getTransportType() { - if (isset ( $this->options [PostmanOptions::TRANSPORT_TYPE] )) - return $this->options [PostmanOptions::TRANSPORT_TYPE]; + if ( isset( $this->options [ PostmanOptions::TRANSPORT_TYPE ] ) ) { + return $this->options [ PostmanOptions::TRANSPORT_TYPE ]; } } public function getAuthenticationType() { - if (isset ( $this->options [PostmanOptions::AUTHENTICATION_TYPE] )) - return $this->options [PostmanOptions::AUTHENTICATION_TYPE]; + if ( isset( $this->options [ PostmanOptions::AUTHENTICATION_TYPE ] ) ) { + return $this->options [ PostmanOptions::AUTHENTICATION_TYPE ]; } } public function getEncryptionType() { - if (isset ( $this->options [PostmanOptions::SECURITY_TYPE] )) - return $this->options [PostmanOptions::SECURITY_TYPE]; + if ( isset( $this->options [ PostmanOptions::SECURITY_TYPE ] ) ) { + return $this->options [ PostmanOptions::SECURITY_TYPE ]; } } public function getUsername() { - if (isset ( $this->options [PostmanOptions::BASIC_AUTH_USERNAME] )) - return $this->options [PostmanOptions::BASIC_AUTH_USERNAME]; + if ( isset( $this->options [ PostmanOptions::BASIC_AUTH_USERNAME ] ) ) { + return $this->options [ PostmanOptions::BASIC_AUTH_USERNAME ]; } } public function getPassword() { - if (isset ( $this->options [PostmanOptions::BASIC_AUTH_PASSWORD] )) - return base64_decode ( $this->options [PostmanOptions::BASIC_AUTH_PASSWORD] ); + if ( isset( $this->options [ PostmanOptions::BASIC_AUTH_PASSWORD ] ) ) { + return base64_decode( $this->options [ PostmanOptions::BASIC_AUTH_PASSWORD ] ); } } public function getMandrillApiKey() { - if (isset ( $this->options [PostmanOptions::MANDRILL_API_KEY] )) - return base64_decode ( $this->options [PostmanOptions::MANDRILL_API_KEY] ); + if ( isset( $this->options [ PostmanOptions::MANDRILL_API_KEY ] ) ) { + return base64_decode( $this->options [ PostmanOptions::MANDRILL_API_KEY ] ); } } public function getSendGridApiKey() { - if (isset ( $this->options [PostmanOptions::SENDGRID_API_KEY] )) - return base64_decode ( $this->options [PostmanOptions::SENDGRID_API_KEY] ); + if ( isset( $this->options [ PostmanOptions::SENDGRID_API_KEY ] ) ) { + return base64_decode( $this->options [ PostmanOptions::SENDGRID_API_KEY ] ); } } public function getReplyTo() { - if (isset ( $this->options [PostmanOptions::REPLY_TO] )) - return $this->options [PostmanOptions::REPLY_TO]; + if ( isset( $this->options [ PostmanOptions::REPLY_TO ] ) ) { + return $this->options [ PostmanOptions::REPLY_TO ]; } } public function getConnectionTimeout() { - if (! empty ( $this->options [self::CONNECTION_TIMEOUT] )) - return $this->options [self::CONNECTION_TIMEOUT]; - else - return self::DEFAULT_TCP_CONNECTION_TIMEOUT; + if ( ! empty( $this->options [ self::CONNECTION_TIMEOUT ] ) ) { + return $this->options [ self::CONNECTION_TIMEOUT ]; + } else { return self::DEFAULT_TCP_CONNECTION_TIMEOUT; } } public function getReadTimeout() { - if (! empty ( $this->options [self::READ_TIMEOUT] )) - return $this->options [self::READ_TIMEOUT]; - else - return self::DEFAULT_TCP_READ_TIMEOUT; + if ( ! empty( $this->options [ self::READ_TIMEOUT ] ) ) { + return $this->options [ self::READ_TIMEOUT ]; + } else { return self::DEFAULT_TCP_READ_TIMEOUT; } } public function isPluginSenderNameEnforced() { - if ($this->isNew ()) - return self::DEFAULT_PLUGIN_MESSAGE_SENDER_NAME_ENFORCED; - if (isset ( $this->options [PostmanOptions::PREVENT_MESSAGE_SENDER_NAME_OVERRIDE] )) - return $this->options [PostmanOptions::PREVENT_MESSAGE_SENDER_NAME_OVERRIDE]; + if ( $this->isNew() ) { + return self::DEFAULT_PLUGIN_MESSAGE_SENDER_NAME_ENFORCED; } + if ( isset( $this->options [ PostmanOptions::PREVENT_MESSAGE_SENDER_NAME_OVERRIDE ] ) ) { + return $this->options [ PostmanOptions::PREVENT_MESSAGE_SENDER_NAME_OVERRIDE ]; } } public function isEmailValidationDisabled() { - if (isset ( $this->options [PostmanOptions::DISABLE_EMAIL_VALIDAITON] )) - return $this->options [PostmanOptions::DISABLE_EMAIL_VALIDAITON]; + if ( isset( $this->options [ PostmanOptions::DISABLE_EMAIL_VALIDAITON ] ) ) { + return $this->options [ PostmanOptions::DISABLE_EMAIL_VALIDAITON ]; } } /** * (non-PHPdoc) @@ -306,125 +293,125 @@ if (! class_exists ( "PostmanOptions" )) { * @deprecated by isPluginSenderNameEnforced */ public function isSenderNameOverridePrevented() { - return $this->isPluginSenderEmailEnforced (); + return $this->isPluginSenderEmailEnforced(); } public function isPluginSenderEmailEnforced() { - if ($this->isNew ()) - return self::DEFAULT_PLUGIN_MESSAGE_SENDER_EMAIL_ENFORCED; - if (isset ( $this->options [PostmanOptions::PREVENT_MESSAGE_SENDER_EMAIL_OVERRIDE] )) - return $this->options [PostmanOptions::PREVENT_MESSAGE_SENDER_EMAIL_OVERRIDE]; + if ( $this->isNew() ) { + return self::DEFAULT_PLUGIN_MESSAGE_SENDER_EMAIL_ENFORCED; } + if ( isset( $this->options [ PostmanOptions::PREVENT_MESSAGE_SENDER_EMAIL_OVERRIDE ] ) ) { + return $this->options [ PostmanOptions::PREVENT_MESSAGE_SENDER_EMAIL_OVERRIDE ]; } } /** * * @deprecated by isPluginSenderEmailEnforced */ public function isSenderEmailOverridePrevented() { - return $this->isPluginSenderEmailEnforced (); + return $this->isPluginSenderEmailEnforced(); } - private function setSenderEmail($senderEmail) { - $this->options [PostmanOptions::MESSAGE_SENDER_EMAIL] = $senderEmail; + private function setSenderEmail( $senderEmail ) { + $this->options [ PostmanOptions::MESSAGE_SENDER_EMAIL ] = $senderEmail; } - public function setMessageSenderEmailIfEmpty($senderEmail) { - if (empty ( $this->options [PostmanOptions::MESSAGE_SENDER_EMAIL] )) { - $this->setSenderEmail ( $senderEmail ); + public function setMessageSenderEmailIfEmpty( $senderEmail ) { + if ( empty( $this->options [ PostmanOptions::MESSAGE_SENDER_EMAIL ] ) ) { + $this->setSenderEmail( $senderEmail ); } } - private function setSenderName($senderName) { - $this->options [PostmanOptions::MESSAGE_SENDER_NAME] = $senderName; + private function setSenderName( $senderName ) { + $this->options [ PostmanOptions::MESSAGE_SENDER_NAME ] = $senderName; } - public function setMessageSenderNameIfEmpty($senderName) { - if (empty ( $this->options [PostmanOptions::MESSAGE_SENDER_NAME] )) { - $this->setSenderName ( $senderName ); + public function setMessageSenderNameIfEmpty( $senderName ) { + if ( empty( $this->options [ PostmanOptions::MESSAGE_SENDER_NAME ] ) ) { + $this->setSenderName( $senderName ); } } public function isAuthTypePassword() { - return $this->isAuthTypeLogin () || $this->isAuthTypeCrammd5 () || $this->isAuthTypePlain (); + return $this->isAuthTypeLogin() || $this->isAuthTypeCrammd5() || $this->isAuthTypePlain(); } public function isAuthTypeOAuth2() { - return PostmanOptions::AUTHENTICATION_TYPE_OAUTH2 == $this->getAuthenticationType (); + return PostmanOptions::AUTHENTICATION_TYPE_OAUTH2 == $this->getAuthenticationType(); } public function isAuthTypeLogin() { - return PostmanOptions::AUTHENTICATION_TYPE_LOGIN == $this->getAuthenticationType (); + return PostmanOptions::AUTHENTICATION_TYPE_LOGIN == $this->getAuthenticationType(); } public function isAuthTypePlain() { - return PostmanOptions::AUTHENTICATION_TYPE_PLAIN == $this->getAuthenticationType (); + return PostmanOptions::AUTHENTICATION_TYPE_PLAIN == $this->getAuthenticationType(); } public function isAuthTypeCrammd5() { - return PostmanOptions::AUTHENTICATION_TYPE_CRAMMD5 == $this->getAuthenticationType (); + return PostmanOptions::AUTHENTICATION_TYPE_CRAMMD5 == $this->getAuthenticationType(); } public function isAuthTypeNone() { - return PostmanOptions::AUTHENTICATION_TYPE_NONE == $this->getAuthenticationType (); + return PostmanOptions::AUTHENTICATION_TYPE_NONE == $this->getAuthenticationType(); } /** * * @deprecated Required by the Postman Gmail Extension - * + * * @see PostmanOptionsInterface::getSenderEmail() */ public function getSenderEmail() { - return $this->getMessageSenderEmail (); + return $this->getMessageSenderEmail(); } /** * * @deprecated Required by the Postman Gmail Extension - * + * * @see PostmanOptionsInterface::getSenderEmail() */ public function getSenderName() { - return $this->getMessageNameEmail (); + return $this->getMessageNameEmail(); } - + /** * * @return string */ public function export() { - if (PostmanPreRequisitesCheck::checkZlibEncode ()) { + if ( PostmanPreRequisitesCheck::checkZlibEncode() ) { $data = $this->options; - $data ['version'] = PostmanState::getInstance ()->getVersion (); - foreach ( PostmanTransportRegistry::getInstance ()->getTransports () as $transport ) { - $data = $transport->prepareOptionsForExport ( $data ); + $data ['version'] = PostmanState::getInstance()->getVersion(); + foreach ( PostmanTransportRegistry::getInstance()->getTransports() as $transport ) { + $data = $transport->prepareOptionsForExport( $data ); } - $data = base64_encode ( gzcompress ( json_encode ( $data ), 9 ) ); + $data = base64_encode( gzcompress( json_encode( $data ), 9 ) ); return $data; } } - + /** * - * @param unknown $data + * @param unknown $data */ - public function import($data) { - if (PostmanPreRequisitesCheck::checkZlibEncode ()) { - $logger = new PostmanLogger ( get_class ( $this ) ); - $logger->debug ( 'Importing Settings' ); + public function import( $data ) { + if ( PostmanPreRequisitesCheck::checkZlibEncode() ) { + $logger = new PostmanLogger( get_class( $this ) ); + $logger->debug( 'Importing Settings' ); $base64 = $data; - $logger->trace ( $base64 ); - $gz = base64_decode ( $base64 ); - $logger->trace ( $gz ); - $json = @gzuncompress ( $gz ); - $logger->trace ( $json ); - if (! empty ( $json )) { - $data = json_decode ( $json, true ); - $logger->trace ( $data ); + $logger->trace( $base64 ); + $gz = base64_decode( $base64 ); + $logger->trace( $gz ); + $json = @gzuncompress( $gz ); + $logger->trace( $json ); + if ( ! empty( $json ) ) { + $data = json_decode( $json, true ); + $logger->trace( $data ); { // overwrite the current version with the version from the imported options // this way database upgrading can occur - $postmanState = get_option ( 'postman_state' ); + $postmanState = get_option( 'postman_state' ); $postmanState ['version'] = $data ['version']; - $logger->trace ( sprintf ( 'Setting Postman version to %s', $postmanState ['version'] ) ); - assert ( $postmanState ['version'] == $data ['version'] ); - update_option ( 'postman_state', $postmanState ); + $logger->trace( sprintf( 'Setting Postman version to %s', $postmanState ['version'] ) ); + assert( $postmanState ['version'] == $data ['version'] ); + update_option( 'postman_state', $postmanState ); } $this->options = $data; - $logger->info ( 'Imported data' ); - $this->save (); + $logger->info( 'Imported data' ); + $this->save(); return true; } else { - $logger->error ( 'Could not import data - data error' ); + $logger->error( 'Could not import data - data error' ); return false; } } } } -}
\ No newline at end of file +} |