Skip to content

Commit

Permalink
added swiftmailer for handling emails
Browse files Browse the repository at this point in the history
  • Loading branch information
ivansf committed Feb 4, 2011
0 parents commit 4868be3
Show file tree
Hide file tree
Showing 147 changed files with 16,421 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Emailq

Kohana 3 module for queueing and delivering emails.

Requeriments:
- ORM Module
- Cron for setting up delivery.
- A new table called email_queue;
4 changes: 4 additions & 0 deletions classes/emailq.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php defined('SYSPATH') or die('No direct script access.');

abstract class Emailq extends Kohana_Emailq {
}
21 changes: 21 additions & 0 deletions classes/kohana/emailq.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php defined('SYSPATH') or die('No direct script access.');
/**
* Email queueing and delivering build for Pear Mail_Queue;
* Check the README file before starting.
*
* @package Kohana/Emailq
*
*/
abstract class Kohana_Emailq {

public static function factory($email, $name, $subject, $body) {
require_once MODPATH . 'emailq/swiftmailer/swift_required.php';
$config_file = Kohana::config('emailq');
$queue = ORM::factory('emailqueue');
$queue->email = $email;
$queue->name = $name;
$queue->subject = $subject;
$queue->body = $body;
$queue->save();
}
}
5 changes: 5 additions & 0 deletions classes/model/emailqueue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php defined('SYSPATH') or die('No direct script access.');

class Model_emailqueue extends ORM {
protected $_table_name = 'email_queue';
}
13 changes: 13 additions & 0 deletions config/emailq.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php defined('SYSPATH') or die('No direct script access.');
return array(
'mail_options' => array(
'driver' => 'smtp',
'host' => 'host',
'port' => 25,
'localhost' => 'localhost',
'auth' => true,
'username' => 'youruser',
'password' => 'yourpassword',
'debug' => false
),
);
Empty file added config/example.php
Empty file.
57 changes: 57 additions & 0 deletions swiftmailer/classes/Swift.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* This file is part of SwiftMailer.
* (c) 2004-2009 Chris Corbyn
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* General utility class in Swift Mailer, not to be instantiated.
*
* @package Swift
*
* @author Chris Corbyn
*/
abstract class Swift
{

/** Swift Mailer Version number generated during dist release process */
const VERSION = '4.0.6';

/**
* Internal autoloader for spl_autoload_register().
*
* @param string $class
*/
public static function autoload($class)
{
//Don't interfere with other autoloaders
if (0 !== strpos($class, 'Swift'))
{
return false;
}

$path = dirname(__FILE__).'/'.str_replace('_', '/', $class).'.php';

if (!file_exists($path))
{
return false;
}

require_once $path;
}

/**
* Configure autoloading using Swift Mailer.
*
* This is designed to play nicely with other autoloaders.
*/
public static function registerAutoload()
{
spl_autoload_register(array('Swift', 'autoload'));
}

}
75 changes: 75 additions & 0 deletions swiftmailer/classes/Swift/Attachment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/*
* This file is part of SwiftMailer.
* (c) 2004-2009 Chris Corbyn
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

//@require 'Swift/Mime/Attachment.php';
//@require 'Swift/ByteStream/FileByteStream.php';
//@require 'Swift/DependencyContainer.php';

/**
* Attachment class for attaching files to a {@link Swift_Mime_Message}.
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
*/
class Swift_Attachment extends Swift_Mime_Attachment
{

/**
* Create a new Attachment.
* Details may be optionally provided to the constructor.
* @param string|Swift_OutputByteStream $data
* @param string $filename
* @param string $contentType
*/
public function __construct($data = null, $filename = null,
$contentType = null)
{
call_user_func_array(
array($this, 'Swift_Mime_Attachment::__construct'),
Swift_DependencyContainer::getInstance()
->createDependenciesFor('mime.attachment')
);

$this->setBody($data);
$this->setFilename($filename);
if ($contentType)
{
$this->setContentType($contentType);
}
}

/**
* Create a new Attachment.
* @param string|Swift_OutputByteStream $data
* @param string $filename
* @param string $contentType
* @return Swift_Mime_Attachment
*/
public static function newInstance($data = null, $filename = null,
$contentType = null)
{
return new self($data, $filename, $contentType);
}

/**
* Create a new Attachment from a filesystem path.
* @param string $path
* @param string $contentType optional
* @return Swift_Mime_Attachment
*/
public static function fromPath($path, $contentType = null)
{
return self::newInstance()->setFile(
new Swift_ByteStream_FileByteStream($path),
$contentType
);
}

}
178 changes: 178 additions & 0 deletions swiftmailer/classes/Swift/ByteStream/AbstractFilterableInputStream.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<?php

