Merge from branch 2.5

This commit is contained in:
Michael RICOIS 2014-01-29 08:39:29 +00:00
parent a3f0d0b25b
commit c848c6a9a0
19 changed files with 95 additions and 2840 deletions

View File

@ -36,7 +36,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
$view->headScript()
->appendFile('/libs/html5shiv.js', 'text/javascript', array('conditional' => 'lt IE 9'))
->appendFile('/libs/respond.min.js', 'text/javascript', array('conditional' => 'lt IE 9'))
->appendFile('/libs/jquery-1.10.2.min.js', 'text/javascript')
->appendFile('/libs/jquery-1.11.0.min.js', 'text/javascript')
->appendFile('/libs/bootstrap-v3.0.3/js/bootstrap.min.js', 'text/javascript');
$view->headTitle()->setSeparator(' - ');

View File

@ -16,7 +16,7 @@ class Metier_Search_Engine
if ($version == 1){
require_once 'Vendors/sphinxapi/sphinxapi-0.9.9.php';
} elseif ($version == 2){
require_once 'Vendors/sphinxapi/sphinxapi-2.1.2.php';
require_once 'Vendors/sphinxapi/sphinxapi-2.1.5.php';
}
}

View File

@ -657,7 +657,7 @@ function clientSphinx(&$formR)
require_once 'Vendors/sphinxapi/sphinxapi-0.9.9.php';
break;
case 2:
require_once 'Vendors/sphinxapi/sphinxapi-2.1.2.php';
require_once 'Vendors/sphinxapi/sphinxapi-2.1.5.php';
break;
}

View File

@ -1,12 +1,12 @@
<?php
//
// $Id: sphinxapi.php 3802 2013-04-10 12:49:42Z tomat $
// $Id: sphinxapi.php 4505 2014-01-22 15:16:21Z deogar $
//
//
// Copyright (c) 2001-2013, Andrew Aksyonoff
// Copyright (c) 2008-2013, Sphinx Technologies Inc
// Copyright (c) 2001-2014, Andrew Aksyonoff
// Copyright (c) 2008-2014, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
@ -382,7 +382,7 @@ function sphFixUint ( $value )
}
}
function SetBit ( $flag, $bit, $on )
function sphSetBit ( $flag, $bit, $on )
{
if ( $on )
{
@ -964,15 +964,15 @@ class SphinxClient
assert ( isset ( $flag_name, $known_names ) );
assert ( in_array( $flag_value, $flags[$flag_name], true ) || ( $flag_name=="max_predicted_time" && is_int ( $flag_value ) && $flag_value>=0 ) );
if ( $flag_name=="reverse_scan" ) $this->_query_flags = SetBit ( $this->_query_flags, 0, $flag_value==1 );
if ( $flag_name=="sort_method" ) $this->_query_flags = SetBit ( $this->_query_flags, 1, $flag_value=="kbuffer" );
if ( $flag_name=="reverse_scan" ) $this->_query_flags = sphSetBit ( $this->_query_flags, 0, $flag_value==1 );
if ( $flag_name=="sort_method" ) $this->_query_flags = sphSetBit ( $this->_query_flags, 1, $flag_value=="kbuffer" );
if ( $flag_name=="max_predicted_time" )
{
$this->_query_flags = SetBit ( $this->_query_flags, 2, $flag_value>0 );
$this->_query_flags = sphSetBit ( $this->_query_flags, 2, $flag_value>0 );
$this->_predictedtime = (int)$flag_value;
}
if ( $flag_name=="boolean_simplify" ) $this->_query_flags = SetBit ( $this->_query_flags, 3, $flag_value );
if ( $flag_name=="idf" ) $this->_query_flags = SetBit ( $this->_query_flags, 4, $flag_value=="plain" );
if ( $flag_name=="boolean_simplify" ) $this->_query_flags = sphSetBit ( $this->_query_flags, 3, $flag_value );
if ( $flag_name=="idf" ) $this->_query_flags = sphSetBit ( $this->_query_flags, 4, $flag_value=="plain" );
}
/// set outer order by parameters
@ -1606,8 +1606,8 @@ class SphinxClient
function EscapeString ( $string )
{
$from = array ( '\\', '(',')','|','-','!','@','~','"','&', '/', '^', '$', '=' );
$to = array ( '\\\\', '\(','\)','\|','\-','\!','\@','\~','\"', '\&', '\/', '\^', '\$', '\=' );
$from = array ( '\\', '(',')','|','-','!','@','~','"','&', '/', '^', '$', '=', '<' );
$to = array ( '\\\\', '\(','\)','\|','\-','\!','\@','\~','\"', '\&', '\/', '\^', '\$', '\=', '\<' );
return str_replace ( $from, $to, $string );
}
@ -1806,5 +1806,5 @@ class SphinxClient
}
//
// $Id: sphinxapi.php 3802 2013-04-10 12:49:42Z tomat $
// $Id: sphinxapi.php 4505 2014-01-22 15:16:21Z deogar $
//

View File

@ -2358,7 +2358,7 @@ class Interne extends WsScore
if (SPHINX_HISTO_VERSION == 1){
require_once 'Vendors/sphinxapi/sphinxapi-0.9.9.php';
} elseif (SPHINX_HISTO_VERSION == 2){
require_once 'Vendors/sphinxapi/sphinxapi-2.1.2.php';
require_once 'Vendors/sphinxapi/sphinxapi-2.1.5.php';
}
$cl = new SphinxClient();

View File

@ -2316,7 +2316,7 @@ class Interne extends WsScore
if (SPHINX_HISTO_VERSION == 1){
require_once 'Vendors/sphinxapi/sphinxapi-0.9.9.php';
} elseif (SPHINX_HISTO_VERSION == 2){
require_once 'Vendors/sphinxapi/sphinxapi-2.1.2.php';
require_once 'Vendors/sphinxapi/sphinxapi-2.1.5.php';
}
$cl = new SphinxClient();

View File

@ -1240,7 +1240,7 @@ class Interne extends WsScore
if (SPHINX_HISTO_VERSION == 1){
require_once 'Vendors/sphinxapi/sphinxapi-0.9.9.php';
} elseif (SPHINX_HISTO_VERSION == 2){
require_once 'Vendors/sphinxapi/sphinxapi-2.1.2.php';
require_once 'Vendors/sphinxapi/sphinxapi-2.1.5.php';
}
$cl = new SphinxClient();

View File

@ -1246,7 +1246,7 @@ class Interne extends WsScore
if (SPHINX_HISTO_VERSION == 1){
require_once 'Vendors/sphinxapi/sphinxapi-0.9.9.php';
} elseif (SPHINX_HISTO_VERSION == 2){
require_once 'Vendors/sphinxapi/sphinxapi-2.1.2.php';
require_once 'Vendors/sphinxapi/sphinxapi-2.1.5.php';
}
$cl = new SphinxClient();

View File

