Skip to content

Commit 2713c57

Browse files
committed
explicitly specify mime text encoding
1 parent 44ef8f0 commit 2713c57

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

TACTLib/Protocol/NGDP/RibbitClient.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public override string Get(string query)
3737
}
3838

3939
var message = MimeMessage.Load(stream);
40-
return message.GetTextBody(TextFormat.Text);
40+
return GetTextBody(message);
4141
}
4242

4343
public override async Task<string> GetAsync(string query, CancellationToken cancellationToken=default)
@@ -55,7 +55,21 @@ public override async Task<string> GetAsync(string query, CancellationToken canc
5555
}
5656

5757
var message = await MimeMessage.LoadAsync(stream, cancellationToken);
58-
return message.GetTextBody(TextFormat.Text);
58+
return GetTextBody(message);
59+
}
60+
61+
private static string GetTextBody(MimeMessage message)
62+
{
63+
// return message.GetTextBody(TextFormat.Text);
64+
// todo: using this (^) pulls in HtmlEntityDecoder which is about 500kb in size
65+
// mimekit needs an overload where the encoding can be specified instead of auto-detecting
66+
67+
var body = (MultipartAlternative)message.Body;
68+
if (!body.TryGetValue(TextFormat.Plain, out var textPart))
69+
{
70+
throw new InvalidDataException("ribbit message had no text part");
71+
}
72+
return textPart.GetText(Encoding.UTF8);
5973
}
6074

6175
public override string GetVersionsQuery(string product) => $"v1/products/{product}/versions";

0 commit comments

Comments
 (0)