summaryrefslogtreecommitdiff
path: root/Postman/Postman-Mail/PostmanDefaultModuleTransport.php
blob: e52c75415d5c529904bea56bc2dab9f3b86fe1e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

require_once 'PostmanModuleTransport.php';
if (! class_exists ( 'PostmanSmtpModuleTransport' )) {
	class PostmanDefaultModuleTransport extends PostmanAbstractZendModuleTransport implements PostmanZendModuleTransport {
		const SLUG = 'default';
		private $fromName;
		private $fromEmail;
		
		/**
		 *
		 * @param mixed $rootPluginFilenameAndPath        	
		 */
		public function __construct($rootPluginFilenameAndPath) {
			parent::__construct ( $rootPluginFilenameAndPath );
			$this->init ();
		}
		
		/**
		 * Copied from WordPress core
		 * Set the from name and email
		 */
		public function init() {
			parent::init();
			// From email and name
			// If we don't have a name from the input headers
			$this->fromName = apply_filters( 'wp_mail_from_name', 'WordPress' );
			
			/*
			 * If we don't have an email from the input headers default to wordpress@$sitename
			 * Some hosts will block outgoing mail from this address if it doesn't exist but
			 * there's no easy alternative. Defaulting to admin_email might appear to be another
			 * option but some hosts may refuse to relay mail from an unknown domain. See
			 * https://core.trac.wordpress.org/ticket/5007.
			 */
			
			// Get the site domain and get rid of www.
			$site_url = get_bloginfo( 'url' );
			$sitename = strtolower ( PostmanUtils::getHost( $site_url ) );
			
			$this->fromEmail = apply_filters( 'wp_mail_from', 'wordpress@' . $sitename );
		}
		public function isConfiguredAndReady() {
			return false;
		}
		public function isReadyToSendMail() {
			return true;
		}
		public function getFromEmailAddress() {
			return $this->fromEmail;
		}
		public function getFromName() {
			return $this->fromName;
		}
		public function getEnvelopeFromEmailAddress() {
			return $this->getFromEmailAddress ();
		}
		public function isEmailValidationSupported() {
			return false;
		}
		
		/**
		 * (non-PHPdoc)
		 *
		 * @see PostmanAbstractZendModuleTransport::validateTransportConfiguration()
		 */
		protected function validateTransportConfiguration() {
			return array ();
			// no-op, always valid
		}
		
		/**
		 * (non-PHPdoc)
		 *
		 * @see PostmanModuleTransport::createMailEngine()
		 */
		public function createMailEngine() {
			require_once 'PostmanZendMailEngine.php';
			return new PostmanZendMailEngine ( $this );
		}
		
		/**
		 * (non-PHPdoc)
		 *
		 * @see PostmanZendModuleTransport::createZendMailTransport()
		 */
		public function createZendMailTransport($fakeHostname, $fakeConfig) {
			$config = array (
					'port' => $this->getPort () 
			);
			return new Postman_Zend_Mail_Transport_Smtp ( $this->getHostname (), $config );
		}
		
		/**
		 * Determines whether Mail Engine locking is needed
		 *
		 * @see PostmanModuleTransport::requiresLocking()
		 */
		public function isLockingRequired() {
			return PostmanOptions::AUTHENTICATION_TYPE_OAUTH2 == $this->getAuthenticationType ();
		}
		public function getSlug() {
			return self::SLUG;
		}
		public function getName() {
			return __ ( 'Default', 'post-smtp' );
		}
		public function getHostname() {
			return 'localhost';
		}
		public function getPort() {
			return 25;
		}
		public function getSecurityType() {
			return PostmanOptions::SECURITY_TYPE_NONE;
		}
		public function getAuthenticationType() {
			return PostmanOptions::AUTHENTICATION_TYPE_NONE;
		}
		public function getCredentialsId() {
			$options = PostmanOptions::getInstance ();
			if ($options->isAuthTypeOAuth2 ()) {
				return $options->getClientId ();
			} else {
				return $options->getUsername ();
			}
		}
		public function getCredentialsSecret() {
			$options = PostmanOptions::getInstance ();
			if ($options->isAuthTypeOAuth2 ()) {
				return $options->getClientSecret ();
			} else {
				return $options->getPassword ();
			}
		}
		public function isServiceProviderGoogle($hostname) {
			return PostmanUtils::endsWith ( $hostname, 'gmail.com' );
		}
		public function isServiceProviderMicrosoft($hostname) {
			return PostmanUtils::endsWith ( $hostname, 'live.com' );
		}
		public function isServiceProviderYahoo($hostname) {
			return strpos ( $hostname, 'yahoo' );
		}
		public function isOAuthUsed($authType) {
			return false;
		}
		public final function getConfigurationBid(PostmanWizardSocket $hostData, $userAuthOverride, $originalSmtpServer) {
			return null;
		}
		
		/**
		 * Does not participate in the Wizard process;
		 *
		 * (non-PHPdoc)
		 *
		 * @see PostmanModuleTransport::getSocketsForSetupWizardToProbe()
		 */
		public function getSocketsForSetupWizardToProbe($hostname, $smtpServerGuess) {
			return array ();
		}
	}
}