Skip to content

Commit

Permalink
Added comments; refactored code.
Browse files Browse the repository at this point in the history
  • Loading branch information
vector-man committed Dec 29, 2023
1 parent a66a813 commit 04cb0db
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
4 changes: 3 additions & 1 deletion PhishyScanConsole/Email.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace PhishyScanConsole;

/// <summary>
/// Email structure.
/// </summary>
public struct Email
{
public string Address;
Expand Down
12 changes: 12 additions & 0 deletions PhishyScanConsole/EmailSecurityLevel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
// See https://aka.ms/new-console-template for more information

/// <summary>
/// Email security level.
/// </summary>
public enum EmailSecurityLevel
{
/// <summary>
/// Passed indicates that the email passed all checks for phishing.
/// </summary>
Passed,
/// <summary>
/// Warn indicates that the email passed all checks for known phishing, but some of the submitted data was suspicious.
/// </summary>
Warn,
/// <summary>
/// Failed indicates that the email failed at least one check for known phishing.
/// </summary>
Failed
}
3 changes: 3 additions & 0 deletions PhishyScanConsole/EmailSecurityResult.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// See https://aka.ms/new-console-template for more information

/// <summary>
/// Email security level.
/// </summary>
public class EmailSecurityResult
{
public EmailSecurityLevel Level;
Expand Down
3 changes: 3 additions & 0 deletions PhishyScanConsole/Models/CommandLineArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using CommandLine;
namespace PhishyScanConsole.Models
{
/// <summary>
/// Command line arguments configuration settings for the PhishyScanConsole application.
/// </summary>
public class CommandLineArguments: IConfiguration
{

Expand Down
3 changes: 3 additions & 0 deletions PhishyScanConsole/Models/IConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using Config.Net;
namespace PhishyScanConsole.Models
{
/// <summary>
/// Interface for configuration settings
/// </summary>
public interface IConfiguration
{
[Option(Alias = "host.verbose")]
Expand Down
11 changes: 8 additions & 3 deletions PhishyScanConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,28 @@
using Flurl.Http;
using System.Configuration;

// Scan endpoint for the PhishyScan API.
const string PhishyScanEndpoint = "/scan";
// Default configuration file name.
const string DefaultConfigurationFile = "config.ini";
// Maximum content length to scan (messages longer than this will be truncated).
const int MaximumContentLength = 4097;
Parser.Default.ParseArguments<CommandLineArguments>(args).WithParsed(ops =>
{
try
{
// Load configuration from file.
var configurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DefaultConfigurationFile);
if (File.Exists(configurationFile))
{
var configuration = new ConfigurationBuilder<IConfiguration>()
.UseIniFile(configurationFile)
.Build();
// If verbose is enabled, print the configuration file name.
if ((bool)configuration?.Verbose) Console.WriteLine($"Configuration loaded from file: {Path.GetFileName(configurationFile)}");
// Parse command line arguments. If a command line argument is specified, it will override a configuration file value.
Parser.Default.ParseArguments<CommandLineArguments>(args)
.WithParsed(o =>
{
Expand All @@ -51,6 +55,7 @@
catch (Exception ex)
{
Console.WriteLine($"Error loading configuration file: {ex.Message}");
return;
}
if (ops?.Host == null)
Expand Down

0 comments on commit 04cb0db

Please sign in to comment.