first commit
This commit is contained in:
86
system/vendor/swift/Swift/Authenticator/@PopB4Smtp.php
vendored
Normal file
86
system/vendor/swift/Swift/Authenticator/@PopB4Smtp.php
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Swift Mailer PopB4Smtp Authenticator Mechanism
|
||||
* Please read the LICENSE file
|
||||
* @author Chris Corbyn <chris@w3style.co.uk>
|
||||
* @package Swift_Authenticator
|
||||
* @license GNU Lesser General Public License
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . "/../ClassLoader.php";
|
||||
Swift_ClassLoader::load("Swift_Authenticator");
|
||||
Swift_ClassLoader::load("Swift_LogContainer");
|
||||
|
||||
/**
|
||||
* Swift PopB4Smtp Authenticator
|
||||
* This form of authentication requires a quick connection to be made with a POP3 server before finally connecting to SMTP
|
||||
* @package Swift_Authenticator
|
||||
* @author Chris Corbyn <chris@w3style.co.uk>
|
||||
*/
|
||||
class Swift_Authenticator_PopB4Smtp implements Swift_Authenticator
|
||||
{
|
||||
protected $connection = null;
|
||||
/**
|
||||
* Constructor
|
||||
* @param mixed Swift_Authenticator_PopB4Smtp_Pop3Connection or string FQDN of POP3 server
|
||||
* @param int The remote port number
|
||||
* @param int The level of encryption to use
|
||||
*/
|
||||
public function __construct($conn=null, $port=110, $encryption=0)
|
||||
{
|
||||
if (is_object($conn)) $this->connection = $conn;
|
||||
else
|
||||
{
|
||||
Swift_ClassLoader::load("Swift_Authenticator_PopB4Smtp_Pop3Connection");
|
||||
$this->connection = new Swift_Authenticator_PopB4Smtp_Pop3Connection($conn, $port, $encryption);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Try to authenticate using the username and password
|
||||
* Returns false on failure
|
||||
* @param string The username
|
||||
* @param string The password
|
||||
* @param Swift The instance of Swift this authenticator is used in
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAuthenticated($user, $pass, Swift $swift)
|
||||
{
|
||||
$log = Swift_LogContainer::getLog();
|
||||
if ($log->hasLevel(Swift_Log::LOG_EVERYTHING))
|
||||
{
|
||||
$log->add("Trying POP3 Before SMTP authentication. Disconnecting from SMTP first.");
|
||||
}
|
||||
$swift->disconnect();
|
||||
try {
|
||||
$this->connection->start();
|
||||
$this->connection->assertOk($this->connection->read());
|
||||
$this->connection->write("USER " . $user);
|
||||
$this->connection->assertOk($this->connection->read());
|
||||
$this->connection->write("PASS " . $pass);
|
||||
$this->connection->assertOk($this->connection->read());
|
||||
$this->connection->write("QUIT");
|
||||
$this->connection->assertOk($this->connection->read());
|
||||
$this->connection->stop();
|
||||
} catch (Swift_ConnectionException $e) {
|
||||
if ($log->hasLevel(Swift_Log::LOG_ERRORS))
|
||||
{
|
||||
$log->add("POP3 authentication failed.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
$options = $swift->getOptions();
|
||||
$swift->setOptions($options | Swift::NO_POST_CONNECT);
|
||||
$swift->connect();
|
||||
$swift->setOptions($options);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Return the name of the AUTH extension this is for
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthExtensionName()
|
||||
{
|
||||
return "*PopB4Smtp";
|
||||
}
|
||||
}
|
||||
73
system/vendor/swift/Swift/Authenticator/CRAMMD5.php
vendored
Normal file
73
system/vendor/swift/Swift/Authenticator/CRAMMD5.php
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Swift Mailer CRAM-MD5 Authenticator Mechanism
|
||||
* Please read the LICENSE file
|
||||
* @author Chris Corbyn <chris@w3style.co.uk>
|
||||
* @package Swift_Authenticator
|
||||
* @license GNU Lesser General Public License
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . "/../ClassLoader.php";
|
||||
Swift_ClassLoader::load("Swift_Authenticator");
|
||||
|
||||
/**
|
||||
* Swift CRAM-MD5 Authenticator
|
||||
* This form of authentication is a secure challenge-response method
|
||||
* @package Swift_Authenticator
|
||||
* @author Chris Corbyn <chris@w3style.co.uk>
|
||||
*/
|
||||
class Swift_Authenticator_CRAMMD5 implements Swift_Authenticator
|
||||
{
|
||||
/**
|
||||
* Try to authenticate using the username and password
|
||||
* Returns false on failure
|
||||
* @param string The username
|
||||
* @param string The password
|
||||
* @param Swift The instance of Swift this authenticator is used in
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAuthenticated($user, $pass, Swift $swift)
|
||||
{
|
||||
try {
|
||||
$encoded_challenge = substr($swift->command("AUTH CRAM-MD5", 334)->getString(), 4);
|
||||
$challenge = base64_decode($encoded_challenge);
|
||||
$response = base64_encode($user . " " . self::generateCRAMMD5Hash($pass, $challenge));
|
||||
$swift->command($response, 235);
|
||||
} catch (Swift_ConnectionException $e) {
|
||||
$swift->reset();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Return the name of the AUTH extension this is for
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthExtensionName()
|
||||
{
|
||||
return "CRAM-MD5";
|
||||
}
|
||||
/**
|
||||
* Generate a CRAM-MD5 hash from a challenge
|
||||
* @param string The string to get a hash from
|
||||
* @param string The challenge to use to make the hash
|
||||
* @return string
|
||||
*/
|
||||
public static function generateCRAMMD5Hash($password, $challenge)
|
||||
{
|
||||
if (strlen($password) > 64)
|
||||
$password = pack('H32', md5($password));
|
||||
|
||||
if (strlen($password) < 64)
|
||||
$password = str_pad($password, 64, chr(0));
|
||||
|
||||
$k_ipad = substr($password, 0, 64) ^ str_repeat(chr(0x36), 64);
|
||||
$k_opad = substr($password, 0, 64) ^ str_repeat(chr(0x5C), 64);
|
||||
|
||||
$inner = pack('H32', md5($k_ipad.$challenge));
|
||||
$digest = md5($k_opad.$inner);
|
||||
|
||||
return $digest;
|
||||
}
|
||||
}
|
||||
49
system/vendor/swift/Swift/Authenticator/LOGIN.php
vendored
Normal file
49
system/vendor/swift/Swift/Authenticator/LOGIN.php
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Swift Mailer LOGIN Authenticator Mechanism
|
||||
* Please read the LICENSE file
|
||||
* @author Chris Corbyn <chris@w3style.co.uk>
|
||||
* @package Swift_Authenticator
|
||||
* @license GNU Lesser General Public License
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . "/../ClassLoader.php";
|
||||
Swift_ClassLoader::load("Swift_Authenticator");
|
||||
|
||||
/**
|
||||
* Swift LOGIN Authenticator
|
||||
* @package Swift_Authenticator
|
||||
* @author Chris Corbyn <chris@w3style.co.uk>
|
||||
*/
|
||||
class Swift_Authenticator_LOGIN implements Swift_Authenticator
|
||||
{
|
||||
/**
|
||||
* Try to authenticate using the username and password
|
||||
* Returns false on failure
|
||||
* @param string The username
|
||||
* @param string The password
|
||||
* @param Swift The instance of Swift this authenticator is used in
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAuthenticated($user, $pass, Swift $swift)
|
||||
{
|
||||
try {
|
||||
$swift->command("AUTH LOGIN", 334);
|
||||
$swift->command(base64_encode($user), 334);
|
||||
$swift->command(base64_encode($pass), 235);
|
||||
} catch (Swift_ConnectionException $e) {
|
||||
$swift->reset();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Return the name of the AUTH extension this is for
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthExtensionName()
|
||||
{
|
||||
return "LOGIN";
|
||||
}
|
||||
}
|
||||
50
system/vendor/swift/Swift/Authenticator/PLAIN.php
vendored
Normal file
50
system/vendor/swift/Swift/Authenticator/PLAIN.php
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Swift Mailer PLAIN Authenticator Mechanism
|
||||
* Please read the LICENSE file
|
||||
* @author Chris Corbyn <chris@w3style.co.uk>
|
||||
* @package Swift_Authenticator
|
||||
* @license GNU Lesser General Public License
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . "/../ClassLoader.php";
|
||||
Swift_ClassLoader::load("Swift_Authenticator");
|
||||
|
||||
/**
|
||||
* Swift PLAIN Authenticator
|
||||
* This form of authentication is unbelievably insecure since everything is done plain-text
|
||||
* @package Swift_Authenticator
|
||||
* @author Chris Corbyn <chris@w3style.co.uk>
|
||||
*/
|
||||
class Swift_Authenticator_PLAIN implements Swift_Authenticator
|
||||
{
|
||||
/**
|
||||
* Try to authenticate using the username and password
|
||||
* Returns false on failure
|
||||
* @param string The username
|
||||
* @param string The password
|
||||
* @param Swift The instance of Swift this authenticator is used in
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAuthenticated($user, $pass, Swift $swift)
|
||||
{
|
||||
try {
|
||||
//The authorization string uses ascii null as a separator (See RFC 2554)
|
||||
$credentials = base64_encode($user . chr(0) . $user . chr(0) . $pass);
|
||||
$swift->command("AUTH PLAIN " . $credentials, 235);
|
||||
} catch (Swift_ConnectionException $e) {
|
||||
$swift->reset();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Return the name of the AUTH extension this is for
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthExtensionName()
|
||||
{
|
||||
return "PLAIN";
|
||||
}
|
||||
}
|
||||
176
system/vendor/swift/Swift/Authenticator/PopB4Smtp/Pop3Connection.php
vendored
Normal file
176
system/vendor/swift/Swift/Authenticator/PopB4Smtp/Pop3Connection.php
vendored
Normal file
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Swift Mailer PopB4Smtp Pop3 Connection component
|
||||
* Please read the LICENSE file
|
||||
* @author Chris Corbyn <chris@w3style.co.uk>
|
||||
* @package Swift_Authenticator
|
||||
* @license GNU Lesser General Public License
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . "/../../ClassLoader.php";
|
||||
|
||||
/**
|
||||
* Swift PopB4Smtp Authenticator Connection Component for the POP3 server
|
||||
* Provides a I/O wrapper for the POP3 connection
|
||||
* @package Swift_Authenticator
|
||||
* @author Chris Corbyn <chris@w3style.co.uk>
|
||||
*/
|
||||
class Swift_Authenticator_PopB4Smtp_Pop3Connection
|
||||
{
|
||||
/**
|
||||
* Constant for no encyption
|
||||
*/
|
||||
const ENC_OFF = 0;
|
||||
/**
|
||||
* Constant for SSL encryption
|
||||
*/
|
||||
const ENC_SSL = 1;
|
||||
/**
|
||||
* The server to connect to (IP or FQDN)
|
||||
* @var string
|
||||
*/
|
||||
protected $server = null;
|
||||
/**
|
||||
* The port to connect to
|
||||
* @var int
|
||||
*/
|
||||
protected $port = null;
|
||||
/**
|
||||
* The open connection resource from fsockopen()
|
||||
* @var resource
|
||||
*/
|
||||
protected $handle = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param string The name of the POP3 server
|
||||
* @param int The port for the POP3 service
|
||||
* @param int The level of encryption to use
|
||||
*/
|
||||
public function __construct($server="localhost", $port=110, $encryption=0)
|
||||
{
|
||||
$this->setServer($server);
|
||||
$this->setPort($port);
|
||||
$this->setEncryption($encryption);
|
||||
}
|
||||
/**
|
||||
* Set the server name
|
||||
* @param string The IP or FQDN of the POP3 server
|
||||
*/
|
||||
public function setServer($server)
|
||||
{
|
||||
$this->server = (string) $server;
|
||||
}
|
||||
/**
|
||||
* Set the port number for the POP3 server
|
||||
* @param int
|
||||
*/
|
||||
public function setPort($port)
|
||||
{
|
||||
$this->port = (int) $port;
|
||||
}
|
||||
/**
|
||||
* Get the server name
|
||||
* @return string
|
||||
*/
|
||||
public function getServer()
|
||||
{
|
||||
return $this->server;
|
||||
}
|
||||
/**
|
||||
* Get the remote port number
|
||||
* @return int
|
||||
*/
|
||||
public function getPort()
|
||||
{
|
||||
return $this->port;
|
||||
}
|
||||
/**
|
||||
* Set the level of enryption to use (see ENC_OFF or ENC_SSL)
|
||||
* @param int The constant for the encryption level
|
||||
*/
|
||||
public function setEncryption($enc)
|
||||
{
|
||||
$this->encryption = (int) $enc;
|
||||
}
|
||||
/**
|
||||
* Get the current encryption level set (corresponds to ENC_SSL or ENC_OFF)
|
||||
* @return int
|
||||
*/
|
||||
public function getEncryption()
|
||||
{
|
||||
return $this->encryption;
|
||||
}
|
||||
/**
|
||||
* Check if the response is a +OK response
|
||||
* @throws Swift_ConnectionException Upon bad response
|
||||
*/
|
||||
public function assertOk($line)
|
||||
{
|
||||
if (substr($line, 0, 3) != "+OK")
|
||||
{
|
||||
Swift_ClassLoader::load("Swift_ConnectionException");
|
||||
throw new Swift_ConnectionException("The POP3 server did not suitably respond with a +OK response. " .
|
||||
"[" . $line . "]");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Try to open the connection
|
||||
* @throws Swift_ConnectionException If the connection will not start
|
||||
*/
|
||||
public function start()
|
||||
{
|
||||
$url = $this->getServer();
|
||||
if ($this->getEncryption() == self::ENC_SSL) $url = "ssl://" . $url;
|
||||
|
||||
if ((false === $this->handle = fsockopen($url, $this->getPort(), $errno, $errstr, $timeout)))
|
||||
{
|
||||
Swift_ClassLoader::load("Swift_ConnectionException");
|
||||
throw new Swift_ConnectionException("The POP3 connection failed to start. The error string returned from fsockopen() is [" . $errstr . "] #" . $errno);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Try to close the connection
|
||||
* @throws Swift_ConnectionException If the connection won't close
|
||||
*/
|
||||
public function stop()
|
||||
{
|
||||
if ($this->handle !== null)
|
||||
{
|
||||
if (false === fclose($this->handle))
|
||||
{
|
||||
Swift_ClassLoader::load("Swift_ConnectionException");
|
||||
throw new Swift_ConnectionException("The POP3 connection did not close successfully.");
|
||||
}
|
||||
}
|
||||
$this->handle = null;
|
||||
}
|
||||
/**
|
||||
* Return the unread buffer contents
|
||||
* @return string
|
||||
* @throws Swift_ConnectionException If the connection will not allow data to be read
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
if (false === $response = fgets($this->handle))
|
||||
{
|
||||
Swift_ClassLoader::load("Swift_ConnectionException");
|
||||
throw new Swift_ConnectionException("Data could not be read from the POP3 connection.");
|
||||
}
|
||||
return trim($response);
|
||||
}
|
||||
/**
|
||||
* Write a command to the remote socket
|
||||
* @param string the command to send (without CRLF)
|
||||
* @throws Swift_ConnectionException If the command cannot be written
|
||||
*/
|
||||
public function write($command)
|
||||
{
|
||||
if (false !== fwrite($this->handle, $command . "\r\n"))
|
||||
{
|
||||
Swift_ClassLoader::load("Swift_ConnectionException");
|
||||
throw new Swift_ConnectionException("Data could not be written to the POP3 connection.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user