Skip to content

Commit 93866b1

Browse files
committed
Added protocol logger.
1 parent dd6ec83 commit 93866b1

4 files changed

Lines changed: 12 additions & 5 deletions

File tree

MailSort.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<TargetFramework>net5.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
<Authors>Collin Alpert</Authors>
8-
<Version>1.0.1</Version>
8+
<Version>1.0.2</Version>
99
<RepositoryUrl>https://github.com/CollinAlpert/MailSort</RepositoryUrl>
1010
<PackageLicenseUrl>https://github.com/CollinAlpert/MailSort/blob/master/LICENSE</PackageLicenseUrl>
1111
<Copyright>Copyright © 2021 Collin Alpert</Copyright>

MailSortConfig.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,11 @@ public class MailSortConfig
1818

1919
[Option('s', "ssl", Required = false, Default = true, HelpText = "Whether or not to connect to the IMAP server securely.")]
2020
public bool UseSsl { get; set; }
21+
22+
[Option('l', "log", Required = false, Default = "imap.log", HelpText = "The file to log the protocol log to.")]
23+
public string LogFile { get; set; } = null!;
24+
25+
[Option("no-log", Required = false, Default = false, HelpText = "Do not create a log file with the protocol log.")]
26+
public bool DontLog { get; set; }
2127
}
2228
}

Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ private static async Task RunAsync(MailSortConfig config)
5959
rules.Where(r => !r.IsCombinationRule)
6060
.Select(r => Tuple.Create(BuildPredicate(GetCombinedRules(r, new Queue<MailSortRule>(new[] { r }), rules)), r.TargetFolder)).ToList();
6161

62-
using var imapClient = new ImapClient();
62+
IProtocolLogger logger = config.DontLog ? new NullProtocolLogger() : new ProtocolLogger(config.LogFile);
63+
using var imapClient = new ImapClient(logger);
6364
await imapClient.ConnectAsync(config.Host, config.UseSsl ? EncryptedImapPort : ImapPort, config.UseSsl).ConfigureAwait(false);
6465
await imapClient.AuthenticateAsync(config.Username, config.Password).ConfigureAwait(false);
6566

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ Already have .NET 5 installed on the target machine? Even better. Just download
1919
This tool works by connecting to an IMAP server, going through all the messages in your inbox, checking if they match some criteria and if so, move that message to a folder.\
2020
The most common usage will probably be to run this tool via a cronjob at certain intervals.\
2121
Here's an example usage:\
22-
`./MailSort -h imap.gmail.com -u your@username.com -p very_secure -s -c /path/to/config/file.json`\
22+
`./MailSort -h imap.gmail.com -u your@username.com -p very_secure -c /path/to/config/file.json`\
2323
or for more clarity\
24-
`./MailSort --host imap.gmail.com --username your@username.com --password very_secure --ssl --config /path/to/config/file.json`\
25-
All of those flags arguments are mandatory, except for the -s/--ssl flag. It specifies whether or not to connect to the IMAP server using SSL (port 993) and is on by default.\
24+
`./MailSort --host imap.gmail.com --username your@username.com --password very_secure --config /path/to/config/file.json`\
25+
These are the mandatory arguments. There are a few more, run `./MailSort --help` to get an overview of all the options.
2626
Please make sure you have the correct credentials to authenticate with the IMAP server. For example, Gmail users will no be able to authenticate with their Google password, they will need to generate and supply an application-specific password.
2727

2828
The config file is a JSON file where you define your rules. Here's an example:

0 commit comments

Comments
 (0)