Hermod
A cross-platform, modular and fully GDPR-compliant email archival solution!
Loading...
Searching...
No Matches
Hermod.EmailImport.EmailImporter Class Reference

EmailImporter plugin. More...

Inheritance diagram for Hermod.EmailImport.EmailImporter:
Hermod.PluginFramework.Plugin Hermod.PluginFramework.IPlugin

Public Member Functions

 EmailImporter ()
 
override void OnConfigChanged (ConfigChangedEventArgs e)
 Method that is called when an application-wide configuration has been modified.
Parameters
eThe ConfigChangedEventArgs that are generated when a config was modified.

 
override void OnConfigLoaded ()
 Method that is called when the application-wide configurations have been loaded.
 
override void OnLoad (IPluginDelegator pluginDelegator)
 Method that is called once the plugin has been loaded. This may be used for pre-init purposes.
Parameters
pluginDelegatorThe delegator allocated to this plugin.

 
override void OnStart ()
 Method that is called once Hermod has completed its startup procedures and is ready to run.
 
override void OnStop ()
 Method that is called when Hermod is shutting down.
 
- Public Member Functions inherited from Hermod.PluginFramework.Plugin
 Plugin (string pluginName, Version pluginVersion, params ICommand[] commands)
 Specialised constructor; allows inheriting classes to set their values immediately.
 
abstract void OnLoad (IPluginDelegator pluginDelegator)
 Method that is called once the plugin has been loaded. This may be used for pre-init purposes.
Parameters
pluginDelegatorThe delegator allocated to this plugin.

 
abstract void OnStart ()
 Method that is called once Hermod has completed its startup procedures and is ready to run.
 
abstract void OnStop ()
 Method that is called when Hermod is shutting down.
 
abstract void OnConfigChanged (ConfigChangedEventArgs e)
 Method that is called when an application-wide configuration has been modified.
Parameters
eThe ConfigChangedEventArgs that are generated when a config was modified.

 
abstract void OnConfigLoaded ()
 Method that is called when the application-wide configurations have been loaded.
 
void OnLoad (IPluginDelegator pluginDelegator)
 Method that is called once the plugin has been loaded. This may be used for pre-init purposes.
 
void OnStart ()
 Method that is called once Hermod has completed its startup procedures and is ready to run.
 
void OnStop ()
 Method that is called when Hermod is shutting down.
 
void OnConfigChanged (ConfigChangedEventArgs e)
 Method that is called when an application-wide configuration has been modified.
 
void OnConfigLoaded ()
 Method that is called when the application-wide configurations have been loaded.
 

Private Member Functions

void PluginDelegator_MessageReceived (object? sender, MessageReceivedEventArgs e)
 Event handler which is called when a message is received on a topic this plugin subscribed.
 
void HandleAddDomainMessageReceived (string topic, object? message)
 
void DoWork ()
 
ICommandResult Handle_GetDomains (params string[] args)
 
ICommandResult Handle_GetSingleDomain (params string[] args)
 
ICommandResult Handle_AddDomain (params string[] args)
 
ICommandResult Handle_RemoveDomain (params string[] args)
 
ICommandResult Handle_GetUsers (params string[] args)
 
ICommandResult Handle_GetUser (params string[] args)
 
ICommandResult Handle_AddUser (params string[] args)
 
ICommandResult Handle_RemoveUser (params string[] args)
 

Private Attributes

readonly string[] m_subscribeTopics
 The topic EmailImport subscribes to when a user is to be removed from a domain.
 
volatile bool m_keepThreadAlive = false
 
DatabaseConnectorm_dbConnector
 
IPluginDelegatorm_pluginDelegator = null
 
Thread? m_importThread = null
 

Static Private Attributes

const string GetDomainTopicAllSuffix = "all"
 
const string AddDomainTopic = "/hermod/domain/add"
 
const string GetDomainTopic = "/hermod/domain/get/+"
 The topic EmailImport subscribes to add a new domain.
 
