|
@@ -22,32 +22,32 @@ final class MimeMailBuilder
|
|
|
|
|
|
|
|
public function setFrom(string $address, string $name = ''): self
|
|
public function setFrom(string $address, string $name = ''): self
|
|
|
{
|
|
{
|
|
|
- $this->from = $address;
|
|
|
|
|
- $this->fromName = $name;
|
|
|
|
|
|
|
+ $this->from = $this->sanitizeAddress($address);
|
|
|
|
|
+ $this->fromName = $this->sanitizeHeaderText($name);
|
|
|
return $this;
|
|
return $this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function setTo(string $address): self
|
|
public function setTo(string $address): self
|
|
|
{
|
|
{
|
|
|
- $this->to = $address;
|
|
|
|
|
|
|
+ $this->to = $this->sanitizeAddress($address);
|
|
|
return $this;
|
|
return $this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function setSubject(string $subject): self
|
|
public function setSubject(string $subject): self
|
|
|
{
|
|
{
|
|
|
- $this->subject = $subject;
|
|
|
|
|
|
|
+ $this->subject = $this->sanitizeHeaderText($subject);
|
|
|
return $this;
|
|
return $this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function setHtmlBody(string $html): self
|
|
public function setHtmlBody(string $html): self
|
|
|
{
|
|
{
|
|
|
- $this->htmlBody = $html;
|
|
|
|
|
|
|
+ $this->htmlBody = $this->sanitizeBodyText($html);
|
|
|
return $this;
|
|
return $this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function setTextBody(string $text): self
|
|
public function setTextBody(string $text): self
|
|
|
{
|
|
{
|
|
|
- $this->textBody = $text;
|
|
|
|
|
|
|
+ $this->textBody = $this->sanitizeBodyText($text);
|
|
|
return $this;
|
|
return $this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -173,6 +173,24 @@ final class MimeMailBuilder
|
|
|
|
|
|
|
|
private function sanitizeFilename(string $name): string
|
|
private function sanitizeFilename(string $name): string
|
|
|
{
|
|
{
|
|
|
|
|
+ $name = $this->sanitizeHeaderText($name);
|
|
|
return preg_replace('/[^\w.\-äöüÄÖÜß]+/u', '_', $name) ?: 'attachment';
|
|
return preg_replace('/[^\w.\-äöüÄÖÜß]+/u', '_', $name) ?: 'attachment';
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private function sanitizeAddress(string $value): string
|
|
|
|
|
+ {
|
|
|
|
|
+ $value = preg_replace('/[\x00-\x1F\x7F]+/', '', $value) ?? '';
|
|
|
|
|
+ return trim($value);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function sanitizeHeaderText(string $value): string
|
|
|
|
|
+ {
|
|
|
|
|
+ $value = preg_replace('/[\x00-\x1F\x7F]+/', ' ', $value) ?? '';
|
|
|
|
|
+ return trim($value);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function sanitizeBodyText(string $value): string
|
|
|
|
|
+ {
|
|
|
|
|
+ return preg_replace('/[\x00\x0B\x0C]/', '', $value) ?? '';
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|