fix(trainer): handle weirdly-formatted emails
This commit is contained in:
parent
2ed31d5c95
commit
dd26a5738c
|
@ -11,7 +11,7 @@
|
|||
<PackageReference Include="ConsoleTables" Version="2.4.2"/>
|
||||
<PackageReference Include="CsvHelper" Version="27.1.1"/>
|
||||
<PackageReference Include="Microsoft.ML" Version="1.6.0"/>
|
||||
<PackageReference Include="MimeKitLite" Version="2.15.0"/>
|
||||
<PackageReference Include="MimeKitLite" Version="2.15.1"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -64,12 +64,18 @@ namespace NoSoliciting.Trainer {
|
|||
};
|
||||
foreach (var emlPath in Directory.GetFiles(path, "*.eml")) {
|
||||
var message = MimeMessage.Load(opts, new FileStream(emlPath, FileMode.Open));
|
||||
var json = message.TextBody.Split('\r', '\n').FirstOrDefault(line => line.StartsWith("JSON: "));
|
||||
if (json == null) {
|
||||
var lines = message.TextBody
|
||||
.Split('\r', '\n')
|
||||
.SkipWhile(line => !line.StartsWith("JSON: "))
|
||||
.Select(line => line.Replace("JSON: ", "").Replace(" ", "").Trim())
|
||||
.ToArray();
|
||||
if (lines.Length == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var jsonText = Encoding.UTF8.GetString(Convert.FromBase64String(json.Split(": ")[1]));
|
||||
var json = string.Join("", lines);
|
||||
|
||||
var jsonText = Encoding.UTF8.GetString(Convert.FromBase64String(json));
|
||||
var report = JsonConvert.DeserializeObject<ReportInput>(jsonText);
|
||||
var content = XivString.GetText(report.Content);
|
||||
var data = new Data(report.Type, content) {
|
||||
|
|
Loading…
Reference in New Issue