const string RemoveDomainTopic = "/hermod/domain/remove/+"
 The topic EmailImport subscribes when another plugin requests a domain.
 
const string GetDomainResponseTopic = "/hermod/domain/response"
 The topic EmailImport subscribes to when a domain shall be removed.
 
const string GetDomainUserTopic = "/hermod/user/get"
 The topic EmailImport publishes to when a topic was requested.
 
const string AddDomainUserTopic = "/hermod/user/add/+"
 The topic EmailImport subscribes to when a user is requested.
 
const string RemoveDomainUserTopic = "/hermod/user/remove"
 The topic EmailImport subscribes to when a user is to be added to a domain.
 

Additional Inherited Members

- Properties inherited from Hermod.PluginFramework.Plugin
Version PluginVersion [get, protected set]
 Gets the version of the plugin.
 
string PluginName [get, protected set]
 Gets the name of the plugin.
 
List< ICommandPluginCommands [get, protected set]
 A list of all commands this plugin provides.
 
- Properties inherited from Hermod.PluginFramework.IPlugin
Version PluginVersion [get]
 Gets the version of the plugin.
 
string PluginName [get]
 Gets the name of the plugin.
 
List< ICommandPluginCommands [get]
 A list of all commands this plugin provides.
 

Detailed Description

EmailImporter plugin.

Definition at line 7 of file EmailImport.MessageHandling.cs.

Constructor & Destructor Documentation

◆ EmailImporter()

Hermod.EmailImport.EmailImporter.EmailImporter ( )
inline

Definition at line 43 of file EmailImporter.cs.

43 : base(nameof(EmailImporter), new Version(0, 0, 1)) {
44 PluginCommands = new List<ICommand> {
45 new TerminalCommand(
46 "get-domains", "Gets a list of all known domains",
47 "This command retrieves a list of all domains currently\n" +
48 "known to the Hermod EmailImporter.\n" +
49 "Usage: get-domains [tld [tld]] # only with these TLDs",
51 ),
52 new TerminalCommand(
53 "get-domain", "Gets information about a single domain",
54 "This command retrieves a single domain and information about it.\n" +
55 "Usage: get-domain <domain-name>",
57 ),
58 new TerminalCommand(
59 "add-domain", "Adds a new domain to the system",
60 "This command allows a new domain to be added to Hermod.\n" +
61 "Usage: add-domain <domain-name [domain-name [...]]> # domain-name is expected as tld.domain[.subdomain]",
63 ),
64 new TerminalCommand(
65 "remove-domain", "Removes one or more domains from the system",
66 "This command removes one or more domains from Hermod.\n" +
67 "Usage: remove-domain <domain-name [domain-name [...]]> # domain-name is expected as tld.domain[.subdomain]",
69 ),
70 new TerminalCommand(
71 "get-users", "Retrieves a list of all users in a domain",
72 "This command retrieves a list of all users allocated to a domain.\n" +
73 "Usage: get-users [domain-name] # domain-name is expected as tld.domain[.subdomain]",
75 ),
76 new TerminalCommand(
77 "get-user", "Gets detailled information about a single user",
78 "This command allows retrievel of detailled information,\n" +
79 "such as email address, password hash, salt and account type\n" +
80 "in a single domain.\n" +
81 "Usage: get-user <domain> <user>",
83 ),
84 new TerminalCommand(
85 "add-user", "Adds a single user to a domain",
86 "This command adds a single user to a single domain,\n" +
87 "provided info: user name, password, password salt, and account type.\n" +
88 "Usage: add-user <domain> <user> <password> <account type>\n" +
89 "Note: this is the only time Hermod will know of the user's cleartext password!",
91 ),
92 new TerminalCommand(
93 "remove-user", "Removes a single user from a domain",
94 "This command allows a single user to be removed from a domain.\n" +
95 "!! WARNING !! This process is irreversible!\n" +
96 "Usage: remove-user <domain> <user>",
98 )
99 };
100 }
ICommandResult Handle_AddUser(params string[] args)
ICommandResult Handle_GetDomains(params string[] args)
ICommandResult Handle_AddDomain(params string[] args)
ICommandResult Handle_RemoveDomain(params string[] args)
ICommandResult Handle_GetUsers(params string[] args)
ICommandResult Handle_GetSingleDomain(params string[] args)
ICommandResult Handle_GetUser(params string[] args)
ICommandResult Handle_RemoveUser(params string[] args)
List< ICommand > PluginCommands
A list of all commands this plugin provides.
Definition: Plugin.cs:34

