-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathBodyParser.cs
50 lines (43 loc) · 1.14 KB
/
BodyParser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
namespace TypeAgent;
public class BodyParser
{
public static readonly BodyParser Default = new BodyParser();
List<string> _delimiters;
public BodyParser()
{
_delimiters = new List<string>
{
"From:",
"Sent:",
"To:",
"Subject:",
"-----Original Message-----",
"----- Forwarded by",
"________________________________________"
};
}
public List<string> Delimiters => _delimiters;
public string GetLatest(string body)
{
if (string.IsNullOrEmpty(body))
{
return string.Empty;
}
int firstDelimiterAt = -1;
foreach (var delimiter in _delimiters)
{
int index = body.IndexOf(delimiter);
if (index >= 0 && (firstDelimiterAt == -1 || index < firstDelimiterAt))
{
firstDelimiterAt = index;
}
}
if (firstDelimiterAt >= 0)
{
return body[..firstDelimiterAt].Trim();
}
return body;
}
}