-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Mailer] Fix signed emails breaking the profiler #53934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
Q | A |
---|---|
Branch? | 5.4 |
Bug fix? | yes |
New feature? | no |
Deprecations? | no |
Issues | Fix #53928 |
License | MIT |
279ee87
to
b202d65
Compare
For 6.4+ : HypeMC@834167c diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/mailer.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/mailer.html.twig
index 386438b825..a0d2d6388b 100644
--- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/mailer.html.twig
+++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/mailer.html.twig
@@ -278,8 +278,24 @@
{% for event in collector.events.events(transport) %}
<tr class="mailer-email-summary-table-row {{ loop.first ? 'active' }}" data-target="#email-{{ loop.index }}">
<td>{{ loop.index }}</td>
- <td>{{ event.message.getSubject() ?? '(No subject)' }}</td>
- <td>{{ event.message.getTo()|map(addr => addr.toString())|join(', ')|default('(empty)') }}</td>
+ <td>
+ {% if event.message.subject is defined %}
+ {{ event.message.getSubject() ?? '(No subject)' }}
+ {% elseif event.message.headers.has('subject') %}
+ {{ event.message.headers.get('subject').toString()|split(': ', 2)[1]|default('(No subject)') }}
+ {% else %}
+ (No subject)
+ {% endif %}
+ </td>
+ <td>
+ {% if event.message.to is defined %}
+ {{ event.message.getTo()|map(addr => addr.toString())|join(', ')|default('(empty)') }}
+ {% elseif event.message.headers.has('to') %}
+ {{ event.message.headers.get('to').toString()|split(': ', 2)[1]|default('(empty)') }}
+ {% else %}
+ (empty)
+ {% endif %}
+ </td>
<td class="visually-hidden"><button class="mailer-email-summary-table-row-button" data-target="#email-{{ loop.index }}">View email details</button></td>
</tr>
{% endfor %}
@@ -323,18 +339,42 @@
<div class="tab-content">
<div class="card-block">
<p class="mailer-message-subject">
- {{ message.getSubject() ?? '(No subject)' }}
+ {% if message.subject is defined %}
+ {{ message.getSubject() ?? '(No subject)' }}
+ {% elseif message.headers.has('subject') %}
+ {{ message.headers.get('subject').toString()|split(': ', 2)[1]|default('(No subject)') }}
+ {% else %}
+ (No subject)
+ {% endif %}
</p>
<div class="mailer-message-headers">
- <p><strong>From:</strong> {{ message.getFrom()|map(addr => addr.toString())|join(', ')|default('(empty)') }}</p>
- <p><strong>To:</strong> {{ message.getTo()|map(addr => addr.toString())|join(', ')|default('(empty)') }}</p>
+ <p>
+ <strong>From:</strong>
+ {% if message.from is defined %}
+ {{ message.getFrom()|map(addr => addr.toString())|join(', ')|default('(empty)') }}
+ {% elseif message.headers.has('from') %}
+ {{ message.headers.get('from').toString()|split(': ', 2)[1]|default('(empty)') }}
+ {% else %}
+ (empty)
+ {% endif %}
+ </p>
+ <p>
+ <strong>To:</strong>
+ {% if message.to is defined %}
+ {{ message.getTo()|map(addr => addr.toString())|join(', ')|default('(empty)') }}
+ {% elseif message.headers.has('to') %}
+ {{ message.headers.get('to').toString()|split(': ', 2)[1]|default('(empty)') }}
+ {% else %}
+ (empty)
+ {% endif %}
+ </p>
{% for header in message.headers.all|filter(header => (header.name ?? '')|lower not in ['subject', 'from', 'to']) %}
<p class="mailer-message-header-secondary">{{ header.toString }}</p>
{% endfor %}
</div>
</div>
- {% if message.attachments %}
+ {% if message.attachments is defined and message.attachments %}
<div class="card-block">
{% set num_of_attachments = message.attachments|length %}
{% set total_attachments_size_in_bytes = message.attachments|reduce((total_size, attachment) => total_size + attachment.body|length, 0) %}
@@ -364,9 +404,10 @@
{% endif %}
<div class="card-block">
- {% set textBody = message.textBody %}
- {% set htmlBody = message.htmlBody %}
<div class="sf-tabs sf-tabs-sm">
+ {% if message.htmlBody is defined %}
+ {% set textBody = message.textBody %}
+ {% set htmlBody = message.htmlBody %}
<div class="tab {{ not textBody ? 'disabled' }} {{ textBody ? 'active' }}">
<h3 class="tab-title">Text content</h3>
<div class="tab-content">
@@ -414,6 +455,23 @@
{% endif %}
</div>
</div>
+ {% else %}
+ {% set body = message.body ? message.body.toString() : null %}
+ <div class="tab {{ not body ? 'disabled' }} {{ body ? 'active' }}">
+ <h3 class="tab-title">Content</h3>
+ <div class="tab-content">
+ {% if body %}
+ <pre class="mailer-email-body prewrap" style="max-height: 600px">
+ {{- body }}
+ </pre>
+ {% else %}
+ <div class="mailer-empty-email-body">
+ <p>The body is empty.</p>
+ </div>
+ {% endif %}
+ </div>
+ </div>
+ {% endif %}
</div>
</div>
</div> |
Thank you @HypeMC. |
Merged
nicolas-grekas
added a commit
that referenced
this pull request
Feb 15, 2024
This PR was merged into the 5.4 branch. Discussion ---------- [Mailer] Simplify fix | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT Follow-up to #53934, I didn't notice the `getBodyAsString()` method, it simplifies the code nicely. For 6.4+: HypeMC@1bb254d ```diff diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/mailer.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/mailer.html.twig index a0d2d63..e220e73 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/mailer.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/mailer.html.twig @@ -282,7 +282,7 @@ {% if event.message.subject is defined %} 8331 {{ event.message.getSubject() ?? '(No subject)' }} {% elseif event.message.headers.has('subject') %} - {{ event.message.headers.get('subject').toString()|split(': ', 2)[1]|default('(No subject)') }} + {{ event.message.headers.get('subject').bodyAsString()|default('(No subject)') }} {% else %} (No subject) {% endif %} @@ -291,7 +291,7 @@ {% if event.message.to is defined %} {{ event.message.getTo()|map(addr => addr.toString())|join(', ')|default('(empty)') }} {% elseif event.message.headers.has('to') %} - {{ event.message.headers.get('to').toString()|split(': ', 2)[1]|default('(empty)') }} + {{ event.message.headers.get('to').bodyAsString()|default('(empty)') }} {% else %} (empty) {% endif %} @@ -342,7 +342,7 @@ {% if message.subject is defined %} {{ message.getSubject() ?? '(No subject)' }} {% elseif message.headers.has('subject') %} - {{ message.headers.get('subject').toString()|split(': ', 2)[1]|default('(No subject)') }} + {{ message.headers.get('subject').bodyAsString()|default('(No subject)') }} {% else %} (No subject) {% endif %} @@ -353,7 +353,7 @@ {% if message.from is defined %} {{ message.getFrom()|map(addr => addr.toString())|join(', ')|default('(empty)') }} {% elseif message.headers.has('from') %} - {{ message.headers.get('from').toString()|split(': ', 2)[1]|default('(empty)') }} + {{ message.headers.get('from').bodyAsString()|default('(empty)') }} {% else %} (empty) {% endif %} @@ -363,7 +363,7 @@ {% if message.to is defined %} {{ message.getTo()|map(addr => addr.toString())|join(', ')|default('(empty)') }} {% elseif message.headers.has('to') %} - {{ message.headers.get('to').toString()|split(': ', 2)[1]|default('(empty)') }} + {{ message.headers.get('to').bodyAsString()|default('(empty)') }} {% else %} (empty) {% endif %} ``` Commits ------- fc7c992 [Mailer] Simplify fix
This was referenced Feb 27, 2024
Merged
Merged
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.