References Hermod.EmailImport.EmailImporter.Handle_AddDomain(), Hermod.EmailImport.EmailImporter.Handle_AddUser(), Hermod.EmailImport.EmailImporter.Handle_GetDomains(), Hermod.EmailImport.EmailImporter.Handle_GetSingleDomain(), Hermod.EmailImport.EmailImporter.Handle_GetUser(), Hermod.EmailImport.EmailImporter.Handle_GetUsers(), Hermod.EmailImport.EmailImporter.Handle_RemoveDomain(), Hermod.EmailImport.EmailImporter.Handle_RemoveUser(), and Hermod.PluginFramework.Plugin.PluginCommands.

Member Function Documentation

◆ DoWork()

void Hermod.EmailImport.EmailImporter.DoWork ( )
inlineprivate

Definition at line 7 of file EmailImporter.BusinessLogic.cs.

7 {
8
9 }

Referenced by Hermod.EmailImport.EmailImporter.OnStart().

◆ Handle_AddDomain()

ICommandResult Hermod.EmailImport.EmailImporter.Handle_AddDomain ( params string[]  args)
inlineprivate

Definition at line 17 of file EmailImporter.CommandHandling.cs.

17 {
18 return new CommandErrorResult("This command is not yet implemented. Sorry");
19 }

Referenced by Hermod.EmailImport.EmailImporter.EmailImporter().

◆ Handle_AddUser()

ICommandResult Hermod.EmailImport.EmailImporter.Handle_AddUser ( params string[]  args)
inlineprivate

Definition at line 33 of file EmailImporter.CommandHandling.cs.

33 {
34 return new CommandErrorResult("This command is not yet implemented. Sorry");
35 }

Referenced by Hermod.EmailImport.EmailImporter.EmailImporter().

◆ Handle_GetDomains()

ICommandResult Hermod.EmailImport.EmailImporter.Handle_GetDomains ( params string[]  args)
inlineprivate

Definition at line 9 of file EmailImporter.CommandHandling.cs.

9 {
10 return new CommandErrorResult("This command is not yet implemented. Sorry");
11 }

Referenced by Hermod.EmailImport.EmailImporter.EmailImporter().

◆ Handle_GetSingleDomain()

ICommandResult Hermod.EmailImport.EmailImporter.Handle_GetSingleDomain ( params string[]  args)
inlineprivate

Definition at line 13 of file EmailImporter.CommandHandling.cs.

13 {
14 return new CommandErrorResult("This command is not yet implemented. Sorry");
15 }

Referenced by Hermod.EmailImport.EmailImporter.EmailImporter().

◆ Handle_GetUser()

ICommandResult Hermod.EmailImport.EmailImporter.Handle_GetUser ( params string[]  args)
inlineprivate

Definition at line 29 of file EmailImporter.CommandHandling.cs.

29 {
30 return new CommandErrorResult("This command is not yet implemented. Sorry");
31 }

Referenced by Hermod.EmailImport.EmailImporter.EmailImporter().

◆ Handle_GetUsers()

ICommandResult Hermod.EmailImport.EmailImporter.Handle_GetUsers ( params string[]  args)
inlineprivate

Definition at line 25 of file EmailImporter.CommandHandling.cs.

