From 98f4e7a6d34ebe3402fd2d676797b5da55c3278b Mon Sep 17 00:00:00 2001 From: Norm MacLennan Date: Wed, 7 May 2014 09:38:59 -0700 Subject: [PATCH 1/4] beginning imap plugin --- src/NOCQ/ImapInput.cs | 37 +++++++++++++++++++++++++++++++++++++ src/NOCQ/NOCQ.csproj | 4 ++++ src/NOCQ/packages.config | 1 + 3 files changed, 42 insertions(+) create mode 100644 src/NOCQ/ImapInput.cs diff --git a/src/NOCQ/ImapInput.cs b/src/NOCQ/ImapInput.cs new file mode 100644 index 0000000..85595e7 --- /dev/null +++ b/src/NOCQ/ImapInput.cs @@ -0,0 +1,37 @@ +using System; + +namespace NOCQ +{ + public class ImapInput + { + private string loginName { get; set; } + private string password { get; set; } + private string server { get; set; } + private string folderPath { get; set; } + + public ImapInput (dynamic settings) + { + if (settings.Login == null + || settings.Password == null + || settings.Server == null + || settings.FolderPath == null) + throw new ArgumentException ("You are missing a required setting."); + + loginName = settings.Login; + password = settings.Password; + server = settings.Server; + folderPath = settings.FolderPath; + } + + public void Run() + { + + } + + public void Stop() + { + + } + } +} + diff --git a/src/NOCQ/NOCQ.csproj b/src/NOCQ/NOCQ.csproj index a39c206..24296e1 100644 --- a/src/NOCQ/NOCQ.csproj +++ b/src/NOCQ/NOCQ.csproj @@ -48,9 +48,13 @@ ..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll + + ..\..\packages\AE.Net.Mail.1.7.9.1\lib\net45\AE.Net.Mail.dll + + diff --git a/src/NOCQ/packages.config b/src/NOCQ/packages.config index 845e173..1da85cc 100644 --- a/src/NOCQ/packages.config +++ b/src/NOCQ/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file From a155a8c54f349017dd8dc5357a13140fb44b596b Mon Sep 17 00:00:00 2001 From: Norm MacLennan Date: Wed, 7 May 2014 10:12:16 -0700 Subject: [PATCH 2/4] early basic email plugin --- src/NOCQ/Extensability/Catalog.cs | 1 - src/NOCQ/ImapInput.cs | 37 ------------- src/NOCQ/NOCQ.csproj | 5 +- src/NOCQ/Plugins/Email/EmailSettings.cs | 16 ++++++ src/NOCQ/Plugins/Email/ImapInput.cs | 72 +++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 39 deletions(-) delete mode 100644 src/NOCQ/ImapInput.cs create mode 100644 src/NOCQ/Plugins/Email/EmailSettings.cs create mode 100644 src/NOCQ/Plugins/Email/ImapInput.cs diff --git a/src/NOCQ/Extensability/Catalog.cs b/src/NOCQ/Extensability/Catalog.cs index f58656e..dbbcecb 100644 --- a/src/NOCQ/Extensability/Catalog.cs +++ b/src/NOCQ/Extensability/Catalog.cs @@ -12,7 +12,6 @@ namespace NOCQ public Catalog() { Container.ComposeParts(this); - } } } diff --git a/src/NOCQ/ImapInput.cs b/src/NOCQ/ImapInput.cs deleted file mode 100644 index 85595e7..0000000 --- a/src/NOCQ/ImapInput.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; - -namespace NOCQ -{ - public class ImapInput - { - private string loginName { get; set; } - private string password { get; set; } - private string server { get; set; } - private string folderPath { get; set; } - - public ImapInput (dynamic settings) - { - if (settings.Login == null - || settings.Password == null - || settings.Server == null - || settings.FolderPath == null) - throw new ArgumentException ("You are missing a required setting."); - - loginName = settings.Login; - password = settings.Password; - server = settings.Server; - folderPath = settings.FolderPath; - } - - public void Run() - { - - } - - public void Stop() - { - - } - } -} - diff --git a/src/NOCQ/NOCQ.csproj b/src/NOCQ/NOCQ.csproj index 0d37b52..483a717 100644 --- a/src/NOCQ/NOCQ.csproj +++ b/src/NOCQ/NOCQ.csproj @@ -54,9 +54,10 @@ - + + @@ -65,5 +66,7 @@ + + diff --git a/src/NOCQ/Plugins/Email/EmailSettings.cs b/src/NOCQ/Plugins/Email/EmailSettings.cs new file mode 100644 index 0000000..5fdedac --- /dev/null +++ b/src/NOCQ/Plugins/Email/EmailSettings.cs @@ -0,0 +1,16 @@ +using System; + +namespace NOCQ.Plugins.Email +{ + public class EmailSettings + { + public string Username {get;set;} + public string Password {get;set;} + public string Host {get;set;} + public int Port {get;set;} + public string Folder {get;set;} + public bool IsSsl {get;set;} + public int Frequency { get; set; } + } +} + diff --git a/src/NOCQ/Plugins/Email/ImapInput.cs b/src/NOCQ/Plugins/Email/ImapInput.cs new file mode 100644 index 0000000..afb40f6 --- /dev/null +++ b/src/NOCQ/Plugins/Email/ImapInput.cs @@ -0,0 +1,72 @@ +using System; +using System.Timers; +using AE.Net.Mail; + +namespace NOCQ.Plugins.Email +{ + public class ImapInput + { + private string loginName { get; set; } + private string password { get; set; } + private string server { get; set; } + private string folderPath { get; set; } + private Timer timer { get; set; } + private int port { get; set; } + private bool ssl { get; set; } + private DateTime lastRun { get; set; } + + + public ImapInput (dynamic settings) + { + var sets = settings as EmailSettings; + + if (sets.Username == null + || sets.Password == null + || sets.Host == null + || sets.Folder == null + || sets.Frequency == null + || sets.Port == null + || sets.IsSsl == null) + throw new ArgumentException ("You are missing a required setting."); + + loginName = settings.Login; + password = settings.Password; + server = settings.Server; + folderPath = settings.FolderPath; + + timer = new Timer (settings.Frequency); + + timer.Elapsed += Execute (); + } + + + public void Execute() + { + using(var imap = new ImapClient(server, loginName, password, ImapClient.AuthMethods.Login, port, ssl)) { + var msgs = imap.SearchMessages( + SearchCondition.Undeleted().And( + SearchCondition.SentSince(new DateTime(2000, 1, 1)) + )); + + foreach (var msg in msgs) + { + var realMsg = msg.Value; + + var from = realMsg.From; + var body = realMsg.Body; + + } + } + } + + public void Run() + { + timer.Start (); + } + + public void Stop() + { + timer.Stop (); + } + } +} \ No newline at end of file From 25f19ff86a3c142d626fddaa991746eaaf7266e3 Mon Sep 17 00:00:00 2001 From: Norm MacLennan Date: Wed, 7 May 2014 10:25:48 -0700 Subject: [PATCH 3/4] more email rule stuff --- NOCQ.userprefs | 23 ++++++++++++++++++++++- src/NOCQ/NOCQ.csproj | 1 + src/NOCQ/Plugins/Email/EmailSettings.cs | 1 + src/NOCQ/Plugins/Email/ImapInput.cs | 4 +++- src/NOCQ/Plugins/Email/ParseRule.cs | 18 ++++++++++++++++++ 5 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/NOCQ/Plugins/Email/ParseRule.cs diff --git a/NOCQ.userprefs b/NOCQ.userprefs index 8a063db..32bfcce 100644 --- a/NOCQ.userprefs +++ b/NOCQ.userprefs @@ -1,6 +1,27 @@  - + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/NOCQ/NOCQ.csproj b/src/NOCQ/NOCQ.csproj index b11c6e6..4f37790 100644 --- a/src/NOCQ/NOCQ.csproj +++ b/src/NOCQ/NOCQ.csproj @@ -60,6 +60,7 @@ + diff --git a/src/NOCQ/Plugins/Email/EmailSettings.cs b/src/NOCQ/Plugins/Email/EmailSettings.cs index 5fdedac..bdfdb0e 100644 --- a/src/NOCQ/Plugins/Email/EmailSettings.cs +++ b/src/NOCQ/Plugins/Email/EmailSettings.cs @@ -11,6 +11,7 @@ namespace NOCQ.Plugins.Email public string Folder {get;set;} public bool IsSsl {get;set;} public int Frequency { get; set; } + public IEnumerable ParseRules {get;set;} } } diff --git a/src/NOCQ/Plugins/Email/ImapInput.cs b/src/NOCQ/Plugins/Email/ImapInput.cs index afb40f6..67159e2 100644 --- a/src/NOCQ/Plugins/Email/ImapInput.cs +++ b/src/NOCQ/Plugins/Email/ImapInput.cs @@ -14,7 +14,7 @@ namespace NOCQ.Plugins.Email private int port { get; set; } private bool ssl { get; set; } private DateTime lastRun { get; set; } - + private IEnumerable parseRules{ get; set; } public ImapInput (dynamic settings) { @@ -29,6 +29,8 @@ namespace NOCQ.Plugins.Email || sets.IsSsl == null) throw new ArgumentException ("You are missing a required setting."); + parseRules = sets.ParseRules.Where (x => x.Enabled); + loginName = settings.Login; password = settings.Password; server = settings.Server; diff --git a/src/NOCQ/Plugins/Email/ParseRule.cs b/src/NOCQ/Plugins/Email/ParseRule.cs new file mode 100644 index 0000000..a67b10f --- /dev/null +++ b/src/NOCQ/Plugins/Email/ParseRule.cs @@ -0,0 +1,18 @@ +using System; + +namespace NOCQ.Plugins.Email +{ + public class ParseRule + { + public string Name { get; set; } + public bool Enabled { get; set; } + public string From {get;set;} + public string Source {get;set;} + public string System {get;set;} + public string Service {get;set;} + public string Data {get;set;} + public string Runbook { get; set;} + public string Severity {get;set;} + } +} + From a251f8f0b31644a0359ca60ea7ec64845e0658df Mon Sep 17 00:00:00 2001 From: Norm MacLennan Date: Wed, 7 May 2014 10:28:09 -0700 Subject: [PATCH 4/4] merge drop --- src/NOCQ/NOCQ.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/NOCQ/NOCQ.csproj b/src/NOCQ/NOCQ.csproj index 066f973..d0dd59a 100644 --- a/src/NOCQ/NOCQ.csproj +++ b/src/NOCQ/NOCQ.csproj @@ -50,6 +50,7 @@ ..\..\packages\AE.Net.Mail.1.7.9.1\lib\net45\AE.Net.Mail.dll + ..\..\packages\csredis.1.4.7.1\lib\net40\csredis.dll