-
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.
- Loading branch information
1 parent
310dfb5
commit 2ac4ba4
Showing
10 changed files
with
275 additions
and
274 deletions.
There are no files selected for viewing
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,3 +1,4 @@ | ||
bin/ | ||
obj/ | ||
.idea/ | ||
test-rules.json |
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,32 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace MailSort | ||
namespace MailSort; | ||
|
||
public static class Extensions | ||
{ | ||
public static class Extensions | ||
public static string? Capitalize(this string? s) | ||
{ | ||
public static string? Capitalize(this string? s) | ||
if (string.IsNullOrWhiteSpace(s)) | ||
{ | ||
if (string.IsNullOrWhiteSpace(s)) | ||
{ | ||
return s; | ||
} | ||
|
||
var charArray = s.ToCharArray(); | ||
if (!char.IsUpper(charArray[0])) | ||
{ | ||
charArray[0] = char.ToUpper(charArray[0]); | ||
} | ||
return s; | ||
} | ||
|
||
return new string(charArray); | ||
var charArray = s.ToCharArray(); | ||
if (!char.IsUpper(charArray[0])) | ||
{ | ||
charArray[0] = char.ToUpper(charArray[0]); | ||
} | ||
|
||
public static void ForEach<T>(this IEnumerable<T> items, Action<T> action) | ||
return new string(charArray); | ||
} | ||
|
||
public static void ForEach<T>(this IEnumerable<T> items, Action<T> action) | ||
{ | ||
foreach (var item in items) | ||
{ | ||
foreach (var item in items) | ||
{ | ||
action(item); | ||
} | ||
action(item); | ||
} | ||
} | ||
} |
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,28 +1,27 @@ | ||
using CommandLine; | ||
|
||
namespace MailSort | ||
namespace MailSort; | ||
|
||
public class MailSortConfig | ||
{ | ||
public class MailSortConfig | ||
{ | ||
[Option('h', "host", Required = true, HelpText = "The IMAP host to connect to.")] | ||
public string Host { get; set; } = null!; | ||
|
||
[Option('u', "username", Required = true, HelpText = "The username to connect via IMAP with.")] | ||
public string Username { get; set; } = null!; | ||
|
||
[Option('p', "password", Required = true, HelpText = "The password to authenticate to the IMAP server with.")] | ||
public string Password { get; set; } = null!; | ||
|
||
[Option('c', "config", Required = true, HelpText = "A JSON file containing the rules by which to sort emails into folders.")] | ||
public string ConfigFile { get; set; } = null!; | ||
|
||
[Option('s', "ssl", Required = false, Default = true, HelpText = "Whether or not to connect to the IMAP server securely.")] | ||
public bool UseSsl { get; set; } | ||
|
||
[Option('l', "log", Required = false, Default = "imap.log", HelpText = "The file to log the protocol log to.")] | ||
public string LogFile { get; set; } = null!; | ||
|
||
[Option("no-log", Required = false, Default = false, HelpText = "Do not create a log file with the protocol log.")] | ||
public bool DontLog { get; set; } | ||
} | ||
[Option('h', "host", Required = true, HelpText = "The IMAP host to connect to.")] | ||
public string Host { get; set; } = null!; | ||
|
||
[Option('u', "username", Required = true, HelpText = "The username to connect via IMAP with.")] | ||
public string Username { get; set; } = null!; | ||
|
||
[Option('p', "password", Required = true, HelpText = "The password to authenticate to the IMAP server with.")] | ||
public string Password { get; set; } = null!; | ||
|
||
[Option('c', "config", Required = true, HelpText = "A JSON file containing the rules by which to sort emails into folders.")] | ||
public string ConfigFile { get; set; } = null!; | ||
|
||
[Option("no-ssl", Required = false, Default = false, HelpText = "Do not connect to the IMAP server through port 993.")] | ||
public bool NoSsl { get; set; } | ||
|
||
[Option('l', "log", Required = false, Default = "imap.log", HelpText = "The file to log the protocol log to.")] | ||
public string LogFile { get; set; } = null!; | ||
|
||
[Option("no-log", Required = false, Default = false, HelpText = "Do not create a log file with the protocol log.")] | ||
public bool DontLog { get; set; } | ||
} |
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,49 +1,48 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MailSort | ||
namespace MailSort; | ||
|
||
public class MailSortRule | ||
{ | ||
public class MailSortRule | ||
{ | ||
[JsonPropertyName("id")] | ||
public string? Id { get; set; } | ||
|
||
[JsonPropertyName("haystack")] | ||
[JsonConverter(typeof(EnumCapitalizationConverter<Haystack>))] | ||
public Haystack Haystack { get; set; } | ||
[JsonPropertyName("id")] | ||
public string? Id { get; set; } | ||
|
||
[JsonPropertyName("haystack")] | ||
[JsonConverter(typeof(EnumCapitalizationConverter<Haystack>))] | ||
public Haystack Haystack { get; set; } | ||
|
||
[JsonPropertyName("needle")] | ||
public string Needle { get; set; } = null!; | ||
[JsonPropertyName("needle")] | ||
public string Needle { get; set; } = null!; | ||
|
||
[JsonPropertyName("matchingMethod")] | ||
[JsonConverter(typeof(EnumCapitalizationConverter<MatchingMethod>))] | ||
public MatchingMethod MatchingMethod { get; set; } | ||
[JsonPropertyName("matchingMethod")] | ||
[JsonConverter(typeof(EnumCapitalizationConverter<MatchingMethod>))] | ||
public MatchingMethod MatchingMethod { get; set; } | ||
|
||
[JsonPropertyName("targetFolder")] | ||
public string TargetFolder { get; set; } = null!; | ||
[JsonPropertyName("targetFolder")] | ||
public string TargetFolder { get; set; } = null!; | ||
|
||
[JsonPropertyName("combineWith")] | ||
public string? CombineWith { get; set; } | ||
[JsonPropertyName("combineWith")] | ||
public string? CombineWith { get; set; } | ||
|
||
[JsonPropertyName("combinationMethod")] | ||
[JsonConverter(typeof(EnumCapitalizationConverter<CombinationMethod>))] | ||
public CombinationMethod CombinationMethod { get; set; } | ||
|
||
[JsonPropertyName("isCombinationRule")] | ||
public bool IsCombinationRule { get; set; } | ||
} | ||
|
||
public enum MatchingMethod | ||
{ | ||
Contains, Equals, ContainsIgnoreCase, EqualsIgnoreCase | ||
} | ||
|
||
public enum CombinationMethod | ||
{ | ||
LogicalAnd, LogicalOr | ||
} | ||
|
||
public enum Haystack | ||
{ | ||
Subject, Body, Cc, Bcc, Sender, Recipients, RecipientsAndCc, RecipientsAndBcc, CcAndBcc, RecipientsAndCcAndBcc | ||
} | ||
[JsonPropertyName("combinationMethod")] | ||
[JsonConverter(typeof(EnumCapitalizationConverter<CombinationMethod>))] | ||
public CombinationMethod CombinationMethod { get; set; } | ||
|
||
[JsonPropertyName("isCombinationRule")] | ||
public bool IsCombinationRule { get; set; } | ||
} | ||
|
||
public enum MatchingMethod | ||
{ | ||
Contains, Equals, ContainsIgnoreCase, EqualsIgnoreCase | ||
} | ||
|
||
public enum CombinationMethod | ||
{ | ||
LogicalAnd, LogicalOr | ||
} | ||
|
||
public enum Haystack | ||
{ | ||
Subject, Body, Cc, Bcc, Sender, Recipients, RecipientsAndCc, RecipientsAndBcc, CcAndBcc, RecipientsAndCcAndBcc | ||
} |
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,34 +1,33 @@ | ||
using System; | ||
using System.Linq.Expressions; | ||
|
||
namespace MailSort | ||
namespace MailSort; | ||
|
||
public static class PredicateBuilder | ||
{ | ||
public static class PredicateBuilder | ||
public static Expression<Func<T, bool>> True<T>() | ||
{ | ||
public static Expression<Func<T, bool>> True<T>() | ||
{ | ||
return f => true; | ||
} | ||
return f => true; | ||
} | ||
|
||
public static Expression<Func<T, bool>> False<T>() | ||
{ | ||
return f => false; | ||
} | ||
public static Expression<Func<T, bool>> False<T>() | ||
{ | ||
return f => false; | ||
} | ||
|
||
public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1, | ||
Expression<Func<T, bool>> expr2) | ||
{ | ||
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters); | ||
return Expression.Lambda<Func<T, bool>> | ||
(Expression.OrElse(expr1.Body, invokedExpr), expr1.Parameters); | ||
} | ||
public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1, | ||
Expression<Func<T, bool>> expr2) | ||
{ | ||
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters); | ||
return Expression.Lambda<Func<T, bool>> | ||
(Expression.OrElse(expr1.Body, invokedExpr), expr1.Parameters); | ||
} | ||
|
||
public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expr1, | ||
Expression<Func<T, bool>> expr2) | ||
{ | ||
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters); | ||
return Expression.Lambda<Func<T, bool>> | ||
(Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters); | ||
} | ||
public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expr1, | ||
Expression<Func<T, bool>> expr2) | ||
{ | ||
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters); | ||
return Expression.Lambda<Func<T, bool>> | ||
(Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters); | ||
} | ||
} |
Oops, something went wrong.