25 {
26 return new CommandErrorResult("This command is not yet implemented. Sorry");
27 }

Referenced by Hermod.EmailImport.EmailImporter.EmailImporter().

◆ Handle_RemoveDomain()

ICommandResult Hermod.EmailImport.EmailImporter.Handle_RemoveDomain ( params string[]  args)
inlineprivate

Definition at line 21 of file EmailImporter.CommandHandling.cs.

21 {
22 return new CommandErrorResult("This command is not yet implemented. Sorry");
23 }

Referenced by Hermod.EmailImport.EmailImporter.EmailImporter().

◆ Handle_RemoveUser()

ICommandResult Hermod.EmailImport.EmailImporter.Handle_RemoveUser ( params string[]  args)
inlineprivate

Definition at line 37 of file EmailImporter.CommandHandling.cs.

37 {
38 return new CommandErrorResult("This command is not yet implemented. Sorry");
39 }

Referenced by Hermod.EmailImport.EmailImporter.EmailImporter().

◆ HandleAddDomainMessageReceived()

void Hermod.EmailImport.EmailImporter.HandleAddDomainMessageReceived ( string  topic,
object?  message 
)
inlineprivate

◆ OnConfigChanged()

override void Hermod.EmailImport.EmailImporter.OnConfigChanged ( ConfigChangedEventArgs  e)
inlinevirtual

Method that is called when an application-wide configuration has been modified.

Parameters
eThe ConfigChangedEventArgs that are generated when a config was modified.

Implements Hermod.PluginFramework.Plugin.

Definition at line 102 of file EmailImporter.cs.

102{ }

◆ OnConfigLoaded()

override void Hermod.EmailImport.EmailImporter.OnConfigLoaded ( )
inlinevirtual

Method that is called when the application-wide configurations have been loaded.

Implements Hermod.PluginFramework.Plugin.

Definition at line 104 of file EmailImporter.cs.

104{ }

◆ OnLoad()

override void Hermod.EmailImport.EmailImporter.OnLoad ( IPluginDelegator  pluginDelegator)
inlinevirtual

Method that is called once the plugin has been loaded. This may be used for pre-init purposes.

Parameters
pluginDelegatorThe delegator allocated to this plugin.

Implements Hermod.PluginFramework.Plugin.

Definition at line 106 of file EmailImporter.cs.

106 {
107 m_pluginDelegator = pluginDelegator;
108
109 if (m_pluginDelegator.GetApplicationConfig<bool>("Accounts.UseDatabase")) {
110 // dynamic dbInfo = m_pluginDelegator.GetApplicationConfig<object>("Accounts.DatabaseInfo");
111 // m_dbConnector = new MySqlDatabaseConnector(
112 // dbInfo.Host,
113 // dbInfo.DatabaseUser,
114 // dbInfo.DatabasePass,
115 // dbInfo.DatabaseName,
116 // pluginDelegator
117 // );
118 throw new Exception("MySqlDatabaseConnector is not usable in this version!");
119 } else if (m_pluginDelegator.GetApplicationConfig<bool>("Accounts.UseJsonFile")) {
120 var filePath = m_pluginDelegator.GetApplicationConfig<string?>("Accounts.JsonFileInfo.FilePath");
121 if (filePath is null) {
122 filePath = AppInfo.GetLocalHermodDirectory().GetSubFile(".accounts.json").FullName;
123 }
124
125 byte[] encKey = null;
126 byte[] initVec = null;
127
128 void GetEncryptionData(ref byte[] encKey, ref byte[] initVec) {
129 var tmpKey = m_pluginDelegator?.GetApplicationConfig<string?>("Accounts.EncryptionKey");
130 if (string.IsNullOrEmpty(tmpKey)) {
131 m_pluginDelegator?.Information("Found invalid encryption keys! Generating new encryption data...");
132 JsonDatabaseConnector.GenerateNewAesKey(out encKey, out initVec);
133 return;
134 }
135 Base64.DecodeFromUtf8(Encoding.UTF8.GetBytes(tmpKey), encKey, out _, out _);
136
137 tmpKey = m_pluginDelegator?.GetApplicationConfig<string?>("Accounts.EncryptionInitVec");
138 if (string.IsNullOrEmpty(tmpKey)) {
139 m_pluginDelegator?.Information("Found invalid encryption keys! Generating new encryption data...");
140 JsonDatabaseConnector.GenerateNewAesKey(out encKey, out initVec);
141 return;
142 }
143
144 Base64.DecodeFromUtf8(Encoding.UTF8.GetBytes(tmpKey), initVec, out _, out _);
145 }
146
147 GetEncryptionData(ref encKey, ref initVec);
148 m_dbConnector = new JsonDatabaseConnector(
149 new FileInfo(filePath),
150 encKey, initVec
151 );
152 } else {
153 throw new InvalidDataSourceException();
154 }
155
156 m_pluginDelegator.Debug("Subscribing all topics...");
157 pluginDelegator.SubscribeTopics(m_subscribeTopics);
158
159 m_pluginDelegator.Information("Email Importer has loaded!");
160 }
IPluginDelegator? m_pluginDelegator
DatabaseConnector? m_dbConnector
readonly string[] m_subscribeTopics
The topic EmailImport subscribes to when a user is to be removed from a domain.
void Debug(string? msg)
Logs a debug message to the logger.
void Information(string? msg)
Logs an information message to the logger.

