Skip to content

Commit

Permalink
feat: add storage implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sascha-andres committed Aug 23, 2020
1 parent 1e8dd0e commit 5f93a57
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 28 deletions.
12 changes: 12 additions & 0 deletions .idea/.idea.MailDiary/.idea/contentModel.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 32 additions & 25 deletions .idea/.idea.MailDiary/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions MailDiary.Filesystem/FilesystemHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace MailDiary.Filesystem
{
using System.IO;
using Types.Configuration;
using Types.Mail;

public class FilesystemHandler
{
private readonly Configuration _configuration;

public FilesystemHandler( Configuration config )
{
_configuration = config;
}

public void Save( MailMessage message )
{
var subFolder = message.Data.Received.ToString( "yyyy/MM/dd" );
var completeFolder = Path.Combine( _configuration.MarkdownBasePath, subFolder );
if ( !Directory.Exists( completeFolder ) ) {
Directory.CreateDirectory( completeFolder );
}
var filename = message.Data.Received.ToString( "HHmmss" ) + ".md";
File.WriteAllText( Path.Combine( completeFolder, filename), message.Data.ToMarkdown() );
}
}
}
11 changes: 11 additions & 0 deletions MailDiary.Filesystem/MailDiary.Filesystem.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\MailDiary.Types\MailDiary.Types.csproj" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion MailDiary.ImapConnector/ImapConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public void Start()
_client.Inbox.Open( FolderAccess.ReadWrite );

foreach ( var folder in _client.Inbox.GetSubfolders( false ) ) {
Console.WriteLine(folder);
if ( null == _whiteListed && folder.Name == ProcessedFolderName )
_whiteListed = folder;
if ( null == _unwanted && folder.Name == UnwantedFolderName )
Expand Down
7 changes: 7 additions & 0 deletions MailDiary.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MailDiaryTypes.Tests", "Mai
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MailDiary.ImapConnector", "MailDiary.ImapConnector\MailDiary.ImapConnector.csproj", "{C2058027-1F91-4930-B721-858CC76E8A0F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MailDiary.Filesystem", "MailDiary.Filesystem\MailDiary.Filesystem.csproj", "{200F045B-A479-4A88-A6C0-41BC0A8A0434}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -34,10 +36,15 @@ Global
{C2058027-1F91-4930-B721-858CC76E8A0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2058027-1F91-4930-B721-858CC76E8A0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2058027-1F91-4930-B721-858CC76E8A0F}.Release|Any CPU.Build.0 = Release|Any CPU
{200F045B-A479-4A88-A6C0-41BC0A8A0434}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{200F045B-A479-4A88-A6C0-41BC0A8A0434}.Debug|Any CPU.Build.0 = Debug|Any CPU
{200F045B-A479-4A88-A6C0-41BC0A8A0434}.Release|Any CPU.ActiveCfg = Release|Any CPU
{200F045B-A479-4A88-A6C0-41BC0A8A0434}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{7DAD7264-A53D-4C91-B910-DB38242B62DD} = {E3AAC9C7-DEBF-4CEB-8659-159A64F9A5B8}
{B40B243F-5B31-47E9-AF6B-AF1C6F48EFFC} = {4CB84535-1933-4B89-A8B8-BEC0CED5C5B2}
{C2058027-1F91-4930-B721-858CC76E8A0F} = {E3AAC9C7-DEBF-4CEB-8659-159A64F9A5B8}
{200F045B-A479-4A88-A6C0-41BC0A8A0434} = {E3AAC9C7-DEBF-4CEB-8659-159A64F9A5B8}
EndGlobalSection
EndGlobal
10 changes: 8 additions & 2 deletions MailDiary/Commands/Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace MailDiary.Commands
{
using System;
using System.Threading;
using Filesystem;
using ImapConnector;
using Microsoft.Extensions.CommandLineUtils;
using Types.Configuration;
Expand All @@ -27,9 +27,15 @@ public static class Process
mailConnector.SetConfiguration( config.Mail );
mailConnector.Start();

var filesystemHandler = new FilesystemHandler( config );
foreach ( var mail in mailConnector.GetMails() ) {
if ( config.Processing.IsWhiteListed( mail.SenderMail ) ) {
Console.WriteLine( mail.ToString() );
try {
filesystemHandler.Save( mail );
mailConnector.Whitelisted( mail );
} catch ( Exception ex ) {
Console.WriteLine($"Error while writing mail: {ex.Message}");
}
} else {
mailConnector.Unwanted( mail );
}
Expand Down
1 change: 1 addition & 0 deletions MailDiary/MailDiary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MailDiary.Filesystem\MailDiary.Filesystem.csproj" />
<ProjectReference Include="..\MailDiary.ImapConnector\MailDiary.ImapConnector.csproj" />
<ProjectReference Include="..\MailDiary.Types\MailDiary.Types.csproj" />
</ItemGroup>
Expand Down

0 comments on commit 5f93a57

Please sign in to comment.