From aa05e7f71376d16419aa5e26bccb7206da673118 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 2 Aug 2010 22:15:29 -0600 Subject: [PATCH] Use Horde_Support_Guid/Horde_Support_Randomid --- framework/Mime/lib/Horde/Mime.php | 13 +-------- framework/Mime/lib/Horde/Mime/Part.php | 4 +-- framework/Mime/package.xml | 4 +++ framework/Support/lib/Horde/Support/Guid.php | 42 +++++++++++++++++++++------- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/framework/Mime/lib/Horde/Mime.php b/framework/Mime/lib/Horde/Mime.php index f048af390..6117967d0 100644 --- a/framework/Mime/lib/Horde/Mime.php +++ b/framework/Mime/lib/Horde/Mime.php @@ -579,18 +579,7 @@ class Horde_Mime */ static public function generateMessageId() { - return '<' . date('YmdHis') . '.Horde.' . self::generateRandomId() . '@' . $_SERVER['SERVER_NAME'] . '>'; - } - - /** - * Generates a Random-ID string suitable for use with MIME features that - * require a random string. - * - * @return string A random string. - */ - static public function generateRandomId($length = 16) - { - return substr(base_convert(dechex(strtr(microtime(), array('0.' => '', ' ' => ''))) . strtr(uniqid(mt_rand(), true), array('.' => '')), 16, 36), 0, $length); + return '<' . strval(new Horde_Support_Guid(array('prefix' => 'Horde'))) . '>'; } /** diff --git a/framework/Mime/lib/Horde/Mime/Part.php b/framework/Mime/lib/Horde/Mime/Part.php index e7e96b22c..5b38b803d 100644 --- a/framework/Mime/lib/Horde/Mime/Part.php +++ b/framework/Mime/lib/Horde/Mime/Part.php @@ -1307,7 +1307,7 @@ class Horde_Mime_Part { if (is_null($this->_contentid)) { $this->_contentid = is_null($cid) - ? (Horde_Mime::generateRandomId() . '@' . $_SERVER['SERVER_NAME']) + ? (strval(new Horde_Support_Randomid()) . '@' . $_SERVER['SERVER_NAME']) : $cid; } @@ -1402,7 +1402,7 @@ class Horde_Mime_Part protected function _generateBoundary() { if (is_null($this->_boundary)) { - $this->_boundary = '=_' . Horde_Mime::generateRandomId(); + $this->_boundary = '=_' . strval(new Horde_Support_Randomid()); } return $this->_boundary; } diff --git a/framework/Mime/package.xml b/framework/Mime/package.xml index a500d28fd..cdef0877a 100644 --- a/framework/Mime/package.xml +++ b/framework/Mime/package.xml @@ -114,6 +114,10 @@ http://pear.php.net/dtd/package-2.0.xsd"> pear.horde.org + Support + pear.horde.org + + Util pear.horde.org diff --git a/framework/Support/lib/Horde/Support/Guid.php b/framework/Support/lib/Horde/Support/Guid.php index 3e2a4d3b7..da6ef6b51 100644 --- a/framework/Support/lib/Horde/Support/Guid.php +++ b/framework/Support/lib/Horde/Support/Guid.php @@ -12,7 +12,7 @@ * * * @@ -25,35 +25,57 @@ class Horde_Support_Guid { /** - * Generated GUID + * Generated GUID. + * * @var string */ private $_guid; /** - * New GUID + * New GUID. + * + * @param array $opts Additional options: + *
+     * 'prefix' - (string) A prefix to add between the date string and the
+     *            random string.
+     *            DEFAULT: NONE
+     * 'rlength' - (integer) The length of the random string.
+     *             DEFAULT: 16
+     * 'server' - (string) The server name.
+     *            DEFAULT: $_SERVER['SERVER_NAME'] (or 'localhost')
+     * 
*/ - public function __construct() + public function __construct(array $opts = array()) { - $this->generate(); + $this->generate($opts); } /** * Generates a GUID. * - * @return string + * @param array $opts Additional options: + *
+     * 'prefix' - (string) A prefix to add between the date string and the
+     *            random string.
+     *            DEFAULT: NONE
+     * 'rlength' - (integer) The length of the random string.
+     *             DEFAULT: 16
+     * 'server' - (string) The server name.
+     *            DEFAULT: $_SERVER['SERVER_NAME'] (or 'localhost')
+     * 
*/ - public function generate() + public function generate(array $opts = array()) { $this->_guid = date('YmdHis') . '.' - . substr(str_pad(base_convert(microtime(), 10, 36), 16, uniqid(mt_rand()), STR_PAD_LEFT), -16) + . (isset($opts['prefix']) ? $opts['prefix'] . '.' : '') + . strval(new Horde_Support_Randomid(isset($opts['rlength']) ? $opts['rlength'] : 16)) . '@' - . (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost'); + . (isset($opts['server']) ? $opts['server'] : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost')); } /** - * Cooerce to string + * Cooerce to string. * * @return string */ -- 2.11.0