microsoft/TypeAgent

Public

mirrored from https://github.com/microsoft/TypeAgentAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
749865d4258b084443a56bffcfa490ef2cdbe80d

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

dotnet/email/BodyParser.cs

48lines · modecode

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