Eml2Pdf / EmlFastDecoder / Program.cs
Code · 57 lines · 1222 bytes
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
51
52
53
54
55
56
57using Eml2MimePart;

using System.Diagnostics;

static async Task ShowPartsAsync(int Depth, MimePart part)
{
	var contentType = part["Content-Type"];

	if (contentType != string.Empty)
	{
		for (var i = 0; i < Depth; i++)
			Debug.Write('\t');
		Debug.WriteLine(contentType);
	}

	if (part["Content-Disposition"].Contains("attachment"))
	{
		if (contentType.Contains("message/rfc822"))
		{
			if (DateTime.TryParse(part.Parts[0]["Date"], out DateTime dtm))
			{
				//await part.SaveAsync($"{dtm:yyyyMMdd-HHmmss}.eml", dtm);
			}
		}
	}


	if (contentType.StartsWith("text/html"))
	{
		//await File.WriteAllTextAsync("a.html", part.TextContent, Encoding.GetEncoding( part.CharSet));
	}

	if (contentType.StartsWith("image/"))
	{
		//await File.WriteAllBytesAsync("a.png", part.BinContent);
	}

	Depth++;
	foreach (var subpart in part.Parts)
	{
		await ShowPartsAsync(Depth, subpart);
	}
}

var sw = Stopwatch.StartNew();

foreach (var path in Directory.EnumerateFiles(@"C:\Users\alphons\Downloads\Rentes2", "*.eml"))
{

	var email = await MimePart.ReadEmlAsync(@"input\jun-jul 2024.eml");

	await ShowPartsAsync(0, email);

	Debug.WriteLine(sw.ElapsedMilliseconds + "mS");
}
Console.Write("enter");
Console.ReadLine();