PageRenderTime 97ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/phpmailer/phpmailer/class.phpmaileroauth.php

https://gitlab.com/thohid44/Complete_Sumitted_Project_Without_Filter_Search
PHP | 196 lines | 110 code | 11 blank | 75 comment | 24 complexity | c8801b86133b744827ac50d61d4952ba MD5 | raw file
  1. <?php
  2. /**
  3. * PHPMailer - PHP email creation and transport class.
  4. * PHP Version 5.4
  5. * @package PHPMailer
  6. * @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
  7. * @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
  8. * @author Jim Jagielski (jimjag) <jimjag@gmail.com>
  9. * @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
  10. * @author Brent R. Matzelle (original founder)
  11. * @copyright 2012 - 2014 Marcus Bointon
  12. * @copyright 2010 - 2012 Jim Jagielski
  13. * @copyright 2004 - 2009 Andy Prevost
  14. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  15. * @note This program is distributed in the hope that it will be useful - WITHOUT
  16. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  17. * FITNESS FOR A PARTICULAR PURPOSE.
  18. */
  19. /**
  20. * PHPMailerOAuth - PHPMailer subclass adding OAuth support.
  21. * @package PHPMailer
  22. * @author @sherryl4george
  23. * @author Marcus Bointon (@Synchro) <phpmailer@synchromedia.co.uk>
  24. */
  25. class PHPMailerOAuth extends PHPMailer
  26. {
  27. /**
  28. * The OAuth user's email address
  29. * @var string
  30. */
  31. public $oauthUserEmail = '';
  32. /**
  33. * The OAuth refresh token
  34. * @var string
  35. */
  36. public $oauthRefreshToken = '';
  37. /**
  38. * The OAuth client ID
  39. * @var string
  40. */
  41. public $oauthClientId = '';
  42. /**
  43. * The OAuth client secret
  44. * @var string
  45. */
  46. public $oauthClientSecret = '';
  47. /**
  48. * An instance of the PHPMailerOAuthGoogle class.
  49. * @var PHPMailerOAuthGoogle
  50. * @access protected
  51. */
  52. protected $oauth = null;
  53. /**
  54. * Get a PHPMailerOAuthGoogle instance to use.
  55. * @return PHPMailerOAuthGoogle
  56. */
  57. public function getOAUTHInstance()
  58. {
  59. if (!is_object($this->oauth)) {
  60. $this->oauth = new PHPMailerOAuthGoogle(
  61. $this->oauthUserEmail,
  62. $this->oauthClientSecret,
  63. $this->oauthClientId,
  64. $this->oauthRefreshToken
  65. );
  66. }
  67. return $this->oauth;
  68. }
  69. /**
  70. * Initiate a connection to an SMTP server.
  71. * Overrides the original smtpConnect method to add support for OAuth.
  72. * @param array $options An array of options compatible with stream_context_create()
  73. * @uses SMTP
  74. * @access public
  75. * @return bool
  76. */
  77. public function smtpConnect($options = array())
  78. {
  79. if (is_null($this->smtp)) {
  80. $this->smtp = $this->getSMTPInstance();
  81. }
  82. if (is_null($this->oauth)) {
  83. $this->oauth = $this->getOAUTHInstance();
  84. }
  85. // Already connected?
  86. if ($this->smtp->connected()) {
  87. return true;
  88. }
  89. $this->smtp->setTimeout($this->Timeout);
  90. $this->smtp->setDebugLevel($this->SMTPDebug);
  91. $this->smtp->setDebugOutput($this->Debugoutput);
  92. $this->smtp->setVerp($this->do_verp);
  93. $hosts = explode(';', $this->Host);
  94. $lastexception = null;
  95. foreach ($hosts as $hostentry) {
  96. $hostinfo = array();
  97. if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
  98. // Not a valid host entry
  99. continue;
  100. }
  101. // $hostinfo[2]: optional ssl or tls prefix
  102. // $hostinfo[3]: the hostname
  103. // $hostinfo[4]: optional port number
  104. // The host string prefix can temporarily override the current setting for SMTPSecure
  105. // If it's not specified, the default value is used
  106. $prefix = '';
  107. $secure = $this->SMTPSecure;
  108. $tls = ($this->SMTPSecure == 'tls');
  109. if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) {
  110. $prefix = 'ssl://';
  111. $tls = false; // Can't have SSL and TLS at the same time
  112. $secure = 'ssl';
  113. } elseif ($hostinfo[2] == 'tls') {
  114. $tls = true;
  115. // tls doesn't use a prefix
  116. $secure = 'tls';
  117. }
  118. //Do we need the OpenSSL extension?
  119. $sslext = defined('OPENSSL_ALGO_SHA1');
  120. if ('tls' === $secure or 'ssl' === $secure) {
  121. //Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled
  122. if (!$sslext) {
  123. throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
  124. }
  125. }
  126. $host = $hostinfo[3];
  127. $port = $this->Port;
  128. $tport = (integer)$hostinfo[4];
  129. if ($tport > 0 and $tport < 65536) {
  130. $port = $tport;
  131. }
  132. if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
  133. try {
  134. if ($this->Helo) {
  135. $hello = $this->Helo;
  136. } else {
  137. $hello = $this->serverHostname();
  138. }
  139. $this->smtp->hello($hello);
  140. //Automatically enable TLS encryption if:
  141. // * it's not disabled
  142. // * we have openssl extension
  143. // * we are not already using SSL
  144. // * the server offers STARTTLS
  145. if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) {
  146. $tls = true;
  147. }
  148. if ($tls) {
  149. if (!$this->smtp->startTLS()) {
  150. throw new phpmailerException($this->lang('connect_host'));
  151. }
  152. // We must resend HELO after tls negotiation
  153. $this->smtp->hello($hello);
  154. }
  155. if ($this->SMTPAuth) {
  156. if (!$this->smtp->authenticate(
  157. $this->Username,
  158. $this->Password,
  159. $this->AuthType,
  160. $this->Realm,
  161. $this->Workstation,
  162. $this->oauth
  163. )
  164. ) {
  165. throw new phpmailerException($this->lang('authenticate'));
  166. }
  167. }
  168. return true;
  169. } catch (phpmailerException $exc) {
  170. $lastexception = $exc;
  171. $this->edebug($exc->getMessage());
  172. // We must have connected, but then failed TLS or Auth, so close connection nicely
  173. $this->smtp->quit();
  174. }
  175. }
  176. }
  177. // If we get here, all connection attempts have failed, so close connection hard
  178. $this->smtp->close();
  179. // As we've caught all exceptions, just report whatever the last one was
  180. if ($this->exceptions and !is_null($lastexception)) {
  181. throw $lastexception;
  182. }
  183. return false;
  184. }
  185. }