Skip to content

Commit 8520ff9

Browse files
committed
Make sure to flush any remaining text in the FlowedToText converter
Fixes issue #1130
1 parent e64eaf5 commit 8520ff9

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

MimeKit/Text/FlowedToText.cs

+7
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ public override void Convert (TextReader reader, TextWriter writer)
171171
}
172172
}
173173

174+
// Flush any remaining paragraph text.
175+
if (para.Length > 0) {
176+
if (paraQuoteDepth > 0)
177+
writer.Write (new string ('>', paraQuoteDepth) + " ");
178+
writer.Write (para);
179+
}
180+
174181
if (!string.IsNullOrEmpty (Footer))
175182
writer.Write (Footer);
176183
}

UnitTests/MimeMessageTests.cs

+14
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
using System.Reflection;
3030

3131
using MimeKit;
32+
using MimeKit.Text;
3233
using MimeKit.Utils;
3334
using MimeKit.Cryptography;
3435

@@ -1562,6 +1563,19 @@ public void TestHtmlAndTextBodies ()
15621563
Assert.That (message.HtmlBody, Is.EqualTo (HtmlBody), "The HTML bodies do not match for body.9.txt.");
15631564
}
15641565

1566+
[Test]
1567+
public void TestFlowedTextBodyIssue1130 ()
1568+
{
1569+
const string TextBody = "We should have access, and apparently did a few months ago, but now there isa \"You do not currently have access to this content.\" at the bottom of therecord\n\nThe URL in question URL:\nhttps://example.com/";
1570+
MimeMessage message;
1571+
1572+
message = MimeMessage.Load (Path.Combine (TestHelper.ProjectDir, "TestData", "messages", "issue1130.txt"));
1573+
1574+
var body = message.GetTextBody (TextFormat.Flowed).Replace ("\r\n", "\n");
1575+
1576+
Assert.That (body, Is.EqualTo (TextBody), "The text bodies do not match for issue1130.txt.");
1577+
}
1578+
15651579
[Test]
15661580
public void TestNoBodyWithTextAttachment ()
15671581
{
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
From: MimeKit UnitTests <[email protected]>
2+
To: MimeKit UnitTests <[email protected]>
3+
Subject: Test of text body with format=flowed; delsp=yes
4+
Date: Thu, 09 Jan 2025 10:26:14 -0500
5+
MIME-Version: 1.0
6+
Content-Type: text/plain; format=flowed; delsp=yes; charset="iso-8859-1"
7+
Content-Transfer-Encoding: quoted-printable
8+
9+
We should have access, and apparently did a few months ago, but now there i=
10+
s=20
11+
a "You do not currently have access to this content." at the bottom of the=
12+
=20
13+
record
14+
15+
The URL in question URL:
16+
https://example.com/=20

0 commit comments

Comments
 (0)