Skip to content

Commit

Permalink
Fix SSL flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinAlpert committed Mar 27, 2023
1 parent 310dfb5 commit 2ac4ba4
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 274 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/post-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.200'
global-json-file: csharp/global.json

- name: Build project
run: dotnet build
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin/
obj/
.idea/
test-rules.json
27 changes: 13 additions & 14 deletions EnumCapitalizationConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace MailSort
namespace MailSort;

public class EnumCapitalizationConverter<TEnum> : JsonConverter<TEnum> where TEnum : struct, Enum
{
public class EnumCapitalizationConverter<TEnum> : JsonConverter<TEnum> where TEnum : struct, Enum
public override TEnum Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
public override TEnum Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
var s = reader.GetString();
if (Enum.TryParse(s?.Capitalize(), out TEnum @enum))
{
var s = reader.GetString();
if (Enum.TryParse(s?.Capitalize(), out TEnum @enum))
{
return @enum;
}

throw new Exception($"'{reader.GetString()}' is an incorrect value for '{typeToConvert.Name}'");
return @enum;
}

public override void Write(Utf8JsonWriter writer, TEnum value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
throw new Exception($"'{s}' is an incorrect value for '{typeToConvert.Name}'");
}

public override void Write(Utf8JsonWriter writer, TEnum value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}
37 changes: 18 additions & 19 deletions Extensions.cs
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);
}
}
}
8 changes: 4 additions & 4 deletions MailSort.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<Authors>Collin Alpert</Authors>
<Version>1.2.0</Version>
<Version>1.2.1</Version>
<RepositoryUrl>https://github.com/CollinAlpert/MailSort</RepositoryUrl>
<PackageLicenseUrl>https://github.com/CollinAlpert/MailSort/blob/master/LICENSE</PackageLicenseUrl>
<Copyright>Copyright © 2022 Collin Alpert</Copyright>
<Copyright>Copyright © 2023 Collin Alpert</Copyright>
<AssemblyName>MailSort</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="MailKit" Version="3.1.1" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="MailKit" Version="3.6.0" />
</ItemGroup>

</Project>
47 changes: 23 additions & 24 deletions MailSortConfig.cs
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; }
}
79 changes: 39 additions & 40 deletions MailSortRule.cs
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
}
47 changes: 23 additions & 24 deletions PredicateBuilder.cs
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);
}
}
Loading

0 comments on commit 2ac4ba4

Please sign in to comment.