| 1: | <?php | 
| 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: | class PHPMailerOAuth extends PHPMailer | 
| 27: | { | 
| 28: |  | 
| 29: |  | 
| 30: |  | 
| 31: |  | 
| 32: | public $oauthUserEmail = ''; | 
| 33: |  | 
| 34: |  | 
| 35: |  | 
| 36: |  | 
| 37: |  | 
| 38: | public $oauthRefreshToken = ''; | 
| 39: |  | 
| 40: |  | 
| 41: |  | 
| 42: |  | 
| 43: |  | 
| 44: | public $oauthClientId = ''; | 
| 45: |  | 
| 46: |  | 
| 47: |  | 
| 48: |  | 
| 49: |  | 
| 50: | public $oauthClientSecret = ''; | 
| 51: |  | 
| 52: |  | 
| 53: |  | 
| 54: |  | 
| 55: |  | 
| 56: |  | 
| 57: | protected $oauth = null; | 
| 58: |  | 
| 59: |  | 
| 60: |  | 
| 61: |  | 
| 62: |  | 
| 63: | public function getOAUTHInstance() | 
| 64: | { | 
| 65: | if (!is_object($this->oauth)) { | 
| 66: | $this->oauth = new PHPMailerOAuthGoogle( | 
| 67: | $this->oauthUserEmail, | 
| 68: | $this->oauthClientSecret, | 
| 69: | $this->oauthClientId, | 
| 70: | $this->oauthRefreshToken | 
| 71: | ); | 
| 72: | } | 
| 73: | return $this->oauth; | 
| 74: | } | 
| 75: |  | 
| 76: |  | 
| 77: |  | 
| 78: |  | 
| 79: |  | 
| 80: |  | 
| 81: |  | 
| 82: |  | 
| 83: |  | 
| 84: |  | 
| 85: | public function smtpConnect($options = array()) | 
| 86: | { | 
| 87: | if (is_null($this->smtp)) { | 
| 88: | $this->smtp = $this->getSMTPInstance(); | 
| 89: | } | 
| 90: |  | 
| 91: | if (is_null($this->oauth)) { | 
| 92: | $this->oauth = $this->getOAUTHInstance(); | 
| 93: | } | 
| 94: |  | 
| 95: |  | 
| 96: | if ($this->smtp->connected()) { | 
| 97: | return true; | 
| 98: | } | 
| 99: |  | 
| 100: | $this->smtp->setTimeout($this->Timeout); | 
| 101: | $this->smtp->setDebugLevel($this->SMTPDebug); | 
| 102: | $this->smtp->setDebugOutput($this->Debugoutput); | 
| 103: | $this->smtp->setVerp($this->do_verp); | 
| 104: | $hosts = explode(';', $this->Host); | 
| 105: | $lastexception = null; | 
| 106: |  | 
| 107: | foreach ($hosts as $hostentry) { | 
| 108: | $hostinfo = array(); | 
| 109: | if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) { | 
| 110: |  | 
| 111: | continue; | 
| 112: | } | 
| 113: |  | 
| 114: |  | 
| 115: |  | 
| 116: |  | 
| 117: |  | 
| 118: | $prefix = ''; | 
| 119: | $secure = $this->SMTPSecure; | 
| 120: | $tls = ($this->SMTPSecure == 'tls'); | 
| 121: | if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) { | 
| 122: | $prefix = 'ssl://'; | 
| 123: | $tls = false; | 
| 124: | $secure = 'ssl'; | 
| 125: | } elseif ($hostinfo[2] == 'tls') { | 
| 126: | $tls = true; | 
| 127: |  | 
| 128: | $secure = 'tls'; | 
| 129: | } | 
| 130: |  | 
| 131: | $sslext = defined('OPENSSL_ALGO_SHA1'); | 
| 132: | if ('tls' === $secure or 'ssl' === $secure) { | 
| 133: |  | 
| 134: | if (!$sslext) { | 
| 135: | throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL); | 
| 136: | } | 
| 137: | } | 
| 138: | $host = $hostinfo[3]; | 
| 139: | $port = $this->Port; | 
| 140: | $tport = (integer)$hostinfo[4]; | 
| 141: | if ($tport > 0 and $tport < 65536) { | 
| 142: | $port = $tport; | 
| 143: | } | 
| 144: | if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) { | 
| 145: | try { | 
| 146: | if ($this->Helo) { | 
| 147: | $hello = $this->Helo; | 
| 148: | } else { | 
| 149: | $hello = $this->serverHostname(); | 
| 150: | } | 
| 151: | $this->smtp->hello($hello); | 
| 152: |  | 
| 153: |  | 
| 154: |  | 
| 155: |  | 
| 156: |  | 
| 157: | if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) { | 
| 158: | $tls = true; | 
| 159: | } | 
| 160: | if ($tls) { | 
| 161: | if (!$this->smtp->startTLS()) { | 
| 162: | throw new phpmailerException($this->lang('connect_host')); | 
| 163: | } | 
| 164: |  | 
| 165: | $this->smtp->hello($hello); | 
| 166: | } | 
| 167: | if ($this->SMTPAuth) { | 
| 168: | if (!$this->smtp->authenticate( | 
| 169: | $this->Username, | 
| 170: | $this->Password, | 
| 171: | $this->AuthType, | 
| 172: | $this->Realm, | 
| 173: | $this->Workstation, | 
| 174: | $this->oauth | 
| 175: | ) | 
| 176: | ) { | 
| 177: | throw new phpmailerException($this->lang('authenticate')); | 
| 178: | } | 
| 179: | } | 
| 180: | return true; | 
| 181: | } catch (phpmailerException $exc) { | 
| 182: | $lastexception = $exc; | 
| 183: | $this->edebug($exc->getMessage()); | 
| 184: |  | 
| 185: | $this->smtp->quit(); | 
| 186: | } | 
| 187: | } | 
| 188: | } | 
| 189: |  | 
| 190: | $this->smtp->close(); | 
| 191: |  | 
| 192: | if ($this->exceptions and !is_null($lastexception)) { | 
| 193: | throw $lastexception; | 
| 194: | } | 
| 195: | return false; | 
| 196: | } | 
| 197: | } | 
| 198: |  |