Skip to content

Commit d877302

Browse files
authored
Fix displaying message/rfc822 parts (#9753)
* Fix displaying message/rfc822 parts The previous code contained a simple error that assigned the body part to the $headers variable (which then couldn't be parsed and got discarded). * Test rendering of attached message/rfc822 parts
1 parent a677d26 commit d877302

File tree

3 files changed

+126
-3
lines changed

3 files changed

+126
-3
lines changed

program/lib/Roundcube/rcube_message.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,10 +663,10 @@ private function parse_structure($structure, $recursive = false)
663663

664664
// parse headers from message/rfc822 part
665665
if (!isset($structure->headers['subject']) && !isset($structure->headers['from'])) {
666-
$part_body = $headers = $this->get_part_body($structure->mime_id, false, 32768);
666+
$part_body = $this->get_part_body($structure->mime_id, false, 32768);
667667

668-
if (($pos = strpos($headers, "\r\n\r\n")) !== false) {
669-
$headers = substr($headers, $pos);
668+
if (strpos($part_body, "\r\n\r\n") !== false) {
669+
[$headers] = explode("\r\n\r\n", $part_body, 2);
670670
}
671671

672672
$structure->headers = rcube_mime::parse_headers($headers);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Tests\MessageRendering;
4+
5+
/**
6+
* Test class to test simple messages.
7+
*/
8+
class MessageRfc822Test extends MessageRenderingTestCase
9+
{
10+
public function testRfc822Part()
11+
{
12+
$domxpath = $this->runAndGetHtmlOutputDomxpath('[email protected]');
13+
$this->assertSame('Fwd: Lines', $this->getScrubbedSubject($domxpath));
14+
15+
$parts = $domxpath->query('//div[@id="messagebody"]/div');
16+
$this->assertCount(3, $parts);
17+
$this->assertSame('message-part', $parts[0]->attributes->getNamedItem('class')->textContent);
18+
$this->assertSame('Check the forwarded message', $parts[0]->textContent);
19+
$this->assertSame('message-part', $parts[2]->attributes->getNamedItem('class')->textContent);
20+
$this->assertStringStartsWith('Plain text message body.', $parts[2]->textContent);
21+
22+
$this->assertSame('message-partheaders', $parts[1]->attributes->getNamedItem('class')->textContent);
23+
24+
$msgRfc822Subject = $domxpath->query('//div[@class="message-partheaders"]//td[@class="header subject"]');
25+
$this->assertCount(1, $msgRfc822Subject);
26+
$this->assertSame('Lines', $msgRfc822Subject[0]->textContent);
27+
28+
$msgRfc822From = $domxpath->query('//div[@class="message-partheaders"]//td[@class="header from"]');
29+
$this->assertCount(1, $msgRfc822From);
30+
$this->assertSame('Thomas B.', $msgRfc822From[0]->textContent);
31+
32+
$msgRfc822To = $domxpath->query('//div[@class="message-partheaders"]//td[@class="header to"]');
33+
$this->assertCount(1, $msgRfc822To);
34+
$this->assertSame('Tom Tester', $msgRfc822To[0]->textContent);
35+
36+
$msgRfc822Cc = $domxpath->query('//div[@class="message-partheaders"]//td[@class="header cc"]');
37+
$this->assertCount(1, $msgRfc822Cc);
38+
39+
40+
$msgRfc822ReplyTo = $domxpath->query('//div[@class="message-partheaders"]//td[@class="header mail-reply-to"]');
41+
$this->assertCount(1, $msgRfc822ReplyTo);
42+
$this->assertSame('[email protected]', $msgRfc822ReplyTo[0]->textContent);
43+
44+
$msgRfc822Date = $domxpath->query('//div[@class="message-partheaders"]//td[@class="header date"]');
45+
$this->assertCount(1, $msgRfc822Date);
46+
// Using a RegExp here, because the result is different depending on the timezone of the testing environment.
47+
$this->assertMatchesRegularExpression('/2014-05-2[234]{1} \d{2}:\d{2}/', $msgRfc822Date[0]->textContent);
48+
}
49+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
MIME-Version: 1.0
2+
Date: Wed, 15 Jan 2025 11:44:00 +0100
3+
4+
5+
Subject: Fwd: Lines
6+
In-Reply-To: <[email protected]>
7+
References: <[email protected]>
8+
Message-ID: <[email protected]>
9+
10+
X-Draft-Info: type=forward; uid=3; folder=B::SU5CT1g=
11+
Content-Type: multipart/mixed;
12+
boundary="=_9b038d50a3b2b5cfe9fdbd53743b1ea9"
13+
14+
--=_9b038d50a3b2b5cfe9fdbd53743b1ea9
15+
Content-Transfer-Encoding: 7bit
16+
Content-Type: text/plain; charset=US-ASCII;
17+
format=flowed
18+
19+
Check the forwarded message
20+
--=_9b038d50a3b2b5cfe9fdbd53743b1ea9
21+
Content-Transfer-Encoding: 8bit
22+
Content-Type: message/rfc822;
23+
name=Lines.eml
24+
Content-Disposition: attachment;
25+
filename=Lines.eml;
26+
size=1382
27+
28+
Return-Path: <[email protected]>
29+
X-Original-To: [email protected]
30+
From: "Thomas B." <[email protected]>
31+
To: Tom Tester <[email protected]>
32+
Subject: Lines
33+
34+
35+
36+
MIME-Version: 1.0
37+
Content-Type: multipart/mixed;
38+
boundary="=_8853bfb47b7da1852ac882e69cc724f3"
39+
Date: Fri, 23 May 2014 19:44:50 +0200
40+
41+
Mail-Reply-To: [email protected]
42+
Message-ID: <[email protected]>
43+
44+
45+
--=_8853bfb47b7da1852ac882e69cc724f3
46+
Content-Transfer-Encoding: 7bit
47+
Content-Type: text/plain; charset=UTF-8;
48+
format=flowed
49+
50+
Plain text message body.
51+
52+
--
53+
Developer of Free Software
54+
Sent with Roundcube Webmail - roundcube.net
55+
--=_8853bfb47b7da1852ac882e69cc724f3
56+
Content-Transfer-Encoding: base64
57+
Content-Type: text/plain;
58+
name=lines.txt
59+
Content-Disposition: attachment;
60+
filename=lines.txt;
61+
size=13
62+
63+
Zm9vDQpiYXINCmduYQ==
64+
--=_8853bfb47b7da1852ac882e69cc724f3
65+
Content-Transfer-Encoding: base64
66+
Content-Type: text/plain;
67+
name=lines_lf.txt
68+
Content-Disposition: attachment;
69+
filename=lines_lf.txt;
70+
size=11
71+
72+
Zm9vCmJhcgpnbmE=
73+
--=_8853bfb47b7da1852ac882e69cc724f3--
74+
--=_9b038d50a3b2b5cfe9fdbd53743b1ea9--

0 commit comments

Comments
 (0)