data = clone $data; $this->sanitizeStringInputs(); } /** * Sanitizes user message. * * ! This is not recursive ! * * Prevent xss injection via markdown interpretation. * * La solution devrai etre de filtrer en sortie, mais il n'est pas possible de * * @return void */ private function sanitizeStringInputs(): void { $this->data = (object) Arr::map((array) $this->data, function ($el) { if (is_string($el)) { $el = \htmlspecialchars(\strip_tags(Blade::render( (string) Markdown::parse($el) ))); $el = Str::of($el)->replaceMatches( '/[^\p{L}0-9\n\s\@\.\:\-\_\?\!\;\(\)\+\-\/\\\=]+/us', '' )->trim()->wordWrap(75, "\n", true)->toString(); } return $el; }); } /** * Get the message envelope. * * @return \Illuminate\Mail\Mailables\Envelope */ public function envelope(): \Illuminate\Mail\Mailables\Envelope { return new Envelope( subject: sprintf( '%s - %s', ObjectEnum::make($this->data->object)->label(), config('app.name') ), ); } /** * Get the message content definition. * * @return \Illuminate\Mail\Mailables\Content */ public function content(): \Illuminate\Mail\Mailables\Content { return new Content( markdown: 'emails.send-contact-form', with: ['data' => $this->data], ); } /** * Get the attachments for the message. * * @return array */ public function attachments(): array { $attachments = []; if (isset($this->data->file)) { $attachments[] = Attachment::fromPath($this->data->file->getRealPath()) ->as($this->data->file->getClientOriginalName()) ->withMime($this->data->file->getClientMimeType()); } return $attachments; } }