Merge branch 'issue-76-mail-display' into 'develop'

fix: characters were still encoded in the sended mail

See merge request ldc-web/projets/tregalette!27
This commit is contained in:
Vincent BRIDIER 2025-03-04 09:20:49 +00:00
commit 848c1007fa
4 changed files with 26 additions and 36 deletions

View file

@ -5,14 +5,11 @@ namespace App\Mail;
use App\Enums\Contact\ObjectEnum;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Mail\Markdown;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Str;
class SendContactMail extends Mailable
{
@ -34,33 +31,6 @@ class SendContactMail extends Mailable
public function __construct(\stdClass $data)
{
$this->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;
});
}
/**
@ -71,8 +41,13 @@ class SendContactMail extends Mailable
public function envelope(): \Illuminate\Mail\Mailables\Envelope
{
return new Envelope(
from: new Address(\config('mail.from.address'), \config('mail.from.name')),
subject: sprintf('%s - %s', ObjectEnum::make($this->data->type)->label() ??
__('Nouveau message'), config('app.name')),
replyTo: [new Address(
$this->data->email,
sprintf('%s %s', $this->data->first_name, $this->data->last_name)
)],
);
}

View file

@ -32,7 +32,7 @@
@component('mail::panel')
```
{{ $data->message }}
{!! $data->message !!}
```
@endcomponent

View file

@ -2,11 +2,9 @@
<td class="header">
<a href="{{ $url }}" style="display: inline-block;">
@if (trim($slot) === 'Laravel')
<img src="https://laravel.com/img/notification-logo.png" class="logo" alt="Laravel Logo">
<img class="logo" src="https://laravel.com/img/notification-logo.png" alt="Laravel Logo">
@else
{{-- FIXME: Personaliser ca --}}
<img src="{{ Vite::asset('resources/assets/images/logo.png') }}" class="logo img-fluid" alt="{{ config('app.name') }}">
{{ $slot }}
<img class="logo img-fluid" src="{{ Vite::asset('resources/assets/images/logo.png') }}" alt="{{ config('app.name') }}">
@endif
</a>
</td>

View file

@ -0,0 +1,17 @@
<table class="panel" width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td class="panel-content">
<table width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td class="panel-item">
{!! clean(nl2br(str($slot)->markdown([
'html_input' => 'strip',
'allow_unsafe_links' => false,
]))) !!}
</td>
</tr>
</table>
</td>
</tr>
</table>