setIds($messageIds); return $header; } /** * @param string $id * @return string */ private static function trimMessageId($id) { return trim($id, "\t\n\r\0\x0B<>"); } /** * @return string */ public function getFieldName() { return $this->fieldName; } /** * @inheritDoc */ public function getFieldValue($format = HeaderInterface::FORMAT_RAW) { return implode(Headers::FOLDING, array_map(static fn($id) => sprintf('<%s>', $id), $this->messageIds)); } /** * @param string $encoding Ignored; headers of this type MUST always be in * ASCII. * @return static This method is a no-op, and implements a fluent interface. */ public function setEncoding($encoding) { return $this; } /** * @return string Always returns ASCII */ public function getEncoding() { return 'ASCII'; } /** * @return string */ public function toString() { return sprintf('%s: %s', $this->getFieldName(), $this->getFieldValue()); } /** * Set the message ids * * @param string[] $ids * @return static This method implements a fluent interface. */ public function setIds($ids) { foreach ($ids as $id) { if ( ! HeaderValue::isValid($id) || preg_match("/[\r\n]/", $id) ) { throw new Exception\InvalidArgumentException('Invalid ID detected'); } } $this->messageIds = array_map([self::class, "trimMessageId"], $ids); return $this; } /** * Retrieve the message ids * * @return string[] */ public function getIds() { return $this->messageIds; } }