IdGenerator.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /*
  3. * This file is part of SwiftMailer.
  4. * (c) 2004-2009 Chris Corbyn
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * Message ID generator.
  11. */
  12. class Swift_Mime_IdGenerator implements Swift_IdGenerator
  13. {
  14. private $idRight;
  15. /**
  16. * @param string $idRight
  17. */
  18. public function __construct($idRight)
  19. {
  20. $this->idRight = $idRight;
  21. }
  22. /**
  23. * Returns the right-hand side of the "@" used in all generated IDs.
  24. *
  25. * @return string
  26. */
  27. public function getIdRight()
  28. {
  29. return $this->idRight;
  30. }
  31. /**
  32. * Sets the right-hand side of the "@" to use in all generated IDs.
  33. *
  34. * @param string $idRight
  35. */
  36. public function setIdRight($idRight)
  37. {
  38. $this->idRight = $idRight;
  39. }
  40. /**
  41. * @return string
  42. */
  43. public function generateId()
  44. {
  45. // 32 hex values for the left part
  46. return bin2hex(random_bytes(16)).'@'.$this->idRight;
  47. }
  48. }