PluginProbe
WPIDE – File Manager & Code Editor / 3.5.9
WPIDE – File Manager & Code Editor v3.5.9
3.5.9 3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 3.3 All 55 releases
wpide / vendor / symfony / mime / Header / MailboxListHeader.php

MailboxListHeader.php in WPIDE – File Manager & Code Editor 3.5.9, at vendor/symfony/mime/Header/MailboxListHeader.php

137 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Mime\Header;
13
14 use Symfony\Component\Mime\Address;
15 use Symfony\Component\Mime\Exception\RfcComplianceException;
16
17 /**
18 * A Mailbox list MIME Header for something like From, To, Cc, and Bcc (one or more named addresses).
19 *
20 * @author Chris Corbyn
21 */
22 final class MailboxListHeader extends AbstractHeader
23 {
24 private $addresses = [];
25
26 /**
27 * @param Address[] $addresses
28 */
29 public function __construct(string $name, array $addresses)
30 {
31 parent::__construct($name);
32
33 $this->setAddresses($addresses);
34 }
35
36 /**
37 * @param Address[] $body
38 *
39 * @throws RfcComplianceException
40 */
41 public function setBody($body)
42 {
43 $this->setAddresses($body);
44 }
45
46 /**
47 * @return Address[]
48 *
49 * @throws RfcComplianceException
50 */
51 public function getBody(): array
52 {
53 return $this->getAddresses();
54 }
55
56 /**
57 * Sets a list of addresses to be shown in this Header.
58 *
59 * @param Address[] $addresses
60 *
61 * @throws RfcComplianceException
62 */
63 public function setAddresses(array $addresses)
64 {
65 $this->addresses = [];
66 $this->addAddresses($addresses);
67 }
68
69 /**
70 * Sets a list of addresses to be shown in this Header.
71 *
72 * @param Address[] $addresses
73 *
74 * @throws RfcComplianceException
75 */
76 public function addAddresses(array $addresses)
77 {
78 foreach ($addresses as $address) {
79 $this->addAddress($address);
80 }
81 }
82
83 /**
84 * @throws RfcComplianceException
85 */
86 public function addAddress(Address $address)
87 {
88 $this->addresses[] = $address;
89 }
90
91 /**
92 * @return Address[]
93 */
94 public function getAddresses(): array
95 {
96 return $this->addresses;
97 }
98
99 /**
100 * Gets the full mailbox list of this Header as an array of valid RFC 2822 strings.
101 *
102 * @return string[]
103 *
104 * @throws RfcComplianceException
105 */
106 public function getAddressStrings(): array
107 {
108 $strings = [];
109 foreach ($this->addresses as $address) {
110 $str = $address->getEncodedAddress();
111 if ($name = $address->getName()) {
112 $str = $this->createPhrase($this, $name, $this->getCharset(), !$strings).' <'.$str.'>';
113 }
114 $strings[] = $str;
115 }
116
117 return $strings;
118 }
119
120 public function getBodyAsString(): string
121 {
122 return implode(', ', $this->getAddressStrings());
123 }
124
125 /**
126 * Redefine the encoding requirements for addresses.
127 *
128 * All "specials" must be encoded as the full header value will not be quoted
129 *
130 * @see RFC 2822 3.2.1
131 */
132 protected function tokenNeedsEncoding(string $token): bool
133 {
134 return preg_match('/[()<>\[\]:;@\,."]/', $token) || parent::tokenNeedsEncoding($token);
135 }
136 }
137