Commit 43dd0a50 authored by Sebastian Kummer's avatar Sebastian Kummer

Merge branch 'develop' of https://stash.z-hub.io/scm/zp/z-push into...

Merge branch 'develop' of https://stash.z-hub.io/scm/zp/z-push into bugfix/ZP-663-backendcombined-reduce-log-levels

Conflicts:
	src/backend/combined/combined.php
parents 38fd783d 669dbd1e
...@@ -62,6 +62,7 @@ class BackendCombined extends Backend { ...@@ -62,6 +62,7 @@ class BackendCombined extends Backend {
public $backends; public $backends;
private $activeBackend; private $activeBackend;
private $activeBackendID; private $activeBackendID;
private $logon_done = false;
/** /**
* Constructor of the combined backend * Constructor of the combined backend
...@@ -116,6 +117,8 @@ class BackendCombined extends Backend { ...@@ -116,6 +117,8 @@ class BackendCombined extends Backend {
return false; return false;
} }
} }
$this->logon_done = true;
ZLog::Write(LOGLEVEL_DEBUG, "Combined->Logon() success"); ZLog::Write(LOGLEVEL_DEBUG, "Combined->Logon() success");
return true; return true;
} }
...@@ -165,6 +168,10 @@ class BackendCombined extends Backend { ...@@ -165,6 +168,10 @@ class BackendCombined extends Backend {
* @return boolean * @return boolean
*/ */
public function Logoff() { public function Logoff() {
// If no Logon in done, omit Logoff
if (!$this->logon_done)
return true;
ZLog::Write(LOGLEVEL_DEBUG, "Combined->Logoff()"); ZLog::Write(LOGLEVEL_DEBUG, "Combined->Logoff()");
foreach ($this->backends as $i => $b){ foreach ($this->backends as $i => $b){
$this->backends[$i]->Logoff(); $this->backends[$i]->Logoff();
......
<?php <?php
// +-----------------------------------------------------------------------+ /**
// | Copyright (c) 2001-2002, Richard Heyes | * RFC 822 Email address list validation Utility
// | All rights reserved. | *
// | | * PHP version 5
// | Redistribution and use in source and binary forms, with or without | *
// | modification, are permitted provided that the following conditions | * LICENSE:
// | are met: | *
// | | * Copyright (c) 2001-2010, Richard Heyes
// | o Redistributions of source code must retain the above copyright | * All rights reserved.
// | notice, this list of conditions and the following disclaimer. | *
// | o Redistributions in binary form must reproduce the above copyright | * Redistribution and use in source and binary forms, with or without
// | notice, this list of conditions and the following disclaimer in the | * modification, are permitted provided that the following conditions
// | documentation and/or other materials provided with the distribution.| * are met:
// | o The names of the authors may not be used to endorse or promote | *
// | products derived from this software without specific prior written | * o Redistributions of source code must retain the above copyright
// | permission. | * notice, this list of conditions and the following disclaimer.
// | | * o Redistributions in binary form must reproduce the above copyright
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | * notice, this list of conditions and the following disclaimer in the
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | * documentation and/or other materials provided with the distribution.
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | * o The names of the authors may not be used to endorse or promote
// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | * products derived from this software without specific prior written
// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | * permission.
// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | *
// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// | | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// +-----------------------------------------------------------------------+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// | Authors: Richard Heyes <richard@phpguru.org> | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// | Chuck Hagenbuch <chuck@horde.org> | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// +-----------------------------------------------------------------------+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Mail
* @package Mail
* @author Richard Heyes <richard@phpguru.org>
* @author Chuck Hagenbuch <chuck@horde.org
* @copyright 2001-2010 Richard Heyes
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version CVS: $Id: RFC822.php 294749 2010-02-08 08:22:25Z clockwerx $
* @link http://pear.php.net/package/Mail/
*/
/** /**
* RFC 822 Email address list validation Utility * RFC 822 Email address list validation Utility
...@@ -52,10 +63,11 @@ ...@@ -52,10 +63,11 @@
* *
* @author Richard Heyes <richard@phpguru.org> * @author Richard Heyes <richard@phpguru.org>
* @author Chuck Hagenbuch <chuck@horde.org> * @author Chuck Hagenbuch <chuck@horde.org>
* @version $Revision: 1.23 $ * @version $Revision$
* @license BSD * @license BSD
* @package Mail * @package Mail
*/ */
class Mail_RFC822 { class Mail_RFC822 {
/** /**
...@@ -109,7 +121,6 @@ class Mail_RFC822 { ...@@ -109,7 +121,6 @@ class Mail_RFC822 {
/** /**
* The number of groups that have been found in the address list. * The number of groups that have been found in the address list.
* @var integer $num_groups * @var integer $num_groups
* @access public
*/ */
var $num_groups = 0; var $num_groups = 0;
...@@ -130,7 +141,6 @@ class Mail_RFC822 { ...@@ -130,7 +141,6 @@ class Mail_RFC822 {
* Sets up the object. The address must either be set here or when * Sets up the object. The address must either be set here or when
* calling parseAddressList(). One or the other. * calling parseAddressList(). One or the other.
* *
* @access public
* @param string $address The address(es) to validate. * @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 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 $nest_groups Whether to return the structure with groups nested for easier viewing.
...@@ -138,7 +148,7 @@ class Mail_RFC822 { ...@@ -138,7 +148,7 @@ class Mail_RFC822 {
* *
* @return object Mail_RFC822 A new Mail_RFC822 object. * @return object Mail_RFC822 A new Mail_RFC822 object.
*/ */
function Mail_RFC822($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null) public function __construct($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null)
{ {
if (isset($address)) $this->address = $address; if (isset($address)) $this->address = $address;
if (isset($default_domain)) $this->default_domain = $default_domain; if (isset($default_domain)) $this->default_domain = $default_domain;
...@@ -151,7 +161,6 @@ class Mail_RFC822 { ...@@ -151,7 +161,6 @@ class Mail_RFC822 {
* Starts the whole process. The address must either be set here * Starts the whole process. The address must either be set here
* or when creating the object. One or the other. * or when creating the object. One or the other.
* *
* @access public
* @param string $address The address(es) to validate. * @param string $address The address(es) to validate.
* @param string $default_domain Default domain/host etc. * @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 $nest_groups Whether to return the structure with groups nested for easier viewing.
...@@ -159,7 +168,7 @@ class Mail_RFC822 { ...@@ -159,7 +168,7 @@ class Mail_RFC822 {
* *
* @return array A structured array of addresses. * @return array A structured array of addresses.
*/ */
function parseAddressList($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null) public function parseAddressList($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null)
{ {
if (!isset($this) || !isset($this->mailRFC822)) { if (!isset($this) || !isset($this->mailRFC822)) {
$obj = new Mail_RFC822($address, $default_domain, $nest_groups, $validate, $limit); $obj = new Mail_RFC822($address, $default_domain, $nest_groups, $validate, $limit);
...@@ -167,6 +176,7 @@ class Mail_RFC822 { ...@@ -167,6 +176,7 @@ class Mail_RFC822 {
} }
if (isset($address)) $this->address = $address; if (isset($address)) $this->address = $address;
// z-push addition
if (strlen(trim($this->address)) == 0) return array(); if (strlen(trim($this->address)) == 0) return array();
if (isset($default_domain)) $this->default_domain = $default_domain; if (isset($default_domain)) $this->default_domain = $default_domain;
if (isset($nest_groups)) $this->nestGroups = $nest_groups; if (isset($nest_groups)) $this->nestGroups = $nest_groups;
...@@ -183,6 +193,7 @@ class Mail_RFC822 { ...@@ -183,6 +193,7 @@ class Mail_RFC822 {
$this->address = preg_replace('/\r\n(\t| )+/', ' ', $this->address); $this->address = preg_replace('/\r\n(\t| )+/', ' ', $this->address);
while ($this->address = $this->_splitAddresses($this->address)); while ($this->address = $this->_splitAddresses($this->address));
if ($this->address === false || isset($this->error)) { if ($this->address === false || isset($this->error)) {
//require_once 'PEAR.php'; //require_once 'PEAR.php';
return $this->raiseError($this->error); return $this->raiseError($this->error);
...@@ -211,11 +222,10 @@ class Mail_RFC822 { ...@@ -211,11 +222,10 @@ class Mail_RFC822 {
/** /**
* Splits an address into separate addresses. * Splits an address into separate addresses.
* *
* @access private
* @param string $address The addresses to split. * @param string $address The addresses to split.
* @return boolean Success or failure. * @return boolean Success or failure.
*/ */
function _splitAddresses($address) protected function _splitAddresses($address)
{ {
if (!empty($this->limit) && count($this->addresses) == $this->limit) { if (!empty($this->limit) && count($this->addresses) == $this->limit) {
return ''; return '';
...@@ -287,11 +297,10 @@ class Mail_RFC822 { ...@@ -287,11 +297,10 @@ class Mail_RFC822 {
/** /**
* Checks for a group at the start of the string. * Checks for a group at the start of the string.
* *
* @access private
* @param string $address The address to check. * @param string $address The address to check.
* @return boolean Whether or not there is a group at the start of the string. * @return boolean Whether or not there is a group at the start of the string.
*/ */
function _isGroup($address) protected function _isGroup($address)
{ {
// First comma not in quotes, angles or escaped: // First comma not in quotes, angles or escaped:
$parts = explode(',', $address); $parts = explode(',', $address);
...@@ -311,12 +320,11 @@ class Mail_RFC822 { ...@@ -311,12 +320,11 @@ class Mail_RFC822 {
/** /**
* A common function that will check an exploded string. * A common function that will check an exploded string.
* *
* @access private
* @param array $parts The exloded string. * @param array $parts The exloded string.
* @param string $char The char that was exploded on. * @param string $char The char that was exploded on.
* @return mixed False if the string contains unclosed quotes/brackets, or the string on success. * @return mixed False if the string contains unclosed quotes/brackets, or the string on success.
*/ */
function _splitCheck($parts, $char) protected function _splitCheck($parts, $char)
{ {
$string = $parts[0]; $string = $parts[0];
...@@ -342,34 +350,49 @@ class Mail_RFC822 { ...@@ -342,34 +350,49 @@ class Mail_RFC822 {
} }
/** /**
* Checks if a string has an unclosed quotes or not. * Checks if a string has unclosed quotes or not.
* *
* @access private * @param string $string The string to check.
* @param string $string The string to check. * @return boolean True if there are unclosed quotes inside the string,
* @return boolean True if there are unclosed quotes inside the string, false otherwise. * false otherwise.
*/ */
function _hasUnclosedQuotes($string) protected function _hasUnclosedQuotes($string)
{ {
$string = explode('"', $string); $string = trim($string);
$string_cnt = count($string); $iMax = strlen($string);
$in_quote = false;
$i = $slashes = 0;
for (; $i < $iMax; ++$i) {
switch ($string[$i]) {
case '\\':
++$slashes;
break;
for ($i = 0; $i < (count($string) - 1); $i++) case '"':
if (substr($string[$i], -1) == '\\') if ($slashes % 2 == 0) {
$string_cnt--; $in_quote = !$in_quote;
}
// Fall through to default action below.
default:
$slashes = 0;
break;
}
}
return ($string_cnt % 2 === 0); return $in_quote;
} }
/** /**
* Checks if a string has an unclosed brackets or not. IMPORTANT: * Checks if a string has an unclosed brackets or not. IMPORTANT:
* This function handles both angle brackets and square brackets; * This function handles both angle brackets and square brackets;
* *
* @access private
* @param string $string The string to check. * @param string $string The string to check.
* @param string $chars The characters to check for. * @param string $chars The characters to check for.
* @return boolean True if there are unclosed brackets inside the string, false otherwise. * @return boolean True if there are unclosed brackets inside the string, false otherwise.
*/ */
function _hasUnclosedBrackets($string, $chars) protected function _hasUnclosedBrackets($string, $chars)
{ {
$num_angle_start = substr_count($string, $chars[0]); $num_angle_start = substr_count($string, $chars[0]);
$num_angle_end = substr_count($string, $chars[1]); $num_angle_end = substr_count($string, $chars[1]);
...@@ -388,13 +411,12 @@ class Mail_RFC822 { ...@@ -388,13 +411,12 @@ class Mail_RFC822 {
/** /**
* Sub function that is used only by hasUnclosedBrackets(). * Sub function that is used only by hasUnclosedBrackets().
* *
* @access private
* @param string $string The string to check. * @param string $string The string to check.
* @param integer &$num The number of occurences. * @param integer &$num The number of occurences.
* @param string $char The character to count. * @param string $char The character to count.
* @return integer The number of occurences of $char in $string, adjusted for backslashes. * @return integer The number of occurences of $char in $string, adjusted for backslashes.
*/ */
function _hasUnclosedBracketsSub($string, &$num, $char) protected function _hasUnclosedBracketsSub($string, &$num, $char)
{ {
$parts = explode($char, $string); $parts = explode($char, $string);
for ($i = 0; $i < count($parts); $i++){ for ($i = 0; $i < count($parts); $i++){
...@@ -410,11 +432,10 @@ class Mail_RFC822 { ...@@ -410,11 +432,10 @@ class Mail_RFC822 {
/** /**
* Function to begin checking the address. * Function to begin checking the address.
* *
* @access private
* @param string $address The address to validate. * @param string $address The address to validate.
* @return mixed False on failure, or a structured array of address information on success. * @return mixed False on failure, or a structured array of address information on success.
*/ */
function _validateAddress($address) protected function _validateAddress($address)
{ {
$is_group = false; $is_group = false;
$addresses = array(); $addresses = array();
...@@ -455,14 +476,6 @@ class Mail_RFC822 { ...@@ -455,14 +476,6 @@ class Mail_RFC822 {
$addresses[] = $address['address']; $addresses[] = $address['address'];
} }
// Check that $addresses is set, if address like this:
// Groupname:;
// Then errors were appearing.
if (!count($addresses)){
$this->error = 'Empty group.';
return false;
}
// Trim the whitespace from all of the address strings. // Trim the whitespace from all of the address strings.
array_map('trim', $addresses); array_map('trim', $addresses);
...@@ -503,14 +516,14 @@ class Mail_RFC822 { ...@@ -503,14 +516,14 @@ class Mail_RFC822 {
/** /**
* Function to validate a phrase. * Function to validate a phrase.
* *
* @access private
* @param string $phrase The phrase to check. * @param string $phrase The phrase to check.
* @return boolean Success or failure. * @return boolean Success or failure.
*/ */
function _validatePhrase($phrase) protected function _validatePhrase($phrase)
{ {
// Splits on one or more Tab or space. // Splits on one or more Tab or space.
$parts = preg_split('/[ \\x09]+/', $phrase, -1, PREG_SPLIT_NO_EMPTY); $parts = preg_split('/[ \\x09]+/', $phrase, -1, PREG_SPLIT_NO_EMPTY);
$phrase_parts = array(); $phrase_parts = array();
while (count($parts) > 0){ while (count($parts) > 0){
$phrase_parts[] = $this->_splitCheck($parts, ' '); $phrase_parts[] = $this->_splitCheck($parts, ' ');
...@@ -543,16 +556,16 @@ class Mail_RFC822 { ...@@ -543,16 +556,16 @@ class Mail_RFC822 {
* can split a list of addresses up before encoding personal names * can split a list of addresses up before encoding personal names
* (umlauts, etc.), for example. * (umlauts, etc.), for example.
* *
* @access private
* @param string $atom The string to check. * @param string $atom The string to check.
* @return boolean Success or failure. * @return boolean Success or failure.
*/ */
function _validateAtom($atom) protected function _validateAtom($atom)
{ {
if (!$this->validate) { if (!$this->validate) {
// Validation has been turned off; assume the atom is okay. // Validation has been turned off; assume the atom is okay.
return true; return true;
} }
// Check for any char from ASCII 0 - ASCII 127 // Check for any char from ASCII 0 - ASCII 127
if (!preg_match('/^[\\x00-\\x7E]+$/i', $atom, $matches)) { if (!preg_match('/^[\\x00-\\x7E]+$/i', $atom, $matches)) {
return false; return false;
...@@ -567,6 +580,7 @@ class Mail_RFC822 { ...@@ -567,6 +580,7 @@ class Mail_RFC822 {
if (preg_match('/[\\x00-\\x1F]+/', $atom)) { if (preg_match('/[\\x00-\\x1F]+/', $atom)) {
return false; return false;
} }
return true; return true;
} }
...@@ -574,11 +588,10 @@ class Mail_RFC822 { ...@@ -574,11 +588,10 @@ class Mail_RFC822 {
* Function to validate quoted string, which is: * Function to validate quoted string, which is:
* quoted-string = <"> *(qtext/quoted-pair) <"> * quoted-string = <"> *(qtext/quoted-pair) <">
* *
* @access private
* @param string $qstring The string to check * @param string $qstring The string to check
* @return boolean Success or failure. * @return boolean Success or failure.
*/ */
function _validateQuotedString($qstring) protected function _validateQuotedString($qstring)
{ {
// Leading and trailing " // Leading and trailing "
$qstring = substr($qstring, 1, -1); $qstring = substr($qstring, 1, -1);
...@@ -592,11 +605,10 @@ class Mail_RFC822 { ...@@ -592,11 +605,10 @@ class Mail_RFC822 {
* mailbox = addr-spec ; simple address * mailbox = addr-spec ; simple address
* / phrase route-addr ; name and route-addr * / phrase route-addr ; name and route-addr
* *
* @access public
* @param string &$mailbox The string to check. * @param string &$mailbox The string to check.
* @return boolean Success or failure. * @return boolean Success or failure.
*/ */
function validateMailbox(&$mailbox) public function validateMailbox(&$mailbox)
{ {
// A couple of defaults. // A couple of defaults.
$phrase = ''; $phrase = '';
...@@ -615,8 +627,8 @@ class Mail_RFC822 { ...@@ -615,8 +627,8 @@ class Mail_RFC822 {
$comment = $this->_splitCheck($parts, ')'); $comment = $this->_splitCheck($parts, ')');
$comments[] = $comment; $comments[] = $comment;
// +1 is for the trailing ) // +2 is for the brackets
$_mailbox = substr($_mailbox, strpos($_mailbox, $comment)+strlen($comment)+1); $_mailbox = substr($_mailbox, strpos($_mailbox, '('.$comment)+strlen($comment)+2);
} else { } else {
break; break;
} }
...@@ -642,7 +654,6 @@ class Mail_RFC822 { ...@@ -642,7 +654,6 @@ class Mail_RFC822 {
} }
if ($this->_validatePhrase($phrase) === false || ($route_addr = $this->_validateRouteAddr($route_addr)) === false) { if ($this->_validatePhrase($phrase) === false || ($route_addr = $this->_validateRouteAddr($route_addr)) === false) {
return false; return false;
} }
...@@ -687,11 +698,10 @@ class Mail_RFC822 { ...@@ -687,11 +698,10 @@ class Mail_RFC822 {
* Angle brackets have already been removed at the point of * Angle brackets have already been removed at the point of
* getting to this function. * getting to this function.
* *
* @access private
* @param string $route_addr The string to check. * @param string $route_addr The string to check.
* @return mixed False on failure, or an array containing validated address/route information on success. * @return mixed False on failure, or an array containing validated address/route information on success.
*/ */
function _validateRouteAddr($route_addr) protected function _validateRouteAddr($route_addr)
{ {
// Check for colon. // Check for colon.
if (strpos($route_addr, ':') !== false) { if (strpos($route_addr, ':') !== false) {
...@@ -737,11 +747,10 @@ class Mail_RFC822 { ...@@ -737,11 +747,10 @@ class Mail_RFC822 {
* Function to validate a route, which is: * Function to validate a route, which is:
* route = 1#("@" domain) ":" * route = 1#("@" domain) ":"
* *
* @access private
* @param string $route The string to check. * @param string $route The string to check.
* @return mixed False on failure, or the validated $route on success. * @return mixed False on failure, or the validated $route on success.
*/ */
function _validateRoute($route) protected function _validateRoute($route)
{ {
// Split on comma. // Split on comma.
$domains = explode(',', trim($route)); $domains = explode(',', trim($route));
...@@ -760,11 +769,10 @@ class Mail_RFC822 { ...@@ -760,11 +769,10 @@ class Mail_RFC822 {
* *
* domain = sub-domain *("." sub-domain) * domain = sub-domain *("." sub-domain)
* *
* @access private
* @param string $domain The string to check. * @param string $domain The string to check.
* @return mixed False on failure, or the validated domain on success. * @return mixed False on failure, or the validated domain on success.
*/ */
function _validateDomain($domain) protected function _validateDomain($domain)
{ {
// Note the different use of $subdomains and $sub_domains // Note the different use of $subdomains and $sub_domains
$subdomains = explode('.', $domain); $subdomains = explode('.', $domain);
...@@ -788,11 +796,10 @@ class Mail_RFC822 { ...@@ -788,11 +796,10 @@ class Mail_RFC822 {
* Function to validate a subdomain: * Function to validate a subdomain:
* subdomain = domain-ref / domain-literal * subdomain = domain-ref / domain-literal
* *
* @access private
* @param string $subdomain The string to check. * @param string $subdomain The string to check.
* @return boolean Success or failure. * @return boolean Success or failure.
*/ */
function _validateSubdomain($subdomain) protected function _validateSubdomain($subdomain)
{ {
if (preg_match('|^\[(.*)]$|', $subdomain, $arr)){ if (preg_match('|^\[(.*)]$|', $subdomain, $arr)){
if (!$this->_validateDliteral($arr[1])) return false; if (!$this->_validateDliteral($arr[1])) return false;
...@@ -808,11 +815,10 @@ class Mail_RFC822 { ...@@ -808,11 +815,10 @@ class Mail_RFC822 {
* Function to validate a domain literal: * Function to validate a domain literal:
* domain-literal = "[" *(dtext / quoted-pair) "]" * domain-literal = "[" *(dtext / quoted-pair) "]"
* *
* @access private
* @param string $dliteral The string to check. * @param string $dliteral The string to check.
* @return boolean Success or failure. * @return boolean Success or failure.
*/ */
function _validateDliteral($dliteral) protected function _validateDliteral($dliteral)
{ {
return !preg_match('/(.)[][\x0D\\\\]/', $dliteral, $matches) && $matches[1] != '\\'; return !preg_match('/(.)[][\x0D\\\\]/', $dliteral, $matches) && $matches[1] != '\\';
} }
...@@ -822,11 +828,10 @@ class Mail_RFC822 { ...@@ -822,11 +828,10 @@ class Mail_RFC822 {
* *
* addr-spec = local-part "@" domain * addr-spec = local-part "@" domain
* *
* @access private
* @param string $addr_spec The string to check. * @param string $addr_spec The string to check.
* @return mixed False on failure, or the validated addr-spec on success. * @return mixed False on failure, or the validated addr-spec on success.
*/ */
function _validateAddrSpec($addr_spec) protected function _validateAddrSpec($addr_spec)
{ {
$addr_spec = trim($addr_spec); $addr_spec = trim($addr_spec);
...@@ -853,17 +858,16 @@ class Mail_RFC822 { ...@@ -853,17 +858,16 @@ class Mail_RFC822 {
* Function to validate the local part of an address: * Function to validate the local part of an address:
* local-part = word *("." word) * local-part = word *("." word)
* *
* @access private
* @param string $local_part * @param string $local_part
* @return mixed False on failure, or the validated local part on success. * @return mixed False on failure, or the validated local part on success.
*/ */
function _validateLocalPart($local_part) protected function _validateLocalPart($local_part)
{ {
$parts = explode('.', $local_part); $parts = explode('.', $local_part);
$words = array(); $words = array();
// Split the local_part into words. // Split the local_part into words.
while (count($parts) > 0){ while (count($parts) > 0) {
$words[] = $this->_splitCheck($parts, '.'); $words[] = $this->_splitCheck($parts, '.');
for ($i = 0; $i < $this->index + 1; $i++) { for ($i = 0; $i < $this->index + 1; $i++) {
array_shift($parts); array_shift($parts);
...@@ -872,6 +876,10 @@ class Mail_RFC822 { ...@@ -872,6 +876,10 @@ class Mail_RFC822 {
// Validate each word. // Validate each word.
foreach ($words as $word) { foreach ($words as $word) {
// word cannot be empty (#17317)
if ($word === '') {
return false;
}
// If this word contains an unquoted space, it is invalid. (6.2.4) // If this word contains an unquoted space, it is invalid. (6.2.4)
if (strpos($word, ' ') && $word[0] !== '"') if (strpos($word, ' ') && $word[0] !== '"')
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment