Recursive AI

Decode format=flowed email text in C#

OneMail is a free, open-source email library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

Join soft line breaks in a decoded plain-text email body.

Terminal
dotnet add package RecursiveAI.OneMail

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using RecursiveAI.OneMail.Bodies;
var body = "Meet at \r\nnoon.\r\n";
Console.WriteLine(FormatFlowed.Decode(body));

Unzip the example, then dotnet run.

Joins the two lines into one sentence.

Text
Meet at noon.

The full program

The full program uses inline strings. Each \r\n is a line break. A space before it marks a soft break. The two > lines join at quote depth 1. The second doesn’t join the >> line because that line is at depth 2. A separate DelSp=yes example splits timezone across two lines.

C#
using RecursiveAI.OneMail.Bodies;
 
// The space before each soft break is written explicitly.
var body = "Meet at " + "\r\nnoon.\r\n" +
    "> Bring " + "\r\n> the map. " + "\r\n" +
    ">> At the station.\r\n";
var paragraphs = FormatFlowed.Parse(body);
if (!paragraphs.Select(p => p.QuoteDepth).SequenceEqual(new[] { 0, 1, 2 }))
    throw new InvalidDataException("Unexpected quote depths.");
 
foreach (var paragraph in paragraphs)
    Console.WriteLine($"Depth {paragraph.QuoteDepth}: {paragraph.Text.TrimEnd()}");
 
var delSp = FormatFlowed.Decode("time " + "\r\nzone.\r\n", delSp: true);
if (delSp.TrimEnd('\r', '\n') != "timezone.")
    throw new InvalidDataException("The DelSp break was not removed.");
Console.WriteLine($"DelSp=yes: {delSp.TrimEnd('\r', '\n')}");

dotnet run prints:

Text
Depth 0: Meet at noon.
Depth 1: Bring the map.
Depth 2: At the station.
DelSp=yes: timezone.

If you don’t know the body was labeled format=flowed, leave its line breaks alone; otherwise a trailing space can turn an intentional break into a join.

Variations

Decode DelSp=yes. Keep the using directive and replace the two lines below it with this example. The trailing space before the line break is removed.

C#
var body = "time " + "\r\nzone.\r\n";
Console.WriteLine(FormatFlowed.Decode(body, delSp: true));
Text
timezone.

Start from an EML file. Replace the snippet at the top with this program and use flowed.eml from the zip. Here is the sample (the quoted-printable =20 encodes a trailing space):

Text
From: Ada <ada@example.test>
Date: Thu, 19 Nov 2026 09:00:00 +0000
Subject: Meeting time
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed; DelSp=yes
Content-Transfer-Encoding: quoted-printable
 
time=20
zone.

TextBody selects the plain-text body. IsFormatFlowed and FlowedDelSp read that part’s Content-Type parameters. ReadText() decodes the transfer encoding and character set first. If the part isn’t marked as flowed, print the text without joining lines.

C#
using RecursiveAI.OneMail;
using RecursiveAI.OneMail.Bodies;
 
using var file = File.OpenRead("flowed.eml");
var part = Mail.Parse(file).TextBody;
if (part is null)
    throw new InvalidDataException("No plain-text body.");
 
var text = part.ReadText();
Console.WriteLine(part.IsFormatFlowed
    ? FormatFlowed.Decode(text, delSp: part.FlowedDelSp)
    : text);
Text
timezone.

Parse an EML file · Create an email reply and forward


The short answer

Once you have the decoded text/plain body, call FormatFlowed.Decode for a display string or FormatFlowed.Parse for separate paragraphs and quote depths. Use delSp: true only if the part’s Content-Type specifies DelSp=yes. The FormatFlowed calls take body text, not headers or an entire MIME message.

What is format=flowed in plain-text email?

format=flowed (RFC 3676) gives a mail reader a way to tell which line breaks it may move while displaying plain text. In the snippet at the top, the trailing space after Meet at marks a soft break. Joining the next line produces Meet at noon. instead of fixing the display to the sender’s wrap width. A fixed line ends its paragraph; a signature separator -- is fixed even though it ends with a space.

Leading > characters count as quote markers. In the full example the two lines starting with one > form one paragraph, and the two-marker line belongs to a different quote level. A change of depth blocks a join even if the preceding line has a soft break. OneMail also removes the extra leading space used to protect lines that would otherwise look like special syntax. The flowed-body docs describe both rules.

What does DelSp=yes do in a flowed email body?

It tells the decoder to delete the one trailing space that marks each soft break as it joins the lines. With DelSp=yes, time followed by zone. becomes timezone.. Without it, the space is kept, which is what you want when Meet at is followed by noon.. Don’t pick delSp by inspecting the English text; read the declared parameter for that part. An absent parameter uses the default behavior, which keeps the space.

How do I decode the plain-text body of an email in C#?

Separate MIME decoding from flowed decoding. A message can first require its transfer encoding and character set to be decoded before the result is a C# string. Then, if that plain-text part says format=flowed, pass the string to the snippet at the top. Trimming lines in between removes the trailing spaces that tell the decoder where to join.

Choose Decode if you want one plain-text string with quote markers. Choose Parse if you want to keep the quote level as a number, for example to indent quoted paragraphs in a reader. Neither method renders HTML or turns an HTML part into text.

All onemail recipes