ok

alphons <alphons@heijden.com> 23 Feb 2025, 16:12
90fdccd8edee33cb18cfc309c87df9a7b7b40652
3 files changed
  • Eml2Pdf.sln
  • Eml2PdfWinApp/Eml2PdfWinApp.csproj
  • Eml2PdfWinApp/Form1.cs
diff --git a/Eml2Pdf.sln b/Eml2Pdf.sln
index f92487d..2dc3afb 100644
--- a/Eml2Pdf.sln
+++ b/Eml2Pdf.sln
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35728.132
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MimePart2Pdf", "Eml2Pdf\MimePart2Pdf.csproj", "{D93A802A-2709-4781-B536-700ABCA34A1D}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MimePart2Pdf", "MimePart2Pdf\MimePart2Pdf.csproj", "{D93A802A-2709-4781-B536-700ABCA34A1D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eml2PdfWinApp", "Eml2PdfWinApp\Eml2PdfWinApp.csproj", "{3B67B712-8408-4F5C-B40E-66F255A61EC7}"
EndProject
diff --git a/Eml2PdfWinApp/Eml2PdfWinApp.csproj b/Eml2PdfWinApp/Eml2PdfWinApp.csproj
index 7a5c14f..efccbff 100644
--- a/Eml2PdfWinApp/Eml2PdfWinApp.csproj
+++ b/Eml2PdfWinApp/Eml2PdfWinApp.csproj
@@ -10,7 +10,7 @@
</PropertyGroup>
<ItemGroup>
- <ProjectReference Include="..\Eml2Pdf\MimePart2Pdf.csproj" />
+ <ProjectReference Include="..\MimePart2Pdf\MimePart2Pdf.csproj" />
</ItemGroup>
<ItemGroup>
diff --git a/Eml2PdfWinApp/Form1.cs b/Eml2PdfWinApp/Form1.cs
index c8bf357..4366586 100644
--- a/Eml2PdfWinApp/Form1.cs
+++ b/Eml2PdfWinApp/Form1.cs
@@ -3,82 +3,81 @@ using MimePart2Pdf;
using System.Diagnostics;
using System.Text;
-namespace Eml2PdfWinApp
+namespace Eml2PdfWinApp;
+
+public partial class Form1 : Form
{
- public partial class Form1 : Form
+ public Form1()
{
- public Form1()
- {
- InitializeComponent();
- }
-
- private async void Button1_Click(object sender, EventArgs e)
- {
- this.button1.Enabled = false;
- this.textBox1.Enabled = false;
- this.textBox2.Enabled = false;
+ InitializeComponent();
+ }
- Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
+ private async void Button1_Click(object sender, EventArgs e)
+ {
+ this.button1.Enabled = false;
+ this.textBox1.Enabled = false;
+ this.textBox2.Enabled = false;
- foreach (var emlPath in Directory.GetFiles(this.textBox2.Text, "*.eml"))
- {
- var name = Path.GetFileNameWithoutExtension(emlPath);
+ Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
- var pdfPath = Path.Combine(this.textBox3.Text, $"{name}.pdf");
+ foreach (var emlPath in Directory.GetFiles(this.textBox2.Text, "*.eml"))
+ {
+ var name = Path.GetFileNameWithoutExtension(emlPath);
- var email = await MimePart.ReadEmlAsync(emlPath);
+ var pdfPath = Path.Combine(this.textBox3.Text, $"{name}.pdf");
- PdfHelper.CreatePdf(email, pdfPath);
+ var email = await MimePart.ReadEmlAsync(emlPath);
- }
+ PdfHelper.CreatePdf(email, pdfPath);
- this.textBox1.Enabled = true;
- this.textBox2.Enabled = true;
- this.button1.Enabled = true;
}
- static async Task SaveMailAttachementsAsync(string OutputDir, MimePart part)
- {
- var contentType = part["Content-Type"];
+ this.textBox1.Enabled = true;
+ this.textBox2.Enabled = true;
+ this.button1.Enabled = true;
+ }
- if (part["Content-Disposition"].Contains("attachment"))
+ static async Task SaveMailAttachementsAsync(string OutputDir, MimePart part)
+ {
+ var contentType = part["Content-Type"];
+
+ if (part["Content-Disposition"].Contains("attachment"))
+ {
+ if (contentType.Contains("message/rfc822"))
{
- if (contentType.Contains("message/rfc822"))
+ if (DateTime.TryParse(part.Parts[0]["Date"], out DateTime dtm))
{
- if (DateTime.TryParse(part.Parts[0]["Date"], out DateTime dtm))
- {
- var outputPath = Path.Combine(OutputDir, $"{dtm:yyyyMMdd-HHmmss}.eml");
-
- await part.SaveAsync(outputPath, dtm);
- }
- else
- {
- Debug.WriteLine("No Date found in message/rfc822 attachement");
- }
- }
- }
+ var outputPath = Path.Combine(OutputDir, $"{dtm:yyyyMMdd-HHmmss}.eml");
- foreach (var subpart in part.Parts)
- {
- await SaveMailAttachementsAsync(OutputDir, subpart);
+ await part.SaveAsync(outputPath, dtm);
+ }
+ else
+ {
+ Debug.WriteLine("No Date found in message/rfc822 attachement");
+ }
}
}
-
- private async void Button2_Click(object sender, EventArgs e)
+ foreach (var subpart in part.Parts)
{
- this.button2.Enabled = false;
+ await SaveMailAttachementsAsync(OutputDir, subpart);
+ }
+ }
- Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
- foreach (var emlPath in Directory.GetFiles(this.textBox1.Text, "*.eml"))
- {
- var email = await MimePart.ReadEmlAsync(emlPath);
+ private async void Button2_Click(object sender, EventArgs e)
+ {
+ this.button2.Enabled = false;
- await SaveMailAttachementsAsync(this.textBox2.Text, email);
- }
+ Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
- this.button2.Enabled = true;
+ foreach (var emlPath in Directory.GetFiles(this.textBox1.Text, "*.eml"))
+ {
+ var email = await MimePart.ReadEmlAsync(emlPath);
+
+ await SaveMailAttachementsAsync(this.textBox2.Text, email);
}
+
+ this.button2.Enabled = true;
}
}