@ -118,7 +118,7 @@ class Pieces extends WsScore
$this->sendError('1010');
}
/*
/**
* Entreprise avec des bilans
* Base RNCS
* Si association alors lire dans la base de données pour établir la liste
@ -199,6 +199,9 @@ class Pieces extends WsScore
$infogreffe = new Metier_Infogreffe_Bi($identifiant);
$list = $infogreffe->getList();
$nbBilans = count($list);
//@todo : Marquer les éléments en commande courrier si déjà commandé ModeDiffusion = O
}
$this->wsLog('greffe_bilans', $identifiant, 'Liste');
@ -301,6 +304,7 @@ class Pieces extends WsScore
break;
case 'C':
case 'F':
//Génération identifiant de commande unique
$refCommande = uniqid();
@ -324,11 +328,13 @@ class Pieces extends WsScore
));
//Commande chez Infogreffe
require_once 'Metier/Infogreffe/InfogreffeBi.php';
$infogreffe = new Metier_Infogreffe_Bi($identifiant);
if ( $infogreffe->getCommandeC($dateCloture, $type, 'G-BI-'.$id) ) {
$commandeM->update( array('dateCommande' => date('YmdHis') ), 'id='.$id);
$this->wsLog('greffe_bilans', $identifiant, $refCommande);
if ( $diffusion == 'C' ) {
require_once 'Metier/Infogreffe/InfogreffeBi.php';
$infogreffe = new Metier_Infogreffe_Bi($identifiant);
if ( $infogreffe->getCommandeC($dateCloture, $type, 'G-BI-'.$id) ) {
$commandeM->update( array('dateCommande' => date('YmdHis') ), 'id='.$id);
$this->wsLog('greffe_bilans', $identifiant, $refCommande);
}
}
return $refCommande;
@ -387,6 +393,9 @@ class Pieces extends WsScore
}
}
}
//@todo : Marquer les éléments en commande courrier si déjà commandé ModeDiffusion = O
}
$this->wsLog('greffe_actes', $identifiant, 'Liste');
@ -461,6 +470,7 @@ class Pieces extends WsScore
break;
case 'C':
case 'F':
//Génération identifiant de commande unique
$refCommande = uniqid();
@ -486,11 +496,13 @@ class Pieces extends WsScore
'dateInsert' => date('YmdHis'),
));
//Commande chez Infogreffe
require_once 'Metier/Infogreffe/InfogreffeAc.php';
$infogreffe = new Metier_Infogreffe_Ac($identifiant);
if ( $infogreffe->getCommandeC($depotDate, $depotNum, $acteType, $acteDate, $acteNum, 'G-AC-'.$id) ) {
$commandeM->update( array('dateCommande' => date('YmdHis') ), 'id='.$id);
if ( $diffusion == 'C') {
//Commande chez Infogreffe
require_once 'Metier/Infogreffe/InfogreffeAc.php';
$infogreffe = new Metier_Infogreffe_Ac($identifiant);
if ( $infogreffe->getCommandeC($depotDate, $depotNum, $acteType, $acteDate, $acteNum, 'G-AC-'.$id) ) {
$commandeM->update( array('dateCommande' => date('YmdHis') ), 'id='.$id);
}
}
return $refCommande;

View File

@ -40,6 +40,8 @@ class Bilan
public $Type;
/**
* Mode de diffusion
* T = Téléchargement, C = Commande pour numérisation, L = Commande pour nuémrisation (archive), O = En commande
* @var string
*/
public $ModeDiffusion;
@ -127,6 +129,8 @@ class Acte
public $ActeTypeLabel;
/**
* Mode de diffusion
* T = Téléchargement, C = Commande pour numérisation, L = Commande pour nuémrisation (archive), O = En commande
* @var string
*/
public $ModeDiffusion;

View File

@ -1,3 +0,0 @@
<?php
include_once(FWK_PATH.'mail/htmlMimeMail5.php');
?>

View File

