Skip to content

Commit dcc5713

Browse files
authored
Merge pull request barbushin#522 from bapcltd/issue/519
Issue/519
2 parents f3900a1 + 3d4566f commit dcc5713

File tree

4 files changed

+211
-2
lines changed

4 files changed

+211
-2
lines changed

src/PhpImap/IncomingMail.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public function embedImageAttachments(): void
219219
$cid = \str_replace('cid:', '', $match);
220220

221221
foreach ($attachments as $attachment) {
222-
if ($attachment->contentId == $cid && 'inline' == $attachment->disposition) {
222+
if ($attachment->contentId == $cid && 'inline' == \mb_strtolower((string) $attachment->disposition)) {
223223
$contents = $attachment->getContents();
224224
$contentType = (string) $attachment->getFileInfo(FILEINFO_MIME);
225225

src/PhpImap/IncomingMailAttachment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function addDataPartInfo(DataPartInfo $dataInfo): void
129129
*
130130
* @psalm-param fileinfoconst $fileinfo_const
131131
*/
132-
public function getFileInfo($fileinfo_const = FILEINFO_NONE): string
132+
public function getFileInfo(int $fileinfo_const = FILEINFO_NONE): string
133133
{
134134
if ((FILEINFO_MIME == $fileinfo_const) and (false != $this->mimeType)) {
135135
return $this->mimeType;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpImap\Fixtures;
6+
7+
use const FILEINFO_MIME;
8+
use const FILEINFO_NONE;
9+
use PhpImap\IncomingMailAttachment as Base;
10+
11+
class IncomingMailAttachment extends Base
12+
{
13+
/** @var string|null */
14+
public $override_getFileInfo_mime = null;
15+
16+
public function getFileInfo(int $fileinfo_const = FILEINFO_NONE): string
17+
{
18+
if (
19+
FILEINFO_MIME === $fileinfo_const &&
20+
isset($this->override_getFileInfo_mime)
21+
) {
22+
return $this->override_getFileInfo_mime;
23+
}
24+
25+
return parent::getFileInfo($fileinfo_const);
26+
}
27+
}

tests/unit/Issue519Test.php

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
<?php
2+
/**
3+
* Live Mailbox - PHPUnit tests.
4+
*
5+
* Runs tests on a live mailbox
6+
*
7+
* @author BAPCLTD-Marv
8+
*/
9+
declare(strict_types=1);
10+
11+
namespace PhpImap;
12+
13+
use const ENC8BIT;
14+
use const ENCBASE64;
15+
use PHPUnit\Framework\TestCase;
16+
use const TYPEIMAGE;
17+
18+
class Issue519Test extends TestCase
19+
{
20+
const HEADER_VALUES = [
21+
'inline',
22+
'Inline',
23+
'iNline',
24+
'INline',
25+
'inLine',
26+
'InLine',
27+
'iNLine',
28+
'INLine',
29+
'inlIne',
30+
'InlIne',
31+
'iNlIne',
32+
'INlIne',
33+
'inLIne',
34+
'InLIne',
35+
'iNLIne',
36+
'INLIne',
37+
'inliNe',
38+
'InliNe',
39+
'iNliNe',
40+
'INliNe',
41+
'inLiNe',
42+
'InLiNe',
43+
'iNLiNe',
44+
'INLiNe',
45+
'inlINe',
46+
'InlINe',
47+
'iNlINe',
48+
'INlINe',
49+
'inLINe',
50+
'InLINe',
51+
'iNLINe',
52+
'INLINe',
53+
'inlinE',
54+
'InlinE',
55+
'iNlinE',
56+
'INlinE',
57+
'inLinE',
58+
'InLinE',
59+
'iNLinE',
60+
'INLinE',
61+
'inlInE',
62+
'InlInE',
63+
'iNlInE',
64+
'INlInE',
65+
'inLInE',
66+
'InLInE',
67+
'iNLInE',
68+
'INLInE',
69+
'inliNE',
70+
'InliNE',
71+
'iNliNE',
72+
'INliNE',
73+
'inLiNE',
74+
'InLiNE',
75+
'iNLiNE',
76+
'INLiNE',
77+
'inlINE',
78+
'InlINE',
79+
'iNlINE',
80+
'INlINE',
81+
'inLINE',
82+
'InLINE',
83+
'iNLINE',
84+
'INLINE',
85+
];
86+
87+
const CID = 'cid:foo.jpg';
88+
89+
const ID = 'foo.jpg';
90+
91+
const SUBTYPE = 'jpeg';
92+
93+
const SIZE_IN_BYTES = 0;
94+
95+
const HTML = 'foo.html';
96+
97+
const HTML_EMBED = '<img src="data:image/jpeg;base64, ">';
98+
99+
const MIME = 'image/jpeg';
100+
101+
const EXPECTED_ATTACHMENT_COUNT = 1;
102+
103+
const EXPECTED_ATTACHMENT_COUNT_AFTER_EMBED = 0;
104+
105+
/**
106+
* @psalm-return array<string, array{0:string}>
107+
*/
108+
public function provider(): array
109+
{
110+
$out = [];
111+
112+
foreach (self::HEADER_VALUES as $value) {
113+
$out[$value] = [$value];
114+
}
115+
116+
return $out;
117+
}
118+
119+
/**
120+
* @dataProvider provider
121+
*/
122+
public function test(string $header_value): void
123+
{
124+
$mailbox = new Mailbox('', '', '');
125+
$mail = new IncomingMail();
126+
$attachment = new Fixtures\IncomingMailAttachment();
127+
$part = new Fixtures\DataPartInfo(
128+
$mailbox,
129+
0,
130+
0,
131+
ENCBASE64,
132+
0
133+
);
134+
135+
$html = new Fixtures\DataPartInfo(
136+
$mailbox,
137+
0,
138+
0,
139+
ENC8BIT,
140+
0
141+
);
142+
143+
$html_string = '<img src="'.self::CID.'">';
144+
145+
$html->setData($html_string);
146+
$part->setData('');
147+
148+
$attachment->id = self::ID;
149+
$attachment->contentId = self::ID;
150+
$attachment->type = TYPEIMAGE;
151+
$attachment->encoding = ENCBASE64;
152+
$attachment->subtype = self::SUBTYPE;
153+
$attachment->description = self::ID;
154+
$attachment->name = self::ID;
155+
$attachment->sizeInBytes = self::SIZE_IN_BYTES;
156+
$attachment->disposition = $header_value;
157+
$attachment->override_getFileInfo_mime = self::MIME;
158+
159+
$attachment->addDataPartInfo($part);
160+
161+
$mail->addDataPartInfo($html, DataPartInfo::TEXT_HTML);
162+
$mail->addAttachment($attachment);
163+
164+
$this->assertTrue($mail->hasAttachments());
165+
166+
$this->assertCount(
167+
self::EXPECTED_ATTACHMENT_COUNT,
168+
$mail->getAttachments()
169+
);
170+
171+
$this->assertSame($html_string, $mail->textHtml);
172+
173+
$mail->embedImageAttachments();
174+
175+
$this->assertCount(
176+
self::EXPECTED_ATTACHMENT_COUNT_AFTER_EMBED,
177+
$mail->getAttachments()
178+
);
179+
180+
$this->assertSame(self::HTML_EMBED, $mail->textHtml);
181+
}
182+
}

0 commit comments

Comments
 (0)