References Hermod.Core.Delegation.IPluginDelegator.Debug(), Hermod.EmailImport.Data.JsonDatabaseConnector.GenerateNewAesKey(), Hermod.Core.AppInfo.GetLocalHermodDirectory(), Hermod.Core.Delegation.IPluginDelegator.Information(), Hermod.EmailImport.EmailImporter.m_dbConnector, Hermod.EmailImport.EmailImporter.m_pluginDelegator, Hermod.EmailImport.EmailImporter.m_subscribeTopics, and Hermod.Core.Delegation.IPluginDelegator.SubscribeTopics().

◆ OnStart()

override void Hermod.EmailImport.EmailImporter.OnStart ( )
inlinevirtual

Method that is called once Hermod has completed its startup procedures and is ready to run.

Implements Hermod.PluginFramework.Plugin.

Definition at line 162 of file EmailImporter.cs.

References Hermod.EmailImport.EmailImporter.DoWork(), Hermod.EmailImport.EmailImporter.m_importThread, and Hermod.EmailImport.EmailImporter.m_keepThreadAlive.

◆ OnStop()

override void Hermod.EmailImport.EmailImporter.OnStop ( )
inlinevirtual

Method that is called when Hermod is shutting down.

Implements Hermod.PluginFramework.Plugin.

Definition at line 168 of file EmailImporter.cs.

168 {
169 m_pluginDelegator?.Information("Stopping worker threads...");
170 m_keepThreadAlive = false;
171 }

References Hermod.Core.Delegation.IPluginDelegator.Information(), Hermod.EmailImport.EmailImporter.m_keepThreadAlive, and Hermod.EmailImport.EmailImporter.m_pluginDelegator.

◆ PluginDelegator_MessageReceived()

void Hermod.EmailImport.EmailImporter.PluginDelegator_MessageReceived ( object?  sender,
MessageReceivedEventArgs  e 
)
inlineprivate

Event handler which is called when a message is received on a topic this plugin subscribed.

Parameters
senderThe IPluginDelegator instance which raised the event.
eThe message.

Definition at line 15 of file EmailImport.MessageHandling.cs.

15 {
16 switch (e.Topic) {
17 case AddDomainTopic:
18 HandleAddDomainMessageReceived(e.Topic, e.Message);
19 break;
20 }
21 }
void HandleAddDomainMessageReceived(string topic, object? message)