@ -1,878 +0,0 @@
<?php
/**
) o------------------------------------------------------------------------------o
* | This is HTMLMimeMail5. It is dual licensed as GPL and a commercial license. |
* | If you use the code commercially (or if you don't want to be restricted by |
* | the GPL license), you will need the commercial license. It's only £49 (GBP - |
* | roughly $98 depending on the exchange rate) and helps me out a lot. Thanks. |
* o------------------------------------------------------------------------------o
*
* © Copyright 2005 Richard Heyes
*/
/**
* RFC 822 Email address list validation Utility
*
* What is it?
*
* This class will take an address string, and parse it into it's consituent
* parts, be that either addresses, groups, or combinations. Nested groups
* are not supported. The structure it returns is pretty straight forward,
* and is similar to that provided by the imap_rfc822_parse_adrlist(). Use
* print_r() to view the structure.
*
* How do I use it?
*
* $address_string = 'My Group: "Richard Heyes" <richard@localhost> (A comment), ted@example.com (Ted Bloggs), Barney;';
* $structure = Mail_RFC822::parseAddressList($address_string, 'example.com', TRUE)
* print_r($structure);
*/
class Mail_RFC822
{
/**
* The address being parsed by the RFC822 object.
* @private string $address
*/
private $address = '';
/**
* The default domain to use for unqualified addresses.
* @private string $default_domain
*/
private $default_domain = 'localhost';
/**
* Should we return a nested array showing groups, or flatten everything?
* @private boolean $nestGroups
*/
private $nestGroups = true;
/**
* Whether or not to validate atoms for non-ascii characters.
* @private boolean $validate
*/
private $validate = true;
/**
* The array of raw addresses built up as we parse.
* @private array $addresses
*/
private $addresses = array();
/**
* The final array of parsed address information that we build up.
* @private array $structure
*/
private $structure = array();
/**
* The current error message, if any.
* @private string $error
*/
private $error = null;
/**
* An internal counter/pointer.
* @private integer $index
*/
private $index = null;
/**
* The number of groups that have been found in the address list.
* @private integer $num_groups
* @access public
*/
private $num_groups = 0;
/**
* A variable so that we can tell whether or not we're inside a
* Mail_RFC822 object.
* @private boolean $mailRFC822
*/
private $mailRFC822 = true;
/**
* A limit after which processing stops
* @private int $limit
*/
private $limit = null;
/**
* Sets up the object. The address must either be set here or when
* calling parseAddressList(). One or the other.
*
* @access public
* @param string $address The address(es) to validate.
* @param string $default_domain Default domain/host etc. If not supplied, will be set to localhost.
* @param boolean $nest_groups Whether to return the structure with groups nested for easier viewing.
* @param boolean $validate Whether to validate atoms. Turn this off if you need to run addresses through before encoding the personal names, for instance.
*
* @return object Mail_RFC822 A new Mail_RFC822 object.
*/
function __construct($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null)
{
if (isset($address)) $this->address = $address;
if (isset($default_domain)) $this->default_domain = $default_domain;
if (isset($nest_groups)) $this->nestGroups = $nest_groups;
if (isset($validate)) $this->validate = $validate;
if (isset($limit)) $this->limit = $limit;
}
/**
* Starts the whole process. The address must either be set here
* or when creating the object. One or the other.
*
* @access public
* @param string $address The address(es) to validate.
* @param string $default_domain Default domain/host etc.
* @param boolean $nest_groups Whether to return the structure with groups nested for easier viewing.
* @param boolean $validate Whether to validate atoms. Turn this off if you need to run addresses through before encoding the personal names, for instance.
*
* @return array A structured array of addresses.
*/
function parseAddressList($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null)
{
if (!isset($this->mailRFC822)) {
$obj = new Mail_RFC822($address, $default_domain, $nest_groups, $validate, $limit);
return $obj->parseAddressList();
}
if (isset($address)) $this->address = $address;
if (isset($default_domain)) $this->default_domain = $default_domain;
if (isset($nest_groups)) $this->nestGroups = $nest_groups;
if (isset($validate)) $this->validate = $validate;
if (isset($limit)) $this->limit = $limit;
$this->structure = array();
$this->addresses = array();
$this->error = null;
$this->index = null;
while ($this->address = $this->_splitAddresses($this->address)) {
continue;
}
if ($this->address === false || isset($this->error)) {
return false;
}
// Reset timer since large amounts of addresses can take a long time to
// get here
set_time_limit(30);
// Loop through all the addresses
for ($i = 0; $i < count($this->addresses); $i++){
if (($return = $this->_validateAddress($this->addresses[$i])) === false
|| isset($this->error)) {
return false;
}
if (!$this->nestGroups) {
$this->structure = array_merge($this->structure, $return);
} else {
$this->structure[] = $return;
}
}
return $this->structure;
}
/**
* Splits an address into seperate addresses.
*
* @access private
* @param string $address The addresses to split.
* @return boolean Success or failure.
*/
function _splitAddresses($address)
{
if (!empty($this->limit) AND count($this->addresses) == $this->limit) {
return '';
}
if ($this->_isGroup($address) && !isset($this->error)) {
$split_char = ';';
$is_group = true;
} elseif (!isset($this->error)) {
$split_char = ',';
$is_group = false;
} elseif (isset($this->error)) {
return false;
}
// Split the string based on the above ten or so lines.
$parts = explode($split_char, $address);
$string = $this->_splitCheck($parts, $split_char);
// If a group...
if ($is_group) {
// If $string does not contain a colon outside of
// brackets/quotes etc then something's fubar.
// First check there's a colon at all:
if (strpos($string, ':') === false) {
$this->error = 'Invalid address: ' . $string;
return false;
}
// Now check it's outside of brackets/quotes:
if (!$this->_splitCheck(explode(':', $string), ':'))
return false;
// We must have a group at this point, so increase the counter:
$this->num_groups++;
}
// $string now contains the first full address/group.
// Add to the addresses array.
$this->addresses[] = array(
'address' => trim($string),
'group' => $is_group
);
// Remove the now stored address from the initial line, the +1
// is to account for the explode character.
$address = trim(substr($address, strlen($string) + 1));
// If the next char is a comma and this was a group, then
// there are more addresses, otherwise, if there are any more
// chars, then there is another address.
if ($is_group && substr($address, 0, 1) == ','){
$address = trim(substr($address, 1));
return $address;
} elseif (strlen($address) > 0) {
return $address;
} else {
return '';
}
// If you got here then something's off
return false;
}
/**
* Checks for a group at the start of the string.
*
* @access private
* @param string $address The address to check.
* @return boolean Whether or not there is a group at the start of the string.
*/
function _isGroup($address)
{
// First comma not in quotes, angles or escaped:
$parts = explode(',', $address);
$string = $this->_splitCheck($parts, ',');
// Now we have the first address, we can reliably check for a
// group by searching for a colon that's not escaped or in
// quotes or angle brackets.
if (count($parts = explode(':', $string)) > 1) {
$string2 = $this->_splitCheck($parts, ':');
return ($string2 !== $string);
} else {
return false;
}
}
/**
* A common function that will check an exploded string.
*
* @access private
* @param array $parts The exloded string.
* @param string $char The char that was exploded on.
* @return mixed False if the string contains unclosed quotes/brackets, or the string on success.
*/
function _splitCheck($parts, $char)
{
$string = $parts[0];
for ($i = 0; $i < count($parts); $i++) {
if ($this->_hasUnclosedQuotes($string)
|| $this->_hasUnclosedBrackets($string, '<>')
|| $this->_hasUnclosedBrackets($string, '[]')
|| $this->_hasUnclosedBrackets($string, '()')
|| substr($string, -1) == '\\') {
if (isset($parts[$i + 1])) {
$string = $string . $char . $parts[$i + 1];
} else {
$this->error = 'Invalid address spec. Unclosed bracket or quotes';
return false;
}
} else {
$this->index = $i;
break;
}
}
return $string;
}
/**
* Checks if a string has an unclosed quotes or not.
*
* @access private
* @param string $string The string to check.
* @return boolean True if there are unclosed quotes inside the string, false otherwise.
*/
function _hasUnclosedQuotes($string)
{
$string = explode('"', $string);
$string_cnt = count($string);
for ($i = 0; $i < (count($string) - 1); $i++)
if (substr($string[$i], -1) == '\\')
$string_cnt--;
return ($string_cnt % 2 === 0);
}
/**
* Checks if a string has an unclosed brackets or not. IMPORTANT:
* This function handles both angle brackets and square brackets;
*
* @access private
* @param string $string The string to check.
* @param string $chars The characters to check for.
* @return boolean True if there are unclosed brackets inside the string, false otherwise.
*/
function _hasUnclosedBrackets($string, $chars)
{
$num_angle_start = substr_count($string, $chars[0]);
$num_angle_end = substr_count($string, $chars[1]);
$this->_hasUnclosedBracketsSub($string, $num_angle_start, $chars[0]);
$this->_hasUnclosedBracketsSub($string, $num_angle_end, $chars[1]);
if ($num_angle_start < $num_angle_end) {
$this->error = 'Invalid address spec. Unmatched quote or bracket (' . $chars . ')';
return false;
} else {
return ($num_angle_start > $num_angle_end);
}
}
/**
* Sub function that is used only by hasUnclosedBrackets().
*
* @access private
* @param string $string The string to check.
* @param integer &$num The number of occurences.
* @param string $char The character to count.
* @return integer The number of occurences of $char in $string, adjusted for backslashes.
*/
function _hasUnclosedBracketsSub($string, &$num, $char)
{
$parts = explode($char, $string);
for ($i = 0; $i < count($parts); $i++){
if (substr($parts[$i], -1) == '\\' || $this->_hasUnclosedQuotes($parts[$i]))
$num--;
if (isset($parts[$i + 1]))
$parts[$i + 1] = $parts[$i] . $char . $parts[$i + 1];
}
return $num;
}
/**
* Function to begin checking the address.
*
* @access private
* @param string $address The address to validate.
* @return mixed False on failure, or a structured array of address information on success.
*/
function _validateAddress($address)
{
$is_group = false;
if ($address['group']) {
$is_group = true;
// Get the group part of the name
$parts = explode(':', $address['address']);
$groupname = $this->_splitCheck($parts, ':');
$structure = array();
// And validate the group part of the name.
if (!$this->_validatePhrase($groupname)){
$this->error = 'Group name did not validate.';
return false;
} else {
// Don't include groups if we are not nesting
// them. This avoids returning invalid addresses.
if ($this->nestGroups) {
$structure = new stdClass;
$structure->groupname = $groupname;
}
}
$address['address'] = ltrim(substr($address['address'], strlen($groupname . ':')));
}
// If a group then split on comma and put into an array.
// Otherwise, Just put the whole address in an array.
if ($is_group) {
while (strlen($address['address']) > 0) {
$parts = explode(',', $address['address']);
$addresses[] = $this->_splitCheck($parts, ',');
$address['address'] = trim(substr($address['address'], strlen(end($addresses) . ',')));
}
} else {
$addresses[] = $address['address'];
}
// Check that $addresses is set, if address like this:
// Groupname:;
// Then errors were appearing.
if (!isset($addresses)){
$this->error = 'Empty group.';
return false;
}
for ($i = 0; $i < count($addresses); $i++) {
$addresses[$i] = trim($addresses[$i]);
}
// Validate each mailbox.
// Format could be one of: name <geezer@domain.com>
// geezer@domain.com
// geezer
// ... or any other format valid by RFC 822.
array_walk($addresses, array($this, 'validateMailbox'));
// Nested format
if ($this->nestGroups) {
if ($is_group) {
$structure->addresses = $addresses;
} else {
$structure = $addresses[0];
}
// Flat format
} else {
if ($is_group) {
$structure = array_merge($structure, $addresses);
} else {
$structure = $addresses;
}
}
return $structure;
}
/**
* Function to validate a phrase.
*
* @access private
* @param string $phrase The phrase to check.
* @return boolean Success or failure.
*/
function _validatePhrase($phrase)
{
// Splits on one or more Tab or space.
$parts = preg_split('/[ \\x09]+/', $phrase, -1, PREG_SPLIT_NO_EMPTY);
$phrase_parts = array();
while (count($parts) > 0){
$phrase_parts[] = $this->_splitCheck($parts, ' ');
for ($i = 0; $i < $this->index + 1; $i++)
array_shift($parts);
}
for ($i = 0; $i < count($phrase_parts); $i++) {
// If quoted string:
if (substr($phrase_parts[$i], 0, 1) == '"') {
if (!$this->_validateQuotedString($phrase_parts[$i]))
return false;
continue;
}
// Otherwise it's an atom:
if (!$this->_validateAtom($phrase_parts[$i])) return false;
}
return true;
}
/**
* Function to validate an atom which from rfc822 is:
* atom = 1*<any CHAR except specials, SPACE and CTLs>
*
* If validation ($this->validate) has been turned off, then
* validateAtom() doesn't actually check anything. This is so that you
* can split a list of addresses up before encoding personal names
* (umlauts, etc.), for example.
*
* @access private
* @param string $atom The string to check.
* @return boolean Success or failure.
*/
function _validateAtom($atom)
{
if (!$this->validate) {
// Validation has been turned off; assume the atom is okay.
return true;
}
// Check for any char from ASCII 0 - ASCII 127
if (!preg_match('/^[\\x00-\\x7E]+$/i', $atom, $matches)) {
return false;
}
// Check for specials:
if (preg_match('/[][()<>@,;\\:". ]/', $atom)) {
return false;
}
// Check for control characters (ASCII 0-31):
if (preg_match('/[\\x00-\\x1F]+/', $atom)) {
return false;
}
return true;
}
/**
* Function to validate quoted string, which is:
* quoted-string = <"> *(qtext/quoted-pair) <">
*
* @access private
* @param string $qstring The string to check
* @return boolean Success or failure.
*/
function _validateQuotedString($qstring)
{
// Leading and trailing "
$qstring = substr($qstring, 1, -1);
// Perform check.
return !(preg_match('/(.)[\x0D\\\\"]/', $qstring, $matches) && $matches[1] != '\\');
}
/**
* Function to validate a mailbox, which is:
* mailbox = addr-spec ; simple address
* / phrase route-addr ; name and route-addr
*
* @access public
* @param string &$mailbox The string to check.
* @return boolean Success or failure.
*/
function validateMailbox(&$mailbox)
{
// A couple of defaults.
$phrase = '';
$comment = '';
// Catch any RFC822 comments and store them separately
$_mailbox = $mailbox;
while (strlen(trim($_mailbox)) > 0) {
$parts = explode('(', $_mailbox);
$before_comment = $this->_splitCheck($parts, '(');
if ($before_comment != $_mailbox) {
// First char should be a (
$comment = substr(str_replace($before_comment, '', $_mailbox), 1);
$parts = explode(')', $comment);
$comment = $this->_splitCheck($parts, ')');
$comments[] = $comment;
// +1 is for the trailing )
$_mailbox = substr($_mailbox, strpos($_mailbox, $comment)+strlen($comment)+1);
} else {
break;
}
}
for($i=0; $i<count(@$comments); $i++){
$mailbox = str_replace('('.$comments[$i].')', '', $mailbox);
}
$mailbox = trim($mailbox);
// Check for name + route-addr
if (substr($mailbox, -1) == '>' && substr($mailbox, 0, 1) != '<') {
$parts = explode('<', $mailbox);
$name = $this->_splitCheck($parts, '<');
$phrase = trim($name);
$route_addr = trim(substr($mailbox, strlen($name.'<'), -1));
if ($this->_validatePhrase($phrase) === false || ($route_addr = $this->_validateRouteAddr($route_addr)) === false)
return false;
// Only got addr-spec
} else {
// First snip angle brackets if present.
if (substr($mailbox,0,1) == '<' && substr($mailbox,-1) == '>')
$addr_spec = substr($mailbox,1,-1);
else
$addr_spec = $mailbox;
if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false)
return false;
}
// Construct the object that will be returned.
$mbox = new stdClass();
// Add the phrase (even if empty) and comments
$mbox->personal = $phrase;
$mbox->comment = isset($comments) ? $comments : array();
if (isset($route_addr)) {
$mbox->mailbox = $route_addr['local_part'];
$mbox->host = $route_addr['domain'];
$route_addr['adl'] !== '' ? $mbox->adl = $route_addr['adl'] : '';
} else {
$mbox->mailbox = $addr_spec['local_part'];
$mbox->host = $addr_spec['domain'];
}
$mailbox = $mbox;
return true;
}
/**
* This function validates a route-addr which is:
* route-addr = "<" [route] addr-spec ">"
*
* Angle brackets have already been removed at the point of
* getting to this function.
*
* @access private
* @param string $route_addr The string to check.
* @return mixed False on failure, or an array containing validated address/route information on success.
*/
function _validateRouteAddr($route_addr)
{
// Check for colon.
if (strpos($route_addr, ':') !== false) {
$parts = explode(':', $route_addr);
$route = $this->_splitCheck($parts, ':');
} else {
$route = $route_addr;
}
// If $route is same as $route_addr then the colon was in
// quotes or brackets or, of course, non existent.
if ($route === $route_addr){
unset($route);
$addr_spec = $route_addr;
if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) {
return false;
}
} else {
// Validate route part.
if (($route = $this->_validateRoute($route)) === false) {
return false;
}
$addr_spec = substr($route_addr, strlen($route . ':'));
// Validate addr-spec part.
if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) {
return false;
}
}
if (isset($route)) {
$return['adl'] = $route;
} else {
$return['adl'] = '';
}
$return = array_merge($return, $addr_spec);
return $return;
}
/**
* Function to validate a route, which is:
* route = 1#("@" domain) ":"
*
* @access private
* @param string $route The string to check.
* @return mixed False on failure, or the validated $route on success.
*/
function _validateRoute($route)
{
// Split on comma.
$domains = explode(',', trim($route));
for ($i = 0; $i < count($domains); $i++) {
$domains[$i] = str_replace('@', '', trim($domains[$i]));
if (!$this->_validateDomain($domains[$i])) return false;
}
return $route;
}
/**
* Function to validate a domain, though this is not quite what
* you expect of a strict internet domain.
*
* domain = sub-domain *("." sub-domain)
*
* @access private
* @param string $domain The string to check.
* @return mixed False on failure, or the validated domain on success.
*/
function _validateDomain($domain)
{
// Note the different use of $subdomains and $sub_domains
$subdomains = explode('.', $domain);
while (count($subdomains) > 0) {
$sub_domains[] = $this->_splitCheck($subdomains, '.');
for ($i = 0; $i < $this->index + 1; $i++)
array_shift($subdomains);
}
for ($i = 0; $i < count($sub_domains); $i++) {
if (!$this->_validateSubdomain(trim($sub_domains[$i])))
return false;
}
// Managed to get here, so return input.
return $domain;
}
/**
* Function to validate a subdomain:
* subdomain = domain-ref / domain-literal
*
* @access private
* @param string $subdomain The string to check.
* @return boolean Success or failure.
*/
function _validateSubdomain($subdomain)
{
if (preg_match('|^\[(.*)]$|', $subdomain, $arr)){
if (!$this->_validateDliteral($arr[1])) return false;
} else {
if (!$this->_validateAtom($subdomain)) return false;
}
// Got here, so return successful.
return true;
}
/**
* Function to validate a domain literal:
* domain-literal = "[" *(dtext / quoted-pair) "]"
*
* @access private
* @param string $dliteral The string to check.
* @return boolean Success or failure.
*/
function _validateDliteral($dliteral)
{
return !preg_match('/(.)[][\x0D\\\\]/', $dliteral, $matches) && $matches[1] != '\\';
}
/**
* Function to validate an addr-spec.
*
* addr-spec = local-part "@" domain
*
* @access private
* @param string $addr_spec The string to check.
* @return mixed False on failure, or the validated addr-spec on success.
*/
function _validateAddrSpec($addr_spec)
{
$addr_spec = trim($addr_spec);
// Split on @ sign if there is one.
if (strpos($addr_spec, '@') !== false) {
$parts = explode('@', $addr_spec);
$local_part = $this->_splitCheck($parts, '@');
$domain = substr($addr_spec, strlen($local_part . '@'));
// No @ sign so assume the default domain.
} else {
$local_part = $addr_spec;
$domain = $this->default_domain;
}
if (($local_part = $this->_validateLocalPart($local_part)) === false) return false;
if (($domain = $this->_validateDomain($domain)) === false) return false;
// Got here so return successful.
return array('local_part' => $local_part, 'domain' => $domain);
}
/**
* Function to validate the local part of an address:
* local-part = word *("." word)
*
* @access private
* @param string $local_part
* @return mixed False on failure, or the validated local part on success.
*/
function _validateLocalPart($local_part)
{
$parts = explode('.', $local_part);
// Split the local_part into words.
while (count($parts) > 0){
$words[] = $this->_splitCheck($parts, '.');
for ($i = 0; $i < $this->index + 1; $i++) {
array_shift($parts);
}
}
// Validate each word.
for ($i = 0; $i < count($words); $i++) {
if ($this->_validatePhrase(trim($words[$i])) === false) return false;
}
// Managed to get here, so return the input.
return $local_part;
}
/**
* Returns an approximate count of how many addresses are
* in the given string. This is APPROXIMATE as it only splits
* based on a comma which has no preceding backslash. Could be
* useful as large amounts of addresses will end up producing
* *large* structures when used with parseAddressList().
*
* @param string $data Addresses to count
* @return int Approximate count
*/
function approximateCount($data)
{
return count(preg_split('/(?<!\\\\),/', $data));
}
/**
* This is a email validating function seperate to the rest
* of the class. It simply validates whether an email is of
* the common internet form: <user>@<domain>. This can be
* sufficient for most people. Optional stricter mode can
* be utilised which restricts mailbox characters allowed
* to alphanumeric, full stop, hyphen and underscore.
*
* @param string $data Address to check
* @param boolean $strict Optional stricter mode
* @return mixed False if it fails, an indexed array
* username/domain if it matches
*/
function isValidInetAddress($data, $strict = false)
{
$regex = $strict ? '/^([.0-9a-z_-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i' : '/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i';
if (preg_match($regex, trim($data), $matches)) {
return array($matches[1], $matches[2]);
} else {
return false;
}
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -1,311 +0,0 @@
<?php
/**
* o------------------------------------------------------------------------------o
* | This is HTMLMimeMail5. It is dual licensed as GPL and a commercial license. |
* | If you use the code commercially (or if you don't want to be restricted by |
* | the GPL license), you will need the commercial license. It's only £49 (GBP - |
* | roughly $98 depending on the exchange rate) and helps me out a lot. Thanks. |
* o------------------------------------------------------------------------------o
*
* © Copyright Richard Heyes
*/
/**
*
* Raw mime encoding class
*
* What is it?
* This class enables you to manipulate and build
* a mime email from the ground up.
*
* Why use this instead of mime.php?
* mime.php is a userfriendly api to this class for
* people who aren't interested in the internals of
* mime mail. This class however allows full control
* over the email.
*
* Eg.
*
* // Since multipart/mixed has no real body, (the body is
* // the subpart), we set the body argument to blank.
*
* $params['content_type'] = 'multipart/mixed';
* $email = new Mail_mimePart('', $params);
*
* // Here we add a text part to the multipart we have
* // already. Assume $body contains plain text.
*
* $params['content_type'] = 'text/plain';
* $params['encoding'] = '7bit';
* $text = $email->addSubPart($body, $params);
*
* // Now add an attachment. Assume $attach is
* the contents of the attachment
*
* $params['content_type'] = 'application/zip';
* $params['encoding'] = 'base64';
* $params['disposition'] = 'attachment';
* $params['dfilename'] = 'example.zip';
* $attach =& $email->addSubPart($body, $params);
*
* // Now build the email. Note that the encode
* // function returns an associative array containing two
* // elements, body and headers. You will need to add extra
* // headers, (eg. Mime-Version) before sending.
*
* $email = $message->encode();
* $email['headers'][] = 'Mime-Version: 1.0';
*
*
* Further examples are available at http://www.phpguru.org
*
* TODO:
* - Set encode() to return the $obj->encoded if encode()
* has already been run. Unless a flag is passed to specifically
* re-build the message.
*
* @author Richard Heyes <richard@phpguru.org>
* @version $Revision: 1.3 $
* @package Mail
*/
class Mail_MIMEPart
{
/**
* The encoding type of this part
* @var string
*/
private $encoding;
/**
* An array of subparts
* @var array
*/
private $subparts;
/**
* The output of this part after being built
* @var string
*/
private $encoded;
/**
* Headers for this part
* @var array
*/
private $headers;
/**
* The body of this part (not encoded)
* @var string
*/
private $body;
/**
* Constructor.
*
* Sets up the object.
*
* @param $body - The body of the mime part if any.
* @param $params - An associative array of parameters:
* content_type - The content type for this part eg multipart/mixed
* encoding - The encoding to use, 7bit, 8bit, base64, or quoted-printable
* cid - Content ID to apply
* disposition - Content disposition, inline or attachment
* dfilename - Optional filename parameter for content disposition
* description - Content description
* charset - Character set to use
* @access public
*/
public function __construct($body = '', $params = array())
{
if (!defined('MAIL_MIMEPART_CRLF')) {
define('MAIL_MIMEPART_CRLF', defined('MAIL_MIME_CRLF') ? MAIL_MIME_CRLF : "\r\n", true);
}
foreach ($params as $key => $value) {
switch ($key) {
case 'content_type':
$headers['Content-Type'] = $value . (isset($charset) ? '; charset="' . $charset . '"' : '');
break;
case 'encoding':
$this->encoding = $value;
$headers['Content-Transfer-Encoding'] = $value;
break;
case 'cid':
$headers['Content-ID'] = '<' . $value . '>';
break;
case 'disposition':
$headers['Content-Disposition'] = $value . (isset($dfilename) ? '; filename="' . $dfilename . '"' : '');
break;
case 'dfilename':
if (isset($headers['Content-Disposition'])) {
$headers['Content-Disposition'] .= '; filename="' . $value . '"';
} else {
$dfilename = $value;
}
break;
case 'description':
$headers['Content-Description'] = $value;
break;
case 'charset':
if (isset($headers['Content-Type'])) {
$headers['Content-Type'] .= '; charset="' . $value . '"';
} else {
$charset = $value;
}
break;
}
}
// Default content-type
if (!isset($headers['Content-Type'])) {
$headers['Content-Type'] = 'text/plain';
}
// Default encoding
if (!isset($this->encoding)) {
$this->encoding = '7bit';
}
// Assign stuff to member variables
$this->encoded = array();
$this->headers = $headers;
$this->body = $body;
}
/**
* Encodes and returns the email. Also stores
* it in the encoded member variable
*
* @return An associative array containing two elements,
* body and headers. The headers element is itself
* an indexed array.
*/
public function encode()
{
$encoded =& $this->encoded;
if (!empty($this->subparts)) {
srand((double)microtime()*1000000);
$boundary = '=_' . md5(uniqid(rand()) . microtime());
$this->headers['Content-Type'] .= ';' . MAIL_MIMEPART_CRLF . "\t" . 'boundary="' . $boundary . '"';
// Add body parts to $subparts
for ($i = 0; $i < count($this->subparts); $i++) {
$headers = array();
$tmp = $this->subparts[$i]->encode();
foreach ($tmp['headers'] as $key => $value) {
$headers[] = $key . ': ' . $value;
}
$subparts[] = implode(MAIL_MIMEPART_CRLF, $headers) . MAIL_MIMEPART_CRLF . MAIL_MIMEPART_CRLF . $tmp['body'];
}
$encoded['body'] = '--' . $boundary . MAIL_MIMEPART_CRLF .
implode('--' . $boundary . MAIL_MIMEPART_CRLF, $subparts) .
'--' . $boundary.'--' . MAIL_MIMEPART_CRLF;
} else {
$encoded['body'] = $this->getEncodedData($this->body, $this->encoding) . MAIL_MIMEPART_CRLF;
}
// Add headers to $encoded
$encoded['headers'] =& $this->headers;
return $encoded;
}
/**
* Adds a subpart to current mime part and returns
* a reference to it
*
* @param $body The body of the subpart, if any.
* @param $params The parameters for the subpart, same
* as the $params argument for constructor.
* @return A reference to the part you just added.
*/
public function addSubPart($body, $params)
{
$this->subparts[] = new Mail_MIMEPart($body, $params);
return $this->subparts[count($this->subparts) - 1];
}
/**
* Returns encoded data based upon encoding passed to it
*
* @param $data The data to encode.
* @param $encoding The encoding type to use, 7bit, base64,
* or quoted-printable.
*/
private function getEncodedData($data, $encoding)
{
switch ($encoding) {
case '8bit':
case '7bit':
return $data;
break;
case 'quoted-printable':
return $this->quotedPrintableEncode($data);
break;
case 'base64':
return rtrim(chunk_split(base64_encode($data), 76, MAIL_MIMEPART_CRLF));
break;
default:
return $data;
}
}
/**
* Encodes data to quoted-printable standard.
*
* @param $input The data to encode
* @param $line_max Optional max line length. Should
* not be more than 76 chars
*/
private function quotedPrintableEncode($input , $line_max = 76)
{
$lines = preg_split("/\r?\n/", $input);
$eol = MAIL_MIMEPART_CRLF;
$escape = '=';
$output = '';
while(list(, $line) = each($lines)){
$linlen = strlen($line);
$newline = '';
for ($i = 0; $i < $linlen; $i++) {
$char = substr($line, $i, 1);
$dec = ord($char);
if (($dec == 32) AND ($i == ($linlen - 1))){ // convert space at eol only
$char = '=20';
} elseif($dec == 9) {
; // Do nothing if a tab.
} elseif(($dec == 61) OR ($dec < 32 ) OR ($dec > 126)) {
$char = $escape . strtoupper(sprintf('%02s', dechex($dec)));
}
if ((strlen($newline) + strlen($char)) >= $line_max) { // MAIL_MIMEPART_CRLF is not counted
$output .= $newline . $escape . $eol; // soft line break; " =\r\n" is okay
$newline = '';
}
$newline .= $char;
} // end of for
$output .= $newline . $eol;
}
$output = substr($output, 0, -1 * strlen($eol)); // Don't want last crlf
return $output;
}
} // End of class
?>

View File

@ -1,103 +1,49 @@
<?
function sendMail($from, $to, $subject, $text='', $html='', /*$priority='high', $tabImgFiles=array(), */$tabAttachedFiles=array())
{
//return true;
$to=preg_split("/[\s,;]+/", $to);
//die(print_r($to));
require_once('Mail.php');
require_once('Mail/mime.php');
$headers=array( 'From'=>$from,
'To'=>$to,
'Subject'=>$subject,
// 'Reply-To'=>$from,
// 'Return-Path'=>$from,
'Content-Transfer-Encoding'=>'8bit',
'MIME-Version'=>'1.0',
'Date'=>date('D, d M Y H:i:s O'),
'Message-ID'=>'<'.md5(date('YmdHis')).'@mail.scores-decisions.com>',
'X-Priority'=>3,
'X-Mailer'=>'PHP v'.phpversion(),
);
/*
# Boundry for marking the split & Multitype Headers
$mime_boundary=md5(time());
$headers .= ''.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg = "";
*/
$mime = new Mail_mime();
$footer="";/*
<?php
_______________________________________________________________________
Ce message et toutes les pièces jointes (ci-après le \"message\") sont établis a l'intention exclusive de ses destinataires.Si vous recevez ce message par erreur, merci de le détruire et d'en avertir immédiatement l'expéditeur par e-mail. Toute utilisation de ce message non conforme a sa destination, toute diffusion ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse. Les communications sur Internet n'étant pas sécurisées, SCORES & DECISIONS S.A.S. informe qu'elle ne peut accepter aucune responsabilite quant au contenu de ce message.
This mail message and attachments (the \"message\") are solely intended for the addressees. It is confidential in nature . If you receive this message in error, please delete it and immediately notify the sender by e-mail. Any use other than its intended purpose, dissemination or disclosure, either whole or partial, is prohibited except if formal approval is granted. As communication on the Internet is not secure, SCORES & DECISIONS S.A.S. does not accept responsability for the content of this message.
/**
*
* @param unknown $from
* @param unknown $to
* @param unknown $subject
* @param string $text
* @param string $html
* @param unknown $tabAttachedFiles
*/
function sendMail($from, $to, $subject, $text='', $html='', $tabAttachedFiles=array())
{
$to = preg_split("/[\s,;]+/", $to);
";*/
if ($text<>'') $mime->setTXTBody($text.$footer);
if ($html<>'') $mime->setHTMLBody($html);
foreach ($tabAttachedFiles as $file)
$mime->addAttachment($file);
//do not ever try to call these lines in reverse order
$body = $mime->get();
$headers = $mime->headers($headers);
$params=array( 'host'=>'smtpauth.online.net', // SMTP_HOST
'port'=>25, //SMTP_PORT,
);
$params=array( 'host'=>SMTP_HOST,
'port'=>SMTP_PORT,
//'debug'=>true,
//'persist'=>true,
);
if (SMTP_USER=='' && SMTP_PASS=='')
$params['auth'] = false;
else {
$params['username'] = SMTP_USER;
$params['password'] = SMTP_PASS;
}/*
$params['auth'] = true;
$params['username'] = 'buzuk@scores-decisions.com';
$params['password'] = 'catsysyo92';
*/
$nbEssais=0;
while (1) {
// Create the mail object using the Mail::factory method
$mail_object = Mail::factory('smtp', $params);
// Trying to send the mail
$send = $mail_object->send($to, $headers, $body);
$nbEssais++;
if (PEAR::isError($send)) {
/** @todo tester les différents codes erreur **/
echo date('Y-m-d H:i:s'). " sendMail.php - essai #$nbEssais : ".$send->getMessage().EOL;
if (preg_match('/too many connections|421/i', $send->getMessage()))
sleep($nbEssais);
else {
$strTo=implode(';', $to);
file_put_contents( LOG_PATH.'/sendMailError.log',
date('Y-m-d H:i:s')."\t#$nbEssais\t$strTo\t".$send->getMessage().EOL,
FILE_APPEND);
break;
}
} else {
/** Si nous sommes en mode CLI, alors on fait en sorte de ne pas atteindre
la limite des 25 mails par minute (ramené à 100 / minute)
**/
if (MODE_EXEC==MODE_CLI) usleep(500000);
break;
}
}
return true;
$mail = new Zend_Mail('ISO-8859-15');
$tr = new Zend_Mail_Transport_Smtp(SMTP_HOST, array('port'=>SMTP_PORT));
$mail->setDefaultTransport($tr);
$mail->setFrom($from);
if ( count($to) > 0 ) {
foreach ( $to as $item ) {
$mail->addTo($item);
}
}
?>
$mail->setSubject($subject);
if ($text!='') {
$mail->setBodyText(mb_convert_encoding($text, 'ISO-8859-15', 'UTF-8'));
}
if ($html!='') {
$mail->setBodyHtml(mb_convert_encoding($html, 'ISO-8859-15', 'UTF-8'));
}
if ( count($tabAttachedFiles) > 0 ) {
foreach ($tabAttachedFiles as $file) {
$at = new Zend_Mime_Part( file_get_contents( $file ) );
$mail->addAttachment($at);
}
}
try {
$mail->send();
} catch (Zend_Mail_Transport_Exception $e) {
file_put_contents(LOG_PATH.'/sendMailError.log',date('Y-m-d H:i:s')." - ".$e->getMessage().PHP_EOL, FILE_APPEND);
}
}
?>

View File

@ -1,33 +0,0 @@
<?
function sendMail($from, $to, $subject, $text='', $html='', $priority='high', $tabImgFiles=array(), $tabAttachedFiles=array())
{
require_once("Mail.php");
$headers["From"] = $from;
$headers["To"] = $to;
$headers["Subject"] = $subject;
$body = $text;
$params["host"] = SMTP_HOST;
$params["port"] = SMTP_PORT;
if (SMTP_USER=='' && SMTP_PASS=='')
$params["auth"] = false;
else {
$params["username"] = SMTP_USER;
$params["password"] = SMTP_PASS;
}
// Create the mail object using the Mail::factory method
$mail_object = Mail::factory("smtp", $params);
$mail_object->send($to, $headers, $body);
if (PEAR::isError($mail_object))
return $mail_object->getMessage();
return true;
}
?>

View File

@ -1,369 +0,0 @@
<?php
/**
) o------------------------------------------------------------------------------o
* | This is HTMLMimeMail5. It is dual licensed as GPL and a commercial license. |
* | If you use the code commercially (or if you don't want to be restricted by |
* | the GPL license), you will need the commercial license. It's only £49 (GBP - |
* | roughly $98 depending on the exchange rate) and helps me out a lot. Thanks. |
* o------------------------------------------------------------------------------o
*
* © Copyright 2005 Richard Heyes
*/
define('SMTP_STATUS_NOT_CONNECTED', 1, true);
define('SMTP_STATUS_CONNECTED', 2, true);
class smtp
{
private $authenticated;
private $connection;
private $recipients;
private $headers;
private $timeout;
private $errors;
private $status;
private $body;
private $from;
private $host;
private $port;
private $helo;
private $auth;
private $user;
private $pass;
/**
* Constructor function. Arguments:
* $params - An assoc array of parameters:
*
* host - The hostname of the smtp server Default: localhost
* port - The port the smtp server runs on Default: 25
* helo - What to send as the HELO command Default: localhost
* (typically the hostname of the
* machine this script runs on)
* auth - Whether to use basic authentication Default: FALSE
* user - Username for authentication Default: <blank>
* pass - Password for authentication Default: <blank>
* timeout - The timeout in seconds for the call Default: 5
* to fsockopen()
*/
public function __construct($params = array())
{
if(!defined('CRLF'))
define('CRLF', "\r\n", TRUE);
$this->authenticated = FALSE;
$this->timeout = 5;
$this->status = SMTP_STATUS_NOT_CONNECTED;
$this->host = 'smtp.free.fr';
$this->port = 25;
$this->helo = 'srvsd01';
$this->auth = FALSE;
$this->user = '';
$this->pass = '';
$this->errors = array();
foreach($params as $key => $value){
$this->$key = $value;
}
}
/**
* Connect function. This will, when called
* statically, create a new smtp object,
* call the connect function (ie this function)
* and return it. When not called statically,
* it will connect to the server and send
* the HELO command.
*/
public function connect($params = array())
{
if (!isset($this->status)) {
$obj = new smtp($params);
if($obj->connect()){
$obj->status = SMTP_STATUS_CONNECTED;
}
return $obj;
} else {
$this->connection = fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
if (function_exists('socket_set_timeout')) {
@socket_set_timeout($this->connection, 5, 0);
}
$greeting = $this->get_data();
if (is_resource($this->connection)) {
return $this->auth ? $this->ehlo() : $this->helo();
} else {
$this->errors[] = 'Failed to connect to server: '.$errstr;
return FALSE;
}
}
}
/**
* Function which handles sending the mail.
* Arguments:
* $params - Optional assoc array of parameters.
* Can contain:
* recipients - Indexed array of recipients
* from - The from address. (used in MAIL FROM:),
* this will be the return path
* headers - Indexed array of headers, one header per array entry
* body - The body of the email
* It can also contain any of the parameters from the connect()
* function
*/
public function send($params = array())
{
foreach ($params as $key => $value) {
$this->set($key, $value);
}
if ($this->is_connected()) {
// Do we auth or not? Note the distinction between the auth variable and auth() function
if ($this->auth AND !$this->authenticated) {
if(!$this->auth())
return false;
}
$this->mail($this->from);
if (is_array($this->recipients)) {
foreach ($this->recipients as $value) {
$this->rcpt($value);
}
} else {
$this->rcpt($this->recipients);
}
if (!$this->data()) {
return false;
}
// Transparency
$headers = str_replace(CRLF.'.', CRLF.'..', trim(implode(CRLF, $this->headers)));
$body = str_replace(CRLF.'.', CRLF.'..', $this->body);
$body = substr($body, 0, 1) == '.' ? '.'.$body : $body;
$this->send_data($headers);
$this->send_data('');
$this->send_data($body);
$this->send_data('.');
$result = (substr(trim($this->get_data()), 0, 3) === '250');
//$this->rset();
return $result;
} else {
$this->errors[] = 'Not connected!';
return FALSE;
}
}
/**
* Function to implement HELO cmd
*/
private function helo()
{
if(is_resource($this->connection)
AND $this->send_data('HELO '.$this->helo)
AND substr(trim($error = $this->get_data()), 0, 3) === '250' ){
return true;
} else {
$this->errors[] = 'HELO command failed, output: ' . trim(substr(trim($error),3));
return false;
}
}
/**
* Function to implement EHLO cmd
*/
private function ehlo()
{
if (is_resource($this->connection)
AND $this->send_data('EHLO '.$this->helo)
AND substr(trim($error = $this->get_data()), 0, 3) === '250' ){
return true;
} else {
$this->errors[] = 'EHLO command failed, output: ' . trim(substr(trim($error),3));
return false;
}
}
/**
* Function to implement RSET cmd
*/
private function rset()
{
if (is_resource($this->connection)
AND $this->send_data('RSET')
AND substr(trim($error = $this->get_data()), 0, 3) === '250' ){
return true;
} else {
$this->errors[] = 'RSET command failed, output: ' . trim(substr(trim($error),3));
return false;
}
}
/**
* Function to implement QUIT cmd
*/
private function quit()
{
if(is_resource($this->connection)
AND $this->send_data('QUIT')
AND substr(trim($error = $this->get_data()), 0, 3) === '221' ){
fclose($this->connection);
$this->status = SMTP_STATUS_NOT_CONNECTED;
return true;
} else {
$this->errors[] = 'QUIT command failed, output: ' . trim(substr(trim($error),3));
return false;
}
}
/**
* Function to implement AUTH cmd
*/
private function auth()
{
if (is_resource($this->connection)
AND $this->send_data('AUTH LOGIN')
AND substr(trim($error = $this->get_data()), 0, 3) === '334'
AND $this->send_data(base64_encode($this->user)) // Send username
AND substr(trim($error = $this->get_data()),0,3) === '334'
AND $this->send_data(base64_encode($this->pass)) // Send password
AND substr(trim($error = $this->get_data()),0,3) === '235' ){
$this->authenticated = true;
return true;
} else {
$this->errors[] = 'AUTH command failed: ' . trim(substr(trim($error),3));
return false;
}
}
/**
* Function that handles the MAIL FROM: cmd
*/
private function mail($from)
{
if ($this->is_connected()
AND $this->send_data('MAIL FROM:<'.$from.'>')
AND substr(trim($this->get_data()), 0, 2) === '250' ) {
return true;
} else {
return false;
}
}
/**
* Function that handles the RCPT TO: cmd
*/
private function rcpt($to)
{
if($this->is_connected()
AND $this->send_data('RCPT TO:<'.$to.'>')
AND substr(trim($error = $this->get_data()), 0, 2) === '25' ){
return true;
} else {
$this->errors[] = trim(substr(trim($error), 3));
return false;
}
}
/**
* Function that sends the DATA cmd
*/
private function data()
{
if($this->is_connected()
AND $this->send_data('DATA')
AND substr(trim($error = $this->get_data()), 0, 3) === '354' ) {
return true;
} else {
$this->errors[] = trim(substr(trim($error), 3));
return false;
}
}
/**
* Function to determine if this object
* is connected to the server or not.
*/
private function is_connected()
{
return (is_resource($this->connection) AND ($this->status === SMTP_STATUS_CONNECTED));
}
/**
* Function to send a bit of data
*/
private function send_data($data)
{
if(is_resource($this->connection)){
return fwrite($this->connection, $data.CRLF, strlen($data)+2);
} else {
return false;
}
}
/**
* Function to get data.
*/
private function get_data()
{
$return = '';
$line = '';
$loops = 0;
if(is_resource($this->connection)){
while((strpos($return, CRLF) === FALSE OR substr($line,3,1) !== ' ') AND $loops < 100){
$line = fgets($this->connection, 512);
$return .= $line;
$loops++;
}
return $return;
}else
return false;
}
/**
* Sets a variable
*/
public function set($var, $value)
{
$this->$var = $value;
return true;
}
/**
* Function to return the errors array
*/
public function getErrors()
{
return $this->errors;
}
} // End of class
?>

File diff suppressed because one or more lines are too long

4
public/libs/jquery-1.11.0.min.js vendored Normal file

File diff suppressed because one or more lines are too long