Commit d4014a12 authored by judas_iscariote's avatar judas_iscariote

swift as external in 0.9.9.x, fixes FS#1218


git-svn-id: https://flyspray.svn.sourceforge.net/svnroot/flyspray/branches/0.9.9@1118 2633ddf7-78cb-0310-bf30-a8c8deaca200
parent d7f31efd
There are a number of people who are supporting this project and who are making
a HUGE difference to the speed of development and the ironing out of any bugs.
I'd just like to say a big thanks you to all who've helped, it does not go un-noticed.
Members of DevNetwork Forums:-
Thanks for your input on the interface of Swift and for feeding em with new ideas.
Mark Carlson (Pinnacle Media Worldwide - http://www.pinnaclemediaworldwide.com/):-
Where do I start? Mark has helped me with all kinds things in this project and has
been an excellent provider of feedback and debug assistance over email. Mark has
identified a number of bugs, several of which he even provided me the fixes for and he
has also done lots of testing on Swift to help me along the way. Thank you Mark!
Björn Sjöström
Bjorn helped immensely with combatting a problem with F-Secure removing mail bodies as if
they were attachments. Bjorn is also a very generous project donor.
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
Swift Mailer is a basic PHP Mailer class intended to do nothing
more than handle sending emails from PHP scripts.
Please refer to the LICENSE file before copying this class
or modifying it (it basically says you can do what you want
with it).
The Swift Mailer library can handle
pretty much everything you'd want when sending emails.
* Attachments
* Multipart Messaging
* Basic, single part messaging
* Custom Headers
* Encoding
* Inline images
* Embedded files
* Redundant connections
* Rotating connections
* Silent recipient denied handling
* TLS Encryption
* Bcc Sending
* Batch Mailing
* Custom SMTP commands
* SSL Connections
* Pluggable SMTP Authentication
* Plugin Support with event handling features
This library does NOT require the use of the mail() function
which is blocked by many shared hosts. Instead, it makes
use of fsockopen() to establish a connection with an SMTP -
server. This connection can be used to perform as many
tasks as required when when sending emails.
The functionality built in to the class should comply with
RFC 2821, and RFC 2554 which you can find under the docs/
directory.
For some examples of using Swift Mailer refer to the snippets at
docs/examples/.
You should refer to the online documentation to be sure you're
reading the most up-to-date stuff: http://swiftmailer.org/documentation/
For bugs and support (limited) please contact the author
"Chris Corbyn" <chris@w3style.co.uk>
This diff is collapsed.
<?php
/**
* Swift Mailer Address Container (purely for rigid RFC conformance)
* Please read the LICENSE file
* @copyright Chris Corbyn <chris@w3style.co.uk>
* @author Chris Corbyn <chris@w3style.co.uk>
* @package Swift
* @license GNU Lesser General Public License
*/
require_once dirname(__FILE__) . "/ClassLoader.php";
Swift_ClassLoader::load("Swift_AddressContainer");
/**
* Swift_Address is just a lone e-mail address reprsented as an object
* @package Swift
* @author Chris Corbyn <chris@w3style.co.uk>
*/
class Swift_Address extends Swift_AddressContainer
{
/**
* The e-mail address portion
* @var string
*/
var $address = null;
/**
* The personal name part
* @var string
*/
var $name = null;
/**
* Constructor
* @param string The address portion
* @param string The personal name, optional
*/
function Swift_Address($address, $name=null)
{
$this->setAddress($address);
if ($name !== null) $this->setName($name);
}
/**
* Set the email address
* @param string
*/
function setAddress($address)
{
$this->address = (string) $address;
}
/**
* Get the address portion
* @return string
*/
function getAddress()
{
return $this->address;
}
/**
* Set the personal name
* @param string
*/
function setName($name)
{
if ($name !== null) $this->name = (string) $name;
else $this->name = null;
}
/**
* Get personal name portion
* @return string
*/
function getName()
{
return $this->name;
}
/**
* Build the address the way it should be structured
* @param boolean If the string will be sent to a SMTP server as an envelope
* @return string
*/
function build($smtp=false)
{
if ($smtp)
{
return "<" . $this->address . ">";
}
else
{
if (($this->name !== null))
{
return $this->name . " <" . $this->address . ">";
}
else return $this->address;
}
}
}
<?php
/**
* This is purely here for identify reasons on some subclasses
* @package Swift
* @author Chris Corbyn <chris@w3style.co.uk>
*/
class Swift_AddressContainer {}
<?php
/**
* Swift Mailer Authenticator Interface
* Please read the LICENSE file
* @author Chris Corbyn <chris@w3style.co.uk>
* @package Swift_Authenticator
* @license GNU Lesser General Public License
*/
/**
* Swift Authenticator Interface
* Lists the methods all authenticators must implement
* @package Swift_Authenticator
* @author Chris Corbyn <chris@w3style.co.uk>
*/
class Swift_Authenticator /*interface*/
{
/**
* 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
*/
function isAuthenticated($username, $password, &$instance) {}
/**
* Return the name of the AUTH extension this is for
* @return string
*/
function getAuthExtensionName() {}
}
<?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 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 extends Swift_Authenticator
{
var $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
*/
function Swift_Authenticator_PopB4Smtp($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
*/
function isAuthenticated($user, $pass, &$swift)
{
$swift->disconnect();
$this->connection->start();
Swift_Errors::expect($e, "Swift_Connection_Exception");
if (!$e) $this->connection->assertOk($this->connection->read());
if (!$e) $this->connection->write("USER " . $user);
if (!$e) $this->connection->assertOk($this->connection->read());
if (!$e) $this->connection->write("PASS " . $pass);
if (!$e) $this->connection->assertOk($this->connection->read());
if (!$e) $this->connection->write("QUIT");
if (!$e) $this->connection->assertOk($this->connection->read());
if (!$e) $this->connection->stop();
if ($e) {
return false;
}
Swift_Errors::clear("Swift_Connection_Exception");
$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
*/
function getAuthExtensionName()
{
return "*PopB4Smtp";
}
}
<?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 extends 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
*/
function isAuthenticated($user, $pass, &$swift)
{
Swift_ClassLoader::load("Swift_Errors");
Swift_Errors::expect($e, "Swift_Connection_Exception");
$res =& $swift->command("AUTH CRAM-MD5", 334);
if (!$e) {
$encoded_challenge = substr($res->getString(), 4);
$challenge = base64_decode($encoded_challenge);
$response = base64_encode($user . " " . $this->generateCRAMMD5Hash($pass, $challenge));
$swift->command($response, 235);
}
if ($e) {
$swift->reset();
return false;
}
Swift_Errors::clear("Swift_Connection_Exception");
return true;
}
/**
* Return the name of the AUTH extension this is for
* @return string
*/
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
*/
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;
}
}
<?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 extends 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
*/
function isAuthenticated($user, $pass, &$swift)
{
Swift_ClassLoader::load("Swift_Errors");
Swift_Errors::expect($e, "Swift_Connection_Exception");
if (!$e) $swift->command("AUTH LOGIN", 334);
if (!$e) $swift->command(base64_encode($user), 334);
if (!$e) $swift->command(base64_encode($pass), 235);
if ($e) {
$swift->reset();
return false;
}
Swift_Errors::clear("Swift_Connection_Exception");
return true;
}
/**
* Return the name of the AUTH extension this is for
* @return string
*/
function getAuthExtensionName()
{
return "LOGIN";
}
}
<?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 extends 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
*/
function isAuthenticated($user, $pass, &$swift)
{
//The authorization string uses ascii null as a separator (See RFC 2554)
$credentials = $user . "\0" . $user . "\0" . $pass;
Swift_ClassLoader::load("Swift_Errors");
Swift_Errors::expect($e, "Swift_Connection_Exception");
$swift->command("AUTH PLAIN " . $credentials, 235);
if ($e) {
$swift->reset();
return false;
}
Swift_Errors::clear("Swift_Connection_Exception");
return true;
}
/**
* Return the name of the AUTH extension this is for
* @return string
*/
function getAuthExtensionName()
{
return "PLAIN";
}
}
<?php
/**
* This is the POP3 Before SMTP Authentication for Swift Mailer, a PHP Mailer class.
*
* @package Swift
* @version >= 2.0.0
* @author Chris Corbyn
* @date 30th July 2006
* @license http://www.gnu.org/licenses/lgpl.txt Lesser GNU Public License
*
* @copyright Copyright &copy; 2006 Chris Corbyn - All Rights Reserved.
* @filesource
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to
*
* The Free Software Foundation, Inc.,
* 51 Franklin Street,
* Fifth Floor,
* Boston,
* MA 02110-1301 USA
*
* "Chris Corbyn" <chris@w3style.co.uk>
*
*/
/**
* SMTP CRAM-MD5 Authenticator Class.
* Runs the commands needed in order to use LOGIN SMTP authentication
* @package Swift
*/
class Swift_Authenticator_POP3SMTP
{
/**
* The string the SMTP server returns to identify
* that it supports this authentication mechanism
* @var string serverString
*/
var $serverString = '*POP-SMTP';
/**
* SwiftInstance parent object
* @var object SwiftInstance (reference)
*/
var $baseObject;
/**
* The port we need to connect to
* @var int $port
*/
var $port;
/**
* The server we need to connect to
* @var string server
*/
var $server;
/**
* The connection to POP3
* @var resource connect handle
*/
var $socket;
function Swift_Authenticator_POP3SMTP($server, $port=110)
{
$this->port = $port;
$this->server = $server;
}
/**
* Loads an instance of Swift to the Plugin
*
* @param object SwiftInstance
* @return void
*/
function loadBaseObject(&$object)
{
$this->baseObject =& $object;
}
/**
* Executes the logic in the authentication mechanism
*
* @param string username
* @param string password
* @return bool successful
*/
function run($username, $password)
{
return $this->popB4SMTP($username, $password);
}
/**
* Connect to the POP3 server and return true on success
* @return bool success
*/
function connect()
{
$this->socket = @fsockopen($this->server, $this->port, $errno, $errstr, 15);
if (!$this->socket) return false;
if (!$this->isOK($this->response())) return false;
return true;
}
/**
* Check for an +OK string
* @return bool +OK
*/
function isOK($string)
{
if (substr($string, 0, 3) == '+OK') return true;
else return false;
}
/**
* Send a command to the server
*/
function command($comm)
{
@fwrite($this->socket, $comm);
}
/**
* Read the server response
* @return string response
*/
function response()
{
return fgets($this->socket);
}
/**
* Executes the logic in the authentication mechanism
*
* @param string username
* @param string password
* @return bool successful
*/
function popB4SMTP($username, $password)
{
//Kill any open session so we can authenticate to POP3 first
$this->baseObject->close();
if (!$this->connect()) return false;
$this->command("USER $username\r\n");
if (!$this->isOK($this->response())) return false;
$this->command("PASS $password\r\n");
if (!$this->isOK($this->response())) return false;
//START patch from Jakob Truelsen - antialize (SF.net)
$this->command("QUIT\r\n");
if (!$this->isOK($this->response())) return false;
//END patch
//Reconnect to the SMTP server
if ($this->baseObject->connect()) return true;
else return false;
}
}
?>
\ No newline at end of file
<?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__) . "/../../Errors.php";
require_once dirname(__FILE__) . "/../../Connection/Exception.php";
if (!defined("SWIFT_AUTH_POP_ENC_SSL")) define("SWIFT_AUTH_POP_ENC_SSL", 1);
if (!defined("SWIFT_AUTH_POP_ENC_OFF")) define("SWIFT_AUTH_POP_ENC_OFF", 0);
/**
* 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
*/
var $ENC_OFF = SWIFT_AUTH_POP_ENC_OFF;
/**
* Constant for SSL encryption
*/
var $ENC_SSL = SWIFT_AUTH_POP_ENC_SSL;
/**
* The server to connect to (IP or FQDN)
* @var string
*/
var $server = null;
/**
* The port to connect to
* @var int
*/
var $port = null;
/**
* The open connection resource from fsockopen()
* @var resource