*/
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'))) . '>';
}
/**
{
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;
}
protected function _generateBoundary()
{
if (is_null($this->_boundary)) {
- $this->_boundary = '=_' . Horde_Mime::generateRandomId();
+ $this->_boundary = '=_' . strval(new Horde_Support_Randomid());
}
return $this->_boundary;
}
* <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
*/