Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MailboxHeader.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Mime\Header;
  11. use Symfony\Component\Mime\Address;
  12. use Symfony\Component\Mime\Exception\RfcComplianceException;
  13. use Symfony\Component\Mime\NamedAddress;
  14. /**
  15. * A Mailbox MIME Header for something like Sender (one named address).
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. *
  19. * @experimental in 4.3
  20. */
  21. final class MailboxHeader extends AbstractHeader
  22. {
  23. private $address;
  24. public function __construct(string $name, Address $address)
  25. {
  26. parent::__construct($name);
  27. $this->setAddress($address);
  28. }
  29. /**
  30. * @param Address $body
  31. *
  32. * @throws RfcComplianceException
  33. */
  34. public function setBody($body)
  35. {
  36. $this->setAddress($body);
  37. }
  38. /**
  39. * @throws RfcComplianceException
  40. *
  41. * @return Address
  42. */
  43. public function getBody()
  44. {
  45. return $this->getAddress();
  46. }
  47. /**
  48. * @throws RfcComplianceException
  49. */
  50. public function setAddress(Address $address)
  51. {
  52. $this->address = $address;
  53. }
  54. /**
  55. * @return Address
  56. */
  57. public function getAddress(): Address
  58. {
  59. return $this->address;
  60. }
  61. public function getBodyAsString(): string
  62. {
  63. $str = $this->address->getEncodedAddress();
  64. if ($this->address instanceof NamedAddress && $name = $this->address->getName()) {
  65. $str = $this->createPhrase($this, $name, $this->getCharset(), true).' <'.$str.'>';
  66. }
  67. return $str;
  68. }
  69. /**
  70. * Redefine the encoding requirements for an address.
  71. *
  72. * All "specials" must be encoded as the full header value will not be quoted
  73. *
  74. * @see RFC 2822 3.2.1
  75. */
  76. protected function tokenNeedsEncoding(string $token): bool
  77. {
  78. return preg_match('/[()<>\[\]:;@\,."]/', $token) || parent::tokenNeedsEncoding($token);
  79. }
  80. }