Use Horde_Support_Guid/Horde_Support_Randomid
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 3 Aug 2010 04:15:29 +0000 (22:15 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 3 Aug 2010 04:21:40 +0000 (22:21 -0600)
framework/Mime/lib/Horde/Mime.php
framework/Mime/lib/Horde/Mime/Part.php
framework/Mime/package.xml
framework/Support/lib/Horde/Support/Guid.php

index f048af3..6117967 100644 (file)
@@ -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'))) . '>';
     }
 
     /**
index e7e96b2..5b38b80 100644 (file)
@@ -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;
     }
index a500d28..cdef087 100644 (file)
@@ -114,6 +114,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
     <channel>pear.horde.org</channel>
    </package>
    <package>
+    <name>Support</name>
+    <channel>pear.horde.org</channel>
+   </package>
+   <package>
     <name>Util</name>
     <channel>pear.horde.org</channel>
    </package>
index 3e2a4d3..da6ef6b 100644 (file)
@@ -12,7 +12,7 @@
  * <code>
  *  <?php
  *
- *  $uid = (string)new Horde_Support_Guid;
+ *  $uid = (string)new Horde_Support_Guid([$opts = array()]);
  *
  *  ?>
  * </code>
 class Horde_Support_Guid
 {
     /**
-     * Generated GUID
+     * Generated GUID.
+     *
      * @var string
      */
     private $_guid;
 
     /**
-     * New GUID
+     * New GUID.
+     *
+     * @param array $opts  Additional options:
+     * <pre>
+     * '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')
+     * </pre>
      */
-    public function __construct()
+    public function __construct(array $opts = array())
     {
-        $this->generate();
+        $this->generate($opts);
     }
 
     /**
      * Generates a GUID.
      *
-     * @return string
+     * @param array $opts  Additional options:
+     * <pre>
+     * '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')
+     * </pre>
      */
-    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
      */