/*
* This file is part of SwiftMailer.
* (c) 2004-2009 Chris Corbyn
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

//@require 'Swift/InputByteStream.php';
//@require 'Swift/Filterable.php';
//@require 'Swift/StreamFilter.php';

/**
* Provides the base functionality for an InputStream supporting filters.
* @package Swift
* @subpackage ByteStream
* @author Chris Corbyn
*/
abstract class Swift_ByteStream_AbstractFilterableInputStream
implements Swift_InputByteStream, Swift_Filterable
{

/** Write sequence */
private $_sequence = 0;

/** StreamFilters */
private $_filters = array();

/** A buffer for writing */
private $_writeBuffer = '';

/** Bound streams */
private $_mirrors = array();

/**
* Commit the given bytes to the storage medium immediately.
* @param string $bytes
* @access protected
*/
abstract protected function _commit($bytes);

/**
* Flush any buffers/content with immediate effect.
* @access protected
*/
abstract protected function _flush();

/**
* Add a StreamFilter to this InputByteStream.
* @param Swift_StreamFilter $filter
* @param string $key
*/
public function addFilter(Swift_StreamFilter $filter, $key)
{
$this->_filters[$key] = $filter;
}

/**
* Remove an already present StreamFilter based on its $key.
* @param string $key
*/
public function removeFilter($key)
{
unset($this->_filters[$key]);
}

/**
* Writes $bytes to the end of the stream.
* @param string $bytes
* @throws Swift_IoException
*/
public function write($bytes)
{
$this->_writeBuffer .= $bytes;
foreach ($this->_filters as $filter)
{
if ($filter->shouldBuffer($this->_writeBuffer))
{
return;
}
}
$this->_doWrite($this->_writeBuffer);
return ++$this->_sequence;
}

/**
* For any bytes that are currently buffered inside the stream, force them
* off the buffer.
*
* @throws Swift_IoException
*/
public function commit()
{
$this->_doWrite($this->_writeBuffer);
}

/**
* Attach $is to this stream.
* The stream acts as an observer, receiving all data that is written.
* All {@link write()} and {@link flushBuffers()} operations will be mirrored.
*
* @param Swift_InputByteStream $is
*/
public function bind(Swift_InputByteStream $is)
{
$this->_mirrors[] = $is;
}

/**
* Remove an already bound stream.
* If $is is not bound, no errors will be raised.
* If the stream currently has any buffered data it will be written to $is
* before unbinding occurs.
*
* @param Swift_InputByteStream $is
*/
public function unbind(Swift_InputByteStream $is)
{
foreach ($this->_mirrors as $k => $stream)
{
if ($is === $stream)
{
if ($this->_writeBuffer !== '')
{
$stream->write($this->_filter($this->_writeBuffer));
}
unset($this->_mirrors[$k]);
}
}
}

/**
* Flush the contents of the stream (empty it) and set the internal pointer
* to the beginning.
* @throws Swift_IoException
*/
public function flushBuffers()
{
if ($this->_writeBuffer !== '')
{
$this->_doWrite($this->_writeBuffer);
}
$this->_flush();

foreach ($this->_mirrors as $stream)
{
$stream->flushBuffers();
}
}

// -- Private methods

/** Run $bytes through all filters */
private function _filter($bytes)
{
foreach ($this->_filters as $filter)
{
$bytes = $filter->filter($bytes);
}
return $bytes;
}

/** Just write the bytes to the stream */
private function _doWrite($bytes)
{
$this->_commit($this->_filter($bytes));

foreach ($this->_mirrors as $stream)
{
$stream->write($bytes);
}

$this->_writeBuffer = '';
}

}
Loading

0 comments on commit 4868be3

Please sign in to comment.