-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add renderer to be able to customize the output
Closes #3
- Loading branch information
1 parent
3b19fe7
commit eb24b70
Showing
12 changed files
with
223 additions
and
87 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Scriban" Version="2.1.4" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\MailDiary.Types\MailDiary.Types.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
namespace MailDiary.Renderer | ||
{ | ||
using System; | ||
using System.ComponentModel; | ||
using Scriban; | ||
using Types.Configuration; | ||
using Types.Mail; | ||
|
||
/// <summary> | ||
/// Used to create a text (markdown) representation of a message | ||
/// </summary> | ||
public class Renderer | ||
{ | ||
private readonly Template _template; | ||
private readonly Configuration _configuration; | ||
|
||
/// <summary> | ||
/// Constructor used to set things up | ||
/// </summary> | ||
/// <param name="configuration"></param> | ||
public Renderer( Configuration configuration ) | ||
{ | ||
_configuration = configuration; | ||
_template = Template.Parse( configuration.Processing.Template ); | ||
} | ||
|
||
/// <summary> | ||
/// Render one message | ||
/// </summary> | ||
/// <param name="message">Generate string from content of this message</param> | ||
/// <returns>Rendered text</returns> | ||
/// <exception cref="InvalidEnumArgumentException"></exception> | ||
public string Render( MailMessage message ) | ||
{ | ||
if ( null == message ) throw new InvalidEnumArgumentException( "message may not be null" ); | ||
if ( string.IsNullOrEmpty( message.Data.Subject ) ) | ||
throw new InvalidOperationException( "Subject may not be empty" ); | ||
if ( string.IsNullOrEmpty( message.Data.Content ) ) | ||
throw new InvalidOperationException( "Content may not be empty" ); | ||
return _template.Render( new { | ||
message.Data.Subject, | ||
message.Data.Content, | ||
Received = | ||
message.Data.Received.ToString( _configuration.Processing.DateTimeFormat ) | ||
} ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,42 @@ | ||
# MailDiary | ||
|
||
is a small tool to allow writing a diary by sending mails to another mail. The programs reads out the mails | ||
and creates chunks of Markdown files. Those can then in turn be concatenated with mdmerge or shell magic. | ||
and creates chunks of Markdown files. Those can then in turn be concatenated with mdmerge or shell magic. | ||
|
||
## Configuration example | ||
|
||
--- | ||
|
||
markdown-base-path: "c:/tools/maildiary" | ||
|
||
mail: | ||
server: "imap.some-server.de" | ||
port: 993 | ||
user: super-secret-user | ||
password: even-more-secret-password | ||
|
||
processing: | ||
whitelisted-senders: | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
date-time-format: "dd.MM.yyyy HH:mm:ss" | ||
template: | | ||
## ({{received}}) {{subject}} | ||
{{content}} | ||
|
||
The configuration sample will have MailDiary to connect to imap.some-server.de using IMAP and iterate over all mails. Foreach mail that was sent from one of the whitelisted senders it will generate a markdown file using the template provided (defaulting to the above one). | ||
|
||
As a templating language this tool uses [scriban](https://github.com/lunet-io/scriban). For informatino about built in functions and how to use it read the documentation of scriban. | ||
|
||
The markdown file will be named after hour, minute and second of the time when the mail was received and stored in a subfolder `year/month/day` in `markdown-base-path`. | ||
|
||
Concatenation of generated markdown files is by design not part of this tool. | ||
|
||
## History | ||
|
||
|Version|Description| | ||
|---|---| | ||
|1.0.0.0|Initial version| |