References Hermod.EmailImport.EmailImporter.AddDomainTopic, Hermod.EmailImport.EmailImporter.HandleAddDomainMessageReceived(), Hermod.Core.Delegation.MessageReceivedEventArgs.Message, and Hermod.Core.Delegation.MessageReceivedEventArgs.Topic.

Member Data Documentation

◆ AddDomainTopic

const string Hermod.EmailImport.EmailImporter.AddDomainTopic = "/hermod/domain/add"
staticprivate

◆ AddDomainUserTopic

const string Hermod.EmailImport.EmailImporter.AddDomainUserTopic = "/hermod/user/add/+"
staticprivate

The topic EmailImport subscribes to when a user is requested.

Definition at line 30 of file EmailImporter.cs.

◆ GetDomainResponseTopic

const string Hermod.EmailImport.EmailImporter.GetDomainResponseTopic = "/hermod/domain/response"
staticprivate

The topic EmailImport subscribes to when a domain shall be removed.

Definition at line 28 of file EmailImporter.cs.

◆ GetDomainTopic

const string Hermod.EmailImport.EmailImporter.GetDomainTopic = "/hermod/domain/get/+"
staticprivate

The topic EmailImport subscribes to add a new domain.

Definition at line 26 of file EmailImporter.cs.

◆ GetDomainTopicAllSuffix

const string Hermod.EmailImport.EmailImporter.GetDomainTopicAllSuffix = "all"
staticprivate

Definition at line 24 of file EmailImporter.cs.

◆ GetDomainUserTopic

const string Hermod.EmailImport.EmailImporter.GetDomainUserTopic = "/hermod/user/get"
staticprivate

The topic EmailImport publishes to when a topic was requested.

Definition at line 29 of file EmailImporter.cs.

◆ m_dbConnector

DatabaseConnector? Hermod.EmailImport.EmailImporter.m_dbConnector
private

Definition at line 39 of file EmailImporter.cs.

Referenced by Hermod.EmailImport.EmailImporter.OnLoad().

◆ m_importThread

Thread? Hermod.EmailImport.EmailImporter.m_importThread = null
private

Definition at line 41 of file EmailImporter.cs.

Referenced by Hermod.EmailImport.EmailImporter.OnStart().

◆ m_keepThreadAlive

volatile bool Hermod.EmailImport.EmailImporter.m_keepThreadAlive = false
private

◆ m_pluginDelegator

IPluginDelegator? Hermod.EmailImport.EmailImporter.m_pluginDelegator = null
private

◆ m_subscribeTopics

readonly string [] Hermod.EmailImport.EmailImporter.m_subscribeTopics
private
Initial value:
= {
}
const string GetDomainTopic
The topic EmailImport subscribes to add a new domain.
const string GetDomainUserTopic
The topic EmailImport publishes to when a topic was requested.
const string RemoveDomainUserTopic
The topic EmailImport subscribes to when a user is to be added to a domain.
const string RemoveDomainTopic
The topic EmailImport subscribes when another plugin requests a domain.
const string AddDomainUserTopic
The topic EmailImport subscribes to when a user is requested.

The topic EmailImport subscribes to when a user is to be removed from a domain.

Definition at line 33 of file EmailImporter.cs.

Referenced by Hermod.EmailImport.EmailImporter.OnLoad().

◆ RemoveDomainTopic

const string Hermod.EmailImport.EmailImporter.RemoveDomainTopic = "/hermod/domain/remove/+"
staticprivate

The topic EmailImport subscribes when another plugin requests a domain.

Definition at line 27 of file EmailImporter.cs.

◆ RemoveDomainUserTopic

const string Hermod.EmailImport.EmailImporter.RemoveDomainUserTopic = "/hermod/user/remove"
staticprivate

The topic EmailImport subscribes to when a user is to be added to a domain.

Definition at line 31 of file EmailImporter.cs.


The documentation for this class was generated from the following files: