Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 19e99a6

Browse files
committed
feature #44917 [Mailer] Add downloadable attachments to profiler (dbrekelmans)
This PR was squashed before being merged into the 6.1 branch. Discussion ---------- [Mailer] Add downloadable attachments to profiler | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | n/a | License | MIT | Doc PR | n/a This PR allows developers to download email attachments from the profiler. This is very useful for debugging if you are sending emails with PDF attachments for example, and you want to check some data within the attachment through the profiler. Commits ------- 4320220 [Mailer] Add downloadable attachments to profiler
2 parents ae3b078 + 4320220 commit 19e99a6

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

src/Symfony/Bundle/WebProfilerBundle/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.1
5+
---
6+
7+
* Add a download link in mailer profiler for email attachments
8+
49
5.4
510
---
611

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/mailer.html.twig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@
187187
<div class="tab">
188188
<h3 class="tab-title">Attachment #{{ loop.index }}</h3>
189189
<div class="tab-content">
190+
<p>
191+
<a href="data:{{ attachment.contentType|default('application/octet-stream') }};base64,{{ collector.base64Encode(attachment.body) }}" download="{{ attachment.filename|default('attachment') }}">
192+
{% if attachment.filename|default %}
193+
{{ attachment.filename }}
194+
{% else %}
195+
<em>(no filename)</em>
196+
{% endif %}
197+
</a>
198+
</p>
190199
<pre class="prewrap" style="max-height: 600px">{{ attachment.toString() }}</pre>
191200
</div>
192201
</div>

src/Symfony/Component/Mime/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.1
5+
---
6+
7+
* Add `DataPart::getFilename()` and `DataPart::getContentType()`
8+
49
6.0
510
---
611

src/Symfony/Component/Mime/Part/DataPart.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ public function asDebugString(): string
122122
return $str;
123123
}
124124

125+
public function getFilename(): ?string
126+
{
127+
return $this->filename;
128+
}
129+
130+
public function getContentType(): string
131+
{
132+
return implode('/', [$this->getMediaType(), $this->getMediaSubtype()]);
133+
}
134+
125135
private function generateContentId(): string
126136
{
127137
return bin2hex(random_bytes(16)).'@symfony';

src/Symfony/Component/Mime/Tests/Part/DataPartTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,24 @@ public function testHasContentId()
135135
$this->assertTrue($p->hasContentId());
136136
}
137137

138+
public function testGetFilename()
139+
{
140+
$p = new DataPart('content', null);
141+
self::assertNull($p->getFilename());
142+
143+
$p = new DataPart('content', 'filename');
144+
self::assertSame('filename', $p->getFilename());
145+
}
146+
147+
public function testGetContentType()
148+
{
149+
$p = new DataPart('content');
150+
self::assertSame('application/octet-stream', $p->getContentType());
151+
152+
$p = new DataPart('content', null, 'application/pdf');
153+
self::assertSame('application/pdf', $p->getContentType());
154+
}
155+
138156
public function testSerialize()
139157
{
140158
$r = fopen('php://memory', 'r+', false);

0 commit comments

Comments
 (0)