Files
@ f43d1a4680a9
Branch filter:
Location: hot67beta/libraries/joomla/mail/helper.php
f43d1a4680a9
4.2 KiB
text/x-php
menubar 0 to 10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | <?php
/**
* @version $Id: helper.php 11380 2009-01-01 15:48:59Z ian $
* @package Joomla.Framework
* @subpackage Mail
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// Check to ensure this file is within the rest of the framework
defined('JPATH_BASE') or die();
/**
* E-Mail helper class, provides static methods to perform various tasks relevant
* to the Joomla e-mail routines.
*
* TODO: Test these methods as the regex work is first run and not tested thoroughly
*
* @static
* @package Joomla.Framework
* @subpackage Mail
* @since 1.5
*/
class JMailHelper
{
/**
* Cleans single line inputs.
*
* @static
* @param string $value String to be cleaned.
* @return string Cleaned string.
*/
function cleanLine( $value ) {
return trim( preg_replace( '/(%0A|%0D|\n+|\r+)/i', '', $value ) );
}
/**
* Cleans multi-line inputs.
*
* @static
* @param string $value Multi-line string to be cleaned.
* @return string Cleaned multi-line string.
*/
function cleanText( $value ) {
return trim( preg_replace( '/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i', '', $value ) );
}
/**
* Cleans any injected headers from the E-Mail body.
*
* @static
* @param string $body E-Mail body string.
* @return string Cleaned E-Mail body string.
* @since 1.5
*/
function cleanBody($body) {
// Strip all E-Mail headers from a string
return preg_replace("/((From:|To:|Cc:|Bcc:|Subject:|Content-type:) ([\S]+))/", "", $body);
}
/**
* Cleans any injected headers from the subject string.
*
* @static
* @param string $subject E-Mail subject string.
* @return string Cleaned E-Mail subject string.
* @since 1.5
*/
function cleanSubject($subject) {
return preg_replace("/((From:|To:|Cc:|Bcc:|Content-type:) ([\S]+))/", "", $subject);
}
/**
* Verifies that an e-mail address does not have any extra headers injected into it.
*
* @static
* @param string $address E-Mail address.
* @return string|false E-Mail address string or boolean false if injected headers are present.
* @since 1.5
*/
function cleanAddress($address)
{
if (preg_match("[\s;,]", $address)) {
return false;
}
return $address;
}
/**
* Verifies that the string is in a proper e-mail address format.
*
* @static
* @param string $email String to be verified.
* @return boolean True if string has the correct format; false otherwise.
* @since 1.5
*/
function isEmailAddress($email)
{
// Split the email into a local and domain
$atIndex = strrpos($email, "@");
$domain = substr($email, $atIndex+1);
$local = substr($email, 0, $atIndex);
// Check Length of domain
$domainLen = strlen($domain);
if ($domainLen < 1 || $domainLen > 255) {
return false;
}
// Check the local address
// We're a bit more conservative about what constitutes a "legal" address, that is, A-Za-z0-9!#$%&\'*+/=?^_`{|}~-
$allowed = 'A-Za-z0-9!#&*+=?_-';
$regex = "/^[$allowed][\.$allowed]{0,63}$/";
if ( ! preg_match($regex, $local) ) {
return false;
}
// No problem if the domain looks like an IP address, ish
$regex = '/^[0-9\.]+$/';
if ( preg_match($regex, $domain)) {
return true;
}
// Check Lengths
$localLen = strlen($local);
if ($localLen < 1 || $localLen > 64) {
return false;
}
// Check the domain
$domain_array = explode(".", rtrim( $domain, '.' ));
$regex = '/^[A-Za-z0-9-]{0,63}$/';
foreach ($domain_array as $domain ) {
// Must be something
if ( ! $domain ) {
return false;
}
// Check for invalid characters
if ( ! preg_match($regex, $domain) ) {
return false;
}
// Check for a dash at the beginning of the domain
if ( strpos($domain, '-' ) === 0 ) {
return false;
}
// Check for a dash at the end of the domain
$length = strlen($domain) -1;
if ( strpos($domain, '-', $length ) === $length ) {
return false;
}
}
return true;
}
}
|