Files
roundcubemail/tests/MessageRendering/TnefEmailsTest.php
Pablo Zmdl 752b152a23 Check if attachment is actually(!) referred to (#9585)
* Check if "inline" msg part is actually referred to

If there's no reference to it in a sibling HTML part then we handle it
as a classic attachment (which is shown as downloadable).

* Fetch all msg headers also for images to always get Content-Location

Previously all headers were only fetched for message/rfc822, or
if the Content-Type's "name" parameter was set, or if a Content-ID was
set.
The RFC doesn't require neither the "name" parameter nor a Content-ID
for using Content-Location, though, so we shouldn't depend on those.

Instead now all headers are also fetched if the main part of the
Content-Type is "image", to catch more cases.

* Parse HTML for references only on demand

* Typos and comment formatting

* Don't skip test anymore

We want it tested!

* More MR tests with images

* Remove early special handling for "inline" images

We decide later, which attachment is considered "inline" and which
isn't.

* Remove early resolving of references in TNEF parts

* Testing message rendering of TNEF emails

* Don't use image disposition, it's unreliable

* Split adding raw parts and attachments

* Fix renaming variable

* Rename file to make its test be run

* Remove outdated script

* Annotate test cases with GitHub issue numbers

* Fix test case class name

* remove comment

* Test inline image message rendering

* Rename test file to reflect cases better

* Reduce image used in test email

It doesn't change much, but there's also no sense in decoding big images
that we don't use.

* Remove unused variable initialisation
2025-02-09 09:56:43 +01:00

56 lines
2.4 KiB
PHP

<?php
namespace Tests\MessageRendering;
/**
* Test class to test "interesting" messages.
*/
class TnefEmailsTest extends MessageRenderingTestCase
{
public function testTnefEmail1()
{
$domxpath = $this->runAndGetHtmlOutputDomxpath('631a672e15f742a98035f1cb7efe1f8db6310138@example.net');
$this->assertSame('', $this->getBody($domxpath));
$attchNames = $domxpath->query('//span[@class="attachment-name"]');
$this->assertCount(1, $attchNames, 'Attachments');
$this->assertStringStartsWith('AUTHORS', $attchNames[0]->textContent);
}
public function testTnefEmail2()
{
$domxpath = $this->runAndGetHtmlOutputDomxpath('b6057653610f8041b120965652ff7f26a1a8f02d@example.net');
$this->assertStringStartsWith('THE BILL OF RIGHTSAmendments 1-10 of the', $this->getBody($domxpath));
$attchNames = $domxpath->query('//span[@class="attachment-name"]');
$this->assertCount(0, $attchNames, 'Attachments');
}
public function testTnefEmail3()
{
$domxpath = $this->runAndGetHtmlOutputDomxpath('cde7964538f283305609ec9146b4a80c121fd0ae@example.net');
$bodyParagraphs = $domxpath->query('//div[@class="rcmBody"]/p');
$this->assertCount(8, $bodyParagraphs, 'Body HTML paragraphs');
$this->assertSame('Casdasdfasdfasd', $bodyParagraphs[0]->textContent);
$this->assertSame('Casdasdfasdfasd', $bodyParagraphs[1]->textContent);
$this->assertSame('Casdasdfasdfasd', $bodyParagraphs[2]->textContent);
$this->assertSame('Casdasdfasdfasd', $bodyParagraphs[3]->textContent);
$this->assertSame('Casdasdfasdfasd', $bodyParagraphs[4]->textContent);
$this->assertSame(' ', $bodyParagraphs[5]->textContent);
$this->assertSame('Casdasdfasdfasd', $bodyParagraphs[6]->textContent);
$this->assertSame(' ', $bodyParagraphs[7]->textContent);
$attchNames = $domxpath->query('//span[@class="attachment-name"]');
$this->assertCount(2, $attchNames, 'Attachments');
$this->assertStringStartsWith('zappa_av1.jpg', $attchNames[0]->textContent);
$this->assertStringStartsWith('bookmark.htm', $attchNames[1]->textContent);
$inlineShownImages = $domxpath->query('//p[@class="image-attachment"]/span[@class="image-filename"]');
$this->assertCount(1, $inlineShownImages, 'Inline shown images');
$this->assertSame('zappa_av1.jpg', $inlineShownImages[0]->textContent);
}
}